jdk/src/share/classes/javax/swing/colorchooser/DefaultPreviewPanel.java
author malenkov
Wed, 07 May 2008 23:20:32 +0400
changeset 466 6acd5ec503a8
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE Summary: Add the Transient annotation and support it (JSR-273) Reviewed-by: peterz, loneid
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2005 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.colorchooser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.image.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The standard preview panel for the color chooser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author Steve Wilson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see JColorChooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
class DefaultPreviewPanel extends JPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private int squareSize = 25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private int squareGap = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private int innerGap = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private int textGap = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private Font font = new Font(Font.DIALOG, Font.PLAIN, 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private String sampleText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private int swatchWidth = 50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private Color oldColor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private JColorChooser getColorChooser() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        return (JColorChooser)SwingUtilities.getAncestorOfClass(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                   JColorChooser.class, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        JComponent host = getColorChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if (host == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            host = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        FontMetrics fm = host.getFontMetrics(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        int ascent = fm.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        int height = fm.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        int width = SwingUtilities2.stringWidth(host, fm, getSampleText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        int y = height*3 + textGap*3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        int x = squareSize * 3 + squareGap*2 + swatchWidth + width + textGap*3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        return new Dimension( x,y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (oldColor == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            oldColor = getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        g.setColor(getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        g.fillRect(0,0,getWidth(),getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (this.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            int squareWidth = paintSquares(g, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            int textWidth = paintText(g, squareWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            paintSwatch(g, squareWidth + textWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            int swatchWidth = paintSwatch(g, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            int textWidth = paintText(g, swatchWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            paintSquares(g , swatchWidth + textWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private int paintSwatch(Graphics g, int offsetX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        int swatchX = offsetX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        g.setColor(oldColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        g.fillRect(swatchX, 0, swatchWidth, (squareSize) + (squareGap/2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        g.setColor(getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        g.fillRect(swatchX, (squareSize) + (squareGap/2), swatchWidth, (squareSize) + (squareGap/2) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        return (swatchX+swatchWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private int paintText(Graphics g, int offsetX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        g.setFont(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        JComponent host = getColorChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if (host == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            host = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        FontMetrics fm = SwingUtilities2.getFontMetrics(host, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        int ascent = fm.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        int height = fm.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        int width = SwingUtilities2.stringWidth(host, fm, getSampleText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        int textXOffset = offsetX + textGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        Color color = getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        SwingUtilities2.drawString(host, g, getSampleText(),textXOffset+(textGap/2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                   ascent+2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        g.fillRect(textXOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                   ( height) + textGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                   width + (textGap),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                   height +2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        SwingUtilities2.drawString(host, g, getSampleText(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                     textXOffset+(textGap/2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                     height+ascent+textGap+2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        g.setColor(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        g.fillRect(textXOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                   ( height + textGap) * 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                   width + (textGap),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                   height +2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        SwingUtilities2.drawString(host, g, getSampleText(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                     textXOffset+(textGap/2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                     ((height+textGap) * 2)+ascent+2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return width + textGap*3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    private int paintSquares(Graphics g, int offsetX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        int squareXOffset = offsetX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        Color color = getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        g.setColor(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        g.fillRect(squareXOffset,0,squareSize,squareSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        g.fillRect(squareXOffset+innerGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                   innerGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                   squareSize - (innerGap*2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                   squareSize - (innerGap*2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        g.setColor(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        g.fillRect(squareXOffset+innerGap*2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                   innerGap*2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                   squareSize - (innerGap*4),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                   squareSize - (innerGap*4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        g.fillRect(squareXOffset,squareSize+squareGap,squareSize,squareSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        g.translate(squareSize+squareGap, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        g.fillRect(squareXOffset,0,squareSize,squareSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        g.fillRect(squareXOffset+innerGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                   innerGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                   squareSize - (innerGap*2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                   squareSize - (innerGap*2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        g.setColor(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        g.fillRect(squareXOffset+innerGap*2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                   innerGap*2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                   squareSize - (innerGap*4),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                   squareSize - (innerGap*4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        g.translate(-(squareSize+squareGap), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        g.translate(squareSize+squareGap, squareSize+squareGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        g.setColor(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        g.fillRect(squareXOffset,0,squareSize,squareSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        g.fillRect(squareXOffset+innerGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                   innerGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                   squareSize - (innerGap*2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                   squareSize - (innerGap*2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        g.translate(-(squareSize+squareGap), -(squareSize+squareGap));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        g.translate((squareSize+squareGap)*2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        g.setColor(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        g.fillRect(squareXOffset,0,squareSize,squareSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        g.fillRect(squareXOffset+innerGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                   innerGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                   squareSize - (innerGap*2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                   squareSize - (innerGap*2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        g.fillRect(squareXOffset+innerGap*2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                   innerGap*2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                   squareSize - (innerGap*4),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                   squareSize - (innerGap*4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        g.translate(-((squareSize+squareGap)*2), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        g.translate((squareSize+squareGap)*2, (squareSize+squareGap));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        g.fillRect(squareXOffset,0,squareSize,squareSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        g.fillRect(squareXOffset+innerGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                   innerGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                   squareSize - (innerGap*2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                   squareSize - (innerGap*2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        g.translate(-((squareSize+squareGap)*2), -(squareSize+squareGap));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return (squareSize*3+squareGap*2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    private String getSampleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (this.sampleText == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            this.sampleText = UIManager.getString("ColorChooser.sampleText", getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return this.sampleText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
}