FileDocCategorySizeDatePackage
DefaultSwatchChooserPanel.javaAPI DocJava SE 6 API15322Tue Jun 10 00:26:42 BST 2008javax.swing.colorchooser

DefaultSwatchChooserPanel

public class DefaultSwatchChooserPanel extends AbstractColorChooserPanel
The standard color swatch 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}.

version
1.34 11/17/05
author
Steve Wilson

Fields Summary
SwatchPanel
swatchPanel
RecentSwatchPanel
recentSwatchPanel
MouseListener
mainSwatchListener
MouseListener
recentSwatchListener
private static String
recentStr
Constructors Summary
public DefaultSwatchChooserPanel()


      
        super();
        setInheritsPopupMenu(true);
    
Methods Summary
protected voidbuildChooser()

      
        GridBagLayout gb = new GridBagLayout();
        GridBagConstraints gbc = new GridBagConstraints();
        JPanel superHolder = new JPanel(gb);

        swatchPanel =  new MainSwatchPanel();
        swatchPanel.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY,
                                      getDisplayName());
        swatchPanel.setInheritsPopupMenu(true);

	recentSwatchPanel = new RecentSwatchPanel();
        recentSwatchPanel.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY,
                                            recentStr);

	mainSwatchListener = new MainSwatchListener();
	swatchPanel.addMouseListener(mainSwatchListener);
	recentSwatchListener = new RecentSwatchListener();
	recentSwatchPanel.addMouseListener(recentSwatchListener);

        JPanel mainHolder = new JPanel(new BorderLayout());
	Border border = new CompoundBorder( new LineBorder(Color.black),
					    new LineBorder(Color.white) );
        mainHolder.setBorder(border);
        mainHolder.add(swatchPanel, BorderLayout.CENTER);
        
        gbc.anchor = GridBagConstraints.LAST_LINE_START;
        gbc.gridwidth = 1;
        gbc.gridheight = 2;
        Insets oldInsets = gbc.insets;
        gbc.insets = new Insets(0, 0, 0, 10);
        superHolder.add(mainHolder, gbc);
        gbc.insets = oldInsets;

	recentSwatchPanel.addMouseListener(recentSwatchListener);
        recentSwatchPanel.setInheritsPopupMenu(true);
        JPanel recentHolder = new JPanel( new BorderLayout() );
        recentHolder.setBorder(border);
        recentHolder.setInheritsPopupMenu(true);
        recentHolder.add(recentSwatchPanel, BorderLayout.CENTER);

	JLabel l = new JLabel(recentStr);
	l.setLabelFor(recentSwatchPanel);

        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.gridheight = 1;
        gbc.weighty = 1.0;
	superHolder.add(l, gbc);
        
        gbc.weighty = 0;
        gbc.gridheight = GridBagConstraints.REMAINDER;
        gbc.insets = new Insets(0, 0, 0, 2);
        superHolder.add(recentHolder, gbc);
        superHolder.setInheritsPopupMenu(true);

	add(superHolder);
    
public java.lang.StringgetDisplayName()

        return UIManager.getString("ColorChooser.swatchesNameText");
    
public intgetDisplayedMnemonicIndex()
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.swatchesDisplayedMnemonicIndex");.

return
Character index to render mnemonic for; -1 to provide no visual identifier for this panel.
see
#getMnemonic
since
1.4

        return getInt("ColorChooser.swatchesDisplayedMnemonicIndex", -1);
    
public javax.swing.IcongetLargeDisplayIcon()

        return null;
    
public intgetMnemonic()
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.swatchesMnemonic, 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.swatchesMnemonic");.

return
KeyEvent.VK constant identifying the mnemonic; <= 0 for no mnemonic
see
#getDisplayedMnemonicIndex
since
1.4

        return getInt("ColorChooser.swatchesMnemonic", -1);
    
public javax.swing.IcongetSmallDisplayIcon()

        return null;
    
public voidinstallChooserPanel(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);
    
public voiduninstallChooserPanel(javax.swing.JColorChooser enclosingChooser)

        super.uninstallChooserPanel(enclosingChooser);
	swatchPanel.removeMouseListener(mainSwatchListener);
	recentSwatchPanel.removeMouseListener(recentSwatchListener);
	swatchPanel = null;
	recentSwatchPanel = null;
	mainSwatchListener = null;
	recentSwatchListener = null;
	removeAll();  // strip out all the sub-components
    
public voidupdateChooser()