package genegui; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.event.*; import javax.swing.*; import main.*; /** NodeViewPanel.java A JPanel extendsion for showing/editing the properties of NodeTemplates. */ public class NodeViewPanel extends JPanel implements GuiInterface { /** Widdle square JPanel for showing node color */ private JPanel ColorSwatch; /** The JTextField for showing/changing the name of the Node */ private JTextField NameField; /** The JCheckbox for determining if the node shows in a new CellViewer by default */ private JCheckBox ShowsInViewer; /** The MainGui object that this belongs to */ private MainGui TheMainGui; /** The Node Template */ private NodeTemplate TheTemplate; /** The JTextField for showing/changing the initial default value of the node */ private JTextField ValueField; public NodeViewPanel(NodeTemplate nodeTemplate, MainGui theMainGui) { TheTemplate = nodeTemplate; TheMainGui = theMainGui; setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); setBackground(Color.lightGray); JPanel p; JLabel l; Dimension d; // Make Node Name Field p = new JPanel(); p.setBackground(Color.lightGray); p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); l = new JLabel("Node Name: "); d = new Dimension(90,20); l.setMinimumSize(d); l.setMaximumSize(d); l.setPreferredSize(d); l.setSize(d); p.add(l); NameField = new JTextField(TheTemplate.getName()); d = new Dimension(120,20); NameField.setMinimumSize(d); NameField.setPreferredSize(d); NameField.setSize(d); p.add(NameField); add(p); // Make initial Value Field p = new JPanel(); p.setBackground(Color.lightGray); p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); l = new JLabel("Initial Value: "); d = new Dimension(90,20); l.setMinimumSize(d); l.setMaximumSize(d); l.setPreferredSize(d); l.setSize(d); p.add(l); ValueField = new JTextField("0.0"); d = new Dimension(200,20); ValueField.setMinimumSize(d); ValueField.setPreferredSize(d); ValueField.setSize(d); p.add(ValueField); add(p); // Make shows in CellViewer by default checkbox p = new JPanel(); p.setBackground(Color.lightGray); p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); ShowsInViewer = new JCheckBox("Shows in Cell Viewer by default: "); ShowsInViewer.setSelected(TheTemplate.getShow()); ShowsInViewer.setHorizontalTextPosition(SwingConstants.LEFT); ShowsInViewer.setOpaque(false); p.add(ShowsInViewer); // Make filler to nudege check box to the left JPanel filler = new JPanel(); filler.setOpaque(false); p.add(filler); add(p); // Make node color selector Panel p = new JPanel(); p.setBackground(Color.lightGray); p.setBorder(BorderFactory.createLineBorder(Color.black,1)); p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); l = new JLabel("Node Color: "); d = new Dimension(90,20); l.setMinimumSize(d); l.setMaximumSize(d); l.setPreferredSize(d); l.setSize(d); p.add(l); // Make color swatch ColorSwatch = new JPanel(); d = new Dimension(20,20); ColorSwatch.setMinimumSize(d); ColorSwatch.setMaximumSize(d); ColorSwatch.setPreferredSize(d); ColorSwatch.setSize(d); ColorSwatch.setBackground(TheTemplate.getColor()); ColorSwatch.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.black)); p.add(ColorSwatch); filler = new JPanel(); filler.setOpaque(false); p.add(filler); // Make node color selection button JButton button = new JButton("Set Node Color"); button.setOpaque(false); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { Color c = JColorChooser.showDialog(null,"Choose Node Color",TheTemplate.getColor()); ColorSwatch.setBackground(c); } }); p.add(button); add(p); // Add the set button that updates all the changes. p = new JPanel(); p.setBackground(Color.lightGray); p.setLayout(new BorderLayout()); p.setOpaque(false); JButton setButton = new JButton("Apply Changes"); setButton.setOpaque(false); setButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setValues(); } }); p.add(setButton,BorderLayout.CENTER); add(p); } /** Update all the selected values. @author WJS */ private void setValues() { // Make changes to the actual NodeTemplate TheTemplate.setName(NameField.getText()); TheTemplate.setColor(ColorSwatch.getBackground()); TheTemplate.setShow(ShowsInViewer.isSelected()); // TODO - What to do with initial value setting? // Notify the MainGui of change so it can be passed on to others TheMainGui.nodeTemplateChanged(GuiInterface.CHANGED,TheTemplate,this); } /** Updates the node display values based upon the current values in its NodeTemplate. @author WJS */ public void updateTemplate() { NameField.setText(TheTemplate.getName()); ColorSwatch.setBackground(TheTemplate.getColor()); ShowsInViewer.setSelected(TheTemplate.getShow()); } /******************** GUItoNet Interface implementation *********************/ /** Called when a change is made to the passed AffectorTemplate @param int operation @param AffectorTemplate affectorTemplate @param GuiInterface source - Originator of this interface change. @author WJS */ public void affectorTemplateChanged(int operation, AffectorTemplate affectorTemplate, GuiInterface source) { } /** Method for invoking general network IO operations. @param int operation - The network IO operation code. @param File file - The file if needed, else don't care. @author WJS */ public boolean networkIO(int operation, File file) { boolean result = true; return(result); } /** Called when a change is made to the passed NodeTemplate @param int operation @param NodeTemplate nodeTemplate @param GuiInterface source - Originator of this interface change. @author WJS */ public void nodeTemplateChanged(int operation, NodeTemplate nodeTemplate, GuiInterface source) { switch (operation) { case GuiInterface.ADDED: break; case GuiInterface.CHANGED: if (nodeTemplate==TheTemplate) updateTemplate(); break; case GuiInterface.REMOVED: break; } } /** Called when a change is made to a parameter or the whole parameter set @param int operation @param int parameterNumber @param GuiInterface source - Originator of this interface change. @author WJS */ public void parameterSetChanged(int operation, int parameterNumber, GuiInterface source) { } /** Method for controling model/iterator runs. @param int operation - Run control code. @author WJS */ public void runControl(int operation) { } /** Method for reporting status of the model/iterator runs @param int operation - Run status code. @author WJS */ public void runStatus(int operation) { } }