package genegui; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.io.*; import javax.swing.*; import javax.swing.event.*; import java.util.*; import affectors.*; import main.*; /** A total re-write of the original NetworkViewer. This portion of NetworkViewer is just a JSplitPane that holds a NetworkPaintPanel on the left side and any of several types of viewers on the right-side (such as Affector or Inspector Viewers). The NetworkPaintPanel does all the hard work on painting the network.

@see NetworkPaintPanel @author WJS */ public class NetworkViewer2 extends JInternalFrame implements ModelStateChangeListener, GuiInterface { public static final int GRAPH_FUNCTION_LINEAR=0; public static final int GRAPH_FUNCTION_LOG=1; public static final int GRAPH_FUNCTION_EXP=2; public static final int GRAPH_FUNCTION_THRESH=3; public static final int GRAPH_FUNCTION_PSUEDO=4; /** When set to true, displays node values for selected cell */ private boolean ActiveDisplayMode = false; /** */ private JMenuItem AutoResizeItem; /** */ private boolean AutoResizePaintPanel = false; /** */ private int CellIndex = 0; /** */ private SingleCellSelector CellSelector; /** Multiplier used for exp color maping*/ private float ExpMultiplier = 1f; /** Specifies what transformation function should be applied to the graph color */ private int GraphFunction = GRAPH_FUNCTION_LINEAR; /** */ private GuiInterface LastViewer = null; /** Multiplier used for log color maping*/ private float LogMultiplier = 1f; /** */ private JMenuBar MainMenu; /** Controls the rate at which the display refreshes by rejecting changes in size below the RefreshReject */ public float RefreshReject = .03125f; /** The right-side panel for holding Node/Affector viewers */ private JPanel RightsidePanel; /** Self reference */ private NetworkViewer2 SaveThis = this; /** MainPanel for storing everything */ private JSplitPane SplitPanel; /** The MainGui object that this belongs to */ private MainGui TheMainGui; /** Pointer to the current model */ private Model TheModel; /** A pointer to the ModelState used to pass information to the CellViewer */ private ModelState TheModelState = null; /** The NetworkPaint panel that holds the display objects and paints the connections */ private NetworkPaintPanel ThePaintPanel; /** The threshold value used by the threshold colormap */ private float ThresholdValue = 0.5f; /** Main constructor. @param Network network - The network this displays. */ public NetworkViewer2(Model model, MainGui theMainGui) { super("Network Viewer",true,true,true,true); TheModel = model; TheMainGui = theMainGui; Network network = model.getNetwork(); TheModelState = TheModel.getModelState(); SplitPanel = new JSplitPane(); setContentPane(SplitPanel); // Create the panel where the network is painted. ThePaintPanel = new NetworkPaintPanel(this); SplitPanel.setLeftComponent(ThePaintPanel); ThePaintPanel.setNetwork(network); // Create a panel for the right-side that will store Node/Affector Viewers RightsidePanel = new JPanel(); RightsidePanel.setBackground(Color.lightGray); JScrollPane scrollPane = new JScrollPane(RightsidePanel); SplitPanel.setRightComponent(scrollPane); // Build the JMenu MainMenu = new JMenuBar(); MainMenu.setBackground(Color.lightGray); // Options menu JMenu OptionsMenu = new JMenu("Options"); OptionsMenu.setBackground(Color.lightGray); JMenuItem item; item = new JMenuItem("Auto-arrange"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { ThePaintPanel.autoArrange(); validate(); doLayout(); repaint(); } }); OptionsMenu.add(item); AutoResizeItem = new JMenuItem("Auto-resize is off"); OptionsMenu.add(AutoResizeItem); AutoResizeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (AutoResizePaintPanel) { AutoResizePaintPanel = false; AutoResizeItem.setText("Auto-resize is off"); } else { AutoResizePaintPanel = true; AutoResizeItem.setText("Auto-resize is on"); } } }); OptionsMenu.add(AutoResizeItem); OptionsMenu.addSeparator(); item = new JMenuItem("Set Affector Selected Color"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { Color c = JColorChooser.showDialog(null,"Choose Affector Highlite Color",ThePaintPanel.getAffectorSelectedColor()); ThePaintPanel.setAffectorSelectedColor(c); } }); OptionsMenu.add(item); item = new JMenuItem("Set Node Selected Color"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { Color c = JColorChooser.showDialog(null,"Choose Node Highlite Color",ThePaintPanel.getNodeSelectedColor()); ThePaintPanel.setNodeSelectedColor(c); } }); OptionsMenu.add(item); OptionsMenu.addSeparator(); item = new JMenuItem("Set Refresh Rejection"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { String newValue = (String)JOptionPane.showInputDialog(null,"Enter new refresh rejection value","Set Refresh Rejection",JOptionPane.QUESTION_MESSAGE,null,null,Float.toString(RefreshReject)); if ((newValue!=null)&&(!newValue.equals(""))) try { RefreshReject = Float.parseFloat(newValue); } catch (NumberFormatException nfe) {} } }); OptionsMenu.add(item); MainMenu.add(OptionsMenu); // Active Display Menu JMenu ActiveDisplayMenu = new JMenu("Active Display"); ActiveDisplayMenu.setBackground(Color.lightGray); final JMenuItem ActiveOnOff = new JMenuItem("Turn Active Display On"); ActiveOnOff.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { ActiveDisplayMode = !ActiveDisplayMode; if (ActiveDisplayMode) ActiveOnOff.setText("Turn Active Display Off"); else ActiveOnOff.setText("Turn Active Display On"); ThePaintPanel.setSelectedCellState(TheModelState.getCellState(CellIndex)); NetworkPaintPanel.NodeDisplay[] nodeDisplays = ThePaintPanel.getNodeDisplays(); for (int i=0;i