package genegui; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import javax.swing.*; public class SingleCellSelector extends JFrame { /** The Index of the cell that is presently selected */ private int CellIndex = -1; /** Preferred dimension for the CellPaintPanel */ private Dimension CellPaintPanelDimension; /** Stores the base cell shapes and locations */ private Polygon[] CellShapeArray; /** ActionListener to send notification of cell selection to */ private ActionListener Listener; /** The scale at which to draw the cell shape objects */ private double Scale = 5.0; /** Pointer to models default ModelState */ private ModelState TheModelState; /** Translation for drawing of cells */ private Point Translation = new Point(5,5); /** Constructor @param ModelState theModelState - Model state from which to draw model information. @param int cellIndex - The index of the currently selected cell (or -1 if none). @param ActionListener listener - ActionListener to which to report selection events. @author WJS */ public SingleCellSelector(ModelState theModelState, int cellIndex, ActionListener listener) { super("Select a cell"); setResizable(false); TheModelState = theModelState; CellIndex = cellIndex; Listener = listener; // Build the cell shape array for use by paint panels CellShapeArray = new Polygon[TheModelState.getNumberOfCells()]; Polygon p; Polygon q; for (int i=0;imaxX) maxX = rect.getX()+rect.getWidth(); if ((rect.getY()+rect.getHeight())>maxY) maxY = rect.getY()+rect.getHeight(); } CellPaintPanelDimension = new Dimension((int)maxX+20,(int)maxY+4); JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BorderLayout()); CellPaintPanel cellPaintPanel = new CellPaintPanel(); mainPanel.add(cellPaintPanel,BorderLayout.CENTER); setContentPane(mainPanel); // Add a window listener to capture closing events. addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ae) { close(); } }); pack(); setVisible(true); } /** Called to properly close the cell selection window @autthor WJS */ public void close() { dispose(); } /** Find the cell which contains point p. This is implemented in a slower but more general way to allow for different/multiple cells shapes and cell positions. It searche through the list of cell shapes and uses the contains method to identify the cell. @param Point p - A point in the ModelStateViewPane. @return int - The index of the cell or -1 if the point is not in a cell. @author WJS */ private int findCellAt(Point p) { for (int i=0;i