package genegui; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; /** ModelStateToolBox.java @author WJS */ public class ModelStateToolBox extends JPanel { /** */ public static final int MODE_SELECT = 0; public static final int MODE_MARQUEE = 1; public static final int MODE_APPLY = 2; public static final int MODE_GRADIENT = 3; public static final int MODE_STRIPE = 4; public static final int MODE_MAGNIFY = 5; /** The mode (which tool is selected) */ private int Mode = MODE_SELECT; /** The Select tool toggle button */ private JToggleButton ButtonSelect; /** The Marquee tool toggle button */ private JToggleButton ButtonMarquee; /** The Apply tool toggle button */ private JToggleButton ButtonApply; /** The Gradient tool toggle button */ private JToggleButton ButtonGradient; /** The Stripe tool toggle button */ private JToggleButton ButtonStripe; /** The Magnify tool toggle button */ private JToggleButton ButtonMagnify; /** The difference between the mouse pointer and UL of the control area for window drag operations */ private Point DragOffset; /** Simple constructor. */ public ModelStateToolBox() { super(); // Make the MainPanel that is the contentPane for the window setLayout(null); setBorder(BorderFactory.createMatteBorder(1,1,2,2,Color.black)); setBackground(Color.lightGray); // Make a button group for all the toggle buttons ButtonGroup g = new ButtonGroup(); // Make a Control area for dragging around the window JPanel controlArea = new JPanel(); controlArea.setBackground(Color.gray); controlArea.setSize(36,20); controlArea.setLocation(1,1); // Create mouse and mouse motion listeners for allowing the window to be // dragged. addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) { DragOffset = me.getPoint(); } public void mouseReleased(MouseEvent me) { } }); addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent me) { Point p = getLocation(); setLocation(p.x+me.getX()-DragOffset.x,p.y+me.getY()-DragOffset.y); } }); add(controlArea); // Defaulty dimension for all buttons Dimension d = new Dimension(36,24); // Select icon ButtonSelect = new JToggleButton(new ImageIcon("icons/MSTBSelect.gif")); ButtonSelect.setSelectedIcon(new ImageIcon("icons/MSTBSelectSelected.gif")); ButtonSelect.setToolTipText("Select individual cells"); ButtonSelect.setSize(d); ButtonSelect.setLocation(0,22); ButtonSelect.setContentAreaFilled(false); ButtonSelect.setBorderPainted(false); ButtonSelect.setFocusPainted(false); ButtonSelect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { Mode = MODE_SELECT; } }); g.add(ButtonSelect); add(ButtonSelect); // Marquee icon ButtonMarquee = new JToggleButton(new ImageIcon("icons/MSTBMarquee.gif")); ButtonMarquee.setSelectedIcon(new ImageIcon("icons/MSTBMarqueeSelected.gif")); ButtonMarquee.setToolTipText("Selects multiple cells"); ButtonMarquee.setSize(d); ButtonMarquee.setLocation(0,46); ButtonMarquee.setContentAreaFilled(false); ButtonMarquee.setBorderPainted(false); ButtonMarquee.setFocusPainted(false); ButtonMarquee.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { Mode = MODE_MARQUEE; } }); g.add(ButtonMarquee); add(ButtonMarquee); // Apply settings icon ButtonApply = new JToggleButton(new ImageIcon("icons/MSTBApply.gif")); ButtonApply.setSelectedIcon(new ImageIcon("icons/MSTBApplySelected.gif")); ButtonApply.setToolTipText("Applies current values to cells"); ButtonApply.setSize(d); ButtonApply.setLocation(0,70); ButtonApply.setContentAreaFilled(false); ButtonApply.setBorderPainted(false); ButtonApply.setFocusPainted(false); ButtonApply.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { Mode = MODE_APPLY; } }); g.add(ButtonApply); add(ButtonApply); // Gradient icon ButtonGradient = new JToggleButton(new ImageIcon("icons/MSTBGradient.gif")); ButtonGradient.setSelectedIcon(new ImageIcon("icons/MSTBGradientSelected.gif")); ButtonGradient.setToolTipText("Applies gradient of a node values across multiple cells"); ButtonGradient.setSize(d); ButtonGradient.setLocation(0,94); ButtonGradient.setContentAreaFilled(false); ButtonGradient.setBorderPainted(false); ButtonGradient.setFocusPainted(false); ButtonGradient.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { Mode = MODE_GRADIENT; } }); g.add(ButtonGradient); add(ButtonGradient); // Strip icon ButtonStripe = new JToggleButton(new ImageIcon("icons/MSTBStripe.gif")); ButtonStripe.setSelectedIcon(new ImageIcon("icons/MSTBStripeSelected.gif")); ButtonStripe.setToolTipText("Applies alternating stripe of a node value across multiple cells"); ButtonStripe.setSize(d); ButtonStripe.setLocation(0,118); ButtonStripe.setContentAreaFilled(false); ButtonStripe.setBorderPainted(false); ButtonStripe.setFocusPainted(false); ButtonStripe.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { Mode = MODE_STRIPE; } }); g.add(ButtonStripe); add(ButtonStripe); // Magnify icon ButtonMagnify = new JToggleButton(new ImageIcon("icons/MSTBMagnify.gif")); ButtonMagnify.setSelectedIcon(new ImageIcon("icons/MSTBMagnifySelected.gif")); ButtonMagnify.setToolTipText("Magnifies cell view"); ButtonMagnify.setSize(d); ButtonMagnify.setLocation(0,142); ButtonMagnify.setContentAreaFilled(false); ButtonMagnify.setBorderPainted(false); ButtonMagnify.setFocusPainted(false); ButtonMagnify.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { Mode = MODE_MAGNIFY; } }); g.add(ButtonMagnify); add(ButtonMagnify); setSize(39,169); setVisible(true); ButtonSelect.setSelected(true); } /** Gets the current mode (which tool is selected). @return int mode - The currently selected tool. @author WJS */ public int getMode() { return(Mode); } }