jdk/src/share/classes/javax/swing/JColorChooser.java

Print this page




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.swing;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;


  30 import java.io.*;
  31 import java.util.*;
  32 
  33 import javax.swing.colorchooser.*;
  34 import javax.swing.plaf.ColorChooserUI;
  35 import javax.accessibility.*;
  36 
  37 import sun.swing.SwingUtilities2;
  38 
  39 
  40 /**
  41  * <code>JColorChooser</code> provides a pane of controls designed to allow
  42  * a user to manipulate and select a color.
  43  * For information about using color choosers, see
  44  * <a
  45  href="http://docs.oracle.com/javase/tutorial/uiswing/components/colorchooser.html">How to Use Color Choosers</a>,
  46  * a section in <em>The Java Tutorial</em>.
  47  *
  48  * <p>
  49  *
  50  * This class provides three levels of API:
  51  * <ol>
  52  * <li>A static convenience method which shows a modal color-chooser
  53  * dialog and returns the color selected by the user.
  54  * <li>A static convenience method for creating a color-chooser dialog
  55  * where <code>ActionListeners</code> can be specified to be invoked when
  56  * the user presses one of the dialog buttons.
  57  * <li>The ability to create instances of <code>JColorChooser</code> panes
  58  * directly (within any container). <code>PropertyChange</code> listeners
  59  * can be added to detect when the current "color" property changes.
  60  * </ol>
  61  * <p>
  62  * <strong>Warning:</strong> Swing is not thread safe. For more
  63  * information see <a
  64  * href="package-summary.html#threading">Swing's Threading
  65  * Policy</a>.
  66  * <p>
  67  * <strong>Warning:</strong>
  68  * Serialized objects of this class will not be compatible with
  69  * future Swing releases. The current serialization support is
  70  * appropriate for short term storage or RMI between applications running
  71  * the same version of Swing.  As of 1.4, support for long term storage
  72  * of all JavaBeans&trade;
  73  * has been added to the <code>java.beans</code> package.
  74  * Please see {@link java.beans.XMLEncoder}.
  75  *
  76  *
  77  * @beaninfo
  78  *      attribute: isContainer false
  79  *    description: A component that supports selecting a Color.
  80  *
  81  *
  82  * @author James Gosling
  83  * @author Amy Fowler
  84  * @author Steve Wilson
  85  * @since 1.2
  86  */


  87 @SuppressWarnings("serial") // Same-version serialization only
  88 public class JColorChooser extends JComponent implements Accessible {
  89 
  90     /**
  91      * @see #getUIClassID
  92      * @see #readObject
  93      */
  94     private static final String uiClassID = "ColorChooserUI";
  95 
  96     private ColorSelectionModel selectionModel;
  97 
  98     private JComponent previewPanel = ColorChooserComponentFactory.getPreviewPanel();
  99 
 100     private AbstractColorChooserPanel[] chooserPanels = new AbstractColorChooserPanel[0];
 101 
 102     private boolean dragEnabled;
 103 
 104     /**
 105      * The selection model property name.
 106      */


 215         selectionModel = model;
 216         updateUI();
 217         dragEnabled = false;
 218     }
 219 
 220     /**
 221      * Returns the L&amp;F object that renders this component.
 222      *
 223      * @return the <code>ColorChooserUI</code> object that renders
 224      *          this component
 225      */
 226     public ColorChooserUI getUI() {
 227         return (ColorChooserUI)ui;
 228     }
 229 
 230     /**
 231      * Sets the L&amp;F object that renders this component.
 232      *
 233      * @param ui  the <code>ColorChooserUI</code> L&amp;F object
 234      * @see UIDefaults#getUI
 235      *
 236      * @beaninfo
 237      *       bound: true
 238      *      hidden: true
 239      * description: The UI object that implements the color chooser's LookAndFeel.
 240      */


 241     public void setUI(ColorChooserUI ui) {
 242         super.setUI(ui);
 243     }
 244 
 245     /**
 246      * Notification from the <code>UIManager</code> that the L&amp;F has changed.
 247      * Replaces the current UI object with the latest version from the
 248      * <code>UIManager</code>.
 249      *
 250      * @see JComponent#updateUI
 251      */
 252     public void updateUI() {
 253         setUI((ColorChooserUI)UIManager.getUI(this));
 254     }
 255 
 256     /**
 257      * Returns the name of the L&amp;F class that renders this component.
 258      *
 259      * @return the string "ColorChooserUI"
 260      * @see JComponent#getUIClassID
 261      * @see UIDefaults#getUI
 262      */

 263     public String getUIClassID() {
 264         return uiClassID;
 265     }
 266 
 267     /**
 268      * Gets the current color value from the color chooser.
 269      * By default, this delegates to the model.
 270      *
 271      * @return the current color value of the color chooser
 272      */
 273     public Color getColor() {
 274         return selectionModel.getSelectedColor();
 275     }
 276 
 277     /**
 278      * Sets the current color of the color chooser to the specified color.
 279      * The <code>ColorSelectionModel</code> will fire a <code>ChangeEvent</code>
 280      * @param color the color to be set in the color chooser
 281      * @see JComponent#addPropertyChangeListener
 282      *
 283      * @beaninfo
 284      *       bound: false
 285      *      hidden: false
 286      * description: The current color the chooser is to display.
 287      */


 288     public void setColor(Color color) {
 289         selectionModel.setSelectedColor(color);
 290 
 291     }
 292 
 293     /**
 294      * Sets the current color of the color chooser to the
 295      * specified RGB color.  Note that the values of red, green,
 296      * and blue should be between the numbers 0 and 255, inclusive.
 297      *
 298      * @param r   an int specifying the amount of Red
 299      * @param g   an int specifying the amount of Green
 300      * @param b   an int specifying the amount of Blue
 301      * @exception IllegalArgumentException if r,g,b values are out of range
 302      * @see java.awt.Color
 303      */
 304     public void setColor(int r, int g, int b) {
 305         setColor(new Color(r,g,b));
 306     }
 307 


 335      * most look and feels begin a drag-and-drop operation
 336      * when the user presses the mouse button over the preview panel.
 337      * Some look and feels might not support automatic drag and drop;
 338      * they will ignore this property.  You can work around such
 339      * look and feels by modifying the component
 340      * to directly call the <code>exportAsDrag</code> method of a
 341      * <code>TransferHandler</code>.
 342      *
 343      * @param b the value to set the <code>dragEnabled</code> property to
 344      * @exception HeadlessException if
 345      *            <code>b</code> is <code>true</code> and
 346      *            <code>GraphicsEnvironment.isHeadless()</code>
 347      *            returns <code>true</code>
 348      *
 349      * @since 1.4
 350      *
 351      * @see java.awt.GraphicsEnvironment#isHeadless
 352      * @see #getDragEnabled
 353      * @see #setTransferHandler
 354      * @see TransferHandler
 355      *
 356      * @beaninfo
 357      *  description: Determines whether automatic drag handling is enabled.
 358      *        bound: false
 359      */


 360     public void setDragEnabled(boolean b) {
 361         if (b && GraphicsEnvironment.isHeadless()) {
 362             throw new HeadlessException();
 363         }
 364         dragEnabled = b;
 365     }
 366 
 367     /**
 368      * Gets the value of the <code>dragEnabled</code> property.
 369      *
 370      * @return  the value of the <code>dragEnabled</code> property
 371      * @see #setDragEnabled
 372      * @since 1.4
 373      */
 374     public boolean getDragEnabled() {
 375         return dragEnabled;
 376     }
 377 
 378     /**
 379      * Sets the current preview panel.
 380      * This will fire a <code>PropertyChangeEvent</code> for the property
 381      * named "previewPanel".
 382      *
 383      * @param preview the <code>JComponent</code> which displays the current color
 384      * @see JComponent#addPropertyChangeListener
 385      *
 386      * @beaninfo
 387      *       bound: true
 388      *      hidden: true
 389      * description: The UI component which displays the current color.
 390      */


 391     public void setPreviewPanel(JComponent preview) {
 392 
 393         if (previewPanel != preview) {
 394             JComponent oldPreview = previewPanel;
 395             previewPanel = preview;
 396             firePropertyChange(JColorChooser.PREVIEW_PANEL_PROPERTY, oldPreview, preview);
 397         }
 398     }
 399 
 400     /**
 401      * Returns the preview panel that shows a chosen color.
 402      *
 403      * @return a <code>JComponent</code> object -- the preview panel
 404      */
 405     public JComponent getPreviewPanel() {
 406         return previewPanel;
 407     }
 408 
 409     /**
 410      * Adds a color chooser panel to the color chooser.


 450         else if (containedAt == 0) {  // at start
 451             System.arraycopy(chooserPanels, 1, newArray, 0, newArray.length);
 452         }
 453         else {  // in middle
 454             System.arraycopy(chooserPanels, 0, newArray, 0, containedAt);
 455             System.arraycopy(chooserPanels, containedAt+1,
 456                              newArray, containedAt, (chooserPanels.length - containedAt - 1));
 457         }
 458 
 459         setChooserPanels(newArray);
 460 
 461         return panel;
 462     }
 463 
 464 
 465     /**
 466      * Specifies the Color Panels used to choose a color value.
 467      *
 468      * @param panels  an array of <code>AbstractColorChooserPanel</code>
 469      *          objects
 470      *
 471      * @beaninfo
 472      *       bound: true
 473      *      hidden: true
 474      * description: An array of different chooser types.
 475      */


 476     public void setChooserPanels( AbstractColorChooserPanel[] panels) {
 477         AbstractColorChooserPanel[] oldValue = chooserPanels;
 478         chooserPanels = panels;
 479         firePropertyChange(CHOOSER_PANELS_PROPERTY, oldValue, panels);
 480     }
 481 
 482     /**
 483      * Returns the specified color panels.
 484      *
 485      * @return an array of <code>AbstractColorChooserPanel</code> objects
 486      */
 487     public AbstractColorChooserPanel[] getChooserPanels() {
 488         return chooserPanels;
 489     }
 490 
 491     /**
 492      * Returns the data model that handles color selections.
 493      *
 494      * @return a <code>ColorSelectionModel</code> object
 495      */
 496     public ColorSelectionModel getSelectionModel() {
 497         return selectionModel;
 498     }
 499 
 500 
 501     /**
 502      * Sets the model containing the selected color.
 503      *
 504      * @param newModel   the new <code>ColorSelectionModel</code> object
 505      *
 506      * @beaninfo
 507      *       bound: true
 508      *      hidden: true
 509      * description: The model which contains the currently selected color.
 510      */


 511     public void setSelectionModel(ColorSelectionModel newModel ) {
 512         ColorSelectionModel oldModel = selectionModel;
 513         selectionModel = newModel;
 514         firePropertyChange(JColorChooser.SELECTION_MODEL_PROPERTY, oldModel, newModel);
 515     }
 516 
 517 
 518     /**
 519      * See <code>readObject</code> and <code>writeObject</code> in
 520      * <code>JComponent</code> for more
 521      * information about serialization in Swing.
 522      */
 523     private void writeObject(ObjectOutputStream s) throws IOException {
 524         s.defaultWriteObject();
 525         if (getUIClassID().equals(uiClassID)) {
 526             byte count = JComponent.getWriteObjCounter(this);
 527             JComponent.setWriteObjCounter(this, --count);
 528             if (count == 0 && ui != null) {
 529                 ui.installUI(this);
 530             }


 554         return super.paramString() +
 555         ",chooserPanels=" + chooserPanelsString.toString() +
 556         ",previewPanel=" + previewPanelString;
 557     }
 558 
 559 /////////////////
 560 // Accessibility support
 561 ////////////////
 562 
 563     protected AccessibleContext accessibleContext = null;
 564 
 565     /**
 566      * Gets the AccessibleContext associated with this JColorChooser.
 567      * For color choosers, the AccessibleContext takes the form of an
 568      * AccessibleJColorChooser.
 569      * A new AccessibleJColorChooser instance is created if necessary.
 570      *
 571      * @return an AccessibleJColorChooser that serves as the
 572      *         AccessibleContext of this JColorChooser
 573      */

 574     public AccessibleContext getAccessibleContext() {
 575         if (accessibleContext == null) {
 576             accessibleContext = new AccessibleJColorChooser();
 577         }
 578         return accessibleContext;
 579     }
 580 
 581     /**
 582      * This class implements accessibility support for the
 583      * <code>JColorChooser</code> class.  It provides an implementation of the
 584      * Java Accessibility API appropriate to color chooser user-interface
 585      * elements.
 586      */
 587     protected class AccessibleJColorChooser extends AccessibleJComponent {
 588 
 589         /**
 590          * Get the role of this object.
 591          *
 592          * @return an instance of AccessibleRole describing the role of the
 593          * object




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */

  25 package javax.swing;
  26 
  27 import java.awt.*;
  28 import java.awt.event.*;
  29 import java.beans.JavaBean;
  30 import java.beans.BeanProperty;
  31 import java.io.*;
  32 import java.util.*;
  33 
  34 import javax.swing.colorchooser.*;
  35 import javax.swing.plaf.ColorChooserUI;
  36 import javax.accessibility.*;
  37 
  38 import sun.swing.SwingUtilities2;
  39 

  40 /**
  41  * <code>JColorChooser</code> provides a pane of controls designed to allow
  42  * a user to manipulate and select a color.
  43  * For information about using color choosers, see
  44  * <a
  45  href="http://docs.oracle.com/javase/tutorial/uiswing/components/colorchooser.html">How to Use Color Choosers</a>,
  46  * a section in <em>The Java Tutorial</em>.
  47  *
  48  * <p>
  49  *
  50  * This class provides three levels of API:
  51  * <ol>
  52  * <li>A static convenience method which shows a modal color-chooser
  53  * dialog and returns the color selected by the user.
  54  * <li>A static convenience method for creating a color-chooser dialog
  55  * where <code>ActionListeners</code> can be specified to be invoked when
  56  * the user presses one of the dialog buttons.
  57  * <li>The ability to create instances of <code>JColorChooser</code> panes
  58  * directly (within any container). <code>PropertyChange</code> listeners
  59  * can be added to detect when the current "color" property changes.
  60  * </ol>
  61  * <p>
  62  * <strong>Warning:</strong> Swing is not thread safe. For more
  63  * information see <a
  64  * href="package-summary.html#threading">Swing's Threading
  65  * Policy</a>.
  66  * <p>
  67  * <strong>Warning:</strong>
  68  * Serialized objects of this class will not be compatible with
  69  * future Swing releases. The current serialization support is
  70  * appropriate for short term storage or RMI between applications running
  71  * the same version of Swing.  As of 1.4, support for long term storage
  72  * of all JavaBeans&trade;
  73  * has been added to the <code>java.beans</code> package.
  74  * Please see {@link java.beans.XMLEncoder}.
  75  *






  76  * @author James Gosling
  77  * @author Amy Fowler
  78  * @author Steve Wilson
  79  * @since 1.2
  80  */
  81 @JavaBean(defaultProperty = "UI", description = "A component that supports selecting a Color.")
  82 @SwingContainer(false)
  83 @SuppressWarnings("serial") // Same-version serialization only
  84 public class JColorChooser extends JComponent implements Accessible {
  85 
  86     /**
  87      * @see #getUIClassID
  88      * @see #readObject
  89      */
  90     private static final String uiClassID = "ColorChooserUI";
  91 
  92     private ColorSelectionModel selectionModel;
  93 
  94     private JComponent previewPanel = ColorChooserComponentFactory.getPreviewPanel();
  95 
  96     private AbstractColorChooserPanel[] chooserPanels = new AbstractColorChooserPanel[0];
  97 
  98     private boolean dragEnabled;
  99 
 100     /**
 101      * The selection model property name.
 102      */


 211         selectionModel = model;
 212         updateUI();
 213         dragEnabled = false;
 214     }
 215 
 216     /**
 217      * Returns the L&amp;F object that renders this component.
 218      *
 219      * @return the <code>ColorChooserUI</code> object that renders
 220      *          this component
 221      */
 222     public ColorChooserUI getUI() {
 223         return (ColorChooserUI)ui;
 224     }
 225 
 226     /**
 227      * Sets the L&amp;F object that renders this component.
 228      *
 229      * @param ui  the <code>ColorChooserUI</code> L&amp;F object
 230      * @see UIDefaults#getUI





 231      */
 232     @BeanProperty(hidden = true, description
 233             = "The UI object that implements the color chooser's LookAndFeel.")
 234     public void setUI(ColorChooserUI ui) {
 235         super.setUI(ui);
 236     }
 237 
 238     /**
 239      * Notification from the <code>UIManager</code> that the L&amp;F has changed.
 240      * Replaces the current UI object with the latest version from the
 241      * <code>UIManager</code>.
 242      *
 243      * @see JComponent#updateUI
 244      */
 245     public void updateUI() {
 246         setUI((ColorChooserUI)UIManager.getUI(this));
 247     }
 248 
 249     /**
 250      * Returns the name of the L&amp;F class that renders this component.
 251      *
 252      * @return the string "ColorChooserUI"
 253      * @see JComponent#getUIClassID
 254      * @see UIDefaults#getUI
 255      */
 256     @BeanProperty(bound = false)
 257     public String getUIClassID() {
 258         return uiClassID;
 259     }
 260 
 261     /**
 262      * Gets the current color value from the color chooser.
 263      * By default, this delegates to the model.
 264      *
 265      * @return the current color value of the color chooser
 266      */
 267     public Color getColor() {
 268         return selectionModel.getSelectedColor();
 269     }
 270 
 271     /**
 272      * Sets the current color of the color chooser to the specified color.
 273      * The <code>ColorSelectionModel</code> will fire a <code>ChangeEvent</code>
 274      * @param color the color to be set in the color chooser
 275      * @see JComponent#addPropertyChangeListener





 276      */
 277     @BeanProperty(bound = false, description
 278             = "The current color the chooser is to display.")
 279     public void setColor(Color color) {
 280         selectionModel.setSelectedColor(color);
 281 
 282     }
 283 
 284     /**
 285      * Sets the current color of the color chooser to the
 286      * specified RGB color.  Note that the values of red, green,
 287      * and blue should be between the numbers 0 and 255, inclusive.
 288      *
 289      * @param r   an int specifying the amount of Red
 290      * @param g   an int specifying the amount of Green
 291      * @param b   an int specifying the amount of Blue
 292      * @exception IllegalArgumentException if r,g,b values are out of range
 293      * @see java.awt.Color
 294      */
 295     public void setColor(int r, int g, int b) {
 296         setColor(new Color(r,g,b));
 297     }
 298 


 326      * most look and feels begin a drag-and-drop operation
 327      * when the user presses the mouse button over the preview panel.
 328      * Some look and feels might not support automatic drag and drop;
 329      * they will ignore this property.  You can work around such
 330      * look and feels by modifying the component
 331      * to directly call the <code>exportAsDrag</code> method of a
 332      * <code>TransferHandler</code>.
 333      *
 334      * @param b the value to set the <code>dragEnabled</code> property to
 335      * @exception HeadlessException if
 336      *            <code>b</code> is <code>true</code> and
 337      *            <code>GraphicsEnvironment.isHeadless()</code>
 338      *            returns <code>true</code>
 339      *
 340      * @since 1.4
 341      *
 342      * @see java.awt.GraphicsEnvironment#isHeadless
 343      * @see #getDragEnabled
 344      * @see #setTransferHandler
 345      * @see TransferHandler




 346      */
 347     @BeanProperty(bound = false, description
 348             = "Determines whether automatic drag handling is enabled.")
 349     public void setDragEnabled(boolean b) {
 350         if (b && GraphicsEnvironment.isHeadless()) {
 351             throw new HeadlessException();
 352         }
 353         dragEnabled = b;
 354     }
 355 
 356     /**
 357      * Gets the value of the <code>dragEnabled</code> property.
 358      *
 359      * @return  the value of the <code>dragEnabled</code> property
 360      * @see #setDragEnabled
 361      * @since 1.4
 362      */
 363     public boolean getDragEnabled() {
 364         return dragEnabled;
 365     }
 366 
 367     /**
 368      * Sets the current preview panel.
 369      * This will fire a <code>PropertyChangeEvent</code> for the property
 370      * named "previewPanel".
 371      *
 372      * @param preview the <code>JComponent</code> which displays the current color
 373      * @see JComponent#addPropertyChangeListener





 374      */
 375     @BeanProperty(hidden = true, description
 376             = "The UI component which displays the current color.")
 377     public void setPreviewPanel(JComponent preview) {
 378 
 379         if (previewPanel != preview) {
 380             JComponent oldPreview = previewPanel;
 381             previewPanel = preview;
 382             firePropertyChange(JColorChooser.PREVIEW_PANEL_PROPERTY, oldPreview, preview);
 383         }
 384     }
 385 
 386     /**
 387      * Returns the preview panel that shows a chosen color.
 388      *
 389      * @return a <code>JComponent</code> object -- the preview panel
 390      */
 391     public JComponent getPreviewPanel() {
 392         return previewPanel;
 393     }
 394 
 395     /**
 396      * Adds a color chooser panel to the color chooser.


 436         else if (containedAt == 0) {  // at start
 437             System.arraycopy(chooserPanels, 1, newArray, 0, newArray.length);
 438         }
 439         else {  // in middle
 440             System.arraycopy(chooserPanels, 0, newArray, 0, containedAt);
 441             System.arraycopy(chooserPanels, containedAt+1,
 442                              newArray, containedAt, (chooserPanels.length - containedAt - 1));
 443         }
 444 
 445         setChooserPanels(newArray);
 446 
 447         return panel;
 448     }
 449 
 450 
 451     /**
 452      * Specifies the Color Panels used to choose a color value.
 453      *
 454      * @param panels  an array of <code>AbstractColorChooserPanel</code>
 455      *          objects





 456      */
 457     @BeanProperty(hidden = true, description
 458             = "An array of different chooser types.")
 459     public void setChooserPanels( AbstractColorChooserPanel[] panels) {
 460         AbstractColorChooserPanel[] oldValue = chooserPanels;
 461         chooserPanels = panels;
 462         firePropertyChange(CHOOSER_PANELS_PROPERTY, oldValue, panels);
 463     }
 464 
 465     /**
 466      * Returns the specified color panels.
 467      *
 468      * @return an array of <code>AbstractColorChooserPanel</code> objects
 469      */
 470     public AbstractColorChooserPanel[] getChooserPanels() {
 471         return chooserPanels;
 472     }
 473 
 474     /**
 475      * Returns the data model that handles color selections.
 476      *
 477      * @return a <code>ColorSelectionModel</code> object
 478      */
 479     public ColorSelectionModel getSelectionModel() {
 480         return selectionModel;
 481     }
 482 
 483 
 484     /**
 485      * Sets the model containing the selected color.
 486      *
 487      * @param newModel   the new <code>ColorSelectionModel</code> object





 488      */
 489     @BeanProperty(hidden = true, description
 490             = "The model which contains the currently selected color.")
 491     public void setSelectionModel(ColorSelectionModel newModel ) {
 492         ColorSelectionModel oldModel = selectionModel;
 493         selectionModel = newModel;
 494         firePropertyChange(JColorChooser.SELECTION_MODEL_PROPERTY, oldModel, newModel);
 495     }
 496 
 497 
 498     /**
 499      * See <code>readObject</code> and <code>writeObject</code> in
 500      * <code>JComponent</code> for more
 501      * information about serialization in Swing.
 502      */
 503     private void writeObject(ObjectOutputStream s) throws IOException {
 504         s.defaultWriteObject();
 505         if (getUIClassID().equals(uiClassID)) {
 506             byte count = JComponent.getWriteObjCounter(this);
 507             JComponent.setWriteObjCounter(this, --count);
 508             if (count == 0 && ui != null) {
 509                 ui.installUI(this);
 510             }


 534         return super.paramString() +
 535         ",chooserPanels=" + chooserPanelsString.toString() +
 536         ",previewPanel=" + previewPanelString;
 537     }
 538 
 539 /////////////////
 540 // Accessibility support
 541 ////////////////
 542 
 543     protected AccessibleContext accessibleContext = null;
 544 
 545     /**
 546      * Gets the AccessibleContext associated with this JColorChooser.
 547      * For color choosers, the AccessibleContext takes the form of an
 548      * AccessibleJColorChooser.
 549      * A new AccessibleJColorChooser instance is created if necessary.
 550      *
 551      * @return an AccessibleJColorChooser that serves as the
 552      *         AccessibleContext of this JColorChooser
 553      */
 554     @BeanProperty(bound = false)
 555     public AccessibleContext getAccessibleContext() {
 556         if (accessibleContext == null) {
 557             accessibleContext = new AccessibleJColorChooser();
 558         }
 559         return accessibleContext;
 560     }
 561 
 562     /**
 563      * This class implements accessibility support for the
 564      * <code>JColorChooser</code> class.  It provides an implementation of the
 565      * Java Accessibility API appropriate to color chooser user-interface
 566      * elements.
 567      */
 568     protected class AccessibleJColorChooser extends AccessibleJComponent {
 569 
 570         /**
 571          * Get the role of this object.
 572          *
 573          * @return an instance of AccessibleRole describing the role of the
 574          * object