jdk/src/share/classes/javax/swing/JColorChooser.java
author darcy
Sun, 23 Mar 2014 13:49:48 -0700
changeset 23697 e556a715949f
parent 22574 7f8ce0c8c20a
child 24969 afa6934dd8e8
permissions -rw-r--r--
8034169: Fix serial lint warnings in javax.swing Reviewed-by: alanb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
     2
 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.colorchooser.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.plaf.ColorChooserUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <code>JColorChooser</code> provides a pane of controls designed to allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * a user to manipulate and select a color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * For information about using color choosers, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <a
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
    45
 href="http://docs.oracle.com/javase/tutorial/uiswing/components/colorchooser.html">How to Use Color Choosers</a>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * This class provides three levels of API:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <li>A static convenience method which shows a modal color-chooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * dialog and returns the color selected by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <li>A static convenience method for creating a color-chooser dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * where <code>ActionListeners</code> can be specified to be invoked when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * the user presses one of the dialog buttons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <li>The ability to create instances of <code>JColorChooser</code> panes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * directly (within any container). <code>PropertyChange</code> listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * can be added to detect when the current "color" property changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
    72
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *      attribute: isContainer false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *    description: A component that supports selecting a Color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @author James Gosling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @author Amy Fowler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @author Steve Wilson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    86
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
public class JColorChooser extends JComponent implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private static final String uiClassID = "ColorChooserUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private ColorSelectionModel selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
6512
ce0a2790e09f 6977726: JColorChooser.getPreviewPanel() returnes null starting from jdk7 b105.
malenkov
parents: 5506
diff changeset
    97
    private JComponent previewPanel = ColorChooserComponentFactory.getPreviewPanel();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private AbstractColorChooserPanel[] chooserPanels = new AbstractColorChooserPanel[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private boolean dragEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * The selection model property name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public static final String      SELECTION_MODEL_PROPERTY = "selectionModel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * The preview panel property name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public static final String      PREVIEW_PANEL_PROPERTY = "previewPanel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * The chooserPanel array property name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public static final String      CHOOSER_PANELS_PROPERTY = "chooserPanels";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Shows a modal color-chooser dialog and blocks until the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * dialog is hidden.  If the user presses the "OK" button, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * this method hides/disposes the dialog and returns the selected color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * If the user presses the "Cancel" button or closes the dialog without
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * pressing "OK", then this method hides/disposes the dialog and returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param component    the parent <code>Component</code> for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param title        the String containing the dialog's title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @param initialColor the initial Color set when the color-chooser is shown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @return the selected color or <code>null</code> if the user opted out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static Color showDialog(Component component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        String title, Color initialColor) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        final JColorChooser pane = new JColorChooser(initialColor != null?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                               initialColor : Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        ColorTracker ok = new ColorTracker(pane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        JDialog dialog = createDialog(component, title, true, pane, ok, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        dialog.addComponentListener(new ColorChooserDialog.DisposeOnClose());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        dialog.show(); // blocks until user brings dialog down...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return ok.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Creates and returns a new dialog containing the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * <code>ColorChooser</code> pane along with "OK", "Cancel", and "Reset"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * buttons. If the "OK" or "Cancel" buttons are pressed, the dialog is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * automatically hidden (but not disposed).  If the "Reset"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * button is pressed, the color-chooser's color will be reset to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * color which was set the last time <code>show</code> was invoked on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * dialog and the dialog will remain showing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param c              the parent component for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @param title          the title for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param modal          a boolean. When true, the remainder of the program
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *                       is inactive until the dialog is closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @param chooserPane    the color-chooser to be placed inside the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @param okListener     the ActionListener invoked when "OK" is pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @param cancelListener the ActionListener invoked when "Cancel" is pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @return a new dialog containing the color-chooser pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public static JDialog createDialog(Component c, String title, boolean modal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        JColorChooser chooserPane, ActionListener okListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        ActionListener cancelListener) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        Window window = JOptionPane.getWindowForComponent(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        ColorChooserDialog dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (window instanceof Frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            dialog = new ColorChooserDialog((Frame)window, title, modal, c, chooserPane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                            okListener, cancelListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            dialog = new ColorChooserDialog((Dialog)window, title, modal, c, chooserPane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                            okListener, cancelListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
14658
67661687f722 4631925: JColor Chooser is not fully accessible
jviswana
parents: 7668
diff changeset
   186
        dialog.getAccessibleContext().setAccessibleDescription(title);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Creates a color chooser pane with an initial color of white.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public JColorChooser() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        this(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Creates a color chooser pane with the specified initial color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param initialColor the initial color set in the chooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public JColorChooser(Color initialColor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        this( new DefaultColorSelectionModel(initialColor) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Creates a color chooser pane with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * <code>ColorSelectionModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @param model the <code>ColorSelectionModel</code> to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public JColorChooser(ColorSelectionModel model) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        selectionModel = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        dragEnabled = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 14658
diff changeset
   220
     * Returns the L&amp;F object that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @return the <code>ColorChooserUI</code> object that renders
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *          this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public ColorChooserUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return (ColorChooserUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 14658
diff changeset
   230
     * Sets the L&amp;F object that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 14658
diff changeset
   232
     * @param ui  the <code>ColorChooserUI</code> L&amp;F object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *      hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * description: The UI object that implements the color chooser's LookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public void setUI(ColorChooserUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 14658
diff changeset
   245
     * Notification from the <code>UIManager</code> that the L&amp;F has changed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Replaces the current UI object with the latest version from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * <code>UIManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        setUI((ColorChooserUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 14658
diff changeset
   256
     * Returns the name of the L&amp;F class that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @return the string "ColorChooserUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Gets the current color value from the color chooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * By default, this delegates to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @return the current color value of the color chooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public Color getColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        return selectionModel.getSelectedColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * Sets the current color of the color chooser to the specified color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * The <code>ColorSelectionModel</code> will fire a <code>ChangeEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param color the color to be set in the color chooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @see JComponent#addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *       bound: false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *      hidden: false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * description: The current color the chooser is to display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public void setColor(Color color) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        selectionModel.setSelectedColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Sets the current color of the color chooser to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * specified RGB color.  Note that the values of red, green,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * and blue should be between the numbers 0 and 255, inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @param r   an int specifying the amount of Red
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @param g   an int specifying the amount of Green
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @param b   an int specifying the amount of Blue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @exception IllegalArgumentException if r,g,b values are out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @see java.awt.Color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public void setColor(int r, int g, int b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        setColor(new Color(r,g,b));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Sets the current color of the color chooser to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * specified color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @param c an integer value that sets the current color in the chooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *          where the low-order 8 bits specify the Blue value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *          the next 8 bits specify the Green value, and the 8 bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *          above that specify the Red value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public void setColor(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        setColor((c >> 16) & 0xFF, (c >> 8) & 0xFF, c & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * Sets the <code>dragEnabled</code> property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * which must be <code>true</code> to enable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * automatic drag handling (the first part of drag and drop)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * The <code>transferHandler</code> property needs to be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * to a non-<code>null</code> value for the drag to do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * anything.  The default value of the <code>dragEnabled</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * is <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * When automatic drag handling is enabled,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * most look and feels begin a drag-and-drop operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * when the user presses the mouse button over the preview panel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Some look and feels might not support automatic drag and drop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * they will ignore this property.  You can work around such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * look and feels by modifying the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * to directly call the <code>exportAsDrag</code> method of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * <code>TransferHandler</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @param b the value to set the <code>dragEnabled</code> property to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *            <code>b</code> is <code>true</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *            <code>GraphicsEnvironment.isHeadless()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *            returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @see #getDragEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @see #setTransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @see TransferHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *  description: Determines whether automatic drag handling is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *        bound: false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public void setDragEnabled(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        if (b && GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        dragEnabled = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * Gets the value of the <code>dragEnabled</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @return  the value of the <code>dragEnabled</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @see #setDragEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public boolean getDragEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return dragEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Sets the current preview panel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * This will fire a <code>PropertyChangeEvent</code> for the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * named "previewPanel".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @param preview the <code>JComponent</code> which displays the current color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @see JComponent#addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *      hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * description: The UI component which displays the current color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    public void setPreviewPanel(JComponent preview) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (previewPanel != preview) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            JComponent oldPreview = previewPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            previewPanel = preview;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            firePropertyChange(JColorChooser.PREVIEW_PANEL_PROPERTY, oldPreview, preview);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * Returns the preview panel that shows a chosen color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @return a <code>JComponent</code> object -- the preview panel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public JComponent getPreviewPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        return previewPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * Adds a color chooser panel to the color chooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @param panel the <code>AbstractColorChooserPanel</code> to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public void addChooserPanel( AbstractColorChooserPanel panel ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        AbstractColorChooserPanel[] oldPanels = getChooserPanels();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        AbstractColorChooserPanel[] newPanels = new AbstractColorChooserPanel[oldPanels.length+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        System.arraycopy(oldPanels, 0, newPanels, 0, oldPanels.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        newPanels[newPanels.length-1] = panel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        setChooserPanels(newPanels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * Removes the Color Panel specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @param panel   a string that specifies the panel to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @return the color panel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @exception IllegalArgumentException if panel is not in list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *                  known chooser panels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    public AbstractColorChooserPanel removeChooserPanel( AbstractColorChooserPanel panel ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        int containedAt = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        for (int i = 0; i < chooserPanels.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            if (chooserPanels[i] == panel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                containedAt = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        if (containedAt == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            throw new IllegalArgumentException("chooser panel not in this chooser");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        AbstractColorChooserPanel[] newArray = new AbstractColorChooserPanel[chooserPanels.length-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        if (containedAt == chooserPanels.length-1) {  // at end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            System.arraycopy(chooserPanels, 0, newArray, 0, newArray.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        else if (containedAt == 0) {  // at start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            System.arraycopy(chooserPanels, 1, newArray, 0, newArray.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        else {  // in middle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            System.arraycopy(chooserPanels, 0, newArray, 0, containedAt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            System.arraycopy(chooserPanels, containedAt+1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                             newArray, containedAt, (chooserPanels.length - containedAt - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        setChooserPanels(newArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        return panel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * Specifies the Color Panels used to choose a color value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @param panels  an array of <code>AbstractColorChooserPanel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *          objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     *      hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * description: An array of different chooser types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    public void setChooserPanels( AbstractColorChooserPanel[] panels) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        AbstractColorChooserPanel[] oldValue = chooserPanels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        chooserPanels = panels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        firePropertyChange(CHOOSER_PANELS_PROPERTY, oldValue, panels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * Returns the specified color panels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @return an array of <code>AbstractColorChooserPanel</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    public AbstractColorChooserPanel[] getChooserPanels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        return chooserPanels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * Returns the data model that handles color selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @return a <code>ColorSelectionModel</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    public ColorSelectionModel getSelectionModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        return selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * Sets the model containing the selected color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @param newModel   the new <code>ColorSelectionModel</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *      hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * description: The model which contains the currently selected color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    public void setSelectionModel(ColorSelectionModel newModel ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        ColorSelectionModel oldModel = selectionModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        selectionModel = newModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        firePropertyChange(JColorChooser.SELECTION_MODEL_PROPERTY, oldModel, newModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * See <code>readObject</code> and <code>writeObject</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * <code>JComponent</code> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * Returns a string representation of this <code>JColorChooser</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * @return  a string representation of this <code>JColorChooser</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        StringBuffer chooserPanelsString = new StringBuffer("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        for (int i=0; i<chooserPanels.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            chooserPanelsString.append("[" + chooserPanels[i].toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                                       + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        String previewPanelString = (previewPanel != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                                     previewPanel.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        ",chooserPanels=" + chooserPanelsString.toString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        ",previewPanel=" + previewPanelString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    protected AccessibleContext accessibleContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * Gets the AccessibleContext associated with this JColorChooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * For color choosers, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * AccessibleJColorChooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * A new AccessibleJColorChooser instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @return an AccessibleJColorChooser that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     *         AccessibleContext of this JColorChooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            accessibleContext = new AccessibleJColorChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * <code>JColorChooser</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * Java Accessibility API appropriate to color chooser user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    protected class AccessibleJColorChooser extends AccessibleJComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            return AccessibleRole.COLOR_CHOOSER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    } // inner class AccessibleJColorChooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
 * Class which builds a color chooser dialog consisting of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
 * a JColorChooser with "Ok", "Cancel", and "Reset" buttons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
 * Note: This needs to be fixed to deal with localization!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
 */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 22574
diff changeset
   609
@SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
class ColorChooserDialog extends JDialog {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    private Color initialColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    private JColorChooser chooserPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    private JButton cancelButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    public ColorChooserDialog(Dialog owner, String title, boolean modal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        Component c, JColorChooser chooserPane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        ActionListener okListener, ActionListener cancelListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        super(owner, title, modal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        initColorChooserDialog(c, chooserPane, okListener, cancelListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    public ColorChooserDialog(Frame owner, String title, boolean modal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        Component c, JColorChooser chooserPane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        ActionListener okListener, ActionListener cancelListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        super(owner, title, modal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        initColorChooserDialog(c, chooserPane, okListener, cancelListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    protected void initColorChooserDialog(Component c, JColorChooser chooserPane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        ActionListener okListener, ActionListener cancelListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        //setResizable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        this.chooserPane = chooserPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        Locale locale = getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        String okString = UIManager.getString("ColorChooser.okText", locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        String cancelString = UIManager.getString("ColorChooser.cancelText", locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        String resetString = UIManager.getString("ColorChooser.resetText", locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        Container contentPane = getContentPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        contentPane.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        contentPane.add(chooserPane, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
         * Create Lower button panel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        JPanel buttonPane = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        JButton okButton = new JButton(okString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        getRootPane().setDefaultButton(okButton);
14658
67661687f722 4631925: JColor Chooser is not fully accessible
jviswana
parents: 7668
diff changeset
   653
        okButton.getAccessibleContext().setAccessibleDescription(okString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        okButton.setActionCommand("OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        okButton.addActionListener(new ActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        if (okListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            okButton.addActionListener(okListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        buttonPane.add(okButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        cancelButton = new JButton(cancelString);
14658
67661687f722 4631925: JColor Chooser is not fully accessible
jviswana
parents: 7668
diff changeset
   666
        cancelButton.getAccessibleContext().setAccessibleDescription(cancelString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        // The following few lines are used to register esc to close the dialog
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 22574
diff changeset
   669
        @SuppressWarnings("serial") // anonymous class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        Action cancelKeyAction = new AbstractAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                ((AbstractButton)e.getSource()).fireActionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        KeyStroke cancelKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        InputMap inputMap = cancelButton.getInputMap(JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                                                     WHEN_IN_FOCUSED_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        ActionMap actionMap = cancelButton.getActionMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        if (inputMap != null && actionMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            inputMap.put(cancelKeyStroke, "cancel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            actionMap.put("cancel", cancelKeyAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        // end esc handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        cancelButton.setActionCommand("cancel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        cancelButton.addActionListener(new ActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        if (cancelListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            cancelButton.addActionListener(cancelListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        buttonPane.add(cancelButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        JButton resetButton = new JButton(resetString);
14658
67661687f722 4631925: JColor Chooser is not fully accessible
jviswana
parents: 7668
diff changeset
   697
        resetButton.getAccessibleContext().setAccessibleDescription(resetString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        resetButton.addActionListener(new ActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
           public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
               reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        int mnemonic = SwingUtilities2.getUIDefaultsInt("ColorChooser.resetMnemonic", locale, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        if (mnemonic != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            resetButton.setMnemonic(mnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        buttonPane.add(resetButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        contentPane.add(buttonPane, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        if (JDialog.isDefaultLookAndFeelDecorated()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            boolean supportsWindowDecorations =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            UIManager.getLookAndFeel().getSupportsWindowDecorations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            if (supportsWindowDecorations) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                getRootPane().setWindowDecorationStyle(JRootPane.COLOR_CHOOSER_DIALOG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        applyComponentOrientation(((c == null) ? getRootPane() : c).getComponentOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        setLocationRelativeTo(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        this.addWindowListener(new Closer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        initialColor = chooserPane.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        super.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    public void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        chooserPane.setColor(initialColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 22574
diff changeset
   734
    @SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    class Closer extends WindowAdapter implements Serializable{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        public void windowClosing(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            cancelButton.doClick(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            Window w = e.getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            w.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 22574
diff changeset
   743
    @SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    static class DisposeOnClose extends ComponentAdapter implements Serializable{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        public void componentHidden(ComponentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            Window w = (Window)e.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            w.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 22574
diff changeset
   753
@SuppressWarnings("serial") // JDK-implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
class ColorTracker implements ActionListener, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    JColorChooser chooser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    Color color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    public ColorTracker(JColorChooser c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        chooser = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        color = chooser.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    public Color getColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        return color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
}