001/* AbstractColorChooserPanel.java -- 002 Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038 039package javax.swing.colorchooser; 040 041import java.awt.Color; 042import java.awt.Graphics; 043 044import javax.swing.Icon; 045import javax.swing.JColorChooser; 046import javax.swing.JPanel; 047 048/** 049 * AbstractColorChooserPanel 050 * 051 * @author Andrew Selkirk 052 * @version 1.0 053 */ 054public abstract class AbstractColorChooserPanel extends JPanel 055{ 056 /** DOCUMENT ME! */ 057 private static final long serialVersionUID = -977469671210173863L; 058 059 /** The chooser associated with this panel. */ 060 private JColorChooser chooser; 061 062 /** 063 * This is the constructor for the AbstractColorChooserPanel. 064 */ 065 public AbstractColorChooserPanel() 066 { 067 // Nothing to do here. 068 } 069 070 /** 071 * This method returns the name displayed in the tab for this chooser panel. 072 * 073 * @return The name displayed in the JTabbedPane's tabs. 074 */ 075 public abstract String getDisplayName(); 076 077 /** 078 * Returns the key code for the mnemonic for this panel. This method returns 079 * zero to indicate no mnemonic, subclasses can override this. 080 * 081 * @return <code>0</code>, to indicate no mnemonic key code. 082 * 083 * @see #getDisplayedMnemonicIndex() 084 * @since 1.4 085 */ 086 public int getMnemonic() 087 { 088 return 0; 089 } 090 091 /** 092 * Returns the index of the character in the display name that is the 093 * mnemonic. This method returns <code>-1</code> to indicate no mnemonic, 094 * subclasses can override. 095 * 096 * @return <code>-1</code>, to indicate no mnemonic. 097 * 098 * @see #getDisplayName() 099 * @see #getMnemonic() 100 * @since 1.4 101 */ 102 public int getDisplayedMnemonicIndex() 103 { 104 return -1; 105 } 106 107 /** 108 * This method updates the chooser panel when the JColorChooser's color has 109 * changed. 110 */ 111 public abstract void updateChooser(); 112 113 /** 114 * This method constructs and does any initialization necessary for the 115 * chooser panel. 116 */ 117 protected abstract void buildChooser(); 118 119 /** 120 * This method sets the small icon used in the JTabbedPane for this chooser 121 * panel. 122 * 123 * @return The small icon used in the JTabbedPane. 124 */ 125 public abstract Icon getSmallDisplayIcon(); 126 127 /** 128 * This method sets the large icon useed in the jTabbedPane for this chooser 129 * panel. 130 * 131 * @return The large icon. 132 */ 133 public abstract Icon getLargeDisplayIcon(); 134 135 /** 136 * This method installs the chooser panel for the given JColorChooser. 137 * 138 * @param chooser The JColorChooser that will have this panel installed. 139 */ 140 public void installChooserPanel(JColorChooser chooser) 141 { 142 this.chooser = chooser; 143 buildChooser(); 144 } // installChooserPanel() 145 146 /** 147 * This method removes the chooser panel from the given JColorChooser and 148 * does any necessary clean up for the chooser panel. 149 * 150 * @param chooser The JColorChooser that is having this panel removed. 151 */ 152 public void uninstallChooserPanel(JColorChooser chooser) 153 { 154 this.chooser = null; 155 } // uninstallChooserPanel() 156 157 /** 158 * This method returns the ColorSelectionModel for the JColorChooser 159 * associated with this chooser panel. 160 * 161 * @return The ColorSelectionModel for the JColorChooser associated with 162 * this chooser panel. 163 */ 164 public ColorSelectionModel getColorSelectionModel() 165 { 166 if (chooser != null) 167 return chooser.getSelectionModel(); 168 return null; 169 } // getColorSelectionModel() 170 171 /** 172 * This method returns the current color stored in the model for this 173 * chooser panel. 174 * 175 * @return The current color. 176 */ 177 protected Color getColorFromModel() 178 { 179 if (chooser != null) 180 return chooser.getColor(); 181 return null; 182 } // getColorFromModel() 183 184 /** 185 * This method paints the chooser panel. 186 * 187 * @param graphics The Graphics object to paint with. 188 */ 189 public void paint(Graphics graphics) 190 { 191 super.paint(graphics); 192 } // paint() 193} // AbstractColorChooserPanel