/* * @(#)ColorSlidersChooser.java * * Copyright (c) 2005-2010 Werner Randelshofer, Immensee, Switzerland. * All rights reserved. * * You may not use, copy or modify this file, except in compliance with the * license agreement you entered into with Werner Randelshofer. * For details see accompanying license terms. */ package ch.randelshofer.quaqua.colorchooser; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.colorchooser.*; import javax.swing.plaf.*; /** * The ColorSlidersChooser contains four individual color slider pages: gray * slider, RGB sliders, CMYK sliders, and HTML sliders. * * @author Werner Randelshofer * @version $Id: ColorSlidersChooser.java 363 2010-11-21 17:41:04Z wrandelshofer $ */ public class ColorSlidersChooser extends AbstractColorChooserPanel implements UIResource { /** * We store here the name of the last selected color sliders panel. * When the ColorSlidersChooser is recreated multiple times in the same * panel, the application 'remembers' which panel the user had opened * before. */ private static int lastSelectedPanelIndex = 1; /** Creates new form. */ public ColorSlidersChooser() { } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() {//GEN-BEGIN:initComponents slidersComboBox = new javax.swing.JComboBox(); slidersHolder = new javax.swing.JPanel(); setLayout(new java.awt.BorderLayout()); add(slidersComboBox, java.awt.BorderLayout.NORTH); slidersHolder.setLayout(new java.awt.CardLayout()); add(slidersHolder, java.awt.BorderLayout.CENTER); }//GEN-END:initComponents protected void buildChooser() { initComponents(); slidersComboBox.setFont(UIManager.getFont("ColorChooser.font")); slidersHolder.add(new GrayChooser(),UIManager.getString("ColorChooser.grayScaleSlider")); slidersHolder.add(new RGBChooser(),UIManager.getString("ColorChooser.rgbSliders")); slidersHolder.add(new CMYKChooser(),UIManager.getString("ColorChooser.cmykSliders")); slidersHolder.add(new HSBChooser(),UIManager.getString("ColorChooser.hsbSliders")); slidersHolder.add(new HTMLChooser(),UIManager.getString("ColorChooser.htmlSliders")); DefaultComboBoxModel cbm = new DefaultComboBoxModel(); cbm.addElement(UIManager.getString("ColorChooser.grayScaleSlider")); cbm.addElement(UIManager.getString("ColorChooser.rgbSliders")); cbm.addElement(UIManager.getString("ColorChooser.cmykSliders")); cbm.addElement(UIManager.getString("ColorChooser.hsbSliders")); cbm.addElement(UIManager.getString("ColorChooser.htmlSliders")); slidersComboBox.setModel(cbm); slidersComboBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent evt) { if (evt.getStateChange() == ItemEvent.SELECTED) { ((CardLayout) slidersHolder.getLayout()).show(slidersHolder, (String) evt.getItem()); lastSelectedPanelIndex = slidersComboBox.getSelectedIndex(); } } }); slidersComboBox.setSelectedIndex(lastSelectedPanelIndex); } public void installChooserPanel(JColorChooser enclosingChooser) { super.installChooserPanel(enclosingChooser); Component[] components = slidersHolder.getComponents(); for (int i=0; i < components.length; i++) { AbstractColorChooserPanel ccp = (AbstractColorChooserPanel) components[i]; ccp.installChooserPanel(enclosingChooser); } } /** * Invoked when the panel is removed from the chooser. * If override this, be sure to call <code>super</code>. */ public void uninstallChooserPanel(JColorChooser enclosingChooser) { Component[] components = slidersHolder.getComponents(); for (int i=0; i < components.length; i++) { AbstractColorChooserPanel ccp = (AbstractColorChooserPanel) components[i]; ccp.uninstallChooserPanel(enclosingChooser); } super.uninstallChooserPanel(enclosingChooser); } public String getDisplayName() { return UIManager.getString("ColorChooser.colorSliders"); } public Icon getLargeDisplayIcon() { return UIManager.getIcon("ColorChooser.colorSlidersIcon"); } public Icon getSmallDisplayIcon() { return getLargeDisplayIcon(); } public void updateChooser() { } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox slidersComboBox; private javax.swing.JPanel slidersHolder; // End of variables declaration//GEN-END:variables }