jdk/src/share/classes/javax/swing/plaf/basic/BasicArrowButton.java
author darcy
Wed, 02 Jul 2014 23:03:27 -0700
changeset 25565 ce603b34c98d
parent 22574 7f8ce0c8c20a
child 25761 c408b10ef757
permissions -rw-r--r--
8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.* 8042849: Fix raw and unchecked warnings in com.sun.java.swing Reviewed-by: pchelko, alexsch
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) 1997, 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
package javax.swing.plaf.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.plaf.UIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * JButton object that draws a scaled Arrow in one of the cardinal directions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * 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: 5506
diff changeset
    42
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author David Kloba
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    48
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public class BasicArrowButton extends JButton implements SwingConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
         * The direction of the arrow. One of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
         * {@code SwingConstants.NORTH}, {@code SwingConstants.SOUTH},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
         * {@code SwingConstants.EAST} or {@code SwingConstants.WEST}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        protected int direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        private Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        private Color darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        private Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
         * Creates a {@code BasicArrowButton} whose arrow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
         * is drawn in the specified direction and with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
         * colors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
         * @param direction the direction of the arrow; one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
         *        {@code SwingConstants.NORTH}, {@code SwingConstants.SOUTH},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
         *        {@code SwingConstants.EAST} or {@code SwingConstants.WEST}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
         * @param background the background color of the button
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
         * @param shadow the color of the shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
         * @param darkShadow the color of the dark shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
         * @param highlight the color of the highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        public BasicArrowButton(int direction, Color background, Color shadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                         Color darkShadow, Color highlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            setRequestFocusEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            setDirection(direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            setBackground(background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            this.shadow = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            this.darkShadow = darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            this.highlight = highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         * Creates a {@code BasicArrowButton} whose arrow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         * is drawn in the specified direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         * @param direction the direction of the arrow; one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
         *        {@code SwingConstants.NORTH}, {@code SwingConstants.SOUTH},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         *        {@code SwingConstants.EAST} or {@code SwingConstants.WEST}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        public BasicArrowButton(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            this(direction, UIManager.getColor("control"), UIManager.getColor("controlShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                 UIManager.getColor("controlDkShadow"), UIManager.getColor("controlLtHighlight"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
         * Returns the direction of the arrow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        public int getDirection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            return direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
         * Sets the direction of the arrow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
         * @param direction the direction of the arrow; one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
         *        of {@code SwingConstants.NORTH},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
         *        {@code SwingConstants.SOUTH},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
         *        {@code SwingConstants.EAST} or {@code SwingConstants.WEST}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        public void setDirection(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            this.direction = direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            Color origColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            boolean isPressed, isEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            int w, h, size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            w = getSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            h = getSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            origColor = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            isPressed = getModel().isPressed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            isEnabled = isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            g.setColor(getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            g.fillRect(1, 1, w-2, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            /// Draw the proper Border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            if (getBorder() != null && !(getBorder() instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                paintBorder(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            } else if (isPressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                g.drawRect(0, 0, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                // Using the background color set above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                g.drawLine(0, 0, 0, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                g.drawLine(1, 0, w-2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                g.setColor(highlight);    // inner 3D border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                g.drawLine(1, 1, 1, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                g.drawLine(2, 1, w-3, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                g.setColor(shadow);       // inner 3D border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                g.drawLine(1, h-2, w-2, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                g.drawLine(w-2, 1, w-2, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                g.setColor(darkShadow);     // black drop shadow  __|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                g.drawLine(0, h-1, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                g.drawLine(w-1, h-1, w-1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            // If there's no room to draw arrow, bail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            if(h < 5 || w < 5)      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                g.setColor(origColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            if (isPressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                g.translate(1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            // Draw the arrow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            size = Math.min((h - 4) / 3, (w - 4) / 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            size = Math.max(size, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            paintTriangle(g, (w - size) / 2, (h - size) / 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                                size, direction, isEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            // Reset the Graphics back to it's original settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            if (isPressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                g.translate(-1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            g.setColor(origColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         * Returns the preferred size of the {@code BasicArrowButton}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         * @return the preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            return new Dimension(16, 16);
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
         * Returns the minimum size of the {@code BasicArrowButton}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         * @return the minimum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            return new Dimension(5, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
         * Returns the maximum size of the {@code BasicArrowButton}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
         * @return the maximum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
         * Returns whether the arrow button should get the focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
         * {@code BasicArrowButton}s are used as a child component of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
         * composite components such as {@code JScrollBar} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
         * {@code JComboBox}. Since the composite component typically gets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
         * focus, this method is overriden to return {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         * @return {@code false}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
          return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
         * Paints a triangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
         * @param g the {@code Graphics} to draw to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
         * @param x the x coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
         * @param y the y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
         * @param size the size of the triangle to draw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
         * @param direction the direction in which to draw the arrow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
         *        one of {@code SwingConstants.NORTH},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
         *        {@code SwingConstants.SOUTH}, {@code SwingConstants.EAST} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
         *        {@code SwingConstants.WEST}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
         * @param isEnabled whether or not the arrow is drawn enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        public void paintTriangle(Graphics g, int x, int y, int size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                                        int direction, boolean isEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            Color oldColor = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            int mid, i, j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            size = Math.max(size, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            mid = (size / 2) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            g.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            if(isEnabled)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                g.setColor(darkShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            switch(direction)       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            case NORTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                for(i = 0; i < size; i++)      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    g.drawLine(mid-i, i, mid+i, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                if(!isEnabled)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                    g.drawLine(mid-i+2, i, mid+i, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            case SOUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                if(!isEnabled)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    g.translate(1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                    for(i = size-1; i >= 0; i--)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                        g.drawLine(mid-i, j, mid+i, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                        j++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    g.translate(-1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                for(i = size-1; i >= 0; i--)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    g.drawLine(mid-i, j, mid+i, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    j++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            case WEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                for(i = 0; i < size; i++)      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    g.drawLine(i, mid-i, i, mid+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                if(!isEnabled)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    g.drawLine(i, mid-i+2, i, mid+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            case EAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                if(!isEnabled)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    g.translate(1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    for(i = size-1; i >= 0; i--)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                        g.drawLine(j, mid-i, j, mid+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                        j++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    g.translate(-1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                for(i = size-1; i >= 0; i--)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                    g.drawLine(j, mid-i, j, mid+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                    j++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            g.translate(-x, -y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            g.setColor(oldColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
}