DefaultRGBChooserPanelpublic class DefaultRGBChooserPanel extends AbstractColorChooserPanel implements ChangeListenerThe standard RGB chooser.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans package.
Please see {@link java.beans.XMLEncoder}. |
Fields Summary |
---|
protected JSlider | redSlider | protected JSlider | greenSlider | protected JSlider | blueSlider | protected JSpinner | redField | protected JSpinner | blueField | protected JSpinner | greenField | private final int | minValue | private final int | maxValue | private boolean | isAdjusting |
Constructors Summary |
---|
public DefaultRGBChooserPanel() // indicates the fields are being set internally
super();
setInheritsPopupMenu(true);
|
Methods Summary |
---|
protected void | buildChooser()
String redString = UIManager.getString("ColorChooser.rgbRedText");
String greenString = UIManager.getString("ColorChooser.rgbGreenText");
String blueString = UIManager.getString("ColorChooser.rgbBlueText");
setLayout( new BorderLayout() );
Color color = getColorFromModel();
JPanel enclosure = new JPanel();
enclosure.setLayout( new SmartGridLayout( 3, 3 ) );
enclosure.setInheritsPopupMenu(true);
// The panel that holds the sliders
add( enclosure, BorderLayout.CENTER );
// sliderPanel.setBorder(new LineBorder(Color.black));
// The row for the red value
JLabel l = new JLabel(redString);
l.setDisplayedMnemonic(AbstractColorChooserPanel.getInt("ColorChooser.rgbRedMnemonic", -1));
enclosure.add(l);
redSlider = new JSlider(JSlider.HORIZONTAL, 0, 255, color.getRed());
redSlider.setMajorTickSpacing( 85 );
redSlider.setMinorTickSpacing( 17 );
redSlider.setPaintTicks( true );
redSlider.setPaintLabels( true );
redSlider.setInheritsPopupMenu(true);
enclosure.add( redSlider );
redField = new JSpinner(
new SpinnerNumberModel(color.getRed(), minValue, maxValue, 1));
l.setLabelFor(redSlider);
redField.setInheritsPopupMenu(true);
JPanel redFieldHolder = new JPanel(new CenterLayout());
redFieldHolder.setInheritsPopupMenu(true);
redField.addChangeListener(this);
redFieldHolder.add(redField);
enclosure.add(redFieldHolder);
// The row for the green value
l = new JLabel(greenString);
l.setDisplayedMnemonic(AbstractColorChooserPanel.getInt("ColorChooser.rgbGreenMnemonic", -1));
enclosure.add(l);
greenSlider = new JSlider(JSlider.HORIZONTAL, 0, 255, color.getGreen());
greenSlider.setMajorTickSpacing( 85 );
greenSlider.setMinorTickSpacing( 17 );
greenSlider.setPaintTicks( true );
greenSlider.setPaintLabels( true );
greenSlider.setInheritsPopupMenu(true);
enclosure.add(greenSlider);
greenField = new JSpinner(
new SpinnerNumberModel(color.getGreen(), minValue, maxValue, 1));
l.setLabelFor(greenSlider);
greenField.setInheritsPopupMenu(true);
JPanel greenFieldHolder = new JPanel(new CenterLayout());
greenFieldHolder.add(greenField);
greenFieldHolder.setInheritsPopupMenu(true);
greenField.addChangeListener(this);
enclosure.add(greenFieldHolder);
// The slider for the blue value
l = new JLabel(blueString);
l.setDisplayedMnemonic(AbstractColorChooserPanel.getInt("ColorChooser.rgbBlueMnemonic", -1));
enclosure.add(l);
blueSlider = new JSlider(JSlider.HORIZONTAL, 0, 255, color.getBlue());
blueSlider.setMajorTickSpacing( 85 );
blueSlider.setMinorTickSpacing( 17 );
blueSlider.setPaintTicks( true );
blueSlider.setPaintLabels( true );
blueSlider.setInheritsPopupMenu(true);
enclosure.add(blueSlider);
blueField = new JSpinner(
new SpinnerNumberModel(color.getBlue(), minValue, maxValue, 1));
l.setLabelFor(blueSlider);
blueField.setInheritsPopupMenu(true);
JPanel blueFieldHolder = new JPanel(new CenterLayout());
blueFieldHolder.add(blueField);
blueField.addChangeListener(this);
blueFieldHolder.setInheritsPopupMenu(true);
enclosure.add(blueFieldHolder);
redSlider.addChangeListener( this );
greenSlider.addChangeListener( this );
blueSlider.addChangeListener( this );
redSlider.putClientProperty("JSlider.isFilled", Boolean.TRUE);
greenSlider.putClientProperty("JSlider.isFilled", Boolean.TRUE);
blueSlider.putClientProperty("JSlider.isFilled", Boolean.TRUE);
| public java.lang.String | getDisplayName()
return UIManager.getString("ColorChooser.rgbNameText");
| public int | getDisplayedMnemonicIndex()Provides a hint to the look and feel as to the index of the character in
getDisplayName that should be visually identified as the
mnemonic. The look and feel should only use this if
getMnemonic returns a value > 0.
The return value here is a hint, it is ultimately up to the look
and feel to honor the return value in some meaningful way. For example,
a look and feel may wish to render each
AbstractColorChooserPanel in a JTabbedPane ,
and further use this return value to underline a character in
the getDisplayName .
This implementation looks up the value from the default
ColorChooser.rgbDisplayedMnemonicIndex , or if it
isn't available (or not an Integer ) returns -1.
The lookup for the default is done through the UIManager :
UIManager.get("ColorChooser.rgbDisplayedMnemonicIndex"); .
return getInt("ColorChooser.rgbDisplayedMnemonicIndex", -1);
| public javax.swing.Icon | getLargeDisplayIcon()
return null;
| public int | getMnemonic()Provides a hint to the look and feel as to the
KeyEvent.VK constant that can be used as a mnemonic to
access the panel. A return value <= 0 indicates there is no mnemonic.
The return value here is a hint, it is ultimately up to the look
and feel to honor the return value in some meaningful way.
This implementation looks up the value from the default
ColorChooser.rgbMnemonic , or if it
isn't available (or not an Integer ) returns -1.
The lookup for the default is done through the UIManager :
UIManager.get("ColorChooser.rgbMnemonic"); .
return getInt("ColorChooser.rgbMnemonic", -1);
| public javax.swing.Icon | getSmallDisplayIcon()
return null;
| public void | installChooserPanel(javax.swing.JColorChooser enclosingChooser)The background color, foreground color, and font are already set to the
defaults from the defaults table before this method is called.
super.installChooserPanel(enclosingChooser);
| private void | setColor(java.awt.Color newColor)Sets the values of the controls to reflect the color
int red = newColor.getRed();
int blue = newColor.getBlue();
int green = newColor.getGreen();
if (redSlider.getValue() != red) {
redSlider.setValue(red);
}
if (greenSlider.getValue() != green) {
greenSlider.setValue(green);
}
if (blueSlider.getValue() != blue) {
blueSlider.setValue(blue);
}
if (((Integer)redField.getValue()).intValue() != red)
redField.setValue(new Integer(red));
if (((Integer)greenField.getValue()).intValue() != green)
greenField.setValue(new Integer(green));
if (((Integer)blueField.getValue()).intValue() != blue )
blueField.setValue(new Integer(blue));
| public void | stateChanged(javax.swing.event.ChangeEvent e)
if ( e.getSource() instanceof JSlider && !isAdjusting) {
int red = redSlider.getValue();
int green = greenSlider.getValue();
int blue = blueSlider.getValue() ;
Color color = new Color (red, green, blue);
getColorSelectionModel().setSelectedColor(color);
} else if (e.getSource() instanceof JSpinner && !isAdjusting) {
int red = ((Integer)redField.getValue()).intValue();
int green = ((Integer)greenField.getValue()).intValue();
int blue = ((Integer)blueField.getValue()).intValue();
Color color = new Color (red, green, blue);
getColorSelectionModel().setSelectedColor(color);
}
| public void | uninstallChooserPanel(javax.swing.JColorChooser enclosingChooser)
super.uninstallChooserPanel(enclosingChooser);
removeAll();
| public void | updateChooser()
if (!isAdjusting) {
isAdjusting = true;
setColor(getColorFromModel());
isAdjusting = false;
}
|
|