package genegui; import java.awt.*; import java.awt.event.*; import javax.swing.*; import main.*; import mygraphs.LineGraphPanel; // TODO Slated for destruction public class InspectorList implements ActionListener { // InspectorFrame inspectorFrame; LineGraphPanel timeGraph = null; int curCell, curNode; AffectorTemplate curAffector = null; Model model = null; Network network = null; boolean first = true; public final static int ADD_WINDOW = 24129378; public final static String UPDATE_MODEL = "Update Model"; // The action type used when passing action events indicating changes in the // user interface status, for instance when the user selects a new node or cell // or model. public final static int INTERFACE_ACTION = 24195134; protected JInternalFrame netViewerFrame = null, //WJS modelFileViewerFrame = null, timeGraphFrame = null; // Sends out action events to and from inspectors private ActionListener actionListener = null; public InspectorList() { } public void makeWindows() { // inspectorFrame = new InspectorFrame(); // inspectorFrame.addListenersToComponent(this); makeTimeGraph(); GeneNet.TheMainGui.addInternalFrame(timeGraphFrame); // netViewerFrame.setVisible(true); // netViewerFrame.toFront(); // // modelFileViewerFrame.setVisible(false); timeGraphFrame.setVisible(false); } public void setModel(Model model) { this.model = model; if (actionListener != null) { actionListener.actionPerformed(new ActionEvent(new Pointer(model), INTERFACE_ACTION, "SetModel")); } // if(model == null) { // netViewerFrame.setTitle("GeneNet"); // } // else { // netViewerFrame.setTitle(model.getNetwork().getName()); // } } public void setNetwork(Network network) { this.network = network; if(actionListener != null) { actionListener.actionPerformed(new ActionEvent(new Pointer(network), INTERFACE_ACTION, "SetNetwork")); } } // public void setNetworkFile(NetworkFile file) { // if(modelFileView != null) { // modelFileView.setTextDocument(file); // file.addActionListener(modelFileView); // } // } // public void makeNetworkViewer() { // // if(netView == null) { // netViewerFrame = makeViewerFrame("Network View"); // netViewerFrame.setBounds(5, 5, 350, 350); // netViewerFrame.getContentPane().setLayout(new BorderLayout()); // netView = new NetworkViewer(); // netViewerFrame.getContentPane().add(netView, BorderLayout.CENTER); // netView.addActionListener(this); // addActionListener(netView); // netViewerFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // actionListener.actionPerformed(new ActionEvent(netViewerFrame, ADD_WINDOW, "")); // // } // } // public void makeModelFileViewer() { // // if(modelFileViewerFrame == null) { // modelFileViewerFrame = makeViewerFrame("Model"); // modelFileViewerFrame.setBounds(200, 200, 400, 300); // modelFileViewerFrame.getContentPane().setLayout(new BorderLayout()); // // // Make the scroll pane // JScrollPane scrollpane = new JScrollPane(); // modelFileViewerFrame.getContentPane().add(scrollpane, BorderLayout.CENTER); // // // Make the text area and put it inside the scrollpane // modelFileView = new ModelFileViewer(); // scrollpane.getViewport().add(modelFileView, BorderLayout.CENTER); // // // Make a bottom part containing an update button // JButton button = new JButton("Update Model"); // modelFileViewerFrame.getContentPane().add(button, BorderLayout.SOUTH); // button.addActionListener(this); // button.setActionCommand("Update Model"); // // modelFileViewerFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); // //// container.add(modelFileViewerFrame); // } // } public void makeTimeGraph() { if(timeGraphFrame != null) return; timeGraphFrame = makeViewerFrame("Time graph"); timeGraphFrame.setBounds(400, 300, 300, 150); timeGraphFrame.getContentPane().setLayout(new BorderLayout()); timeGraph = new LineGraphPanel(); timeGraphFrame.getContentPane().add("Center", timeGraph); addActionListener(timeGraph); // To get update model events } private JInternalFrame makeViewerFrame(String title) { return(new JInternalFrame(title,true,true,true,true)); } // private JFrame makeViewerFrame(String title) { // // JFrame frame = new JFrame(title); //// frame.setClosable(true); //// frame.setIconifiable(true); // frame.setResizable(true); //// frame.setMaximizable(true); // // return frame; // } public void makePhasePortraitDlog() { // Bring up phase portrait dlog PhasePortraitDlog dlog = new PhasePortraitDlog(network, model); dlog.setVisible(true); } public int getNode() { return curNode; } public void setNode(int node_num) { curNode = node_num; if(actionListener != null) { actionListener.actionPerformed(new ActionEvent(new Integer(node_num), INTERFACE_ACTION, "SetNode")); } } public int getCell() { return curCell; } public void setCell(int cell_num) { curCell = cell_num; if(actionListener != null) { actionListener.actionPerformed(new ActionEvent(new Integer(cell_num), INTERFACE_ACTION, "SetCell")); } } public AffectorTemplate getAffector() { return curAffector; } public void setAffector(AffectorTemplate aff) { curAffector = aff; if(actionListener != null) { actionListener.actionPerformed(new ActionEvent(new Pointer(curAffector), InspectorList.INTERFACE_ACTION, "SetAffector")); } } public void actionPerformed(ActionEvent event) { if(event.getID() == INTERFACE_ACTION) { if((event.getActionCommand()).equals("SetCell")) { setCell(((Integer)event.getSource()).intValue()); } else if((event.getActionCommand()).equals("SetNode")) { setNode(((Integer)event.getSource()).intValue()); } else if((event.getActionCommand()).equals("SetAffector")) { setAffector( (AffectorTemplate)(((Pointer)(event.getSource())).object) ); } } else if(event.getID() == ActionEvent.ACTION_PERFORMED) { if((event.getActionCommand()).equals("Inspect Network")) { netViewerFrame.setVisible(true); netViewerFrame.toFront(); } else if((event.getActionCommand()).equals("Model State Editor")) { if (model!=null) { // ModelStateEditor modelStateEditor = new ModelStateEditor(model,TheMainGui); } } else if((event.getActionCommand()).equals("Inspect Cells")) { ModelState state = model.getModelState(); if (state==null) { state = new ModelState(model); model.setModelState(state); } // CellSurfaceViewer viewer = new CellSurfaceViewer(model); // viewer.setModelState(state); // state.addModelStateChangeListener(viewer); // GeneNet.TheMainGui.addInternalFrame(viewer); } else if((event.getActionCommand()).equals("Inspect Model File")) { modelFileViewerFrame.setVisible(true); modelFileViewerFrame.toFront(); } else if((event.getActionCommand()).equals("Inspect Parameters...")) { if(model == null) return; new ParInspector(); } else if((event.getActionCommand()).equals(UPDATE_MODEL)) { if(actionListener != null) actionListener.actionPerformed(new ActionEvent(this, INTERFACE_ACTION, UPDATE_MODEL)); // pass it on } else if((event.getActionCommand()).equals("Phase Portrait")) { if(model == null) return; if(network == null) return; makePhasePortraitDlog(); } else if((event.getActionCommand()).equals("AddToGraph")) { timeGraphFrame.setVisible(true); NodeSpecifier ns = (NodeSpecifier)(event.getSource()); timeGraph.addItem(ns.getCell(model), ns.getNode(model), model, network.getNode(ns.getNodeNum()).getColor()); } else if((event.getActionCommand()).equals("RemoveFromGraph")) { // Remove it ... } } } // Stock code for sending out action events public void addActionListener(ActionListener l) { actionListener = AWTEventMulticaster.add(actionListener, l); } public void removeActionListener(ActionListener l) { actionListener = AWTEventMulticaster.remove(actionListener, l); } }