jdk/src/share/classes/com/sun/java/swing/plaf/motif/MotifGraphicsUtils.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 455 11d2fe22f245
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 455
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  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
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 com.sun.java.swing.plaf.motif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.FontMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.event.KeyEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.swing.text.View;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author Jeff Dinkins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author Dave Kloba
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public class MotifGraphicsUtils implements SwingConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /* Client Property keys for text and accelerator text widths */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static final String MAX_ACC_WIDTH  =  "maxAccWidth";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Draws the point (<b>x</b>, <b>y</b>) in the current color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static void drawPoint(Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        g.drawLine(x, y, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Convenience method for drawing a grooved line
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public static void drawGroove(Graphics g, int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                                  Color shadow, Color highlight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        Color oldColor = g.getColor();  // Make no net change to g
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        g.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        g.drawRect(0, 0, w-2, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        g.drawLine(1, h-3, 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        g.drawLine(1, 1, w-3, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        g.drawLine(0, h-1, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        g.drawLine(w-1, h-1, w-1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        g.translate(-x, -y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        g.setColor(oldColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /** Draws <b>aString</b> in the rectangle defined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
      * (<b>x</b>, <b>y</b>, <b>width</b>, <b>height</b>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
      * <b>justification</b> specifies the text's justification, one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
      * LEFT, CENTER, or RIGHT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
      * <b>drawStringInRect()</b> does not clip to the rectangle, but instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
      * uses this rectangle and the desired justification to compute the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
      * at which to begin drawing the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
      * @see #drawString
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public static void drawStringInRect(Graphics g, String aString, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                 int width, int height, int justification) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        drawStringInRect(null, g, aString, x, y, width, height, justification);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    static void drawStringInRect(JComponent c, Graphics g, String aString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                 int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                 int justification) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        FontMetrics  fontMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        int          drawWidth, startX, startY, delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (g.getFont() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
//            throw new InconsistencyException("No font set");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        fontMetrics = SwingUtilities2.getFontMetrics(c, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (fontMetrics == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
//            throw new InconsistencyException("No metrics for Font " + font());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (justification == CENTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            drawWidth = SwingUtilities2.stringWidth(c, fontMetrics, aString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            if (drawWidth > width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                drawWidth = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            startX = x + (width - drawWidth) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        } else if (justification == RIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            drawWidth = SwingUtilities2.stringWidth(c, fontMetrics, aString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            if (drawWidth > width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                drawWidth = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            startX = x + width - drawWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            startX = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        delta = (height - fontMetrics.getAscent() - fontMetrics.getDescent()) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (delta < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            delta = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        startY = y + height - delta - fontMetrics.getDescent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        SwingUtilities2.drawString(c, g, aString, startX, startY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
   * This method is not being used to paint menu item since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
   * 6.0 This code left for compatibility only. Do not use or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
   * override it, this will not cause any visible effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
  public static void paintMenuItem(Graphics g, JComponent c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                   Icon checkIcon, Icon arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                                   Color background, Color foreground,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                   int defaultTextIconGap)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        JMenuItem b = (JMenuItem) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        Dimension size = b.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        Insets i = c.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        Rectangle viewRect = new Rectangle(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        viewRect.x += i.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        viewRect.y += i.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        viewRect.width -= (i.right + viewRect.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        viewRect.height -= (i.bottom + viewRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        Rectangle iconRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        Rectangle textRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        Rectangle acceleratorRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        Rectangle checkRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        Rectangle arrowRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        Font holdf = g.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        Font f = c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        g.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        FontMetrics fmAccel = SwingUtilities2.getFontMetrics(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            c, g, UIManager.getFont("MenuItem.acceleratorFont"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (c.isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            if (model.isArmed()|| (c instanceof JMenu && model.isSelected())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                g.setColor(background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                g.setColor(c.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            g.fillRect(0,0, size.width, size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        // get Accelerator text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        KeyStroke accelerator =  b.getAccelerator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        String acceleratorText = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (accelerator != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            int modifiers = accelerator.getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            if (modifiers > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                acceleratorText += "+";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            acceleratorText += KeyEvent.getKeyText(accelerator.getKeyCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        // layout the text and icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        String text = layoutMenuItem(c, fm, b.getText(), fmAccel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                                     acceleratorText, b.getIcon(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                                     checkIcon, arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                                     b.getVerticalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                     b.getHorizontalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                                     b.getVerticalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                                     b.getHorizontalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                                     viewRect, iconRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                                     textRect, acceleratorRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                     checkRect, arrowRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                     b.getText() == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                                     ? 0 : defaultTextIconGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                     defaultTextIconGap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                                     );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        // Paint the Check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        Color holdc = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (checkIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            if(model.isArmed() || (c instanceof JMenu && model.isSelected()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                g.setColor(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            checkIcon.paintIcon(c, g, checkRect.x, checkRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            g.setColor(holdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        // Paint the Icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if(b.getIcon() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            Icon icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            if(!model.isEnabled()) {
455
11d2fe22f245 6693507: There are unnecessary compilation warnings in the com.sun.java.swing.plaf.motif package
rupashka
parents: 2
diff changeset
   228
                icon = b.getDisabledIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            } else if(model.isPressed() && model.isArmed()) {
455
11d2fe22f245 6693507: There are unnecessary compilation warnings in the com.sun.java.swing.plaf.motif package
rupashka
parents: 2
diff changeset
   230
                icon = b.getPressedIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                if(icon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    // Use default icon
455
11d2fe22f245 6693507: There are unnecessary compilation warnings in the com.sun.java.swing.plaf.motif package
rupashka
parents: 2
diff changeset
   233
                    icon = b.getIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            } else {
455
11d2fe22f245 6693507: There are unnecessary compilation warnings in the com.sun.java.swing.plaf.motif package
rupashka
parents: 2
diff changeset
   236
                icon = b.getIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            if (icon!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                icon.paintIcon(c, g, iconRect.x, iconRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        // Draw the Text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if(text != null && !text.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            // Once BasicHTML becomes public, use BasicHTML.propertyKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            // instead of the hardcoded string below!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            View v = (View) c.getClientProperty("html");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                v.paint(g, textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                int mnemIndex = b.getDisplayedMnemonicIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                if(!model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    // *** paint the text disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                    g.setColor(b.getBackground().brighter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    SwingUtilities2.drawStringUnderlineCharAt(b, g,text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                        mnemIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                        textRect.x, textRect.y + fmAccel.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    g.setColor(b.getBackground().darker());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    SwingUtilities2.drawStringUnderlineCharAt(b, g,text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                        mnemIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                        textRect.x - 1, textRect.y + fmAccel.getAscent() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    // *** paint the text normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    if (model.isArmed()|| (c instanceof JMenu && model.isSelected())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                        g.setColor(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                        g.setColor(b.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    SwingUtilities2.drawStringUnderlineCharAt(b, g,text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                                                  mnemIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                                                  textRect.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                                  textRect.y + fm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        // Draw the Accelerator Text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if(acceleratorText != null && !acceleratorText.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            //Get the maxAccWidth from the parent to calculate the offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            int accOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            Container parent = b.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            if (parent != null && parent instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                JComponent p = (JComponent) parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                Integer maxValueInt = (Integer) p.getClientProperty(MotifGraphicsUtils.MAX_ACC_WIDTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                int maxValue = maxValueInt != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    maxValueInt.intValue() : acceleratorRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                //Calculate the offset, with which the accelerator texts will be drawn with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                accOffset = maxValue - acceleratorRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            g.setFont( UIManager.getFont("MenuItem.acceleratorFont") );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            if(!model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                // *** paint the acceleratorText disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                g.setColor(b.getBackground().brighter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                SwingUtilities2.drawString(c, g,acceleratorText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                              acceleratorRect.x - accOffset, acceleratorRect.y + fm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                g.setColor(b.getBackground().darker());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                SwingUtilities2.drawString(c, g,acceleratorText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                                              acceleratorRect.x - accOffset - 1, acceleratorRect.y + fm.getAscent() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                // *** paint the acceleratorText normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                if (model.isArmed()|| (c instanceof JMenu && model.isSelected()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                        g.setColor(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                        g.setColor(b.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                SwingUtilities2.drawString(c, g,acceleratorText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                                              acceleratorRect.x - accOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                                              acceleratorRect.y + fmAccel.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        // Paint the Arrow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (arrowIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            if(model.isArmed() || (c instanceof JMenu && model.isSelected()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                g.setColor(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            if( !(b.getParent() instanceof JMenuBar) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                arrowIcon.paintIcon(c, g, arrowRect.x, arrowRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        g.setColor(holdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        g.setFont(holdf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * Compute and return the location of the icons origin, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * location of origin of the text baseline, and a possibly clipped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * version of the compound labels string.  Locations are computed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * relative to the viewR rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    private static String layoutMenuItem(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        JComponent c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        FontMetrics fm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        String text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        FontMetrics fmAccel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        String acceleratorText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        Icon icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        Icon checkIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        Icon arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        int verticalAlignment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        int horizontalAlignment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        int verticalTextPosition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        int horizontalTextPosition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        Rectangle viewR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        Rectangle iconR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        Rectangle textR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        Rectangle acceleratorR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        Rectangle checkIconR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        Rectangle arrowIconR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        int textIconGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        int menuItemGap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        SwingUtilities.layoutCompoundLabel(c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                                           fm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                                           text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                                           icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                                           verticalAlignment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                                           horizontalAlignment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                                           verticalTextPosition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                                           horizontalTextPosition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                                           viewR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                                           iconR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                                           textR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                                           textIconGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        /* Initialize the acceelratorText bounds rectangle textR.  If a null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
         * or and empty String was specified we substitute "" here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
         * and use 0,0,0,0 for acceleratorTextR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        if( (acceleratorText == null) || acceleratorText.equals("") ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            acceleratorR.width = acceleratorR.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            acceleratorText = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            acceleratorR.width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                = SwingUtilities2.stringWidth(c, fmAccel, acceleratorText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            acceleratorR.height = fmAccel.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        /* Initialize the checkIcon bounds rectangle checkIconR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        if (checkIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            checkIconR.width = checkIcon.getIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            checkIconR.height = checkIcon.getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            checkIconR.width = checkIconR.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        /* Initialize the arrowIcon bounds rectangle arrowIconR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        if (arrowIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            arrowIconR.width = arrowIcon.getIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            arrowIconR.height = arrowIcon.getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            arrowIconR.width = arrowIconR.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        Rectangle labelR = iconR.union(textR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if( MotifGraphicsUtils.isLeftToRight(c) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            textR.x += checkIconR.width + menuItemGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            iconR.x += checkIconR.width + menuItemGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            // Position the Accelerator text rect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            acceleratorR.x = viewR.x + viewR.width - arrowIconR.width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                             - menuItemGap - acceleratorR.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            // Position the Check and Arrow Icons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            checkIconR.x = viewR.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            arrowIconR.x = viewR.x + viewR.width - menuItemGap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                           - arrowIconR.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            textR.x -= (checkIconR.width + menuItemGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            iconR.x -= (checkIconR.width + menuItemGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            // Position the Accelerator text rect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            acceleratorR.x = viewR.x + arrowIconR.width + menuItemGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            // Position the Check and Arrow Icons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            checkIconR.x = viewR.x + viewR.width - checkIconR.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            arrowIconR.x = viewR.x + menuItemGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        // Align the accelertor text and the check and arrow icons vertically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        // with the center of the label rect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        acceleratorR.y = labelR.y + (labelR.height/2) - (acceleratorR.height/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        arrowIconR.y = labelR.y + (labelR.height/2) - (arrowIconR.height/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        checkIconR.y = labelR.y + (labelR.height/2) - (checkIconR.height/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
          System.out.println("Layout: v=" +viewR+"  c="+checkIconR+" i="+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
          iconR+" t="+textR+" acc="+acceleratorR+" a="+arrowIconR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        return text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
  private static void drawMenuBezel(Graphics g, Color background,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                                    int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                                    int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
      // shadowed button region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
      g.setColor(background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
      g.fillRect(x,y,width,height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
      g.setColor(background.brighter().brighter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
      g.drawLine(x+1,       y+height-1,  x+width-1, y+height-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
      g.drawLine(x+width-1, y+height-2,  x+width-1, y+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
      g.setColor(background.darker().darker());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
      g.drawLine(x,   y,   x+width-2, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
      g.drawLine(x,   y+1, x,         y+height-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * Convenience function for determining ComponentOrientation.  Helps us
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * avoid having Munge directives throughout the code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    static boolean isLeftToRight( Component c ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        return c.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
}