if (selectedButtons != null)
{
JButton button = null;
- for (int i = 0; i < selectedButtons.size(); i++)
+ for (int i = 0; i < selectedButtons.size(); i++)
{
button = (JButton) selectedButtons.elementAt(i);
button.setBackground(colorChooser.getColor());
- button.setForeground(button.getBackground().brighter().brighter()
- .brighter());
+ button.setForeground(brighterThan(button.getBackground()));
}
if (button == lcaseColour)
{
{
button = (JButton) lowerCaseButtons.elementAt(i);
button.setBackground(colorChooser.getColor());
- button.setForeground(button.getBackground().brighter().brighter()
- .brighter());
+ button.setForeground(brighterThan(button.getBackground()));
}
}
}
JButton button = (JButton) buttonPanel.getComponent(b);
if (!selectedButtons.contains(button))
{
- button.setForeground(button.getBackground().brighter().brighter());
+ button.setForeground(brighterThan(button.getBackground()));
selectedButtons.add(button);
}
}
for (int b = 0; b < selectedButtons.size(); b++)
{
JButton button = (JButton) selectedButtons.elementAt(b);
- button.setForeground(button.getBackground().darker().darker());
+ button.setForeground(darkerThan(button.getBackground()));
}
selectedButtons.clear();
- pressed.setForeground(pressed.getBackground().brighter().brighter());
+ pressed.setForeground(brighterThan(pressed.getBackground()));
selectedButtons.addElement(pressed);
}
{
if (selectedButtons.contains(pressed))
{
- pressed.setForeground(pressed.getBackground().darker().darker());
+ pressed.setForeground(darkerThan(pressed.getBackground()));
selectedButtons.remove(pressed);
}
else
{
- pressed.setForeground(pressed.getBackground().brighter().brighter());
+ pressed.setForeground(brighterThan(pressed.getBackground()));
selectedButtons.addElement(pressed);
}
}
button.setOpaque(true); // required for the next line to have effect
button.setBackground(col);
button.setText(label);
- button.setForeground(col.darker().darker().darker());
+ button.setForeground(darkerThan(col));
button.setFont(new java.awt.Font("Verdana", Font.BOLD, 10));
return button;
}
/**
+ * Returns a colour three shades darker.
+ *
+ * We use darker text to indicate unselected buttons, lighter text for selected.
+ * @param col
+ * @return
+ */
+ public static Color darkerThan(Color col) {
+ return col.darker().darker().darker();
+ }
+
+ /**
+ * Returns a colour three shades brighter.
+ *
+ * We use darker text to indicate unselected buttons, lighter text for selected.
+ * @param col
+ * @return
+ */
+ public static Color brighterThan(Color col) {
+ return col.brighter().brighter().brighter();
+ }
+
+ /**
* DOCUMENT ME!
*
* @param e