|
@@ -0,0 +1,225 @@
|
|
|
|
+package ui.view;
|
|
|
|
+
|
|
|
|
+import javax.swing.JSplitPane;
|
|
|
|
+import javax.swing.JScrollPane;
|
|
|
|
+import javax.swing.JPanel;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+
|
|
|
|
+import javax.swing.GroupLayout;
|
|
|
|
+import javax.swing.GroupLayout.Alignment;
|
|
|
|
+import javax.swing.JLabel;
|
|
|
|
+import javax.swing.LayoutStyle.ComponentPlacement;
|
|
|
|
+import javax.swing.event.TreeSelectionEvent;
|
|
|
|
+import javax.swing.event.TreeSelectionListener;
|
|
|
|
+import javax.swing.tree.DefaultMutableTreeNode;
|
|
|
|
+import javax.swing.tree.DefaultTreeModel;
|
|
|
|
+import javax.swing.tree.MutableTreeNode;
|
|
|
|
+import javax.swing.tree.TreeNode;
|
|
|
|
+
|
|
|
|
+import classes.HolonObject;
|
|
|
|
+import interfaces.GraphListener;
|
|
|
|
+
|
|
|
|
+import javax.swing.JTextField;
|
|
|
|
+import javax.swing.JComboBox;
|
|
|
|
+import javax.swing.JButton;
|
|
|
|
+import javax.swing.JTree;
|
|
|
|
+
|
|
|
|
+public class splitPane extends JSplitPane implements GraphListener {
|
|
|
|
+ private JTextField graphNrTxtField;
|
|
|
|
+ private JTextField redField;
|
|
|
|
+ private JTextField blueField;
|
|
|
|
+ private JTextField greenField;
|
|
|
|
+ private JTree objectTree;
|
|
|
|
+ private DefaultTreeModel treeModel;
|
|
|
|
+ DefaultMutableTreeNode objectsNode;
|
|
|
|
+ DefaultMutableTreeNode wholeHolon;
|
|
|
|
+ JLabel showObjectlbl;
|
|
|
|
+ JLabel showPropertylbl;
|
|
|
|
+ public splitPane() {
|
|
|
|
+
|
|
|
|
+ JPanel panel = new JPanel();
|
|
|
|
+ setLeftComponent(panel);
|
|
|
|
+
|
|
|
|
+ JScrollPane treeScrollPane = new JScrollPane();
|
|
|
|
+
|
|
|
|
+ JLabel lblObject = new JLabel("Object(s):");
|
|
|
|
+
|
|
|
|
+ showObjectlbl = new JLabel("...");
|
|
|
|
+
|
|
|
|
+ JLabel lblProperty = new JLabel("Property:");
|
|
|
|
+
|
|
|
|
+ showPropertylbl = new JLabel("...");
|
|
|
|
+
|
|
|
|
+ JLabel lblGraph = new JLabel("Graph:");
|
|
|
|
+
|
|
|
|
+ graphNrTxtField = new JTextField();
|
|
|
|
+ graphNrTxtField.setColumns(10);
|
|
|
|
+
|
|
|
|
+ JLabel lblColor = new JLabel("Color:");
|
|
|
|
+
|
|
|
|
+ JComboBox colorComboBox = new JComboBox();
|
|
|
|
+
|
|
|
|
+ redField = new JTextField();
|
|
|
|
+ redField.setColumns(10);
|
|
|
|
+
|
|
|
|
+ blueField = new JTextField();
|
|
|
|
+ blueField.setColumns(10);
|
|
|
|
+
|
|
|
|
+ greenField = new JTextField();
|
|
|
|
+ greenField.setColumns(10);
|
|
|
|
+
|
|
|
|
+ JLabel lblR = new JLabel("R:");
|
|
|
|
+
|
|
|
|
+ JLabel lblB = new JLabel("B:");
|
|
|
|
+
|
|
|
|
+ JLabel lblG = new JLabel("G:");
|
|
|
|
+
|
|
|
|
+ JButton btnAdd = new JButton("Add");
|
|
|
|
+ GroupLayout gl_panel = new GroupLayout(panel);
|
|
|
|
+ gl_panel.setHorizontalGroup(
|
|
|
|
+ gl_panel.createParallelGroup(Alignment.LEADING)
|
|
|
|
+ .addGroup(gl_panel.createSequentialGroup()
|
|
|
|
+ .addContainerGap()
|
|
|
|
+ .addGroup(gl_panel.createParallelGroup(Alignment.TRAILING, false)
|
|
|
|
+ .addComponent(treeScrollPane, Alignment.LEADING)
|
|
|
|
+ .addGroup(Alignment.LEADING, gl_panel.createSequentialGroup()
|
|
|
|
+ .addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
|
|
|
|
+ .addComponent(lblGraph)
|
|
|
|
+ .addComponent(lblObject)
|
|
|
|
+ .addComponent(lblProperty)
|
|
|
|
+ .addComponent(lblColor)
|
|
|
|
+ .addGroup(gl_panel.createSequentialGroup()
|
|
|
|
+ .addComponent(lblR)
|
|
|
|
+ .addPreferredGap(ComponentPlacement.RELATED)
|
|
|
|
+ .addComponent(redField, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)))
|
|
|
|
+ .addPreferredGap(ComponentPlacement.RELATED)
|
|
|
|
+ .addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false)
|
|
|
|
+ .addComponent(showObjectlbl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
|
|
+ .addComponent(showPropertylbl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
|
|
+ .addComponent(graphNrTxtField)
|
|
|
|
+ .addGroup(gl_panel.createParallelGroup(Alignment.TRAILING, false)
|
|
|
|
+ .addComponent(colorComboBox, Alignment.LEADING, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
|
|
+ .addGroup(Alignment.LEADING, gl_panel.createSequentialGroup()
|
|
|
|
+ .addComponent(lblB)
|
|
|
|
+ .addPreferredGap(ComponentPlacement.RELATED)
|
|
|
|
+ .addComponent(blueField, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)
|
|
|
|
+ .addPreferredGap(ComponentPlacement.RELATED)
|
|
|
|
+ .addComponent(lblG)
|
|
|
|
+ .addPreferredGap(ComponentPlacement.RELATED)
|
|
|
|
+ .addComponent(greenField, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
|
|
|
|
+ .addComponent(btnAdd, Alignment.LEADING)))))
|
|
|
|
+ .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
|
|
|
+ );
|
|
|
|
+ gl_panel.setVerticalGroup(
|
|
|
|
+ gl_panel.createParallelGroup(Alignment.LEADING)
|
|
|
|
+ .addGroup(gl_panel.createSequentialGroup()
|
|
|
|
+ .addContainerGap()
|
|
|
|
+ .addComponent(treeScrollPane, GroupLayout.PREFERRED_SIZE, 153, GroupLayout.PREFERRED_SIZE)
|
|
|
|
+ .addGap(27)
|
|
|
|
+ .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
|
|
|
|
+ .addComponent(lblObject, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
|
|
|
|
+ .addComponent(showObjectlbl))
|
|
|
|
+ .addPreferredGap(ComponentPlacement.RELATED)
|
|
|
|
+ .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
|
|
|
|
+ .addComponent(lblProperty)
|
|
|
|
+ .addComponent(showPropertylbl))
|
|
|
|
+ .addPreferredGap(ComponentPlacement.RELATED)
|
|
|
|
+ .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
|
|
|
|
+ .addComponent(lblGraph)
|
|
|
|
+ .addComponent(graphNrTxtField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
|
|
|
+ .addPreferredGap(ComponentPlacement.RELATED)
|
|
|
|
+ .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
|
|
|
|
+ .addComponent(lblColor)
|
|
|
|
+ .addComponent(colorComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
|
|
|
+ .addGap(18)
|
|
|
|
+ .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
|
|
|
|
+ .addComponent(lblR)
|
|
|
|
+ .addComponent(redField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
|
|
|
|
+ .addComponent(lblB)
|
|
|
|
+ .addComponent(blueField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
|
|
|
|
+ .addComponent(lblG)
|
|
|
|
+ .addComponent(greenField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
|
|
|
+ .addPreferredGap(ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
|
|
|
|
+ .addComponent(btnAdd)
|
|
|
|
+ .addContainerGap())
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ objectTree = new JTree();
|
|
|
|
+ treeModel = new DefaultTreeModel(null);
|
|
|
|
+ DefaultMutableTreeNode root = new DefaultMutableTreeNode("Statistics");
|
|
|
|
+ wholeHolon = new DefaultMutableTreeNode("whole Holon");
|
|
|
|
+ wholeHolon.add(new DefaultMutableTreeNode("total Production"));
|
|
|
|
+ wholeHolon.add(new DefaultMutableTreeNode("total Consumption"));
|
|
|
|
+ wholeHolon.add(new DefaultMutableTreeNode("Percentage of Supplied Objects"));
|
|
|
|
+ wholeHolon.add(new DefaultMutableTreeNode("Percentage of not Supplied Objects"));
|
|
|
|
+ wholeHolon.add(new DefaultMutableTreeNode("Percentage of partially Supplied Objects"));
|
|
|
|
+
|
|
|
|
+ objectsNode = new DefaultMutableTreeNode("Objects");
|
|
|
|
+ DefaultMutableTreeNode defaultNode = new DefaultMutableTreeNode("empty");
|
|
|
|
+
|
|
|
|
+ objectsNode.add(defaultNode);
|
|
|
|
+ treeModel.setRoot(root);
|
|
|
|
+ root.add(wholeHolon);
|
|
|
|
+ root.add(objectsNode);
|
|
|
|
+ objectTree.setModel(treeModel);
|
|
|
|
+
|
|
|
|
+ treeScrollPane.setViewportView(objectTree);
|
|
|
|
+
|
|
|
|
+ objectTree.addTreeSelectionListener(new TreeSelectionListener(){
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void valueChanged(TreeSelectionEvent e) {
|
|
|
|
+ showObjectlbl.setText("...");
|
|
|
|
+ showPropertylbl.setText("...");
|
|
|
|
+ DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)objectTree.getLastSelectedPathComponent();
|
|
|
|
+ if(selectedNode == null){
|
|
|
|
+ return;
|
|
|
|
+ }else{
|
|
|
|
+ if(selectedNode.getLevel() == 1){
|
|
|
|
+ showObjectlbl.setText(selectedNode.toString());
|
|
|
|
+ }
|
|
|
|
+ if(selectedNode.getLevel() == 2){
|
|
|
|
+ if(((DefaultMutableTreeNode)selectedNode.getParent()).toString().equals("whole Holon")){
|
|
|
|
+ showPropertylbl.setText(selectedNode.toString());
|
|
|
|
+ showObjectlbl.setText(selectedNode.getParent().toString());
|
|
|
|
+ }else{
|
|
|
|
+ showObjectlbl.setText(selectedNode.toString());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(selectedNode.getLevel() == 3){
|
|
|
|
+ showObjectlbl.setText(((DefaultMutableTreeNode)selectedNode.getParent()).toString());
|
|
|
|
+ showPropertylbl.setText(selectedNode.toString());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+ panel.setLayout(gl_panel);
|
|
|
|
+
|
|
|
|
+ JScrollPane graphScrollPane = new JScrollPane();
|
|
|
|
+ setRightComponent(graphScrollPane);
|
|
|
|
+ }
|
|
|
|
+ @Override
|
|
|
|
+ public void repaintGraph() {
|
|
|
|
+ // TODO Auto-generated method stub
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ @Override
|
|
|
|
+ public void addTrackedObject(ArrayList<HolonObject> hlList) {
|
|
|
|
+ if(hlList.size() > 0 && hlList != null){
|
|
|
|
+ objectsNode.removeAllChildren();
|
|
|
|
+ for(HolonObject hO : hlList){
|
|
|
|
+ DefaultMutableTreeNode tmp = new DefaultMutableTreeNode(hO.getName() + " " + hO.getID());
|
|
|
|
+ tmp.add(new DefaultMutableTreeNode("total Production"));
|
|
|
|
+ tmp.add(new DefaultMutableTreeNode("total Consumption"));
|
|
|
|
+ tmp.add(new DefaultMutableTreeNode("number of activated Elements"));
|
|
|
|
+ objectsNode.add(tmp);
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ objectsNode.add(new DefaultMutableTreeNode("empty"));
|
|
|
|
+ }
|
|
|
|
+ objectTree.repaint();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|