package mygraphs; import java.awt.*; import java.awt.event.*; import java.awt.font.*; import java.awt.geom.*; import java.util.*; import javax.swing.*; import genegui.*; import main.*; import parameters.*; import stat.*; /** CamGraph2.java A re-write of the original CamGraph to provide for cleaner visuals and to allow integration with the IteratorViewer. @author WJS */ public class CamGraph2 extends JInternalFrame { private static final int INNER_CIRCLE = 100; private static final int OUTER_CIRCLE = 800; private static final int RAY_LENGTH = 420; /** */ private Color[] GraphColors; /** */ private String[] GraphNames; /** */ private Polygon[] GraphPolygons; /** */ private float[] GraphScores; /** */ private boolean[] GraphVisible; /** */ private JToggleButton HoldButton; /** */ private Font LabelFont = new Font("Arial",Font.BOLD,14); /** */ private JWindow LabelWindow; /** */ private JPanel MainPanel; /** */ private JComboBox ParametersBox; /** */ private String[] ParameterNames; /** */ private Rectangle[] ParameterNameAreas; /** */ private JToggleButton PlotAllButton; /** */ private JTextField ScoreJTextField; /** */ private PaintPanel ThePaintPanel; /** */ private SuccessList TheSuccessList; /** */ private int ViewIndex = 0; /** */ private int[] XRays; /** */ private int[] YRays; /** */ private int[] XNames; /** */ private int[] YNames; public CamGraph2(ParameterSet protoTypeParameterSet) { super("CamGraph",true,true,true,false); MainPanel = new JPanel(); setContentPane(MainPanel); MainPanel.setLayout(new BoxLayout(MainPanel,BoxLayout.Y_AXIS)); MainPanel.setBackground(Color.lightGray); // Set up the paint panel used for the display ThePaintPanel = new CamGraph2.PaintPanel(); ThePaintPanel.setBorder(BorderFactory.createMatteBorder(0,0,1,0,Color.black)); MainPanel.add(ThePaintPanel); ThePaintPanel.paintOffScreen(true,false,0); // Setup the control area JPanel controls = new JPanel(); controls.setBackground(Color.lightGray); controls.setOpaque(true); controls.setLayout(new BoxLayout(controls,BoxLayout.X_AXIS)); // Fix the size of the controlspanel so it forces the ThePaintPanel // to do all the resizinf when resizing. Dimension controlDim = new Dimension(400,60); controls.setSize(controlDim); controls.setMaximumSize(controlDim); controls.setMinimumSize(controlDim); controls.setPreferredSize(controlDim); MainPanel.add(controls); // Left Side JPanel leftSide = new JPanel(); leftSide.setBackground(Color.lightGray); leftSide.setOpaque(true); leftSide.setLayout(new BoxLayout(leftSide,BoxLayout.Y_AXIS)); controls.add(leftSide); // Navigation buttons and results list JPanel p = new JPanel(); p.setBackground(Color.lightGray); p.setOpaque(true); p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); leftSide.add(p); JButton LeftLeftArrow = new JButton(new ImageIcon("icons/ArrowLeftLeft13.gif")); LeftLeftArrow.setContentAreaFilled(false); LeftLeftArrow.setBorderPainted(false); LeftLeftArrow.setFocusPainted(false); LeftLeftArrow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { ViewIndex=0; setViewIndex(ViewIndex); } }); p.add(LeftLeftArrow); JButton LeftArrow = new JButton(new ImageIcon("icons/ArrowLeft13.gif")); LeftArrow.setContentAreaFilled(false); LeftArrow.setBorderPainted(false); LeftArrow.setFocusPainted(false); LeftArrow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { ViewIndex--; if (ViewIndex<0) ViewIndex=0; setViewIndex(ViewIndex); } }); p.add(LeftArrow); // The combobox for displaying results to be viewed ParametersBox = new JComboBox(); ParametersBox.setOpaque(false); ParametersBox.setFont(new Font("Arial",Font.BOLD,10)); ParametersBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { ViewIndex = ParametersBox.getSelectedIndex(); if (ViewIndex<0) ViewIndex=0; setViewIndex(ViewIndex); } }); p.add(ParametersBox); JButton RightArrow = new JButton(new ImageIcon("icons/ArrowRight13.gif")); RightArrow.setContentAreaFilled(false); RightArrow.setBorderPainted(false); RightArrow.setFocusPainted(false); RightArrow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { ViewIndex++; if (ViewIndex==GraphPolygons.length) ViewIndex--; setViewIndex(ViewIndex); } }); p.add(RightArrow); JButton RightRightArrow = new JButton(new ImageIcon("icons/ArrowRightRight13.gif")); RightRightArrow.setContentAreaFilled(false); RightRightArrow.setBorderPainted(false); RightRightArrow.setFocusPainted(false); RightRightArrow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { ViewIndex=GraphPolygons.length-1; setViewIndex(ViewIndex); } }); p.add(RightRightArrow); // Control buttons p = new JPanel(); p.setBackground(Color.lightGray); p.setOpaque(true); p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); leftSide.add(p); // Hold button tells camgraph to keep this parameterset displayed HoldButton = new JToggleButton("Hold"); HoldButton.setOpaque(false); HoldButton.setFont(new Font("Arial",Font.BOLD,10)); HoldButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { GraphVisible[ViewIndex] = HoldButton.isSelected(); } }); p.add(HoldButton); // Plot All button causes all parameter sets to be displayed PlotAllButton = new JToggleButton("Plot All"); PlotAllButton.setOpaque(false); PlotAllButton.setFont(new Font("Arial",Font.BOLD,10)); PlotAllButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (PlotAllButton.isSelected()) plotAll(); else { clearGraphs(); setViewIndex(ViewIndex); } } }); p.add(PlotAllButton); JPanel filler = new JPanel(); filler.setOpaque(false); // Clear button erases all parameter sets being displayed JButton ClearButton = new JButton("Clear"); ClearButton.setOpaque(false); ClearButton.setFont(new Font("Arial",Font.BOLD,10)); ClearButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { clearGraphs(); } }); p.add(ClearButton); // Right Side JPanel rightSide = new JPanel(); rightSide.setBackground(Color.lightGray); rightSide.setOpaque(true); rightSide.setLayout(new BoxLayout(rightSide,BoxLayout.Y_AXIS)); controls.add(rightSide); JLabel l; Dimension labelDim = new Dimension(50,14); // Make panel for displaying score p = new JPanel(); p.setBackground(Color.lightGray); p.setOpaque(true); p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); l = new JLabel("Score: "); l.setHorizontalAlignment(SwingConstants.RIGHT); l.setSize(labelDim); l.setMinimumSize(labelDim); l.setPreferredSize(labelDim); l.setFont(new Font("Arial",Font.BOLD,10)); p.add(l); // JTextField for displaying the parameter set score ScoreJTextField = new JTextField(); ScoreJTextField.setFont(new Font("Arial",Font.PLAIN,10)); ScoreJTextField.setEditable(false); p.add(ScoreJTextField); rightSide.add(p); // Make panels for displaying threshold fields p = new JPanel(); p.setBackground(Color.lightGray); p.setOpaque(true); p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); l = new JLabel("High: "); l.setHorizontalAlignment(SwingConstants.RIGHT); l.setSize(labelDim); l.setMinimumSize(labelDim); l.setPreferredSize(labelDim); l.setFont(new Font("Arial",Font.BOLD,10)); p.add(l); // JTextField for high Threshold JTextField HighJTextField = new JTextField(); HighJTextField.setFont(new Font("Arial",Font.PLAIN,10)); p.add(HighJTextField); rightSide.add(p); p = new JPanel(); p.setBackground(Color.lightGray); p.setOpaque(true); p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); l = new JLabel("Low: "); l.setSize(labelDim); l.setHorizontalAlignment(SwingConstants.RIGHT); l.setMinimumSize(labelDim); l.setPreferredSize(labelDim); l.setFont(new Font("Arial",Font.BOLD,10)); p.add(l); // JTextField for high Threshold JTextField LowJTextField = new JTextField(); LowJTextField.setFont(new Font("Arial",Font.PLAIN,10)); p.add(LowJTextField); rightSide.add(p); filler = new JPanel(); filler.setOpaque(false); pack(); setVisible(true); // If a prototype ParameterSet was passed, then build the empty graph // and labels. if (protoTypeParameterSet!=null) setLinesAndLabels(protoTypeParameterSet); LabelWindow = new JWindow(); } /** @param ParameterSet ps @author WJS */ public void addParameterSet(ParameterSet ps, String name, Color color, float score) { // Check to see if this is the first parameter set if (XRays==null) { setLinesAndLabels(ps); ThePaintPanel.paintOffScreen(true,false,0); } // Go through the parameter set and build the polygon representation Polygon p = new Polygon(); float l; float u; float v; double z=0; int m; int n = ps.getNumParams(); double wedge = 2*Math.PI/(double)n; double theta = 0; double r = (OUTER_CIRCLE-INNER_CIRCLE)/2d; for (int i=0;i