123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816 |
- package ui.view;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.ItemEvent;
- import java.awt.event.ItemListener;
- import java.util.ArrayList;
- import java.util.Hashtable;
- import java.util.Random;
- import javax.swing.Box;
- import javax.swing.BoxLayout;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JLabel;
- import javax.swing.JMenuItem;
- import javax.swing.JPanel;
- import javax.swing.JPopupMenu;
- import javax.swing.JScrollPane;
- import javax.swing.JSplitPane;
- import javax.swing.JTextField;
- import javax.swing.JTree;
- import javax.swing.border.EmptyBorder;
- import javax.swing.border.LineBorder;
- import javax.swing.event.DocumentEvent;
- import javax.swing.event.DocumentListener;
- import javax.swing.event.TreeSelectionEvent;
- import javax.swing.event.TreeSelectionListener;
- import javax.swing.tree.DefaultMutableTreeNode;
- import javax.swing.tree.DefaultTreeModel;
- import DataSets.GraphDataSet;
- import DataSets.PropertyDataSet;
- import classes.AbstractCpsObject;
- import classes.CpsUpperNode;
- import classes.HolonObject;
- import classes.HolonSwitch;
- import classes.TrackedDataSet;
- import interfaces.GraphListener;
- import ui.controller.Control;
- public class StatisticPanel extends JSplitPane implements GraphListener {
- public static final String MAIN_GRID = "Main Grid";
- public static final String HOLON = "Holons";
-
- // Property Strings
- public static final String TOT_PROD_HOLON = "total Holon Production";
- public static final String TOT_CONS_HOLON = "total Holon Consumption";
- public static final String SUPPLIED_OBJ = "Percentage of supplied Objects";
- public static final String NOT_SUPPLIED_OBJ = "Percentage of not supplied Objects";
- public static final String PART_SUPPLIED_OBJ = "Percentage of partially supplied Objects";
- public static final String NR_SUBNETS = "Nr. of Subnets";
- public static final String NR_CLOSED_SWITCHES = "Nr. of closed Switches";
- public static final String AVG_OBJ_IN_HOLONS = "Average amount of Objects in Holons";
- public static final String AVG_ELEM_IN_HOLONS = "Average amount of Elements in Holons";
- public static final String AVG_PRODS_IN_HOLONS ="Average amount of Producers in Holons";
- public static final String AVG_CONS_ENERGY_IN_HOLONS = "Average consumed Energy";
- public static final String AVG_WASTED_ENERGY_HOLONS = "Average wasted Energy";
- public static final String NR_BROKEN_EDGES = "Amount of broken Edges";
- public static final String PROD_CONS_RATIO = "Producer/Consumer Ratio";
- public static final String AVG_CLOSED_SW_HOLON = "Average of closed Switches per Holon";
- public static final String AVG_ACTIVE_ELEMENTS_HOLON = "Average of active Elements per Holon";
- public static final String AVG_INACTIVE_ELEMENTS_HOLON = "Average of inactive Elements per Holon";
- public static final String AVG_PRODUCTION_HOLON = "Average Production per Holon";
-
- public static final String TOT_PROD_OBJ = "total Production";
- public static final String TOT_CONS_OBJ = "total Consumption";
- public static final String NR_ACTIVE_ELEMENTS = "active Elements";
-
- public static final String SW_ACTIVE = "active";
-
- public static final String TOT_PROD_GRID = "total Grid Production";
- public static final String TOT_CONS_GRID = "total Grid Consumption";
- private DefaultTreeModel treeModel;
- private DefaultMutableTreeNode objectsNode;
- private DefaultMutableTreeNode mainGrid;
- private DefaultMutableTreeNode holonNode;
- private DefaultMutableTreeNode switchesNode;
- private DefaultMutableTreeNode groupNode;
-
- private Hashtable<String, GraphDataSet> objectHashtable;
- private Hashtable<String, StatisticGraphPanel> graphHashtable;
- private Hashtable<String, PropertyDataSet> holonHashtable;
- private Hashtable<String, Integer> propValTable;
-
- //contains information about a selected property
- private PropertyDataSet currentProperty = new PropertyDataSet();
- private Control controller;
- private JPanel graphPanel;
-
- //WindowBuilder Components
- private JTree objectTree;
- private JTextField graphNrTxtField;
- private JTextField redField;
- private JTextField greenField;
- private JTextField blueField;
- private JPanel colorPanel;
- private JComboBox colorComboBox;
- private JLabel showObjectlbl;
- private JLabel showPropertylbl;
- private JButton btnAdd;
-
- public StatisticPanel(Control cont) {
- setBorder(null);
- setMaximumSize(new Dimension(0, 0));
- setPreferredSize(new Dimension(0, 0));
- setMinimumSize(new Dimension(0, 0));
- this.setDividerLocation(180);
- setContinuousLayout(true);
- this.controller = cont;
- objectHashtable = new Hashtable<String, GraphDataSet>();
- graphHashtable = new Hashtable<String, StatisticGraphPanel>();
- controller.setGraphTable(graphHashtable);
-
- holonHashtable = new Hashtable<String, PropertyDataSet>();
- holonHashtable.put(TOT_PROD_HOLON, new PropertyDataSet());
- holonHashtable.put(TOT_CONS_HOLON, new PropertyDataSet());
- holonHashtable.put(SUPPLIED_OBJ, new PropertyDataSet());
- holonHashtable.put(NOT_SUPPLIED_OBJ, new PropertyDataSet());
- holonHashtable.put(PART_SUPPLIED_OBJ, new PropertyDataSet());
- holonHashtable.put(NR_SUBNETS, new PropertyDataSet());
- holonHashtable.put(NR_CLOSED_SWITCHES, new PropertyDataSet());
- holonHashtable.put(AVG_OBJ_IN_HOLONS, new PropertyDataSet());
- holonHashtable.put(AVG_ELEM_IN_HOLONS, new PropertyDataSet());
- holonHashtable.put(AVG_PRODS_IN_HOLONS, new PropertyDataSet());
- holonHashtable.put(AVG_CONS_ENERGY_IN_HOLONS, new PropertyDataSet());
- holonHashtable.put(AVG_WASTED_ENERGY_HOLONS, new PropertyDataSet());
- holonHashtable.put(NR_BROKEN_EDGES, new PropertyDataSet());
- holonHashtable.put(PROD_CONS_RATIO, new PropertyDataSet());
- holonHashtable.put(AVG_CLOSED_SW_HOLON, new PropertyDataSet());
- holonHashtable.put(AVG_ACTIVE_ELEMENTS_HOLON, new PropertyDataSet());
- holonHashtable.put(AVG_INACTIVE_ELEMENTS_HOLON, new PropertyDataSet());
- holonHashtable.put(AVG_PRODUCTION_HOLON, new PropertyDataSet());
-
- //propValTable associates the Strings to the numbers
- propValTable = new Hashtable<String, Integer>();
- propValTable.put(TOT_PROD_OBJ, TrackedDataSet.PRODUCTION);
- propValTable.put(TOT_CONS_OBJ, TrackedDataSet.CONSUMPTION);
- propValTable.put(NR_ACTIVE_ELEMENTS, TrackedDataSet.ACTIVATED_ELEMENTS);
- propValTable.put(SW_ACTIVE, TrackedDataSet.ON_OFF);
- propValTable.put(TOT_PROD_HOLON, TrackedDataSet.TOTAL_PRODUCTION);
- propValTable.put(TOT_CONS_HOLON, TrackedDataSet.TOTAL_CONSUMPTION);
- propValTable.put(SUPPLIED_OBJ, TrackedDataSet.PERCENT_SUPPLIED);
- propValTable.put(NOT_SUPPLIED_OBJ, TrackedDataSet.PERCENT_NOT_SUPPLIED);
- propValTable.put(PART_SUPPLIED_OBJ, TrackedDataSet.PERCENT_PARTIAL_SUPPLIED);
- propValTable.put(TOT_PROD_GRID, TrackedDataSet.GROUP_PRODUCTION);
- propValTable.put(TOT_CONS_GRID, TrackedDataSet.GROUP_CONSUMPTION);
- propValTable.put(NR_SUBNETS, TrackedDataSet.AMOUNT_HOLONS);
- propValTable.put(NR_CLOSED_SWITCHES, TrackedDataSet.AMOUNT_CLOSED_SWITCHES);
- propValTable.put(AVG_OBJ_IN_HOLONS, TrackedDataSet.AVG_AMOUNT_OBJECTS_IN_HOLONS);
- propValTable.put(AVG_ELEM_IN_HOLONS, TrackedDataSet.AVG_AMOUNT_ELEMENTS_IN_HOLONS);
- propValTable.put(AVG_PRODS_IN_HOLONS, TrackedDataSet.AVG_AMOUNT_PRODUCERS_IN_HOLONS);
- propValTable.put(AVG_CONS_ENERGY_IN_HOLONS, TrackedDataSet.AVG_CONSUMED_ENERGY_IN_HOLONS);
- propValTable.put(AVG_WASTED_ENERGY_HOLONS, TrackedDataSet.AVG_WASTED_ENERGY_IN_HOLONS);
- propValTable.put(NR_BROKEN_EDGES, TrackedDataSet.AMOUNT_BROKEN_EDGES);
- propValTable.put(PROD_CONS_RATIO, TrackedDataSet.RATIO_PRODUCERS_CONSUMERS);
- propValTable.put(AVG_CLOSED_SW_HOLON, TrackedDataSet.AVG_AMOUNT_CLOSED_SWITCHES_IN_HOLONS);
- propValTable.put(AVG_ACTIVE_ELEMENTS_HOLON, TrackedDataSet.AVG_AMOUNT_ACTIVE_ELEMENTS_IN_HOLONS);
- propValTable.put(AVG_INACTIVE_ELEMENTS_HOLON, TrackedDataSet.AVG_AMOUNT_INACTIVE_ELEMENTS_IN_HOLONS);
- propValTable.put(AVG_PRODUCTION_HOLON, TrackedDataSet.AVG_PRODUCED_ENERGY_IN_HOLONS);
-
- JScrollPane graphScrollPane = new JScrollPane();
- graphScrollPane.setBorder(null);
- setRightComponent(graphScrollPane);
- graphPanel = new JPanel();
- graphPanel.setLayout(new BoxLayout(graphPanel, BoxLayout.Y_AXIS));
- graphPanel.revalidate();
- graphPanel.updateUI();
- graphScrollPane.setViewportView(graphPanel);
-
- JSplitPane splitPane = new JSplitPane();
- splitPane.setResizeWeight(0.5);
- splitPane.setBorder(null);
- splitPane.setPreferredSize(new Dimension(0, 0));
- splitPane.setMinimumSize(new Dimension(0, 0));
- splitPane.setMaximumSize(new Dimension(0, 0));
- splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
- setLeftComponent(splitPane);
-
- //========================== TREE STRUCTURE ===============================//
- JScrollPane treeScrollPane = new JScrollPane();
- treeScrollPane.setBorder(null);
- objectTree = new JTree();
- objectTree.setBorder(new EmptyBorder(0, 0, 0, 0));
- treeModel = (DefaultTreeModel) objectTree.getModel();
- DefaultMutableTreeNode root = new DefaultMutableTreeNode("Statistics");
- mainGrid = new DefaultMutableTreeNode(MAIN_GRID);
- mainGrid.add(new DefaultMutableTreeNode(TOT_PROD_HOLON));
- mainGrid.add(new DefaultMutableTreeNode(TOT_CONS_HOLON));
- mainGrid.add(new DefaultMutableTreeNode(SUPPLIED_OBJ));
- mainGrid.add(new DefaultMutableTreeNode(NOT_SUPPLIED_OBJ));
- mainGrid.add(new DefaultMutableTreeNode(PART_SUPPLIED_OBJ));
- mainGrid.add(new DefaultMutableTreeNode(NR_SUBNETS));
- mainGrid.add(new DefaultMutableTreeNode(PROD_CONS_RATIO));
- mainGrid.add(new DefaultMutableTreeNode(NR_BROKEN_EDGES));
- mainGrid.add(new DefaultMutableTreeNode(NR_CLOSED_SWITCHES));
-
- holonNode = new DefaultMutableTreeNode(HOLON);
- holonNode.add(new DefaultMutableTreeNode(AVG_OBJ_IN_HOLONS));
- holonNode.add(new DefaultMutableTreeNode(AVG_ELEM_IN_HOLONS));
- holonNode.add(new DefaultMutableTreeNode(AVG_WASTED_ENERGY_HOLONS));
- holonNode.add(new DefaultMutableTreeNode(AVG_CONS_ENERGY_IN_HOLONS));
- holonNode.add(new DefaultMutableTreeNode(AVG_PRODS_IN_HOLONS));
- holonNode.add(new DefaultMutableTreeNode(AVG_CLOSED_SW_HOLON));
- holonNode.add(new DefaultMutableTreeNode(AVG_ACTIVE_ELEMENTS_HOLON));
- holonNode.add(new DefaultMutableTreeNode(AVG_INACTIVE_ELEMENTS_HOLON));
- holonNode.add(new DefaultMutableTreeNode(AVG_PRODUCTION_HOLON));
- objectsNode = new DefaultMutableTreeNode("Objects");
- objectsNode.add(new DefaultMutableTreeNode("empty"));
-
- switchesNode = new DefaultMutableTreeNode("Switches");
- switchesNode.add(new DefaultMutableTreeNode("empty"));
-
- groupNode = new DefaultMutableTreeNode("Groups");
- groupNode.add(new DefaultMutableTreeNode("empty"));
-
- treeModel.setRoot(root);
- root.add(mainGrid);
- root.add(holonNode);
- root.add(objectsNode);
- root.add(switchesNode);
- root.add(groupNode);
- objectTree.setModel(treeModel);
- treeScrollPane.setViewportView(objectTree);
- JPopupMenu popupMenu = new JPopupMenu();
- addPopup(objectTree, popupMenu);
- JMenuItem mntmUntrack = new JMenuItem("Untrack");
- mntmUntrack.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) objectTree
- .getLastSelectedPathComponent();
- if (selectedNode.getLevel() == 2 && !selectedNode.getParent().toString().equals("whole Holon")) {
- String object = selectedNode.toString();
- controller.removeTrackingObj(objectHashtable.get(object).getObject());
- }
- }
- });
- popupMenu.add(mntmUntrack);
- objectTree.addTreeSelectionListener(new TreeSelectionListener() {
- @Override
- public void valueChanged(TreeSelectionEvent e) {
- resetFields();
- showObjectlbl.setText("...");
- //showPropertylbl.setText("...");
- DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) objectTree
- .getLastSelectedPathComponent();
- if (selectedNode == null) {
- return;
- } else {
- if (selectedNode.getLevel() == 0) {
- disableFields();
- }
- if (selectedNode.getLevel() == 1) {
- disableFields();
- currentProperty = null;
- graphNrTxtField.setText("");
- showObjectlbl.setText(selectedNode.toString());
- }
- if (selectedNode.getLevel() == 2) {
- if (((DefaultMutableTreeNode) selectedNode.getParent()).toString().equals(MAIN_GRID)
- || ((DefaultMutableTreeNode) selectedNode.getParent()).toString().equals(HOLON)) {
- enableFields();
- String object = selectedNode.getParent().toString();
- String property = selectedNode.toString();
- currentProperty = holonHashtable.get(property);
- Color color = currentProperty.getColor();
-
- redField.setText(Integer.toString(color.getRed()));
- greenField.setText(Integer.toString(color.getGreen()));
- blueField.setText(Integer.toString(color.getBlue()));
-
- showPropertylbl.setText(property);
- showObjectlbl.setText(object);
- graphNrTxtField.setText(currentProperty.getAssignedGraph());
- colorPanel.setBackground(color);
- } else {
- disableFields();
- currentProperty = null;
- graphNrTxtField.setText("");
- showObjectlbl.setText(selectedNode.toString());
- }
- }
- if (selectedNode.getLevel() == 3) {
- enableFields();
- String object = ((DefaultMutableTreeNode) selectedNode.getParent()).toString();
- String property = selectedNode.toString();
- currentProperty = objectHashtable.get(object).getPropertytTable().get(property);
- Color color = currentProperty.getColor();
- redField.setText(Integer.toString(color.getRed()));
- greenField.setText(Integer.toString(color.getGreen()));
- blueField.setText(Integer.toString(color.getBlue()));
- showObjectlbl.setText(object);
- showPropertylbl.setText(property);
- graphNrTxtField.setText(currentProperty.getAssignedGraph());
- colorPanel.setBackground(color);
- }
- }
- }
- });
-
- splitPane.setLeftComponent(treeScrollPane);
- repaintTree();
- //=========================== TREE STRUCTURE END ==========================//
-
- //================= COLOR COMBOBOX ===========================//
-
- colorComboBox = new JComboBox();
- colorComboBox.addItem("");
- colorComboBox.addItem("Red");
- colorComboBox.addItem("Blue");
- colorComboBox.addItem("Green");
- colorComboBox.addItem("Yellow");
- colorComboBox.addItem("Orange");
- colorComboBox.addItem("Cyan");
- colorComboBox.addItem("Magenta");
- colorComboBox.addItem("Pink");
- colorComboBox.addItem("Gray");
- colorComboBox.addItem("Random");
- colorComboBox.addItemListener(new ItemListener() {
- @Override
- public void itemStateChanged(ItemEvent e) {
- String colorName = (String) colorComboBox.getSelectedItem();
- Color tmpColor = Color.WHITE;
- switch (colorName) {
- case "":
- tmpColor = currentProperty.getColor();
- break;
- case "Red":
- tmpColor = Color.RED;
- colorChanged(tmpColor);
- break;
- case "Blue":
- tmpColor = Color.BLUE;
- colorChanged(tmpColor);
- break;
- case "Green":
- tmpColor = Color.GREEN;
- colorChanged(tmpColor);
- break;
- case "Yellow":
- tmpColor = Color.YELLOW;
- colorChanged(tmpColor);
- break;
- case "Orange":
- tmpColor = Color.ORANGE;
- colorChanged(tmpColor);
- break;
- case "Cyan":
- tmpColor = Color.CYAN;
- colorChanged(tmpColor);
- break;
- case "Magenta":
- tmpColor = Color.MAGENTA;
- colorChanged(tmpColor);
- break;
- case "Pink":
- tmpColor = Color.PINK;
- colorChanged(tmpColor);
- break;
- case "Gray":
- tmpColor = Color.GRAY;
- colorChanged(tmpColor);
- break;
- case "Random":
- Random rdm = new Random();
- tmpColor = new Color(rdm.nextInt(255), rdm.nextInt(255), rdm.nextInt(255));
- }
- redField.setText(Integer.toString(tmpColor.getRed()));
- greenField.setText(Integer.toString(tmpColor.getGreen()));
- blueField.setText(Integer.toString(tmpColor.getBlue()));
- }
- });
-
- // ==================== COLORBOX END ==========================//
-
- // ====================RED TEXTFIELD===========================//
- redField = new JTextField();
- redField.setColumns(10);
- redField.getDocument().addDocumentListener(new DocumentListener() {
- /*
- * if textField for Red changes, changes will applied in the
- * DataStructure "currentProperty" if Value is legit
- */
- @Override
- public void insertUpdate(DocumentEvent e) {
- int tmp = -1;
- try {
- tmp = Integer.parseInt(redField.getText());
- } catch (NumberFormatException e1) {
- }
- if (tmp > -1 && tmp <= 255) {
- if (currentProperty != null) {
- Color oldColor = currentProperty.getColor();
- Color color = new Color(tmp, oldColor.getGreen(), oldColor.getBlue());
- currentProperty.setColor(color);
- colorChanged(color);
- }
- }
- }
- @Override
- public void removeUpdate(DocumentEvent e) {
- int tmp = -1;
- try {
- tmp = Integer.parseInt(redField.getText());
- } catch (NumberFormatException e1) {
- }
- if (tmp > -1 && tmp <= 255) {
- if (currentProperty != null) {
- Color oldColor = currentProperty.getColor();
- Color color = new Color(tmp, oldColor.getGreen(), oldColor.getBlue());
- currentProperty.setColor(color);
- colorChanged(color);
- }
- }
- }
- @Override
- public void changedUpdate(DocumentEvent e) {
- }
- });
- // ======================RED TEXTFIELD END==========================//
-
- // ======================GREEN TEXTFIELD============================//
- greenField = new JTextField();
- greenField.setColumns(10);
- greenField.getDocument().addDocumentListener(new DocumentListener() {
- /*
- * if textField for Red changes, changes will applied in the
- * DataStructure "currentProperty" if Value is legit
- */
- @Override
- public void insertUpdate(DocumentEvent e) {
- int tmp = -1;
- try {
- tmp = Integer.parseInt(greenField.getText());
- } catch (NumberFormatException e1) {
- }
- if (tmp > -1 && tmp <= 255) {
- if (currentProperty != null) {
- Color oldColor = currentProperty.getColor();
- Color color = new Color(oldColor.getRed(), tmp, oldColor.getBlue());
- currentProperty.setColor(color);
- colorChanged(color);
- }
- }
- }
- @Override
- public void removeUpdate(DocumentEvent e) {
- int tmp = -1;
- try {
- tmp = Integer.parseInt(greenField.getText());
- } catch (NumberFormatException e1) {
- }
- if (tmp > -1 && tmp <= 255) {
- if (currentProperty != null) {
- Color oldColor = currentProperty.getColor();
- Color color = new Color(oldColor.getRed(), tmp, oldColor.getBlue());
- currentProperty.setColor(color);
- colorChanged(color);
- }
- }
- }
- @Override
- public void changedUpdate(DocumentEvent e) {
- }
- });
- // ======================GREEN TEXTFIELD END========================//
-
- // ======================BLUE TEXTFIELD=============================//
- blueField = new JTextField();
- blueField.setColumns(10);
- blueField.getDocument().addDocumentListener(new DocumentListener() {
- /*
- * if textField for Red changes, changes will applied in the
- * DataStructure "currentProperty" if Value is legit
- */
- @Override
- public void insertUpdate(DocumentEvent e) {
- int tmp = -1;
- try {
- tmp = Integer.parseInt(blueField.getText());
- } catch (NumberFormatException e1) {
- }
- if (tmp > -1 && tmp <= 255) {
- if (currentProperty != null) {
- Color oldColor = currentProperty.getColor();
- Color color = new Color(oldColor.getRed(), oldColor.getGreen(), tmp);
- currentProperty.setColor(color);
- colorChanged(color);
- }
- }
- }
- @Override
- public void removeUpdate(DocumentEvent e) {
- int tmp = -1;
- try {
- tmp = Integer.parseInt(blueField.getText());
- } catch (NumberFormatException e1) {
- }
- if (tmp > -1 && tmp <= 255) {
- if (currentProperty != null) {
- Color oldColor = currentProperty.getColor();
- Color color = new Color(oldColor.getRed(), oldColor.getGreen(), tmp);
- currentProperty.setColor(color);
- colorChanged(color);
- }
- }
- }
- @Override
- public void changedUpdate(DocumentEvent e) {
- }
- });
- // ======================BLUE TEXTFIELD END=========================//
-
- // ======================GRAPH NR TEXTFIELD=========================//
- graphNrTxtField = new JTextField();
- graphNrTxtField.setColumns(10);
- graphNrTxtField.getDocument().addDocumentListener(new DocumentListener() {
- /*
- * if textField for Red changes, changes will applied in the
- * DataStructure "currentProperty" if Value is legit
- */
- @Override
- public void insertUpdate(DocumentEvent e) {
- if (currentProperty != null) {
- currentProperty.setGraph(graphNrTxtField.getText());
- }
- }
- @Override
- public void removeUpdate(DocumentEvent e) {
- if (currentProperty != null) {
- currentProperty.setGraph(graphNrTxtField.getText());
- }
- }
- @Override
- public void changedUpdate(DocumentEvent e) {
- }
- });
- // ======================= GRAPH NR TEXTFIELD END==================//
-
- //======================== ADD BUTTON =============================//
- JButton btnAdd = new JButton("Add");
- btnAdd.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) objectTree
- .getLastSelectedPathComponent();
- if (selectedNode == null) {
- return;
- } else {
- if (selectedNode.getLevel() == 3 || (selectedNode.getLevel() == 2 &&
- (selectedNode.getParent().toString().equals(HOLON) || selectedNode.getParent().toString().equals(MAIN_GRID) ))) {
- StatisticGraphPanel tmp = null;
- if (graphNrTxtField.getText().length() > 0) {
- if (!graphHashtable.containsKey(graphNrTxtField.getText())
- && graphNrTxtField.getText().length() > 0) {
- tmp = new StatisticGraphPanel(controller.getModel(), controller,
- graphNrTxtField.getText(), graphHashtable);
- graphPanel.add(tmp);
- graphPanel.add(Box.createRigidArea(new Dimension(50, 50)));
- graphPanel.revalidate();
- graphPanel.updateUI();
- graphHashtable.put(graphNrTxtField.getText(), tmp);
- }
- String object = ((DefaultMutableTreeNode) selectedNode.getParent()).toString();
- String property = selectedNode.toString();
- AbstractCpsObject absCps = null;
- if(!object.equals(MAIN_GRID) && !object.equals(HOLON)){
- GraphDataSet dataSet = objectHashtable.get(object);
- absCps = dataSet.getObject();
- }
- TrackedDataSet tds = new TrackedDataSet(absCps, propValTable.get(property),
- currentProperty.getColor());
- graphHashtable.get(graphNrTxtField.getText()).addObject(tds);
- }
- }
- }
- }
- });
-
- //============================== ADD BUTTON END ==============================//
-
- //=========================== WINDOWBUILDER COMPONENTS ====================//
- JScrollPane scrollPane = new JScrollPane();
- scrollPane.setBorder(null);
- splitPane.setRightComponent(scrollPane);
-
- JPanel editPanel = new JPanel();
- //editPanel.setBounds(0,0,600,600);
- editPanel.setPreferredSize(new Dimension(170, 240));
- //scrollPane.setBounds(0,0,600,600);
- scrollPane.setViewportView(editPanel);
- editPanel.setLayout(null);
-
- JLabel lblObject = new JLabel("Object(s):");
- lblObject.setBounds(10, 11, 59, 20);
- editPanel.add(lblObject);
-
- showObjectlbl = new JLabel("...");
- showObjectlbl.setBounds(69, 11, 101, 20);
- editPanel.add(showObjectlbl);
-
- JLabel lblProperty = new JLabel("Property:");
- lblProperty.setBounds(10, 36, 59, 20);
- editPanel.add(lblProperty);
-
- showPropertylbl = new JLabel("...");
- showPropertylbl.setBounds(69, 36, 101, 20);
- editPanel.add(showPropertylbl);
-
- JLabel lblGraph = new JLabel("Graph:");
- lblGraph.setBounds(10, 61, 49, 23);
- editPanel.add(lblGraph);
-
- graphNrTxtField.setColumns(10);
- graphNrTxtField.setBounds(69, 61, 101, 23);
- editPanel.add(graphNrTxtField);
-
- JLabel lblColor = new JLabel("Color:");
- lblColor.setBounds(10, 95, 49, 23);
- editPanel.add(lblColor);
-
- colorComboBox.setBounds(69, 95, 101, 23);
- editPanel.add(colorComboBox);
-
- JLabel lblR = new JLabel("R");
- lblR.setBounds(10, 139, 11, 14);
- editPanel.add(lblR);
-
- redField.setColumns(10);
- redField.setBounds(22, 136, 37, 20);
- editPanel.add(redField);
-
- JLabel lblG = new JLabel("G");
- lblG.setBounds(68, 139, 11, 14);
- editPanel.add(lblG);
-
- greenField.setColumns(10);
- greenField.setBounds(79, 136, 37, 20);
- editPanel.add(greenField);
-
- JLabel lblB = new JLabel("B");
- lblB.setBounds(126, 139, 10, 14);
- editPanel.add(lblB);
-
- blueField.setColumns(10);
- blueField.setBounds(133, 136, 37, 20);
- editPanel.add(blueField);
-
- colorPanel = new JPanel();
- colorPanel.setBorder(new LineBorder(new Color(0, 0, 0)));
- colorPanel.setBackground(Color.WHITE);
- colorPanel.setBounds(10, 164, 59, 38);
- editPanel.add(colorPanel);
-
- btnAdd.setBounds(10, 213, 59, 23);
- editPanel.add(btnAdd);
-
- //============================= WINDOWBUILDER COMPONENTS END =================//
-
- }
-
- //=============================== END CONSTRUCTOR ==============================//
-
- //=============================== METHODS ======================================//
- @Override
- public void repaintTree() {
- treeModel.reload();
- }
- @Override
- public void addTrackedObject(ArrayList<AbstractCpsObject> hlList) {
- objectsNode.removeAllChildren();
- switchesNode.removeAllChildren();
- groupNode.removeAllChildren();
- objectHashtable.clear();
- if (hlList.size() > 0 && hlList != null) {
- for (AbstractCpsObject abs : hlList) {
- String name = abs.getName() + " " + abs.getId();
- DefaultMutableTreeNode tmp = new DefaultMutableTreeNode(name);
- Hashtable<String, PropertyDataSet> tmpHash = new Hashtable<String, PropertyDataSet>();
- //HolonObjects
- if(abs instanceof HolonObject){
- tmp.add(new DefaultMutableTreeNode(TOT_PROD_OBJ));
- tmp.add(new DefaultMutableTreeNode(TOT_CONS_OBJ));
- tmp.add(new DefaultMutableTreeNode(NR_ACTIVE_ELEMENTS));
- tmpHash.put(TOT_PROD_OBJ, new PropertyDataSet());
- tmpHash.put(TOT_CONS_OBJ, new PropertyDataSet());
- tmpHash.put(NR_ACTIVE_ELEMENTS, new PropertyDataSet());
- objectsNode.add(tmp);
- }
-
- //HolonSwitches
- if(abs instanceof HolonSwitch){
- tmp.add(new DefaultMutableTreeNode(SW_ACTIVE));
- tmpHash.put(SW_ACTIVE, new PropertyDataSet());
- switchesNode.add(tmp);
- }
-
- //NodesOfNodes
- if(abs instanceof CpsUpperNode){
- tmp.add(new DefaultMutableTreeNode(TOT_PROD_GRID));
- tmp.add(new DefaultMutableTreeNode(TOT_CONS_GRID));
- tmpHash.put(TOT_PROD_GRID, new PropertyDataSet());
- tmpHash.put(TOT_CONS_GRID, new PropertyDataSet());
- groupNode.add(tmp);
- }
-
- GraphDataSet gS = new GraphDataSet(abs, tmpHash);
- objectHashtable.put(name, gS);
- }
- }
- if(objectsNode.getChildCount() == 0){
- objectsNode.add(new DefaultMutableTreeNode("empty"));
- }
- if(switchesNode.getChildCount() == 0){
- switchesNode.add(new DefaultMutableTreeNode("empty"));
- }
- if(groupNode.getChildCount() == 0){
- groupNode.add(new DefaultMutableTreeNode("empty"));
- }
- }
- public void colorChanged(Color color) {
- colorPanel.setBackground(color);
- }
- public void resetFields() {
- colorPanel.setBackground(Color.WHITE);
- redField.setText("");
- greenField.setText("");
- blueField.setText("");
- colorComboBox.setSelectedIndex(0);
- }
- public void disableFields() {
- redField.setEnabled(false);
- greenField.setEnabled(false);
- blueField.setEnabled(false);
- graphNrTxtField.setEnabled(false);
- colorComboBox.setEnabled(false);
- colorPanel.setBackground(Color.LIGHT_GRAY);
- }
- public void enableFields() {
- redField.setEnabled(true);
- greenField.setEnabled(true);
- blueField.setEnabled(true);
- graphNrTxtField.setEnabled(true);
- colorComboBox.setEnabled(true);
- colorPanel.setBackground(Color.WHITE);
- }
- public void repaintGraphs() {
- for (StatisticGraphPanel sg : graphHashtable.values()) {
- sg.calcMaximum();
- sg.addValues();
- sg.repaint();
- }
- }
-
- public JPanel getGraphPanel(){
- return graphPanel;
- }
- private static void addPopup(Component component, final JPopupMenu popup) {
- }
-
-
- }
|