/** * A ChoicePanel is a list of ChoiceChecks (see ChoiceCheck.java), each * of which has a color that can be edited. The background of all the * ChoiceCheck boxes should be that of the bgColor ChoiceCheck. The * text of all the other ChoiceChecks should be the chosen color for * that ChoiceCheck. * * A bug in Java prevents the background of a ChoiceCheck from being * chosen unless that checkbox is checked. So whenever bgColor is set, * we walk through all the ChoiceChecks and check them, then recheck * the bgColor. * * Whatever class is actually manipulating colors doesn't know about * ChoicePanels. It knows about the UseColor interface, and it is * handed this class as a UseColor, so that's how this gets notified * when colors are chosen. */ import java.awt.*; final class ChoicePanel extends Panel implements UseColor { final int MAXCHOICES = 7; int numchoices; /* number of choices the user actually asked for */ int which; /* which color is being chosen now */ ColorApplet a; String colors[]; /* colors chosen */ String names[]; /* names of choices */ ChoiceCheck checks[]; /* checkboxes */ ChoicePanel(ColorApplet a, int width, int height) { this.a = a; which = 0; colors = new String[MAXCHOICES]; names = new String[MAXCHOICES]; checks = new ChoiceCheck[MAXCHOICES]; resize(width, height); } void init() { CheckboxGroup cbg = new CheckboxGroup(); setBackground(Color.white); setLayout(new GridLayout(0, 1)); for (numchoices = 0; names[numchoices] != null; ++numchoices) { if (colors[numchoices] == null) colors[numchoices] = (names[numchoices].equals("bgColor")) ? "ffffff" : "808080"; checks[numchoices] = new ChoiceCheck( names[numchoices], cbg, (numchoices==0), numchoices, this); add(checks[numchoices]); } } void setcolors() { if (names[which].equals("bgColor")) { Color nc = ColorApplet.s2c(colors[which]); setBackground(nc); if ((nc.getRGB() & 0x808080) != 0) { checks[which].setForeground(Color.black); } else { checks[which].setForeground(Color.white); } for (int j=0; j