jdk/src/share/classes/javax/swing/plaf/basic/BasicMenuItemUI.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 438 2ae294e4518c
child 1299 027d966d5658
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: 438
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.swing.MenuItemCheckIconFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import static sun.swing.SwingUtilities2.BASICMENUITEMUI_MAX_TEXT_OFFSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.text.View;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.swing.UIAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.swing.StringUIClientPropertyKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * BasicMenuItem implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author Georges Saab
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author David Karlton
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author Arnaud Weber
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author Fredrik Lagerblad
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class BasicMenuItemUI extends MenuItemUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    protected JMenuItem menuItem = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    protected Color selectionBackground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    protected Color selectionForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    protected Color disabledForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    protected Color acceleratorForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected Color acceleratorSelectionForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private   String acceleratorDelimiter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    protected int defaultTextIconGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    protected Font acceleratorFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    protected MouseInputListener mouseInputListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected MenuDragMouseListener menuDragMouseListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected MenuKeyListener menuKeyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * <code>PropertyChangeListener</code> returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * <code>createPropertyChangeListener</code>. You should not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * need to access this field, rather if you want to customize the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * <code>PropertyChangeListener</code> override
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <code>createPropertyChangeListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @see #createPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    protected PropertyChangeListener propertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    // BasicMenuUI also uses this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    Handler handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected Icon arrowIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    protected Icon checkIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    protected boolean oldBorderPainted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /* diagnostic aids -- should be false for production builds. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static final boolean TRACE =   false; // trace creates and disposes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private static final boolean VERBOSE = false; // show reuse hits/misses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private static final boolean DEBUG =   false;  // show bad params, misc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // Allows to reuse layoutInfo object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    // Shouldn't be used directly. Use getLayoutInfo() instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private final transient LayoutInfo layoutInfo = new LayoutInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /* Client Property keys for calculation of maximal widths */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    static final StringUIClientPropertyKey MAX_ARROW_WIDTH =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                        new StringUIClientPropertyKey("maxArrowWidth");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    static final StringUIClientPropertyKey MAX_CHECK_WIDTH =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                        new StringUIClientPropertyKey("maxCheckWidth");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    static final StringUIClientPropertyKey MAX_ICON_WIDTH =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                        new StringUIClientPropertyKey("maxIconWidth");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    static final StringUIClientPropertyKey MAX_TEXT_WIDTH =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                        new StringUIClientPropertyKey("maxTextWidth");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    static final StringUIClientPropertyKey MAX_ACC_WIDTH =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                        new StringUIClientPropertyKey("maxAccWidth");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    static final StringUIClientPropertyKey MAX_LABEL_WIDTH =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                        new StringUIClientPropertyKey("maxLabelWidth");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    static void loadActionMap(LazyActionMap map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        // NOTE: BasicMenuUI also calls into this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        map.put(new Actions(Actions.CLICK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        BasicLookAndFeel.installAudioActionMap(map);
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 static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return new BasicMenuItemUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        menuItem = (JMenuItem) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        installComponents(menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        String prefix = getPropertyPrefix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        acceleratorFont = UIManager.getFont("MenuItem.acceleratorFont");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        Object opaque = UIManager.get(getPropertyPrefix() + ".opaque");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (opaque != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            LookAndFeel.installProperty(menuItem, "opaque", opaque);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            LookAndFeel.installProperty(menuItem, "opaque", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if(menuItem.getMargin() == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
           (menuItem.getMargin() instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            menuItem.setMargin(UIManager.getInsets(prefix + ".margin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   149
        LookAndFeel.installProperty(menuItem, "iconTextGap", Integer.valueOf(4));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        defaultTextIconGap = menuItem.getIconTextGap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        LookAndFeel.installBorder(menuItem, prefix + ".border");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        oldBorderPainted = menuItem.isBorderPainted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        LookAndFeel.installProperty(menuItem, "borderPainted",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                                    UIManager.get(prefix + ".borderPainted"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        LookAndFeel.installColorsAndFont(menuItem,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                         prefix + ".background",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                         prefix + ".foreground",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                         prefix + ".font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        // MenuItem specific defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if (selectionBackground == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            selectionBackground instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            selectionBackground =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                UIManager.getColor(prefix + ".selectionBackground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (selectionForeground == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            selectionForeground instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            selectionForeground =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                UIManager.getColor(prefix + ".selectionForeground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (disabledForeground == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            disabledForeground instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            disabledForeground =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                UIManager.getColor(prefix + ".disabledForeground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (acceleratorForeground == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            acceleratorForeground instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            acceleratorForeground =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                UIManager.getColor(prefix + ".acceleratorForeground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (acceleratorSelectionForeground == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            acceleratorSelectionForeground instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            acceleratorSelectionForeground =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                UIManager.getColor(prefix + ".acceleratorSelectionForeground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        // Get accelerator delimiter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        acceleratorDelimiter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            UIManager.getString("MenuItem.acceleratorDelimiter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (acceleratorDelimiter == null) { acceleratorDelimiter = "+"; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        // Icons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (arrowIcon == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            arrowIcon instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            arrowIcon = UIManager.getIcon(prefix + ".arrowIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (checkIcon == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            checkIcon instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            checkIcon = UIManager.getIcon(prefix + ".checkIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            //In case of column layout, .checkIconFactory is defined for this UI,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            //the icon is compatible with it and useCheckAndArrow() is true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            //then the icon is handled by the checkIcon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            boolean isColumnLayout = LayoutInfo.isColumnLayout(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    BasicGraphicsUtils.isLeftToRight(menuItem), menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            if (isColumnLayout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                MenuItemCheckIconFactory iconFactory =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    (MenuItemCheckIconFactory) UIManager.get(prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                        + ".checkIconFactory");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                if (iconFactory != null && useCheckAndArrow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                        && iconFactory.isCompatible(checkIcon, prefix)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    checkIcon = iconFactory.getIcon(menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    protected void installComponents(JMenuItem menuItem){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        BasicHTML.updateRenderer(menuItem, menuItem.getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    protected String getPropertyPrefix() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return "MenuItem";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if ((mouseInputListener = createMouseInputListener(menuItem)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            menuItem.addMouseListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            menuItem.addMouseMotionListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if ((menuDragMouseListener = createMenuDragMouseListener(menuItem)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            menuItem.addMenuDragMouseListener(menuDragMouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        if ((menuKeyListener = createMenuKeyListener(menuItem)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            menuItem.addMenuKeyListener(menuKeyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if ((propertyChangeListener = createPropertyChangeListener(menuItem)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            menuItem.addPropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    protected void installKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        installLazyActionMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        updateAcceleratorBinding();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    void installLazyActionMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        LazyActionMap.installLazyActionMap(menuItem, BasicMenuItemUI.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                                           getPropertyPrefix() + ".actionMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        menuItem = (JMenuItem)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        uninstallComponents(menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        // Remove values from the parent's Client Properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        JComponent p = getMenuItemParent(menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if(p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            p.putClientProperty(BasicMenuItemUI.MAX_ARROW_WIDTH, null );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            p.putClientProperty(BasicMenuItemUI.MAX_CHECK_WIDTH, null );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            p.putClientProperty(BasicMenuItemUI.MAX_ACC_WIDTH, null );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            p.putClientProperty(BasicMenuItemUI.MAX_TEXT_WIDTH, null );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            p.putClientProperty(BasicMenuItemUI.MAX_ICON_WIDTH, null );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            p.putClientProperty(BasicMenuItemUI.MAX_LABEL_WIDTH, null );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            p.putClientProperty(BASICMENUITEMUI_MAX_TEXT_OFFSET, null );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        menuItem = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        LookAndFeel.uninstallBorder(menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        LookAndFeel.installProperty(menuItem, "borderPainted", oldBorderPainted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (menuItem.getMargin() instanceof UIResource)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            menuItem.setMargin(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (arrowIcon instanceof UIResource)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            arrowIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (checkIcon instanceof UIResource)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            checkIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    protected void uninstallComponents(JMenuItem menuItem){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        BasicHTML.updateRenderer(menuItem, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        if (mouseInputListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            menuItem.removeMouseListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            menuItem.removeMouseMotionListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (menuDragMouseListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            menuItem.removeMenuDragMouseListener(menuDragMouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if (menuKeyListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            menuItem.removeMenuKeyListener(menuKeyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        if (propertyChangeListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            menuItem.removePropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        mouseInputListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        menuDragMouseListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        menuKeyListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        propertyChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        handler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    protected void uninstallKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        SwingUtilities.replaceUIActionMap(menuItem, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        SwingUtilities.replaceUIInputMap(menuItem, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                                         WHEN_IN_FOCUSED_WINDOW, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    protected MouseInputListener createMouseInputListener(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    protected MenuDragMouseListener createMenuDragMouseListener(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    protected MenuKeyListener createMenuKeyListener(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Creates a <code>PropertyChangeListener</code> which will be added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * the menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * If this method returns null then it will not be added to the menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @return an instance of a <code>PropertyChangeListener</code> or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    protected PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                                  createPropertyChangeListener(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    Handler getHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    InputMap createInputMap(int condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            return new ComponentInputMapUIResource(menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    void updateAcceleratorBinding() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        KeyStroke accelerator = menuItem.getAccelerator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        InputMap windowInputMap = SwingUtilities.getUIInputMap(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                       menuItem, JComponent.WHEN_IN_FOCUSED_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        if (windowInputMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            windowInputMap.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        if (accelerator != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            if (windowInputMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                windowInputMap = createInputMap(JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                                                WHEN_IN_FOCUSED_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                SwingUtilities.replaceUIInputMap(menuItem,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                           JComponent.WHEN_IN_FOCUSED_WINDOW, windowInputMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            windowInputMap.put(accelerator, "doClick");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public Dimension getMinimumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        Dimension d = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            d = getPreferredSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        return getPreferredMenuItemSize(c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                                        checkIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                                        arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                                        defaultTextIconGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        Dimension d = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            d = getPreferredSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            d.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    // Returns parent of this component if it is not a top-level menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    // Otherwise returns null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    private static JComponent getMenuItemParent(JMenuItem mi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        Container parent = mi.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if ((parent instanceof JComponent) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
             (!(mi instanceof JMenu) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
               !((JMenu)mi).isTopLevelMenu())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return (JComponent) parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    protected Dimension getPreferredMenuItemSize(JComponent c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                                                 Icon checkIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                                                 Icon arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                                 int defaultTextIconGap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        // The method also determines the preferred width of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        // parent popup menu (through DefaultMenuLayout class).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        // The menu width equals to the maximal width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        // among child menu items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        // Menu item width will be a sum of the widest check icon, label,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        // arrow icon and accelerator text among neighbor menu items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        // For the latest menu item we will know the maximal widths exactly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        // It will be the widest menu item and it will determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        // the width of the parent popup menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        // There is a conceptual problem: if user sets preferred size manually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        // for a menu item, this method won't be called for it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        // (see JComponent.getPreferredSize()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        // maximal widths won't be calculated, other menu items won't be able
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        // to take them into account and will be layouted in such a way,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        // as there is no the item with manual preferred size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        // But after the first paint() method call, all maximal widths
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        // will be correctly calculated and layout of some menu items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        // can be changed. For example, it can cause a shift of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        // the icon and text when user points a menu item by mouse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        JMenuItem mi = (JMenuItem) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        LayoutInfo li = getLayoutInfo(mi, checkIcon, arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                createMaxViewRect(), defaultTextIconGap, acceleratorDelimiter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                BasicGraphicsUtils.isLeftToRight(mi), acceleratorFont,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                useCheckAndArrow(), getPropertyPrefix());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        Dimension result = new Dimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        // Calculate the result width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        result.width = li.leadingGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        addWidth(li.maxCheckWidth, li.afterCheckIconGap, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        // Take into account mimimal text offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        if ((!li.isTopLevelMenu)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                && (li.minTextOffset > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                && (result.width < li.minTextOffset)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            result.width = li.minTextOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        addWidth(li.maxLabelWidth, li.gap, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        addWidth(li.maxAccWidth, li.gap, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        addWidth(li.maxArrowWidth, li.gap, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        // Calculate the result height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        result.height = max(li.checkRect.height, li.labelRect.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                            li.accRect.height, li.arrowRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        // Take into account menu item insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        Insets insets = li.mi.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        if(insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            result.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            result.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        // if the width is even, bump it up one. This is critical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        // for the focus dash line to draw properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        if(result.width%2 == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            result.width++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        // if the height is even, bump it up one. This is critical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        // for the text to center properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        if(result.height%2 == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                && Boolean.TRUE !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                    UIManager.get(getPropertyPrefix() + ".evenHeight")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            result.height++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        li.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    private Rectangle createMaxViewRect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        return new Rectangle(0,0,Short.MAX_VALUE, Short.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    private void addWidth(int width, int gap, Dimension result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        if (width > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            result.width += width + gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    private static int max(int... values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        int maxValue = Integer.MIN_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        for (int i : values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            if (i > maxValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                maxValue = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        return maxValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    // LayoutInfo helps to calculate preferred size and to paint a menu item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    private static class LayoutInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        JMenuItem mi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        JComponent miParent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        FontMetrics fm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        FontMetrics accFm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        Icon icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        Icon checkIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        Icon arrowIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        String text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        String accText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        boolean isColumnLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        boolean useCheckAndArrow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        boolean isLeftToRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        boolean isTopLevelMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        View htmlView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        int verticalAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        int horizontalAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        int verticalTextPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        int horizontalTextPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        int gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        int leadingGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        int afterCheckIconGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        int minTextOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        Rectangle viewRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        Rectangle iconRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        Rectangle textRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        Rectangle accRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        Rectangle checkRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        Rectangle arrowRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        Rectangle labelRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        int origIconWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        int origTextWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        int origAccWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        int origCheckWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        int origArrowWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        int maxIconWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        int maxTextWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        int maxAccWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        int maxCheckWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        int maxArrowWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        int maxLabelWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        // Empty constructor helps to create "final" LayoutInfo object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        public LayoutInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        public LayoutInfo(JMenuItem mi, Icon checkIcon, Icon arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                          Rectangle viewRect, int gap, String accDelimiter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                          boolean isLeftToRight, Font acceleratorFont,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                          boolean useCheckAndArrow, String propertyPrefix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            reset(mi, checkIcon, arrowIcon, viewRect, gap, accDelimiter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                  isLeftToRight, acceleratorFont, useCheckAndArrow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                  propertyPrefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        // Allows to reuse a LayoutInfo object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        public void reset(JMenuItem mi, Icon checkIcon, Icon arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                          Rectangle viewRect, int gap, String accDelimiter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                          boolean isLeftToRight, Font acceleratorFont,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                          boolean useCheckAndArrow, String propertyPrefix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            this.mi = mi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            this.miParent = getMenuItemParent(mi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            this.accText = getAccText(accDelimiter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            this.verticalAlignment = mi.getVerticalAlignment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            this.horizontalAlignment = mi.getHorizontalAlignment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            this.verticalTextPosition = mi.getVerticalTextPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            this.horizontalTextPosition = mi.getHorizontalTextPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            this.useCheckAndArrow = useCheckAndArrow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            this.fm = mi.getFontMetrics(mi.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            this.accFm = mi.getFontMetrics(acceleratorFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            this.isLeftToRight = isLeftToRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            this.isColumnLayout = isColumnLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            this.isTopLevelMenu = (this.miParent == null)? true : false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            this.checkIcon = checkIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            this.icon = getIcon(propertyPrefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            this.arrowIcon = arrowIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            this.text = mi.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            this.gap = gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            this.afterCheckIconGap = getAfterCheckIconGap(propertyPrefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            this.minTextOffset = getMinTextOffset(propertyPrefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            this.htmlView = (View) mi.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            this.viewRect = viewRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            this.iconRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            this.textRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            this.accRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            this.checkRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            this.arrowRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            this.labelRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            calcWidthsAndHeights();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            this.origIconWidth = iconRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            this.origTextWidth = textRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            this.origAccWidth = accRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            this.origCheckWidth = checkRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            this.origArrowWidth = arrowRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            calcMaxWidths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            this.leadingGap = getLeadingGap(propertyPrefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            calcMaxTextOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        // Clears fields to remove all links to other objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        // to prevent memory leaks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        public void clear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            mi = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            miParent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            fm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            accFm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            icon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            checkIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            arrowIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            text = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            accText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            htmlView = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            viewRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            iconRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            textRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            accRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            checkRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            arrowRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            labelRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        private String getAccText(String acceleratorDelimiter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            String accText = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            KeyStroke accelerator = mi.getAccelerator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            if (accelerator != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                int modifiers = accelerator.getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                if (modifiers > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                    accText = KeyEvent.getKeyModifiersText(modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                    accText += acceleratorDelimiter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                int keyCode = accelerator.getKeyCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                if (keyCode != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                    accText += KeyEvent.getKeyText(keyCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                    accText += accelerator.getKeyChar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            return accText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        // In case of column layout, .checkIconFactory is defined for this UI,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        // the icon is compatible with it and useCheckAndArrow() is true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        // then the icon is handled by the checkIcon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        private Icon getIcon(String propertyPrefix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            Icon icon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            MenuItemCheckIconFactory iconFactory =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                (MenuItemCheckIconFactory) UIManager.get(propertyPrefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                    + ".checkIconFactory");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            if (!isColumnLayout || !useCheckAndArrow || iconFactory == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                    || !iconFactory.isCompatible(checkIcon, propertyPrefix)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
               icon = mi.getIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        private int getMinTextOffset(String propertyPrefix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            int minimumTextOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            Object minimumTextOffsetObject =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                    UIManager.get(propertyPrefix + ".minimumTextOffset");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            if (minimumTextOffsetObject instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                minimumTextOffset = (Integer) minimumTextOffsetObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            return minimumTextOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        private int getAfterCheckIconGap(String propertyPrefix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            int afterCheckIconGap = gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            Object afterCheckIconGapObject =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                    UIManager.get(propertyPrefix + ".afterCheckIconGap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            if (afterCheckIconGapObject instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                afterCheckIconGap = (Integer) afterCheckIconGapObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            return afterCheckIconGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        private int getLeadingGap(String propertyPrefix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            if (maxCheckWidth > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                return getCheckOffset(propertyPrefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                return gap; // There is no any check icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        private int getCheckOffset(String propertyPrefix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            int checkIconOffset = gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            Object checkIconOffsetObject =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                    UIManager.get(propertyPrefix + ".checkIconOffset");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            if (checkIconOffsetObject instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                checkIconOffset = (Integer) checkIconOffsetObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            return checkIconOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        private void calcWidthsAndHeights()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            // iconRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                iconRect.width = icon.getIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                iconRect.height = icon.getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            // accRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            if (!accText.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                accRect.width = SwingUtilities2.stringWidth(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                        mi, accFm, accText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                accRect.height = accFm.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            // textRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            if (text == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                text = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            } else if (!text.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                if (htmlView != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                    // Text is HTML
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                    textRect.width =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                            (int) htmlView.getPreferredSpan(View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                    textRect.height =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                            (int) htmlView.getPreferredSpan(View.Y_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                    // Text isn't HTML
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                    textRect.width =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                            SwingUtilities2.stringWidth(mi, fm, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                    textRect.height = fm.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            if (useCheckAndArrow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                // checkIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                if (checkIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                    checkRect.width = checkIcon.getIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                    checkRect.height = checkIcon.getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                // arrowRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                if (arrowIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                    arrowRect.width = arrowIcon.getIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                    arrowRect.height = arrowIcon.getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            // labelRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            if (isColumnLayout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                labelRect.width = iconRect.width + textRect.width + gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                labelRect.height = max(checkRect.height, iconRect.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                        textRect.height, accRect.height, arrowRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                textRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                iconRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                SwingUtilities.layoutCompoundLabel(mi, fm, text, icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                        verticalAlignment, horizontalAlignment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                        verticalTextPosition, horizontalTextPosition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                        viewRect, iconRect, textRect, gap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                 labelRect = iconRect.union(textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        private void calcMaxWidths() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            maxCheckWidth = calcMaxValue(BasicMenuItemUI.MAX_CHECK_WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                    checkRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            maxArrowWidth = calcMaxValue(BasicMenuItemUI.MAX_ARROW_WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                    arrowRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            maxAccWidth = calcMaxValue(BasicMenuItemUI.MAX_ACC_WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                    accRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            if (isColumnLayout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                maxIconWidth = calcMaxValue(BasicMenuItemUI.MAX_ICON_WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                        iconRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                maxTextWidth = calcMaxValue(BasicMenuItemUI.MAX_TEXT_WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                        textRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                int curGap = gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                if ((maxIconWidth == 0) || (maxTextWidth == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                    curGap = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                maxLabelWidth =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                        calcMaxValue(BasicMenuItemUI.MAX_LABEL_WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                        maxIconWidth + maxTextWidth + curGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                // We shouldn't use current icon and text widths
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                // in maximal widths calculation for complex layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                maxIconWidth = getParentIntProperty(BasicMenuItemUI.MAX_ICON_WIDTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                maxLabelWidth = calcMaxValue(BasicMenuItemUI.MAX_LABEL_WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                        labelRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                // If maxLabelWidth is wider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                // than the widest icon + the widest text + gap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                // we should update the maximal text witdh
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                int candidateTextWidth = maxLabelWidth - maxIconWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                if (maxIconWidth > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                    candidateTextWidth -= gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                maxTextWidth = calcMaxValue(BasicMenuItemUI.MAX_TEXT_WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                        candidateTextWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        // Calculates and returns maximal value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        // through specified parent component client property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        private int calcMaxValue(Object propertyName, int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            // Get maximal value from parent client property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            int maxValue = getParentIntProperty(propertyName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            // Store new maximal width in parent client property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            if (value > maxValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                if (miParent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                    miParent.putClientProperty(propertyName, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                return maxValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        // Returns parent client property as int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        private int getParentIntProperty(Object propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            Object value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            if (miParent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                value = miParent.getClientProperty(propertyName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            if ((value == null) || !(value instanceof Integer)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            return (Integer)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        private boolean isColumnLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            return isColumnLayout(isLeftToRight, horizontalAlignment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                    horizontalTextPosition, verticalTextPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        public static boolean isColumnLayout(boolean isLeftToRight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                                             JMenuItem mi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            assert(mi != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            return isColumnLayout(isLeftToRight, mi.getHorizontalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                    mi.getHorizontalTextPosition(), mi.getVerticalTextPosition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        // Answers should we do column layout for a menu item or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        // We do it when a user doesn't set any alignments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        // and text positions manually, except the vertical alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        public static boolean isColumnLayout( boolean isLeftToRight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                int horizontalAlignment, int horizontalTextPosition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                int verticalTextPosition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            if (verticalTextPosition != SwingConstants.CENTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            if (isLeftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                if (horizontalAlignment != SwingConstants.LEADING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                 && horizontalAlignment != SwingConstants.LEFT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                if (horizontalTextPosition != SwingConstants.TRAILING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                 && horizontalTextPosition != SwingConstants.RIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                if (horizontalAlignment != SwingConstants.LEADING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                 && horizontalAlignment != SwingConstants.RIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                if (horizontalTextPosition != SwingConstants.TRAILING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                 && horizontalTextPosition != SwingConstants.LEFT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        // Calculates maximal text offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        // It is required for some L&Fs (ex: Vista L&F).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        // The offset is meaningful only for L2R column layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        private void calcMaxTextOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            if (!isColumnLayout || !isLeftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            // Calculate the current text offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            int offset = viewRect.x + leadingGap + maxCheckWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                     + afterCheckIconGap + maxIconWidth + gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            if (maxCheckWidth == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                offset -= afterCheckIconGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            if (maxIconWidth == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                offset -= gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            // maximal text offset shouldn't be less than minimal text offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            if (offset < minTextOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                offset = minTextOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            // Calculate and store the maximal text offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            calcMaxValue(BASICMENUITEMUI_MAX_TEXT_OFFSET, offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            StringBuilder result = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            result.append(super.toString()).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            result.append("accFm = ").append(accFm).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            result.append("accRect = ").append(accRect).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            result.append("accText = ").append(accText).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            result.append("afterCheckIconGap = ").append(afterCheckIconGap)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                    .append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            result.append("arrowIcon = ").append(arrowIcon).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            result.append("arrowRect = ").append(arrowRect).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            result.append("checkIcon = ").append(checkIcon).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            result.append("checkRect = ").append(checkRect).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            result.append("fm = ").append(fm).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            result.append("gap = ").append(gap).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            result.append("horizontalAlignment = ").append(horizontalAlignment)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                    .append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            result.append("horizontalTextPosition = ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                    .append(horizontalTextPosition).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            result.append("htmlView = ").append(htmlView).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            result.append("icon = ").append(icon).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            result.append("iconRect = ").append(iconRect).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            result.append("isColumnLayout = ").append(isColumnLayout).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            result.append("isLeftToRight = ").append(isLeftToRight).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            result.append("isTopLevelMenu = ").append(isTopLevelMenu).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            result.append("labelRect = ").append(labelRect).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            result.append("leadingGap = ").append(leadingGap).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            result.append("maxAccWidth = ").append(maxAccWidth).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            result.append("maxArrowWidth = ").append(maxArrowWidth).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            result.append("maxCheckWidth = ").append(maxCheckWidth).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            result.append("maxIconWidth = ").append(maxIconWidth).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            result.append("maxLabelWidth = ").append(maxLabelWidth).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            result.append("maxTextWidth = ").append(maxTextWidth).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            result.append("maxTextOffset = ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                    .append(getParentIntProperty(BASICMENUITEMUI_MAX_TEXT_OFFSET))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                    .append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            result.append("mi = ").append(mi).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            result.append("minTextOffset = ").append(minTextOffset).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            result.append("miParent = ").append(miParent).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            result.append("origAccWidth = ").append(origAccWidth).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            result.append("origArrowWidth = ").append(origArrowWidth).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            result.append("origCheckWidth = ").append(origCheckWidth).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            result.append("origIconWidth = ").append(origIconWidth).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            result.append("origTextWidth = ").append(origTextWidth).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            result.append("text = ").append(text).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            result.append("textRect = ").append(textRect).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            result.append("useCheckAndArrow = ").append(useCheckAndArrow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    .append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            result.append("verticalAlignment = ").append(verticalAlignment)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                    .append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            result.append("verticalTextPosition = ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                    .append(verticalTextPosition).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            result.append("viewRect = ").append(viewRect).append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            return result.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    } // End of LayoutInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    // Reuses layoutInfo object to reduce the amount of produced garbage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    private LayoutInfo getLayoutInfo(JMenuItem mi, Icon checkIcon, Icon arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                             Rectangle viewRect, int gap, String accDelimiter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                             boolean isLeftToRight, Font acceleratorFont,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                             boolean useCheckAndArrow, String propertyPrefix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        // layoutInfo is final and always not null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        layoutInfo.reset(mi, checkIcon, arrowIcon, viewRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                gap, accDelimiter, isLeftToRight, acceleratorFont,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                useCheckAndArrow, propertyPrefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        return layoutInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * We draw the background in paintMenuItem()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * so override update (which fills the background of opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * components by default) to just call paint().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        paint(g, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        paintMenuItem(g, c, checkIcon, arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                      selectionBackground, selectionForeground,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                      defaultTextIconGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    protected void paintMenuItem(Graphics g, JComponent c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                                     Icon checkIcon, Icon arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                                     Color background, Color foreground,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                                     int defaultTextIconGap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        // Save original graphics font and color
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        Font holdf = g.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        Color holdc = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        JMenuItem mi = (JMenuItem) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        g.setFont(mi.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        applyInsets(viewRect, mi.getInsets());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        LayoutInfo li = getLayoutInfo(mi, checkIcon, arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                viewRect, defaultTextIconGap, acceleratorDelimiter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                BasicGraphicsUtils.isLeftToRight(mi), acceleratorFont,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                useCheckAndArrow(), getPropertyPrefix());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        layoutMenuItem(li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        paintBackground(g, mi, background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        paintCheckIcon(g, li, holdc, foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        paintIcon(g, li, holdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        paintText(g, li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        paintAccText(g, li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        paintArrowIcon(g, li, foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        // Restore original graphics font and color
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        g.setColor(holdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        g.setFont(holdf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        li.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    private void paintIcon(Graphics g, LayoutInfo li, Color holdc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        if (li.icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            Icon icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            ButtonModel model = li.mi.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            if (!model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                icon = (Icon) li.mi.getDisabledIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            } else if (model.isPressed() && model.isArmed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                icon = (Icon) li.mi.getPressedIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                if (icon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                    // Use default icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                    icon = (Icon) li.mi.getIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                icon = (Icon) li.mi.getIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                icon.paintIcon(li.mi, g, li.iconRect.x, li.iconRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                g.setColor(holdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    private void paintCheckIcon(Graphics g, LayoutInfo li,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                                Color holdc, Color foreground) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        if (li.checkIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            ButtonModel model = li.mi.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            if (model.isArmed()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                    || (li.mi instanceof JMenu && model.isSelected())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                g.setColor(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                g.setColor(holdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            if (li.useCheckAndArrow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                li.checkIcon.paintIcon(li.mi, g, li.checkRect.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                                       li.checkRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            g.setColor(holdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    private void paintAccText(Graphics g, LayoutInfo li) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        if (!li.accText.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            ButtonModel model = li.mi.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            g.setFont(acceleratorFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            if (!model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                // *** paint the accText disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                if (disabledForeground != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                    g.setColor(disabledForeground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                    SwingUtilities2.drawString(li.mi, g, li.accText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                                 li.accRect.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                                 li.accRect.y + li.accFm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                    g.setColor(li.mi.getBackground().brighter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                    SwingUtilities2.drawString(li.mi, g, li.accText, li.accRect.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                                 li.accRect.y + li.accFm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                    g.setColor(li.mi.getBackground().darker());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                    SwingUtilities2.drawString(li.mi, g, li.accText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                            li.accRect.x - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                            li.accRect.y + li.accFm.getAscent() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                // *** paint the accText normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                if (model.isArmed() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                        (li.mi instanceof JMenu && model.isSelected())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                    g.setColor(acceleratorSelectionForeground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                    g.setColor(acceleratorForeground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                SwingUtilities2.drawString(li.mi, g, li.accText, li.accRect.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                        li.accRect.y + li.accFm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    private void paintText(Graphics g, LayoutInfo li) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        if (!li.text.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            if (li.htmlView != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                // Text is HTML
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                li.htmlView.paint(g, li.textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                // Text isn't HTML
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                paintText(g, li.mi, li.textRect, li.text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    private void paintArrowIcon(Graphics g, LayoutInfo li, Color foreground) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        if (li.arrowIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            ButtonModel model = li.mi.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            if (model.isArmed()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                    || (li.mi instanceof JMenu && model.isSelected())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                g.setColor(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            if (li.useCheckAndArrow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                li.arrowIcon.paintIcon(li.mi, g, li.arrowRect.x, li.arrowRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    private void applyInsets(Rectangle rect, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        if(insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            rect.x += insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            rect.y += insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            rect.width -= (insets.right + rect.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            rect.height -= (insets.bottom + rect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * Draws the background of the menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * @param g the paint graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * @param menuItem menu item to be painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * @param bgColor selection background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        ButtonModel model = menuItem.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        Color oldColor = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        int menuWidth = menuItem.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        int menuHeight = menuItem.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        if(menuItem.isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            if (model.isArmed()|| (menuItem instanceof JMenu && model.isSelected())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                g.setColor(bgColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                g.fillRect(0,0, menuWidth, menuHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                g.setColor(menuItem.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                g.fillRect(0,0, menuWidth, menuHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            g.setColor(oldColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        else if (model.isArmed() || (menuItem instanceof JMenu &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                                     model.isSelected())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            g.setColor(bgColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            g.fillRect(0,0, menuWidth, menuHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            g.setColor(oldColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     * Renders the text of the current menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     * @param g graphics context
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     * @param menuItem menu item to render
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * @param textRect bounding rectangle for rendering the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * @param text string to render
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        ButtonModel model = menuItem.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        FontMetrics fm = SwingUtilities2.getFontMetrics(menuItem, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        int mnemIndex = menuItem.getDisplayedMnemonicIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        if(!model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            // *** paint the text disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            if ( UIManager.get("MenuItem.disabledForeground") instanceof Color ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                g.setColor( UIManager.getColor("MenuItem.disabledForeground") );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                SwingUtilities2.drawStringUnderlineCharAt(menuItem, g,text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                          mnemIndex, textRect.x,  textRect.y + fm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                g.setColor(menuItem.getBackground().brighter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                           mnemIndex, textRect.x, textRect.y + fm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                g.setColor(menuItem.getBackground().darker());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                SwingUtilities2.drawStringUnderlineCharAt(menuItem, g,text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                           mnemIndex,  textRect.x - 1, textRect.y +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                           fm.getAscent() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            // *** paint the text normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            if (model.isArmed()|| (menuItem instanceof JMenu && model.isSelected())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                g.setColor(selectionForeground); // Uses protected field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            SwingUtilities2.drawStringUnderlineCharAt(menuItem, g,text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                           mnemIndex, textRect.x, textRect.y + fm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     * Layout icon, text, check icon, accelerator text and arrow icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     * in the viewRect and return their positions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     * If horizontalAlignment, verticalTextPosition and horizontalTextPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * are default (user doesn't set any manually) the layouting algorithm is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     * Elements are layouted in the five columns:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * check icon + icon + text + accelerator text + arrow icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     * In the other case elements are layouted in the four columns:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * check icon + label + accelerator text + arrow icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * Label is icon and text rectangles union.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * The order of columns can be reversed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * It depends on the menu item orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    private void layoutMenuItem(LayoutInfo li)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        li.checkRect.width = li.maxCheckWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        li.accRect.width = li.maxAccWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        li.arrowRect.width = li.maxArrowWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        if (li.isColumnLayout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            if (li.isLeftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                doLTRColumnLayout(li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                doRTLColumnLayout(li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            if (li.isLeftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                doLTRComplexLayout(li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                doRTLComplexLayout(li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        alignAccCheckAndArrowVertically(li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    // Aligns the accelertor text and the check and arrow icons vertically
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    // with the center of the label rect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    private void alignAccCheckAndArrowVertically(LayoutInfo li) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        li.accRect.y = (int)(li.labelRect.y + (float)li.labelRect.height/2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                - (float)li.accRect.height/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        fixVerticalAlignment(li, li.accRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        if (li.useCheckAndArrow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            li.arrowRect.y = (int)(li.labelRect.y + (float)li.labelRect.height/2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                    - (float)li.arrowRect.height/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
            li.checkRect.y = (int)(li.labelRect.y + (float)li.labelRect.height/2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                    - (float)li.checkRect.height/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
            fixVerticalAlignment(li, li.arrowRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            fixVerticalAlignment(li, li.checkRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    // Fixes vertical alignment of all menu item elements if a rect.y
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    // or (rect.y + rect.height) is out of viewRect bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    private void fixVerticalAlignment(LayoutInfo li, Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        int delta = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        if (r.y < li.viewRect.y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            delta = li.viewRect.y - r.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        } else if (r.y + r.height > li.viewRect.y + li.viewRect.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            delta = li.viewRect.y + li.viewRect.height - r.y - r.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        if (delta != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            li.checkRect.y += delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            li.iconRect.y += delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            li.textRect.y += delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            li.accRect.y += delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
            li.arrowRect.y += delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    private void doLTRColumnLayout(LayoutInfo li) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        // Set maximal width for all the five basic rects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        // (three other ones are already maximal)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        li.iconRect.width = li.maxIconWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
        li.textRect.width = li.maxTextWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        // Set X coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        // All rects will be aligned at the left side
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        calcXPositionsL2R(li.viewRect.x, li.leadingGap, li.gap, li.checkRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                li.iconRect, li.textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        // Tune afterCheckIconGap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        if (li.checkRect.width > 0) { // there is the afterCheckIconGap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            li.iconRect.x += li.afterCheckIconGap - li.gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            li.textRect.x += li.afterCheckIconGap - li.gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        calcXPositionsR2L(li.viewRect.x + li.viewRect.width, li.gap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                li.arrowRect, li.accRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        // Take into account minimal text offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        int textOffset = li.textRect.x - li.viewRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        if (!li.isTopLevelMenu && (textOffset < li.minTextOffset)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            li.textRect.x += li.minTextOffset - textOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        // Take into account the left side bearings for text and accelerator text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        fixTextRects(li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        // Set Y coordinate for text and icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        // Y coordinates for other rects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        // will be calculated later in layoutMenuItem.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        calcTextAndIconYPositions(li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        // Calculate valid X and Y coordinates for labelRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        li.labelRect = li.textRect.union(li.iconRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    private void doLTRComplexLayout(LayoutInfo li) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        li.labelRect.width = li.maxLabelWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        // Set X coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        calcXPositionsL2R(li.viewRect.x, li.leadingGap, li.gap, li.checkRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                li.labelRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        // Tune afterCheckIconGap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        if (li.checkRect.width > 0) { // there is the afterCheckIconGap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            li.labelRect.x += li.afterCheckIconGap - li.gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        calcXPositionsR2L(li.viewRect.x + li.viewRect.width, li.gap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                li.arrowRect, li.accRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        // Take into account minimal text offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        int labelOffset = li.labelRect.x - li.viewRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        if (!li.isTopLevelMenu && (labelOffset < li.minTextOffset)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
            li.labelRect.x += li.minTextOffset - labelOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        // Take into account the left side bearing for accelerator text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        // The LSB for text is taken into account in layoutCompoundLabel() below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        fixAccTextRect(li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        // Layout icon and text with SwingUtilities.layoutCompoundLabel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        // within the labelRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        li.textRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        li.iconRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        SwingUtilities.layoutCompoundLabel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                            li.mi, li.fm, li.text, li.icon, li.verticalAlignment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                            li.horizontalAlignment, li.verticalTextPosition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                            li.horizontalTextPosition, li.labelRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                            li.iconRect, li.textRect, li.gap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    private void doRTLColumnLayout(LayoutInfo li) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        // Set maximal width for all the five basic rects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        // (three other ones are already maximal)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        li.iconRect.width = li.maxIconWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        li.textRect.width = li.maxTextWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        // Set X coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        calcXPositionsR2L(li.viewRect.x + li.viewRect.width, li.leadingGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                li.gap, li.checkRect, li.iconRect, li.textRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        // Tune the gap after check icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        if (li.checkRect.width > 0) { // there is the gap after check icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
            li.iconRect.x -= li.afterCheckIconGap - li.gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            li.textRect.x -= li.afterCheckIconGap - li.gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        calcXPositionsL2R(li.viewRect.x, li.gap, li.arrowRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                li.accRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        // Take into account minimal text offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        int textOffset = (li.viewRect.x + li.viewRect.width)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                       - (li.textRect.x + li.textRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        if (!li.isTopLevelMenu && (textOffset < li.minTextOffset)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
            li.textRect.x -= li.minTextOffset - textOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        // Align icon, text, accelerator text, check icon and arrow icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        // at the right side
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        rightAlignAllRects(li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        // Take into account the left side bearings for text and accelerator text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
        fixTextRects(li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        // Set Y coordinates for text and icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        // Y coordinates for other rects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        // will be calculated later in layoutMenuItem.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        calcTextAndIconYPositions(li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
        // Calculate valid X and Y coordinate for labelRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        li.labelRect = li.textRect.union(li.iconRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
    private void doRTLComplexLayout(LayoutInfo li) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        li.labelRect.width = li.maxLabelWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
        // Set X coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        calcXPositionsR2L(li.viewRect.x + li.viewRect.width, li.leadingGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                li.gap, li.checkRect, li.labelRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        // Tune the gap after check icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
        if (li.checkRect.width > 0) { // there is the gap after check icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
            li.labelRect.x -= li.afterCheckIconGap - li.gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        calcXPositionsL2R(li.viewRect.x, li.gap, li.arrowRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                li.accRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
        // Take into account minimal text offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        int labelOffset = (li.viewRect.x + li.viewRect.width)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                        - (li.labelRect.x + li.labelRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        if (!li.isTopLevelMenu && (labelOffset < li.minTextOffset)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
            li.labelRect.x -= li.minTextOffset - labelOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        // Align icon, text, accelerator text, check icon and arrow icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        // at the right side
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        rightAlignAllRects(li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
        // Take into account the left side bearing for accelerator text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        // The LSB for text is taken into account in layoutCompoundLabel() below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        fixAccTextRect(li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        // Layout icon and text with SwingUtilities.layoutCompoundLabel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
        // within the labelRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        li.textRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        li.iconRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
        SwingUtilities.layoutCompoundLabel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                            menuItem, li.fm, li.text, li.icon, li.verticalAlignment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                            li.horizontalAlignment, li.verticalTextPosition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                            li.horizontalTextPosition, li.labelRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                            li.iconRect, li.textRect, li.gap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
    private void calcXPositionsL2R(int startXPos, int leadingGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
                                   int gap, Rectangle... rects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
        int curXPos = startXPos + leadingGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
        for (Rectangle rect : rects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
            rect.x = curXPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
            if (rect.width > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
                curXPos += rect.width + gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
    private void calcXPositionsL2R(int startXPos, int gap, Rectangle... rects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        calcXPositionsL2R(startXPos, gap, gap, rects);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
    private void calcXPositionsR2L(int startXPos, int leadingGap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                                   int gap, Rectangle... rects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        int curXPos = startXPos - leadingGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        for (Rectangle rect : rects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            rect.x = curXPos - rect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            if (rect.width > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                curXPos -= rect.width + gap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
    private void calcXPositionsR2L(int startXPos, int gap, Rectangle... rects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        calcXPositionsR2L(startXPos, gap, gap, rects);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
    // Takes into account the left side bearings for text and accelerator text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
    private void fixTextRects(LayoutInfo li) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        if (li.htmlView == null) { // The text isn't a HTML
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            int lsb = SwingUtilities2.getLeftSideBearing(li.mi, li.fm, li.text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            if (lsb < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                li.textRect.x -= lsb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        fixAccTextRect(li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
    // Takes into account the left side bearing for accelerator text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
    private void fixAccTextRect(LayoutInfo li) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        int lsb = SwingUtilities2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                .getLeftSideBearing(li.mi, li.accFm, li.accText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        if (lsb < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
            li.accRect.x -= lsb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
    // Sets Y coordinates of text and icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
    // taking into account the vertical alignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
    private void calcTextAndIconYPositions(LayoutInfo li) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        if (li.verticalAlignment == SwingUtilities.TOP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
            li.textRect.y  = (int)(li.viewRect.y
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
                    + (float)li.labelRect.height/2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
                    - (float)li.textRect.height/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            li.iconRect.y  = (int)(li.viewRect.y
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
                    + (float)li.labelRect.height/2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
                    - (float)li.iconRect.height/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
        } else if (li.verticalAlignment == SwingUtilities.CENTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            li.textRect.y = (int)(li.viewRect.y
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                    + (float)li.viewRect.height/2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                    - (float)li.textRect.height/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            li.iconRect.y = (int)(li.viewRect.y
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                    + (float)li.viewRect.height/2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
                    - (float)li.iconRect.height/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
        else if (li.verticalAlignment == SwingUtilities.BOTTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
            li.textRect.y = (int)(li.viewRect.y + li.viewRect.height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
                    - (float)li.labelRect.height/2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                    - (float)li.textRect.height/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
            li.iconRect.y = (int)(li.viewRect.y + li.viewRect.height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                    - (float)li.labelRect.height/2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                    - (float)li.iconRect.height/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
    // Aligns icon, text, accelerator text, check icon and arrow icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
    // at the right side
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
    private void rightAlignAllRects(LayoutInfo li) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
        li.iconRect.x = li.iconRect.x + li.iconRect.width - li.origIconWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
        li.iconRect.width = li.origIconWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
        li.textRect.x = li.textRect.x + li.textRect.width - li.origTextWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        li.textRect.width = li.origTextWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
        li.accRect.x = li.accRect.x + li.accRect.width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                - li.origAccWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
        li.accRect.width = li.origAccWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
        li.checkRect.x = li.checkRect.x + li.checkRect.width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                - li.origCheckWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        li.checkRect.width = li.origCheckWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
        li.arrowRect.x = li.arrowRect.x + li.arrowRect.width -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                li.origArrowWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
        li.arrowRect.width = li.origArrowWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
     * Returns false if the component is a JMenu and it is a top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
     * level menu (on the menubar).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
    private boolean useCheckAndArrow(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
        boolean b = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        if((menuItem instanceof JMenu) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
           (((JMenu)menuItem).isTopLevelMenu())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
            b = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
    public MenuElement[] getPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
        MenuSelectionManager m = MenuSelectionManager.defaultManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
        MenuElement oldPath[] = m.getSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
        MenuElement newPath[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
        int i = oldPath.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
        if (i == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
            return new MenuElement[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
        Component parent = menuItem.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        if (oldPath[i-1].getComponent() == parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
            // The parent popup menu is the last so far
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
            newPath = new MenuElement[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
            System.arraycopy(oldPath, 0, newPath, 0, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
            newPath[i] = menuItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
            // A sibling menuitem is the current selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
            //  This probably needs to handle 'exit submenu into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
            // a menu item.  Search backwards along the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
            // selection until you find the parent popup menu,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
            // then copy up to that and add yourself...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
            int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
            for (j = oldPath.length-1; j >= 0; j--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                if (oldPath[j].getComponent() == parent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
            newPath = new MenuElement[j+2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
            System.arraycopy(oldPath, 0, newPath, 0, j+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
            newPath[j+1] = menuItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
            System.out.println("Sibling condition -- ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
            System.out.println("Old array : ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
            printMenuElementArray(oldPath, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
            System.out.println("New array : ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
            printMenuElementArray(newPath, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        return newPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
    void printMenuElementArray(MenuElement path[], boolean dumpStack) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
        System.out.println("Path is(");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
        int i, j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
        for(i=0,j=path.length; i<j ;i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
            for (int k=0; k<=i; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                System.out.print("  ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
            MenuElement me = (MenuElement) path[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
            if(me instanceof JMenuItem)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                System.out.println(((JMenuItem)me).getText() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
            else if (me == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                System.out.println("NULL , ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
                System.out.println("" + me + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        System.out.println(")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
        if (dumpStack == true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
            Thread.dumpStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
    protected class MouseInputHandler implements MouseInputListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        // NOTE: This class exists only for backward compatability. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
        public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
            getHandler().mouseClicked(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
            getHandler().mousePressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
            getHandler().mouseReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
        public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
            getHandler().mouseEntered(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
        public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
            getHandler().mouseExited(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
        public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
            getHandler().mouseDragged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
        public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
            getHandler().mouseMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
    private static class Actions extends UIAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
        private static final String CLICK = "doClick";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
        Actions(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
            super(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
            JMenuItem mi = (JMenuItem)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
            MenuSelectionManager.defaultManager().clearSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
            mi.doClick();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
     * Call this method when a menu item is to be activated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
     * This method handles some of the details of menu item activation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
     * such as clearing the selected path and messaging the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
     * JMenuItem's doClick() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
     * @param msm  A MenuSelectionManager. The visual feedback and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
     *             internal bookkeeping tasks are delegated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
     *             this MenuSelectionManager. If <code>null</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
     *             passed as this argument, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
     *             <code>MenuSelectionManager.defaultManager</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
     *             used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
     * @see MenuSelectionManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
     * @see JMenuItem#doClick(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
    protected void doClick(MenuSelectionManager msm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
        // Auditory cue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
        if (! isInternalFrameSystemMenu()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
            BasicLookAndFeel.playSound(menuItem, getPropertyPrefix() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                                       ".commandSound");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
        // Visual feedback
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
        if (msm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
            msm = MenuSelectionManager.defaultManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
        msm.clearSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        menuItem.doClick(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
     * This is to see if the menu item in question is part of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
     * system menu on an internal frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
     * The Strings that are being checked can be found in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
     * MetalInternalFrameTitlePaneUI.java,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
     * WindowsInternalFrameTitlePaneUI.java, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     * MotifInternalFrameTitlePaneUI.java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
    private boolean isInternalFrameSystemMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
        String actionCommand = menuItem.getActionCommand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        if ((actionCommand == "Close") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
            (actionCommand == "Minimize") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
            (actionCommand == "Restore") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
            (actionCommand == "Maximize")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
          return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
          return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
    // BasicMenuUI subclasses this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
    class Handler implements MenuDragMouseListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
                          MouseInputListener, PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
        // MouseInputListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
        public void mouseClicked(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
            if (!menuItem.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
            MenuSelectionManager manager =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
                MenuSelectionManager.defaultManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
            Point p = e.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
            if(p.x >= 0 && p.x < menuItem.getWidth() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
               p.y >= 0 && p.y < menuItem.getHeight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
                doClick(manager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
                manager.processMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            MenuSelectionManager manager = MenuSelectionManager.defaultManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            int modifiers = e.getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
            // 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
            if ((modifiers & (InputEvent.BUTTON1_MASK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
                              InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) !=0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
                MenuSelectionManager.defaultManager().processMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
            manager.setSelectedPath(getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
        public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
            MenuSelectionManager manager = MenuSelectionManager.defaultManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
            int modifiers = e.getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
            // 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
            if ((modifiers & (InputEvent.BUTTON1_MASK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
                              InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) !=0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
                MenuSelectionManager.defaultManager().processMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
                MenuElement path[] = manager.getSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
                if (path.length > 1 && path[path.length-1] == menuItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
                    MenuElement newPath[] = new MenuElement[path.length-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                    int i,c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
                    for(i=0,c=path.length-1;i<c;i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
                        newPath[i] = path[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                    manager.setSelectedPath(newPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
        public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
            MenuSelectionManager.defaultManager().processMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
        public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
        // MenuDragListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
        public void menuDragMouseEntered(MenuDragMouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
            MenuSelectionManager manager = e.getMenuSelectionManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
            MenuElement path[] = e.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
            manager.setSelectedPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
        public void menuDragMouseDragged(MenuDragMouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
            MenuSelectionManager manager = e.getMenuSelectionManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
            MenuElement path[] = e.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
            manager.setSelectedPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
        public void menuDragMouseExited(MenuDragMouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
        public void menuDragMouseReleased(MenuDragMouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
            if (!menuItem.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
            MenuSelectionManager manager = e.getMenuSelectionManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
            MenuElement path[] = e.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
            Point p = e.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
            if (p.x >= 0 && p.x < menuItem.getWidth() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
                    p.y >= 0 && p.y < menuItem.getHeight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
                doClick(manager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
                manager.clearSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
        // PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
            String name = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
            if (name == "labelFor" || name == "displayedMnemonic" ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
                name == "accelerator") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
                updateAcceleratorBinding();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
            } else if (name == "text" || "font" == name ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
                       "foreground" == name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
                // remove the old html view client property if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                // existed, and install a new one if the text installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
                // into the JLabel is html source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
                JMenuItem lbl = ((JMenuItem) e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                String text = lbl.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
                BasicHTML.updateRenderer(lbl, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
            } else if (name  == "iconTextGap") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
                defaultTextIconGap = ((Number)e.getNewValue()).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
}