jdk/src/share/classes/javax/swing/colorchooser/ColorPanel.java
author darcy
Sun, 23 Mar 2014 13:49:48 -0700
changeset 23697 e556a715949f
parent 23010 6dadb192ad81
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:
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
     4
 *
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
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: 1288
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1288
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    10
 *
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    15
 * accompanied this code).
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    16
 *
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1288
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1288
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1288
diff changeset
    23
 * questions.
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    24
 */
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    25
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    26
package javax.swing.colorchooser;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    27
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    28
import java.awt.Color;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    29
import java.awt.ContainerOrderFocusTraversalPolicy;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    30
import java.awt.GridBagConstraints;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    31
import java.awt.GridBagLayout;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    32
import java.awt.Insets;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    33
import java.awt.event.ActionEvent;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    34
import java.awt.event.ActionListener;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    35
import javax.swing.ButtonGroup;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    36
import javax.swing.JLabel;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    37
import javax.swing.JPanel;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    38
import javax.swing.JRadioButton;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    39
import javax.swing.border.EmptyBorder;
14658
67661687f722 4631925: JColor Chooser is not fully accessible
jviswana
parents: 5506
diff changeset
    40
import javax.swing.JSpinner.DefaultEditor;
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    41
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
    42
@SuppressWarnings("serial") // Superclass is not serializable across versions
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    43
final class ColorPanel extends JPanel implements ActionListener {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    44
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    45
    private final SlidingSpinner[] spinners = new SlidingSpinner[5];
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    46
    private final float[] values = new float[this.spinners.length];
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    47
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    48
    private final ColorModel model;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    49
    private Color color;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    50
    private int x = 1;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    51
    private int y = 2;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    52
    private int z;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    53
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    54
    ColorPanel(ColorModel model) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    55
        super(new GridBagLayout());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    56
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    57
        GridBagConstraints gbc = new GridBagConstraints();
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    58
        gbc.fill = GridBagConstraints.HORIZONTAL;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    59
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    60
        gbc.gridx = 1;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    61
        ButtonGroup group = new ButtonGroup();
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    62
        EmptyBorder border = null;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    63
        for (int i = 0; i < this.spinners.length; i++) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    64
            if (i < 3) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    65
                JRadioButton button = new JRadioButton();
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    66
                if (i == 0) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    67
                    Insets insets = button.getInsets();
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    68
                    insets.left = button.getPreferredSize().width;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    69
                    border = new EmptyBorder(insets);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    70
                    button.setSelected(true);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    71
                    gbc.insets.top = 5;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    72
                }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    73
                add(button, gbc);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    74
                group.add(button);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    75
                button.setActionCommand(Integer.toString(i));
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    76
                button.addActionListener(this);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    77
                this.spinners[i] = new SlidingSpinner(this, button);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    78
            }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    79
            else {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    80
                JLabel label = new JLabel();
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    81
                add(label, gbc);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    82
                label.setBorder(border);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    83
                label.setFocusable(false);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    84
                this.spinners[i] = new SlidingSpinner(this, label);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    85
            }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    86
        }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    87
        gbc.gridx = 2;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    88
        gbc.weightx = 1.0;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    89
        gbc.insets.top = 0;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    90
        gbc.insets.left = 5;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    91
        for (SlidingSpinner spinner : this.spinners) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    92
            add(spinner.getSlider(), gbc);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    93
            gbc.insets.top = 5;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    94
        }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    95
        gbc.gridx = 3;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    96
        gbc.weightx = 0.0;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    97
        gbc.insets.top = 0;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    98
        for (SlidingSpinner spinner : this.spinners) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
    99
            add(spinner.getSpinner(), gbc);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   100
            gbc.insets.top = 5;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   101
        }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   102
        setFocusTraversalPolicy(new ContainerOrderFocusTraversalPolicy());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   103
        setFocusTraversalPolicyProvider(true);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   104
        setFocusable(false);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   105
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   106
        this.model = model;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   107
    }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   108
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   109
    public void actionPerformed(ActionEvent event) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   110
        try {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   111
            this.z = Integer.parseInt(event.getActionCommand());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   112
            this.y = (this.z != 2) ? 2 : 1;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   113
            this.x = (this.z != 0) ? 0 : 1;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   114
            getParent().repaint();
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   115
        }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   116
        catch (NumberFormatException exception) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   117
        }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   118
    }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   119
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   120
    void buildPanel() {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   121
        int count = this.model.getCount();
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   122
        this.spinners[4].setVisible(count > 4);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   123
        for (int i = 0; i < count; i++) {
14658
67661687f722 4631925: JColor Chooser is not fully accessible
jviswana
parents: 5506
diff changeset
   124
            String text = this.model.getLabel(this, i);
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   125
            Object object = this.spinners[i].getLabel();
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   126
            if (object instanceof JRadioButton) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   127
                JRadioButton button = (JRadioButton) object;
14658
67661687f722 4631925: JColor Chooser is not fully accessible
jviswana
parents: 5506
diff changeset
   128
                button.setText(text);
67661687f722 4631925: JColor Chooser is not fully accessible
jviswana
parents: 5506
diff changeset
   129
                button.getAccessibleContext().setAccessibleDescription(text);
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   130
            }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   131
            else if (object instanceof JLabel) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   132
                JLabel label = (JLabel) object;
14658
67661687f722 4631925: JColor Chooser is not fully accessible
jviswana
parents: 5506
diff changeset
   133
                label.setText(text);
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   134
            }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   135
            this.spinners[i].setRange(this.model.getMinimum(i), this.model.getMaximum(i));
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   136
            this.spinners[i].setValue(this.values[i]);
14658
67661687f722 4631925: JColor Chooser is not fully accessible
jviswana
parents: 5506
diff changeset
   137
            this.spinners[i].getSlider().getAccessibleContext().setAccessibleName(text);
67661687f722 4631925: JColor Chooser is not fully accessible
jviswana
parents: 5506
diff changeset
   138
            this.spinners[i].getSpinner().getAccessibleContext().setAccessibleName(text);
67661687f722 4631925: JColor Chooser is not fully accessible
jviswana
parents: 5506
diff changeset
   139
            DefaultEditor editor = (DefaultEditor) this.spinners[i].getSpinner().getEditor();
67661687f722 4631925: JColor Chooser is not fully accessible
jviswana
parents: 5506
diff changeset
   140
            editor.getTextField().getAccessibleContext().setAccessibleName(text);
67661687f722 4631925: JColor Chooser is not fully accessible
jviswana
parents: 5506
diff changeset
   141
            this.spinners[i].getSlider().getAccessibleContext().setAccessibleDescription(text);
67661687f722 4631925: JColor Chooser is not fully accessible
jviswana
parents: 5506
diff changeset
   142
            this.spinners[i].getSpinner().getAccessibleContext().setAccessibleDescription(text);
67661687f722 4631925: JColor Chooser is not fully accessible
jviswana
parents: 5506
diff changeset
   143
            editor.getTextField().getAccessibleContext().setAccessibleDescription(text);
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   144
        }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   145
    }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   146
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   147
    void colorChanged() {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   148
        this.color = new Color(getColor(0), true);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   149
        Object parent = getParent();
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   150
        if (parent instanceof ColorChooserPanel) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   151
            ColorChooserPanel chooser = (ColorChooserPanel) parent;
1288
27aaa860d855 6707406: BasicColorChooserUI tests throw NPE while getColorSelectionModel if isPropertyChanged() returns true
malenkov
parents: 1282
diff changeset
   152
            chooser.setSelectedColor(this.color);
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   153
            chooser.repaint();
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   154
        }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   155
    }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   156
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   157
    float getValueX() {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   158
        return this.spinners[this.x].getValue();
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   159
    }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   160
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   161
    float getValueY() {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   162
        return 1.0f - this.spinners[this.y].getValue();
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   163
    }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   164
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   165
    float getValueZ() {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   166
        return 1.0f - this.spinners[this.z].getValue();
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   167
    }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   168
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   169
    void setValue(float z) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   170
        this.spinners[this.z].setValue(1.0f - z);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   171
        colorChanged();
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   172
    }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   173
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   174
    void setValue(float x, float y) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   175
        this.spinners[this.x].setValue(x);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   176
        this.spinners[this.y].setValue(1.0f - y);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   177
        colorChanged();
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   178
    }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   179
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   180
    int getColor(float z) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   181
        setDefaultValue(this.x);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   182
        setDefaultValue(this.y);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   183
        this.values[this.z] = 1.0f - z;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   184
        return getColor(3);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   185
    }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   186
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   187
    int getColor(float x, float y) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   188
        this.values[this.x] = x;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   189
        this.values[this.y] = 1.0f - y;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   190
        setValue(this.z);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   191
        return getColor(3);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   192
    }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   193
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   194
    void setColor(Color color) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   195
        if (!color.equals(this.color)) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   196
            this.color = color;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   197
            this.model.setColor(color.getRGB(), this.values);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   198
            for (int i = 0; i < this.model.getCount(); i++) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   199
                this.spinners[i].setValue(this.values[i]);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   200
            }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   201
        }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   202
    }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   203
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   204
    private int getColor(int index) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   205
        while (index < this.model.getCount()) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   206
            setValue(index++);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   207
        }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   208
        return this.model.getColor(this.values);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   209
    }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   210
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   211
    private void setValue(int index) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   212
        this.values[index] = this.spinners[index].getValue();
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   213
    }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   214
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   215
    private void setDefaultValue(int index) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   216
        float value = this.model.getDefault(index);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   217
        this.values[index] = (value < 0.0f)
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   218
                ? this.spinners[index].getValue()
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   219
                : value;
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   220
    }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents:
diff changeset
   221
}