FileDocCategorySizeDatePackage
BasicColorChooserUI.javaAPI DocJava SE 5 API10889Fri Aug 26 14:58:02 BST 2005javax.swing.plaf.basic

BasicColorChooserUI

public class BasicColorChooserUI extends ColorChooserUI
Provides the basic look and feel for a JColorChooser.

version
1.46 12/19/03
author
Tom Santos
author
Steve Wilson

Fields Summary
protected JColorChooser
chooser
JColorChooser this BasicColorChooserUI is installed on.
JTabbedPane
tabbedPane
JPanel
singlePanel
JPanel
previewPanelHolder
JComponent
previewPanel
boolean
isMultiPanel
private static TransferHandler
defaultTransferHandler
protected AbstractColorChooserPanel[]
defaultChoosers
protected ChangeListener
previewListener
protected PropertyChangeListener
propertyChangeListener
private Handler
handler
Constructors Summary
Methods Summary
protected javax.swing.colorchooser.AbstractColorChooserPanel[]createDefaultChoosers()

        AbstractColorChooserPanel[] panels = ColorChooserComponentFactory.getDefaultChooserPanels();
	return panels;
    
protected java.beans.PropertyChangeListenercreatePropertyChangeListener()

        return getHandler();
    
public static javax.swing.plaf.ComponentUIcreateUI(javax.swing.JComponent c)


         
	return new BasicColorChooserUI();
    
private javax.swing.plaf.basic.BasicColorChooserUI$HandlergetHandler()

        if (handler == null) {
            handler = new Handler();
        }
        return handler;
    
protected voidinstallDefaults()

        LookAndFeel.installColorsAndFont(chooser, "ColorChooser.background", 
                                              "ColorChooser.foreground",
                                              "ColorChooser.font");
        LookAndFeel.installProperty(chooser, "opaque", Boolean.TRUE);
	TransferHandler th = chooser.getTransferHandler();
	if (th == null || th instanceof UIResource) {
	    chooser.setTransferHandler(defaultTransferHandler);
	}
    
protected voidinstallListeners()

        propertyChangeListener = createPropertyChangeListener();
	chooser.addPropertyChangeListener( propertyChangeListener );

	previewListener = getHandler();
	chooser.getSelectionModel().addChangeListener(previewListener);
    
protected voidinstallPreviewPanel()

	if (previewPanel != null) {
	    previewPanelHolder.remove(previewPanel);
	    previewPanel.removeMouseListener(getHandler());
	}

	previewPanel = chooser.getPreviewPanel();
        Dimension layoutSize = new Dimension(); // fix for bug 4759306
        if (previewPanel != null) {
            layoutSize = new BorderLayout().minimumLayoutSize(previewPanel);
            if ((previewPanelHolder != null) && (chooser != null) &&
            (layoutSize.getWidth() + layoutSize.getHeight() == 0)) {
              chooser.remove(previewPanelHolder);
              return;
            }
        }
	if (previewPanel == null || previewPanel instanceof UIResource) { 
	  previewPanel = ColorChooserComponentFactory.getPreviewPanel(); // get from table?
	    chooser.setPreviewPanel(previewPanel);
	}
	previewPanel.setForeground(chooser.getColor());
	previewPanelHolder.add(previewPanel);
	previewPanel.addMouseListener(getHandler());
    
public voidinstallUI(javax.swing.JComponent c)

        chooser = (JColorChooser)c;

        super.installUI( c );

	installDefaults();
	installListeners();

	tabbedPane = new JTabbedPane();
        tabbedPane.setName("ColorChooser.tabPane");
	singlePanel = new JPanel(new CenterLayout());
        singlePanel.setName("ColorChooser.panel");

	chooser.setLayout( new BorderLayout() );

	defaultChoosers = createDefaultChoosers();
	chooser.setChooserPanels(defaultChoosers);

	previewPanelHolder = new JPanel(new CenterLayout());
        previewPanelHolder.setName("ColorChooser.previewPanelHolder");

        if (DefaultLookup.getBoolean(chooser, this,
                                  "ColorChooser.showPreviewPanelText", true)) {
            String previewString = UIManager.getString(
                "ColorChooser.previewText", chooser.getLocale());
            previewPanelHolder.setBorder(new TitledBorder(previewString));
        }
	chooser.add(previewPanelHolder, BorderLayout.SOUTH);

	installPreviewPanel();
	chooser.applyComponentOrientation(c.getComponentOrientation());
    
protected voiduninstallDefaultChoosers()

        AbstractColorChooserPanel[] choosers = chooser.getChooserPanels();
        for( int i = 0 ; i < choosers.length; i++) {
       	    chooser.removeChooserPanel( choosers[i] );
	}
    
protected voiduninstallDefaults()

	if (chooser.getTransferHandler() instanceof UIResource) {
	    chooser.setTransferHandler(null);
	}
    
protected voiduninstallListeners()

	chooser.removePropertyChangeListener( propertyChangeListener );
	chooser.getSelectionModel().removeChangeListener(previewListener);
	previewPanel.removeMouseListener(getHandler());
    
public voiduninstallUI(javax.swing.JComponent c)

	chooser.remove(tabbedPane);
	chooser.remove(singlePanel);
	chooser.remove(previewPanelHolder);

        uninstallDefaultChoosers();
	uninstallListeners();
	uninstallDefaults();

	previewPanelHolder.remove(previewPanel);
	if (previewPanel instanceof UIResource) {
	    chooser.setPreviewPanel(null);
	}

	previewPanelHolder = null;
	previewPanel = null;
	defaultChoosers = null;
	chooser = null;
	tabbedPane = null;

        handler = null;