// Controls.java // S. Tanimoto 1 Feb. 2000 import java.awt.*; import java.awt.event.*; import java.util.*; public class Controls extends Panel { private PolyDraw pd; int lineThickness; int gridSpacing; boolean useGrid; Checkbox useGridCB; Valuator gridSpacingValuator, redValuator, greenValuator, blueValuator; public int getGridSpacing() { return gridSpacingValuator.getValue(); } public boolean usingGrid() { return useGrid; } public Color getColor() { return new Color(redValuator.getValue(), greenValuator.getValue(), blueValuator.getValue()); } Controls(PolyDraw thePD) { pd = thePD; setBackground(Color.gray); useGridCB = new Checkbox(); useGridCB.addItemListener(new UseGridCBHandler()); GridBagLayout gbl = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); setLayout(gbl); gbc.gridx = 1; gbc.gridy = 1; gbc.gridwidth = 2; Label l1 = new Label("Use grid"); gbl.setConstraints(l1, gbc); add(l1); gbc.gridx = 1; gbc.gridy = 2; gbc.gridwidth = 2; gbl.setConstraints(useGridCB, gbc); add(useGridCB); gridSpacingValuator = new Valuator("Grid spacing", 10, 50, Color.white); gbc.gridx = 1; gbc.gridy = 3; gbc.gridwidth = 2; gbl.setConstraints(gridSpacingValuator, gbc); add(gridSpacingValuator); redValuator = new Valuator("Red", 64, 256, Color.red); gbc.gridx = 1; gbc.gridy = 4; gbc.gridwidth = 2; gbl.setConstraints(redValuator, gbc); add(redValuator); greenValuator = new Valuator("Green", 64, 256, Color.green); gbc.gridx = 1; gbc.gridy = 5; gbc.gridwidth = 2; gbl.setConstraints(greenValuator, gbc); add(greenValuator); blueValuator = new Valuator("Blue", 64, 256, Color.blue); gbc.gridx = 1; gbc.gridy = 6; gbc.gridwidth = 2; gbl.setConstraints(blueValuator, gbc); add(blueValuator); lineThickness = 2; gridSpacing = 10; useGrid = false; } class UseGridCBHandler implements ItemListener { public void itemStateChanged(ItemEvent e) { useGrid = useGridCB.getState(); } } }