jdk/src/share/classes/javax/swing/plaf/synth/SynthMenuUI.java
author peterz
Thu, 28 Jan 2010 17:06:54 +0300
changeset 4848 ffcc849b9351
parent 4394 92a8ec883f5d
child 5506 202f599c92aa
permissions -rw-r--r--
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods Reviewed-by: rupashka
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
     2
 * Copyright 2002-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.plaf.synth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.basic.*;
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
    32
import sun.swing.MenuItemLayoutHelper;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    35
 * Provides the Synth L&F UI delegate for
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    36
 * {@link javax.swing.JMenu}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author Georges Saab
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @author David Karlton
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @author Arnaud Weber
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    41
 * @since 1.7
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    43
public class SynthMenuUI extends BasicMenuUI
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    44
                         implements PropertyChangeListener, SynthUI {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private SynthStyle style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private SynthStyle accStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    48
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    49
     * Creates a new UI object for the given component.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    50
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    51
     * @param x component to create UI object for
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    52
     * @return the UI object
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    53
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static ComponentUI createUI(JComponent x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        return new SynthMenuUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    58
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    59
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    60
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    61
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        updateStyle(menuItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    66
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    67
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    68
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
    69
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        menuItem.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private void updateStyle(JMenuItem mi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        SynthStyle oldStyle = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        SynthContext context = getContext(mi, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (oldStyle != style) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            String prefix = getPropertyPrefix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            defaultTextIconGap = style.getInt(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                           context, prefix + ".textIconGap", 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            if (menuItem.getMargin() == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                         (menuItem.getMargin() instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                Insets insets = (Insets)style.get(context, prefix + ".margin");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                if (insets == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    // Some places assume margins are non-null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                    insets = SynthLookAndFeel.EMPTY_UIRESOURCE_INSETS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                menuItem.setMargin(insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            acceleratorDelimiter = style.getString(context, prefix +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                            ".acceleratorDelimiter", "+");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
    97
            if (MenuItemLayoutHelper.useCheckAndArrow(menuItem)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                checkIcon = style.getIcon(context, prefix + ".checkIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                arrowIcon = style.getIcon(context, prefix + ".arrowIcon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                // Not needed in this case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                checkIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                arrowIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            ((JMenu)menuItem).setDelay(style.getInt(context, prefix +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                                                    ".delay", 200));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            if (oldStyle != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        SynthContext accContext = getContext(mi, Region.MENU_ITEM_ACCELERATOR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                             ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        accStyle = SynthLookAndFeel.updateStyle(accContext, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        accContext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   122
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   123
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   124
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   125
    @Override
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   126
    public void uninstallUI(JComponent c) {
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   127
        super.uninstallUI(c);
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   128
        // Remove values from the parent's Client Properties.
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   129
        JComponent p = MenuItemLayoutHelper.getMenuItemParent((JMenuItem) c);
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   130
        if (p != null) {
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   131
            p.putClientProperty(
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   132
                    SynthMenuItemLayoutHelper.MAX_ACC_OR_ARROW_WIDTH, null);
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   133
        }
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   134
    }
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   135
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   136
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   137
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   138
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   139
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        SynthContext context = getContext(menuItem, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        SynthContext accContext = getContext(menuItem,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                     Region.MENU_ITEM_ACCELERATOR, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        accStyle.uninstallDefaults(accContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        accContext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        accStyle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        super.uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   155
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   156
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   157
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   158
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        menuItem.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   164
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   165
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   166
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   167
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public SynthContext getContext(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return getContext(c, getComponentState(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    SynthContext getContext(JComponent c, int state) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   173
        Region region = SynthLookAndFeel.getRegion(c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return SynthContext.getContext(SynthContext.class, c, region,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                       style, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   178
    SynthContext getContext(JComponent c, Region region) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return getContext(c, region, getComponentState(c, region));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    private SynthContext getContext(JComponent c, Region region, int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return SynthContext.getContext(SynthContext.class, c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                       region, accStyle, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    private int getComponentState(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        int state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (!c.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            return DISABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (menuItem.isArmed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            state = MOUSE_OVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            state = SynthLookAndFeel.getComponentState(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (menuItem.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            state |= SELECTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    private int getComponentState(JComponent c, Region region) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return getComponentState(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   209
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   210
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   211
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   212
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    protected Dimension getPreferredMenuItemSize(JComponent c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                                                     Icon checkIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                                                     Icon arrowIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                                                     int defaultTextIconGap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        SynthContext accContext = getContext(c, Region.MENU_ITEM_ACCELERATOR);
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   219
        Dimension value = SynthGraphicsUtils.getPreferredMenuItemSize(
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   220
                context, accContext, c, checkIcon, arrowIcon,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   221
                defaultTextIconGap, acceleratorDelimiter,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   222
                MenuItemLayoutHelper.useCheckAndArrow(menuItem),
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   223
                getPropertyPrefix());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        accContext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   229
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   230
     * Notifies this UI delegate to repaint the specified component.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   231
     * This method paints the component background, then calls
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   232
     * the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   233
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   234
     * <p>In general, this method does not need to be overridden by subclasses.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   235
     * All Look and Feel rendering code should reside in the {@code paint} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   236
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   237
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   238
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   239
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   240
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   241
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        context.getPainter().paintMenuBackground(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                          g, 0, 0, c.getWidth(), c.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   252
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   253
     * Paints the specified component according to the Look and Feel.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   254
     * <p>This method is not used by Synth Look and Feel.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   255
     * Painting is handled by the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   256
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   257
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   258
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   259
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   260
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   261
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   269
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   270
     * Paints the specified component. This implementation does nothing.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   271
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   272
     * @param context context for the component being painted
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   273
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   274
     * @see #update(Graphics,JComponent)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   275
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        SynthContext accContext = getContext(menuItem,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                                             Region.MENU_ITEM_ACCELERATOR);
1295
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   279
        // Refetch the appropriate check indicator for the current state
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   280
        String prefix = getPropertyPrefix();
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   281
        Icon checkIcon = style.getIcon(context, prefix + ".checkIcon");
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   282
        Icon arrowIcon = style.getIcon(context, prefix + ".arrowIcon");
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   283
        SynthGraphicsUtils.paint(context, accContext, g, checkIcon, arrowIcon,
3cf2264a5743 6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents: 2
diff changeset
   284
              acceleratorDelimiter, defaultTextIconGap, getPropertyPrefix());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        accContext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   288
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   289
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   290
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   291
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        context.getPainter().paintMenuBorder(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   297
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   298
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   299
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1295
diff changeset
   300
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        if (SynthLookAndFeel.shouldUpdateStyle(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            updateStyle((JMenu)e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
}