package genegui; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.event.*; import javax.swing.*; import main.*; /** ModelStateEditor.java The ModelStateEditor allows the user to define node states for each cell in the model.

The ModelStateEditor is based on a JFrame with InternalJFrames. @author WJS */ public class ModelStateEditor extends JInternalFrame implements GuiInterface { /** Self Referencce */ private ModelStateEditor SaveThis = this; /** The Desktop used to manage all object in the Editor*/ private JDesktopPane TheDeskTop; /** The MainGui object that this belongs to */ private MainGui TheMainGui; /** The ModelState being edited */ private ModelState TheModelState; /** The toolbox with neat function for modifying ModelViews */ private ModelStateToolBox TheToolBox; public ModelStateEditor(Model model, MainGui theMainGui) { super("Model State Editor",true,true,true,true); TheMainGui = theMainGui; TheDeskTop = new JDesktopPane(); TheDeskTop.setBackground(Color.lightGray); setContentPane(TheDeskTop); // Create the ModelState object that the user will be editing TheModelState = new ModelState(model); TheModelState.setModelStateEditor(this); // Create the toolbox TheToolBox = new ModelStateToolBox(); TheDeskTop.add(TheToolBox); TheToolBox.setLocation(10,10); TheModelState.setToolBox(TheToolBox); // Create the node palette ModelStateNodePalette palette = new ModelStateNodePalette(TheModelState, TheMainGui); TheDeskTop.add(palette); palette.setLocation(70,10); TheModelState.setActiveModelStateNodePalette(palette); TheMainGui.addGUIListener(palette); // Create a ModelStateView. User may create more later. ModelStateView view = new ModelStateView(TheModelState, SaveThis, TheMainGui); addModelStateView(view); // Create the menu bar JMenuBar menuBar = new JMenuBar(); menuBar.setBackground(Color.lightGray); JMenuItem item; JMenu fileMenu = new JMenu("File"); fileMenu.setBackground(Color.lightGray); // item = new JMenuItem("New"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { } }); fileMenu.add(item); // item = new JMenuItem("Open"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { } }); fileMenu.add(item); // item = new JMenuItem("Close"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { } }); fileMenu.add(item); fileMenu.addSeparator(); // item = new JMenuItem("Save"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { } }); fileMenu.add(item); // item = new JMenuItem("Save as"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { } }); fileMenu.add(item); fileMenu.addSeparator(); // item = new JMenuItem("Exit Model State Editor"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { } }); fileMenu.add(item); menuBar.add(fileMenu); JMenu editMenu = new JMenu("Edit"); editMenu.setBackground(Color.lightGray); item = new JMenuItem("Undo"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { } }); editMenu.add(item); editMenu.addSeparator(); item = new JMenuItem("Reset"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { TheModelState.reset(); } }); editMenu.add(item); menuBar.add(editMenu); JMenu viewMenu = new JMenu("View"); viewMenu.setBackground(Color.lightGray); // Opens up a new ModelStateView item = new JMenuItem("New View"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { ModelStateView view = new ModelStateView(TheModelState, SaveThis,TheMainGui); addModelStateView(view); } }); viewMenu.add(item); viewMenu.addSeparator(); // Closes all open ModelStateViews item = new JMenuItem("Close All Views"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { TheModelState.removeAllModelStateViews(); } }); viewMenu.add(item); menuBar.add(viewMenu); setJMenuBar(menuBar); // Add an internal frame listener for capturing frame closing events addInternalFrameListener(new InternalFrameAdapter() { public void internalFrameClosing(InternalFrameEvent ife) { close(); } }); setSize(800,600); setVisible(true); // Reposition the first ModelStateViewer. view.setLocation((getWidth()-view.getWidth())/2,((getHeight()-view.getHeight())/2)); } /** Called when a new ModelStateView is to be added to the ModelStateEditor. @param ModelStateView modelStateView - The ModelStateView being open. @author WJS */ public void addModelStateView(ModelStateView view) { TheModelState.addModelStateView(view); TheModelState.setActiveModelStateView(view); TheDeskTop.add(view); view.setLocation((getWidth()-view.getWidth())/2,((getHeight()-view.getHeight())/2)); TheMainGui.addGUIListener(view); } /** Close up the JFrame properly, and disconnect fromlistener lists. @author WJS */ private void close() { dispose(); GeneNet.TheMainGui.removeInternalFrame(this); } /** To be called by the ModelState when a modelStateView is being closed down. View is cleany removed from the desktop. @param ModelStateView modelStateView - The ModelStateView being closed. @author WJS */ public void closeModelStateView(ModelStateView modelStateView) { TheDeskTop.remove(modelStateView); Rectangle bounds = modelStateView.getBounds(); TheDeskTop.repaint(bounds); TheMainGui.removeGUIListener(this); } /** Moves a ModelStateView to the "front" which in this case is still behind the ToolBox and NodePalette which should always be on top. @param ModelStateView modelStateView - The ModelStateView to be moved forward @author WJS */ public void moveModelStateViewToFront(ModelStateView modelStateView) { TheDeskTop.remove(modelStateView); TheDeskTop.add(modelStateView,2); } /******************** 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: // TODO break; case GuiInterface.CHANGED: // TODO break; case GuiInterface.REMOVED: // TODO 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) { } }