jdk/src/share/classes/javax/swing/plaf/basic/BasicArrowButton.java
author rupashka
Mon, 02 Jun 2008 19:08:13 +0400
changeset 676 8cf833d60e87
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6709530: There are unnecessary code in slider classes, such as in JSlider and SliderUIs Summary: Removed unnecessary code like unused variables, castings, imports etc Reviewed-by: peterz
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 1997-2006 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
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
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
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class BasicArrowButton extends JButton implements SwingConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
         * The direction of the arrow. One of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
         * {@code SwingConstants.NORTH}, {@code SwingConstants.SOUTH},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
         * {@code SwingConstants.EAST} or {@code SwingConstants.WEST}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        protected int direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        private Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        private Color darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        private Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
         * Creates a {@code BasicArrowButton} whose arrow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
         * is drawn in the specified direction and with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
         * colors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
         * @param direction the direction of the arrow; one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
         *        {@code SwingConstants.NORTH}, {@code SwingConstants.SOUTH},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
         *        {@code SwingConstants.EAST} or {@code SwingConstants.WEST}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
         * @param background the background color of the button
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
         * @param shadow the color of the shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
         * @param darkShadow the color of the dark shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
         * @param highlight the color of the highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        public BasicArrowButton(int direction, Color background, Color shadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                         Color darkShadow, Color highlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            setRequestFocusEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            setDirection(direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            setBackground(background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            this.shadow = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            this.darkShadow = darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            this.highlight = highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
         * Creates a {@code BasicArrowButton} whose arrow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         * is drawn in the specified direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         * @param direction the direction of the arrow; one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         *        {@code SwingConstants.NORTH}, {@code SwingConstants.SOUTH},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
         *        {@code SwingConstants.EAST} or {@code SwingConstants.WEST}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        public BasicArrowButton(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            this(direction, UIManager.getColor("control"), UIManager.getColor("controlShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                 UIManager.getColor("controlDkShadow"), UIManager.getColor("controlLtHighlight"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
         * Returns the direction of the arrow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        public int getDirection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            return direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         * Sets the direction of the arrow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
         * @param direction the direction of the arrow; one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
         *        of {@code SwingConstants.NORTH},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
         *        {@code SwingConstants.SOUTH},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
         *        {@code SwingConstants.EAST} or {@code SwingConstants.WEST}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        public void setDirection(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            this.direction = direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            Color origColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            boolean isPressed, isEnabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            int w, h, size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            w = getSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            h = getSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            origColor = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            isPressed = getModel().isPressed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            isEnabled = isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            g.setColor(getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            g.fillRect(1, 1, w-2, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            /// Draw the proper Border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            if (getBorder() != null && !(getBorder() instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                paintBorder(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            } else if (isPressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                g.drawRect(0, 0, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                // Using the background color set above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                g.drawLine(0, 0, 0, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                g.drawLine(1, 0, w-2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                g.setColor(highlight);    // inner 3D border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                g.drawLine(1, 1, 1, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                g.drawLine(2, 1, w-3, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                g.setColor(shadow);       // inner 3D border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                g.drawLine(1, h-2, w-2, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                g.drawLine(w-2, 1, w-2, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                g.setColor(darkShadow);     // black drop shadow  __|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                g.drawLine(0, h-1, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                g.drawLine(w-1, h-1, w-1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            // If there's no room to draw arrow, bail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            if(h < 5 || w < 5)      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                g.setColor(origColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            if (isPressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                g.translate(1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            // Draw the arrow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            size = Math.min((h - 4) / 3, (w - 4) / 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            size = Math.max(size, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            paintTriangle(g, (w - size) / 2, (h - size) / 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                size, direction, isEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            // Reset the Graphics back to it's original settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            if (isPressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                g.translate(-1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            g.setColor(origColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
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
         * Returns the preferred size of the {@code BasicArrowButton}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         * @return the preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            return new Dimension(16, 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
         * Returns the minimum size of the {@code BasicArrowButton}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
         * @return the minimum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            return new Dimension(5, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         * Returns the maximum size of the {@code BasicArrowButton}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
         * @return the maximum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
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
         * Returns whether the arrow button should get the focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
         * {@code BasicArrowButton}s are used as a child component of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
         * composite components such as {@code JScrollBar} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
         * {@code JComboBox}. Since the composite component typically gets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
         * focus, this method is overriden to return {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         * @return {@code false}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
          return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
         * Paints a triangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
         * @param g the {@code Graphics} to draw to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
         * @param x the x coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
         * @param y the y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
         * @param size the size of the triangle to draw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
         * @param direction the direction in which to draw the arrow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
         *        one of {@code SwingConstants.NORTH},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
         *        {@code SwingConstants.SOUTH}, {@code SwingConstants.EAST} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
         *        {@code SwingConstants.WEST}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
         * @param isEnabled whether or not the arrow is drawn enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        public void paintTriangle(Graphics g, int x, int y, int size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                                        int direction, boolean isEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            Color oldColor = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            int mid, i, j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            size = Math.max(size, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            mid = (size / 2) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            g.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            if(isEnabled)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                g.setColor(darkShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            switch(direction)       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            case NORTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                for(i = 0; i < size; i++)      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    g.drawLine(mid-i, i, mid+i, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                if(!isEnabled)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    g.drawLine(mid-i+2, i, mid+i, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            case SOUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                if(!isEnabled)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    g.translate(1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    for(i = size-1; i >= 0; i--)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                        g.drawLine(mid-i, j, mid+i, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                        j++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    g.translate(-1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                for(i = size-1; i >= 0; i--)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    g.drawLine(mid-i, j, mid+i, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    j++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            case WEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                for(i = 0; i < size; i++)      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    g.drawLine(i, mid-i, i, mid+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                if(!isEnabled)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    g.drawLine(i, mid-i+2, i, mid+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            case EAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                if(!isEnabled)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    g.translate(1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    for(i = size-1; i >= 0; i--)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                        g.drawLine(j, mid-i, j, mid+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                        j++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    g.translate(-1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                for(i = size-1; i >= 0; i--)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                    g.drawLine(j, mid-i, j, mid+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                    j++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            g.translate(-x, -y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            g.setColor(oldColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
}