jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuItemUI.java
author weijun
Thu, 11 Dec 2014 15:19:12 +0800
changeset 28228 be83f404724d
parent 25859 3317bb8137f4
child 30461 57e36ed1a9ab
permissions -rw-r--r--
8067207: Replace concat String to append in StringBuilder parameters (client) Reviewed-by: serb Contributed-by: Otavio Santana <otaviojava@java.net>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
    23
 * questions.
2
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 java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.text.View;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
    38
import sun.swing.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * BasicMenuItem implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author Georges Saab
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author David Karlton
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author Arnaud Weber
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author Fredrik Lagerblad
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class BasicMenuItemUI extends MenuItemUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
{
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    50
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    51
     * The instance of {@code JMenuItem}.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    52
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    protected JMenuItem menuItem = null;
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    54
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    55
     * The color of the selection background.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    56
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    protected Color selectionBackground;
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    58
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    59
     * The color of the selection foreground.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    60
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    protected Color selectionForeground;
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    62
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    63
     * The color of the disabled foreground.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    64
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    protected Color disabledForeground;
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    66
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    67
     * The color of the accelerator foreground.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    68
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    protected Color acceleratorForeground;
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    70
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    71
     * The color of the accelerator selection.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    72
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected Color acceleratorSelectionForeground;
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    74
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    75
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    76
     * Accelerator delimiter string, such as {@code '+'} in {@code 'Ctrl+C'}.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    77
     * @since 1.7
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    78
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    79
    protected String acceleratorDelimiter;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    81
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    82
     * The gap between the text and the icon.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    83
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    protected int defaultTextIconGap;
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    85
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    86
     * The accelerator font.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    87
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    protected Font acceleratorFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    90
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    91
     * The instance of {@code MouseInputListener}.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    92
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    protected MouseInputListener mouseInputListener;
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    94
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    95
     * The instance of {@code MenuDragMouseListener}.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    96
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    protected MenuDragMouseListener menuDragMouseListener;
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    98
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
    99
     * The instance of {@code MenuKeyListener}.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   100
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    protected MenuKeyListener menuKeyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   103
     * {@code PropertyChangeListener} returned from
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   104
     * {@code createPropertyChangeListener}. You should not
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * need to access this field, rather if you want to customize the
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   106
     * {@code PropertyChangeListener} override
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   107
     * {@code createPropertyChangeListener}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @see #createPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    protected PropertyChangeListener propertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    // BasicMenuUI also uses this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    Handler handler;
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   115
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   116
     * The arrow icon.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   117
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    protected Icon arrowIcon = null;
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   119
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   120
     * The check icon.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   121
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    protected Icon checkIcon = null;
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   123
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   124
     * The value represents if the old border is painted.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   125
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    protected boolean oldBorderPainted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /* diagnostic aids -- should be false for production builds. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private static final boolean TRACE =   false; // trace creates and disposes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private static final boolean VERBOSE = false; // show reuse hits/misses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private static final boolean DEBUG =   false;  // show bad params, misc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    static void loadActionMap(LazyActionMap map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        // NOTE: BasicMenuUI also calls into this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        map.put(new Actions(Actions.CLICK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        BasicLookAndFeel.installAudioActionMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   140
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   141
     * Returns a new instance of {@code BasicMenuItemUI}.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   142
     *
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   143
     * @param c a component
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   144
     * @return a new instance of {@code BasicMenuItemUI}
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   145
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return new BasicMenuItemUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        menuItem = (JMenuItem) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        installComponents(menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   159
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   160
     * Installs default properties.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   161
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        String prefix = getPropertyPrefix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        acceleratorFont = UIManager.getFont("MenuItem.acceleratorFont");
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1299
diff changeset
   166
        // use default if missing so that BasicMenuItemUI can be used in other
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1299
diff changeset
   167
        // LAFs like Nimbus
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1299
diff changeset
   168
        if (acceleratorFont == null) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1299
diff changeset
   169
            acceleratorFont = UIManager.getFont("MenuItem.font");
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1299
diff changeset
   170
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        Object opaque = UIManager.get(getPropertyPrefix() + ".opaque");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (opaque != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            LookAndFeel.installProperty(menuItem, "opaque", opaque);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            LookAndFeel.installProperty(menuItem, "opaque", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if(menuItem.getMargin() == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
           (menuItem.getMargin() instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            menuItem.setMargin(UIManager.getInsets(prefix + ".margin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   184
        LookAndFeel.installProperty(menuItem, "iconTextGap", Integer.valueOf(4));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        defaultTextIconGap = menuItem.getIconTextGap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        LookAndFeel.installBorder(menuItem, prefix + ".border");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        oldBorderPainted = menuItem.isBorderPainted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        LookAndFeel.installProperty(menuItem, "borderPainted",
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1299
diff changeset
   190
                                    UIManager.getBoolean(prefix + ".borderPainted"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        LookAndFeel.installColorsAndFont(menuItem,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                                         prefix + ".background",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                         prefix + ".foreground",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                                         prefix + ".font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        // MenuItem specific defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (selectionBackground == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            selectionBackground instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            selectionBackground =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                UIManager.getColor(prefix + ".selectionBackground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (selectionForeground == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            selectionForeground instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            selectionForeground =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                UIManager.getColor(prefix + ".selectionForeground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (disabledForeground == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            disabledForeground instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            disabledForeground =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                UIManager.getColor(prefix + ".disabledForeground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (acceleratorForeground == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            acceleratorForeground instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            acceleratorForeground =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                UIManager.getColor(prefix + ".acceleratorForeground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (acceleratorSelectionForeground == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            acceleratorSelectionForeground instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            acceleratorSelectionForeground =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                UIManager.getColor(prefix + ".acceleratorSelectionForeground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        // Get accelerator delimiter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        acceleratorDelimiter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            UIManager.getString("MenuItem.acceleratorDelimiter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (acceleratorDelimiter == null) { acceleratorDelimiter = "+"; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        // Icons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        if (arrowIcon == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            arrowIcon instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            arrowIcon = UIManager.getIcon(prefix + ".arrowIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (checkIcon == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            checkIcon instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            checkIcon = UIManager.getIcon(prefix + ".checkIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            //In case of column layout, .checkIconFactory is defined for this UI,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            //the icon is compatible with it and useCheckAndArrow() is true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            //then the icon is handled by the checkIcon.
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   237
            boolean isColumnLayout = MenuItemLayoutHelper.isColumnLayout(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    BasicGraphicsUtils.isLeftToRight(menuItem), menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            if (isColumnLayout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                MenuItemCheckIconFactory iconFactory =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    (MenuItemCheckIconFactory) UIManager.get(prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                        + ".checkIconFactory");
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   243
                if (iconFactory != null
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   244
                        && MenuItemLayoutHelper.useCheckAndArrow(menuItem)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                        && iconFactory.isCompatible(checkIcon, prefix)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    checkIcon = iconFactory.getIcon(menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   253
     *
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   254
     * @param menuItem a menu item
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    protected void installComponents(JMenuItem menuItem){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        BasicHTML.updateRenderer(menuItem, menuItem.getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   261
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   262
     * Returns a property prefix.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   263
     *
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   264
     * @return a property prefix
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   265
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    protected String getPropertyPrefix() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return "MenuItem";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   270
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   271
     * Registers listeners.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   272
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if ((mouseInputListener = createMouseInputListener(menuItem)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            menuItem.addMouseListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            menuItem.addMouseMotionListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if ((menuDragMouseListener = createMenuDragMouseListener(menuItem)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            menuItem.addMenuDragMouseListener(menuDragMouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if ((menuKeyListener = createMenuKeyListener(menuItem)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            menuItem.addMenuKeyListener(menuKeyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if ((propertyChangeListener = createPropertyChangeListener(menuItem)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            menuItem.addPropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   289
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   290
     * Registers keyboard action.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   291
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    protected void installKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        installLazyActionMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        updateAcceleratorBinding();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    void installLazyActionMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        LazyActionMap.installLazyActionMap(menuItem, BasicMenuItemUI.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                           getPropertyPrefix() + ".actionMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        menuItem = (JMenuItem)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        uninstallComponents(menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        uninstallKeyboardActions();
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   308
        MenuItemLayoutHelper.clearUsedParentClientProperties(menuItem);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        menuItem = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   312
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   313
     * Uninstalls default properties.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   314
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        LookAndFeel.uninstallBorder(menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        LookAndFeel.installProperty(menuItem, "borderPainted", oldBorderPainted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        if (menuItem.getMargin() instanceof UIResource)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            menuItem.setMargin(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (arrowIcon instanceof UIResource)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            arrowIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if (checkIcon instanceof UIResource)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            checkIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   327
     * Unregisters components.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   328
     *
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   329
     * @param menuItem a menu item
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    protected void uninstallComponents(JMenuItem menuItem){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        BasicHTML.updateRenderer(menuItem, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   336
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   337
     * Unregisters listeners.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   338
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        if (mouseInputListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            menuItem.removeMouseListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            menuItem.removeMouseMotionListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (menuDragMouseListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            menuItem.removeMenuDragMouseListener(menuDragMouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        if (menuKeyListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            menuItem.removeMenuKeyListener(menuKeyListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if (propertyChangeListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            menuItem.removePropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        mouseInputListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        menuDragMouseListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        menuKeyListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        propertyChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        handler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   361
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   362
     * Unregisters keyboard actions.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   363
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    protected void uninstallKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        SwingUtilities.replaceUIActionMap(menuItem, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        SwingUtilities.replaceUIInputMap(menuItem, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                                         WHEN_IN_FOCUSED_WINDOW, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   370
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   371
     * Returns an instance of {@code MouseInputListener}.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   372
     *
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   373
     * @param c a component
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   374
     * @return an instance of {@code MouseInputListener}
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   375
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    protected MouseInputListener createMouseInputListener(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   380
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   381
     * Returns an instance of {@code MenuDragMouseListener}.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   382
     *
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   383
     * @param c a component
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   384
     * @return an instance of {@code MenuDragMouseListener}
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   385
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    protected MenuDragMouseListener createMenuDragMouseListener(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   390
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   391
     * Returns an instance of {@code MenuKeyListener}.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   392
     *
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   393
     * @param c a component
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   394
     * @return an instance of {@code MenuKeyListener}
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   395
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    protected MenuKeyListener createMenuKeyListener(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    /**
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   401
     * Creates a {@code PropertyChangeListener} which will be added to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * the menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * If this method returns null then it will not be added to the menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   405
     * @param c a component
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   406
     * @return an instance of a {@code PropertyChangeListener} or null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    protected PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                                  createPropertyChangeListener(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    Handler getHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    InputMap createInputMap(int condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            return new ComponentInputMapUIResource(menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    void updateAcceleratorBinding() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        KeyStroke accelerator = menuItem.getAccelerator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        InputMap windowInputMap = SwingUtilities.getUIInputMap(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                       menuItem, JComponent.WHEN_IN_FOCUSED_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        if (windowInputMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            windowInputMap.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (accelerator != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            if (windowInputMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                windowInputMap = createInputMap(JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                                                WHEN_IN_FOCUSED_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                SwingUtilities.replaceUIInputMap(menuItem,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                           JComponent.WHEN_IN_FOCUSED_WINDOW, windowInputMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            windowInputMap.put(accelerator, "doClick");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    public Dimension getMinimumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        Dimension d = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            d = getPreferredSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        return getPreferredMenuItemSize(c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                                        checkIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                                        arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                                        defaultTextIconGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        Dimension d = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            d = getPreferredSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            d.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   474
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   475
     * Returns the preferred size of a menu item.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   476
     *
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   477
     * @param c a component
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   478
     * @param checkIcon a check icon
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   479
     * @param arrowIcon an arrow icon
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   480
     * @param defaultTextIconGap a gap between a text and an icon
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   481
     * @return the preferred size of a menu item
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   482
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    protected Dimension getPreferredMenuItemSize(JComponent c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                                                 Icon checkIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                                                 Icon arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                                                 int defaultTextIconGap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        // The method also determines the preferred width of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        // parent popup menu (through DefaultMenuLayout class).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        // The menu width equals to the maximal width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        // among child menu items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        // Menu item width will be a sum of the widest check icon, label,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        // arrow icon and accelerator text among neighbor menu items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        // For the latest menu item we will know the maximal widths exactly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        // It will be the widest menu item and it will determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        // the width of the parent popup menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        // There is a conceptual problem: if user sets preferred size manually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        // for a menu item, this method won't be called for it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        // (see JComponent.getPreferredSize()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        // maximal widths won't be calculated, other menu items won't be able
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        // to take them into account and will be layouted in such a way,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        // as there is no the item with manual preferred size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        // But after the first paint() method call, all maximal widths
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        // will be correctly calculated and layout of some menu items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        // can be changed. For example, it can cause a shift of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        // the icon and text when user points a menu item by mouse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        JMenuItem mi = (JMenuItem) c;
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   512
        MenuItemLayoutHelper lh = new MenuItemLayoutHelper(mi, checkIcon,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   513
                arrowIcon, MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   514
                acceleratorDelimiter, BasicGraphicsUtils.isLeftToRight(mi),
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   515
                mi.getFont(), acceleratorFont,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   516
                MenuItemLayoutHelper.useCheckAndArrow(menuItem),
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   517
                getPropertyPrefix());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        Dimension result = new Dimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        // Calculate the result width
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   522
        result.width = lh.getLeadingGap();
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   523
        MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(),
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   524
                lh.getAfterCheckIconGap(), result);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        // Take into account mimimal text offset.
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   526
        if ((!lh.isTopLevelMenu())
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   527
                && (lh.getMinTextOffset() > 0)
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   528
                && (result.width < lh.getMinTextOffset())) {
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   529
            result.width = lh.getMinTextOffset();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        }
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   531
        MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), lh.getGap(), result);
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   532
        MenuItemLayoutHelper.addMaxWidth(lh.getAccSize(), lh.getGap(), result);
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   533
        MenuItemLayoutHelper.addMaxWidth(lh.getArrowSize(), lh.getGap(), result);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        // Calculate the result height
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   536
        result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(),
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   537
                lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(),
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   538
                lh.getArrowSize().getHeight());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        // Take into account menu item insets
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   541
        Insets insets = lh.getMenuItem().getInsets();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        if(insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            result.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            result.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        // if the width is even, bump it up one. This is critical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        // for the focus dash line to draw properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        if(result.width%2 == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            result.width++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        // if the height is even, bump it up one. This is critical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        // for the text to center properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        if(result.height%2 == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                && Boolean.TRUE !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                    UIManager.get(getPropertyPrefix() + ".evenHeight")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            result.height++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * We draw the background in paintMenuItem()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * so override update (which fills the background of opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * components by default) to just call paint().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        paint(g, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        paintMenuItem(g, c, checkIcon, arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                      selectionBackground, selectionForeground,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                      defaultTextIconGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   580
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   581
     * Paints a menu item.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   582
     *
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   583
     * @param g an instance of {@code Graphics}
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   584
     * @param c a component
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   585
     * @param checkIcon a check icon
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   586
     * @param arrowIcon an arrow icon
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   587
     * @param background a background color
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   588
     * @param foreground a foreground color
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   589
     * @param defaultTextIconGap a gap between a text and an icon
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   590
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    protected void paintMenuItem(Graphics g, JComponent c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                                     Icon checkIcon, Icon arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                                     Color background, Color foreground,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                                     int defaultTextIconGap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        // Save original graphics font and color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        Font holdf = g.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        Color holdc = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        JMenuItem mi = (JMenuItem) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        g.setFont(mi.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        applyInsets(viewRect, mi.getInsets());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   605
        MenuItemLayoutHelper lh = new MenuItemLayoutHelper(mi, checkIcon,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   606
                arrowIcon, viewRect, defaultTextIconGap, acceleratorDelimiter,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   607
                BasicGraphicsUtils.isLeftToRight(mi), mi.getFont(),
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   608
                acceleratorFont, MenuItemLayoutHelper.useCheckAndArrow(menuItem),
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   609
                getPropertyPrefix());
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   610
        MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        paintBackground(g, mi, background);
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   613
        paintCheckIcon(g, lh, lr, holdc, foreground);
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   614
        paintIcon(g, lh, lr, holdc);
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   615
        paintText(g, lh, lr);
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   616
        paintAccText(g, lh, lr);
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   617
        paintArrowIcon(g, lh, lr, foreground);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        // Restore original graphics font and color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        g.setColor(holdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        g.setFont(holdf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   624
    private void paintIcon(Graphics g, MenuItemLayoutHelper lh,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   625
                           MenuItemLayoutHelper.LayoutResult lr, Color holdc) {
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   626
        if (lh.getIcon() != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            Icon icon;
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   628
            ButtonModel model = lh.getMenuItem().getModel();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            if (!model.isEnabled()) {
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   630
                icon = lh.getMenuItem().getDisabledIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            } else if (model.isPressed() && model.isArmed()) {
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   632
                icon = lh.getMenuItem().getPressedIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                if (icon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                    // Use default icon
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   635
                    icon = lh.getMenuItem().getIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            } else {
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   638
                icon = lh.getMenuItem().getIcon();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            if (icon != null) {
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   642
                icon.paintIcon(lh.getMenuItem(), g, lr.getIconRect().x,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   643
                        lr.getIconRect().y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                g.setColor(holdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   649
    private void paintCheckIcon(Graphics g, MenuItemLayoutHelper lh,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   650
                                MenuItemLayoutHelper.LayoutResult lr,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                                Color holdc, Color foreground) {
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   652
        if (lh.getCheckIcon() != null) {
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   653
            ButtonModel model = lh.getMenuItem().getModel();
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   654
            if (model.isArmed() || (lh.getMenuItem() instanceof JMenu
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   655
                    && model.isSelected())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                g.setColor(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                g.setColor(holdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            }
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   660
            if (lh.useCheckAndArrow()) {
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   661
                lh.getCheckIcon().paintIcon(lh.getMenuItem(), g,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   662
                        lr.getCheckRect().x, lr.getCheckRect().y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            g.setColor(holdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   668
    private void paintAccText(Graphics g, MenuItemLayoutHelper lh,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   669
                              MenuItemLayoutHelper.LayoutResult lr) {
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   670
        if (!lh.getAccText().equals("")) {
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   671
            ButtonModel model = lh.getMenuItem().getModel();
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   672
            g.setFont(lh.getAccFontMetrics().getFont());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            if (!model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                // *** paint the accText disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                if (disabledForeground != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    g.setColor(disabledForeground);
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   677
                    SwingUtilities2.drawString(lh.getMenuItem(), g,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   678
                        lh.getAccText(), lr.getAccRect().x,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   679
                        lr.getAccRect().y + lh.getAccFontMetrics().getAscent());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                } else {
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   681
                    g.setColor(lh.getMenuItem().getBackground().brighter());
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   682
                    SwingUtilities2.drawString(lh.getMenuItem(), g,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   683
                        lh.getAccText(), lr.getAccRect().x,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   684
                        lr.getAccRect().y + lh.getAccFontMetrics().getAscent());
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   685
                    g.setColor(lh.getMenuItem().getBackground().darker());
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   686
                    SwingUtilities2.drawString(lh.getMenuItem(), g,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   687
                        lh.getAccText(), lr.getAccRect().x - 1,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   688
                        lr.getAccRect().y + lh.getFontMetrics().getAscent() - 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                // *** paint the accText normally
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   692
                if (model.isArmed()
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   693
                        || (lh.getMenuItem() instanceof JMenu
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   694
                        && model.isSelected())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                    g.setColor(acceleratorSelectionForeground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                    g.setColor(acceleratorForeground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                }
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   699
                SwingUtilities2.drawString(lh.getMenuItem(), g, lh.getAccText(),
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   700
                        lr.getAccRect().x, lr.getAccRect().y +
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   701
                        lh.getAccFontMetrics().getAscent());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   706
    private void paintText(Graphics g, MenuItemLayoutHelper lh,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   707
                           MenuItemLayoutHelper.LayoutResult lr) {
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   708
        if (!lh.getText().equals("")) {
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   709
            if (lh.getHtmlView() != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                // Text is HTML
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   711
                lh.getHtmlView().paint(g, lr.getTextRect());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                // Text isn't HTML
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   714
                paintText(g, lh.getMenuItem(), lr.getTextRect(), lh.getText());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   719
    private void paintArrowIcon(Graphics g, MenuItemLayoutHelper lh,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   720
                                MenuItemLayoutHelper.LayoutResult lr,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   721
                                Color foreground) {
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   722
        if (lh.getArrowIcon() != null) {
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   723
            ButtonModel model = lh.getMenuItem().getModel();
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   724
            if (model.isArmed() || (lh.getMenuItem() instanceof JMenu
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   725
                                && model.isSelected())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                g.setColor(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            }
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   728
            if (lh.useCheckAndArrow()) {
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   729
                lh.getArrowIcon().paintIcon(lh.getMenuItem(), g,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 1290
diff changeset
   730
                        lr.getArrowRect().x, lr.getArrowRect().y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    private void applyInsets(Rectangle rect, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        if(insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            rect.x += insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            rect.y += insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            rect.width -= (insets.right + rect.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            rect.height -= (insets.bottom + rect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * Draws the background of the menu item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * @param g the paint graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * @param menuItem menu item to be painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * @param bgColor selection background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        ButtonModel model = menuItem.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        Color oldColor = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        int menuWidth = menuItem.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        int menuHeight = menuItem.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        if(menuItem.isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            if (model.isArmed()|| (menuItem instanceof JMenu && model.isSelected())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                g.setColor(bgColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                g.fillRect(0,0, menuWidth, menuHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                g.setColor(menuItem.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                g.fillRect(0,0, menuWidth, menuHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            g.setColor(oldColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        else if (model.isArmed() || (menuItem instanceof JMenu &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                                     model.isSelected())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            g.setColor(bgColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            g.fillRect(0,0, menuWidth, menuHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            g.setColor(oldColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * Renders the text of the current menu item.
23715
54ae9dd9df73 8039074: Tidy warnings cleanup for javax.swing
yan
parents: 23010
diff changeset
   778
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * @param g graphics context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * @param menuItem menu item to render
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * @param textRect bounding rectangle for rendering the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * @param text string to render
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        ButtonModel model = menuItem.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        FontMetrics fm = SwingUtilities2.getFontMetrics(menuItem, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        int mnemIndex = menuItem.getDisplayedMnemonicIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        if(!model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            // *** paint the text disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            if ( UIManager.get("MenuItem.disabledForeground") instanceof Color ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                g.setColor( UIManager.getColor("MenuItem.disabledForeground") );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                SwingUtilities2.drawStringUnderlineCharAt(menuItem, g,text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                          mnemIndex, textRect.x,  textRect.y + fm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                g.setColor(menuItem.getBackground().brighter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                           mnemIndex, textRect.x, textRect.y + fm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                g.setColor(menuItem.getBackground().darker());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                SwingUtilities2.drawStringUnderlineCharAt(menuItem, g,text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                           mnemIndex,  textRect.x - 1, textRect.y +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                           fm.getAscent() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            // *** paint the text normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            if (model.isArmed()|| (menuItem instanceof JMenu && model.isSelected())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                g.setColor(selectionForeground); // Uses protected field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            SwingUtilities2.drawStringUnderlineCharAt(menuItem, g,text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                           mnemIndex, textRect.x, textRect.y + fm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
25765
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   815
    /**
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   816
     * Returns a menu element path.
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   817
     *
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   818
     * @return a menu element path
88051e6ecdc7 8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents: 23715
diff changeset
   819
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    public MenuElement[] getPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        MenuSelectionManager m = MenuSelectionManager.defaultManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        MenuElement oldPath[] = m.getSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        MenuElement newPath[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        int i = oldPath.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        if (i == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            return new MenuElement[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        Component parent = menuItem.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        if (oldPath[i-1].getComponent() == parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            // The parent popup menu is the last so far
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            newPath = new MenuElement[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            System.arraycopy(oldPath, 0, newPath, 0, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            newPath[i] = menuItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            // A sibling menuitem is the current selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            //  This probably needs to handle 'exit submenu into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            // a menu item.  Search backwards along the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            // selection until you find the parent popup menu,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            // then copy up to that and add yourself...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            for (j = oldPath.length-1; j >= 0; j--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                if (oldPath[j].getComponent() == parent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            newPath = new MenuElement[j+2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            System.arraycopy(oldPath, 0, newPath, 0, j+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            newPath[j+1] = menuItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            System.out.println("Sibling condition -- ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            System.out.println("Old array : ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            printMenuElementArray(oldPath, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            System.out.println("New array : ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            printMenuElementArray(newPath, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        return newPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    void printMenuElementArray(MenuElement path[], boolean dumpStack) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        System.out.println("Path is(");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        int i, j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        for(i=0,j=path.length; i<j ;i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            for (int k=0; k<=i; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                System.out.print("  ");
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 438
diff changeset
   865
            MenuElement me = path[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            if(me instanceof JMenuItem)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                System.out.println(((JMenuItem)me).getText() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            else if (me == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                System.out.println("NULL , ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                System.out.println("" + me + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        System.out.println(")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        if (dumpStack == true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            Thread.dumpStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    protected class MouseInputHandler implements MouseInputListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   879
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            getHandler().mouseClicked(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            getHandler().mousePressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            getHandler().mouseReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            getHandler().mouseEntered(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            getHandler().mouseExited(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            getHandler().mouseDragged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            getHandler().mouseMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    private static class Actions extends UIAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        private static final String CLICK = "doClick";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        Actions(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            super(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            JMenuItem mi = (JMenuItem)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            MenuSelectionManager.defaultManager().clearSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            mi.doClick();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * Call this method when a menu item is to be activated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * This method handles some of the details of menu item activation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * such as clearing the selected path and messaging the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * JMenuItem's doClick() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * @param msm  A MenuSelectionManager. The visual feedback and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     *             internal bookkeeping tasks are delegated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     *             this MenuSelectionManager. If <code>null</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     *             passed as this argument, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     *             <code>MenuSelectionManager.defaultManager</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     *             used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * @see MenuSelectionManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * @see JMenuItem#doClick(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    protected void doClick(MenuSelectionManager msm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        // Auditory cue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        if (! isInternalFrameSystemMenu()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            BasicLookAndFeel.playSound(menuItem, getPropertyPrefix() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                                       ".commandSound");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        // Visual feedback
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        if (msm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            msm = MenuSelectionManager.defaultManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        msm.clearSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        menuItem.doClick(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * This is to see if the menu item in question is part of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * system menu on an internal frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * The Strings that are being checked can be found in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * MetalInternalFrameTitlePaneUI.java,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * WindowsInternalFrameTitlePaneUI.java, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * MotifInternalFrameTitlePaneUI.java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    private boolean isInternalFrameSystemMenu() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        String actionCommand = menuItem.getActionCommand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        if ((actionCommand == "Close") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            (actionCommand == "Minimize") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            (actionCommand == "Restore") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            (actionCommand == "Maximize")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
          return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
          return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    // BasicMenuUI subclasses this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    class Handler implements MenuDragMouseListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                          MouseInputListener, PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        // MouseInputListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        public void mouseClicked(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            if (!menuItem.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            MenuSelectionManager manager =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                MenuSelectionManager.defaultManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            Point p = e.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            if(p.x >= 0 && p.x < menuItem.getWidth() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
               p.y >= 0 && p.y < menuItem.getHeight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                doClick(manager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                manager.processMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            MenuSelectionManager manager = MenuSelectionManager.defaultManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            int modifiers = e.getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            // 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            if ((modifiers & (InputEvent.BUTTON1_MASK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                              InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) !=0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                MenuSelectionManager.defaultManager().processMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            manager.setSelectedPath(getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            MenuSelectionManager manager = MenuSelectionManager.defaultManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            int modifiers = e.getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            // 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            if ((modifiers & (InputEvent.BUTTON1_MASK |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                              InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) !=0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                MenuSelectionManager.defaultManager().processMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                MenuElement path[] = manager.getSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                if (path.length > 1 && path[path.length-1] == menuItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                    MenuElement newPath[] = new MenuElement[path.length-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                    int i,c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                    for(i=0,c=path.length-1;i<c;i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                        newPath[i] = path[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                    manager.setSelectedPath(newPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            MenuSelectionManager.defaultManager().processMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        // MenuDragListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        public void menuDragMouseEntered(MenuDragMouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            MenuSelectionManager manager = e.getMenuSelectionManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            MenuElement path[] = e.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            manager.setSelectedPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        public void menuDragMouseDragged(MenuDragMouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            MenuSelectionManager manager = e.getMenuSelectionManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            MenuElement path[] = e.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            manager.setSelectedPath(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        public void menuDragMouseExited(MenuDragMouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        public void menuDragMouseReleased(MenuDragMouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            if (!menuItem.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            MenuSelectionManager manager = e.getMenuSelectionManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            MenuElement path[] = e.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            Point p = e.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            if (p.x >= 0 && p.x < menuItem.getWidth() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                    p.y >= 0 && p.y < menuItem.getHeight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                doClick(manager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                manager.clearSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        // PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            String name = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            if (name == "labelFor" || name == "displayedMnemonic" ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                name == "accelerator") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                updateAcceleratorBinding();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            } else if (name == "text" || "font" == name ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                       "foreground" == name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                // remove the old html view client property if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                // existed, and install a new one if the text installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                // into the JLabel is html source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                JMenuItem lbl = ((JMenuItem) e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                String text = lbl.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                BasicHTML.updateRenderer(lbl, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            } else if (name  == "iconTextGap") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                defaultTextIconGap = ((Number)e.getNewValue()).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
}