jdk/src/share/classes/javax/swing/plaf/synth/SynthButtonUI.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 20168 137788883a22
child 25100 d527cc827d7d
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 20168
diff changeset
     2
 * Copyright (c) 2002, 2013, 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: 4848
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: 4848
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: 4848
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
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.synth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    28
import javax.swing.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.plaf.basic.BasicButtonUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.basic.BasicHTML;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.text.View;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 13037
diff changeset
    37
 * Provides the Synth L&F UI delegate for
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    38
 * {@link javax.swing.JButton}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @author Scott Violet
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
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: 1639
diff changeset
    43
public class SynthButtonUI extends BasicButtonUI implements
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
                                 PropertyChangeListener, SynthUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private SynthStyle style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    47
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    48
     * Creates a new UI object for the given component.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    49
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    50
     * @param c component to create UI object for
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    51
     * @return the UI object
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    52
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        return new SynthButtonUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    57
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 13037
diff changeset
    58
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    59
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    60
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    protected void installDefaults(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        updateStyle(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        LookAndFeel.installProperty(b, "rolloverEnabled", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    67
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 13037
diff changeset
    68
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    69
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    70
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected void installListeners(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        super.installListeners(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        b.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    void updateStyle(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        SynthContext context = getContext(b, SynthConstants.ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        SynthStyle oldStyle = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (style != oldStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            if (b.getMargin() == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                (b.getMargin() instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                Insets margin = (Insets)style.get(context,getPropertyPrefix() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                                                  "margin");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                if (margin == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                    // Some places assume margins are non-null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                    margin = SynthLookAndFeel.EMPTY_UIRESOURCE_INSETS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                b.setMargin(margin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            Object value = style.get(context, getPropertyPrefix() + "iconTextGap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                        LookAndFeel.installProperty(b, "iconTextGap", value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            value = style.get(context, getPropertyPrefix() + "contentAreaFilled");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            LookAndFeel.installProperty(b, "contentAreaFilled",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                        value != null? value : Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            if (oldStyle != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                uninstallKeyboardActions(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                installKeyboardActions(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   111
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 13037
diff changeset
   112
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   113
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   114
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    protected void uninstallListeners(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        super.uninstallListeners(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        b.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   120
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 13037
diff changeset
   121
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   122
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   123
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    protected void uninstallDefaults(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        SynthContext context = getContext(b, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   132
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 13037
diff changeset
   133
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   134
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   135
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public SynthContext getContext(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return getContext(c, getComponentState(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    SynthContext getContext(JComponent c, int state) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   141
        Region region = SynthLookAndFeel.getRegion(c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return SynthContext.getContext(SynthContext.class, c, region,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                       style, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Returns the current state of the passed in <code>AbstractButton</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    private int getComponentState(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        int state = ENABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (!c.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            state = DISABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
13037
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   155
        if (SynthLookAndFeel.getSelectedUI() == this) {
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   156
            return SynthLookAndFeel.getSelectedUIState() | SynthConstants.ENABLED;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        AbstractButton button = (AbstractButton) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        ButtonModel model = button.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (model.isPressed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            if (model.isArmed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                state = PRESSED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                state = MOUSE_OVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (model.isRollover()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            state |= MOUSE_OVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            state |= SELECTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (c.isFocusOwner() && button.isFocusPainted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            state |= FOCUSED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if ((c instanceof JButton) && ((JButton)c).isDefaultButton()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            state |= DEFAULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   184
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 13037
diff changeset
   185
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   186
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   187
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public int getBaseline(JComponent c, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            throw new NullPointerException("Component must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (width < 0 || height < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    "Width and height must be >= 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        String text = b.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (text == null || "".equals(text)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        Insets i = b.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        Rectangle viewRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        Rectangle textRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        Rectangle iconRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        viewRect.x = i.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        viewRect.y = i.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        viewRect.width = width - (i.right + viewRect.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        viewRect.height = height - (i.bottom + viewRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        // layout the text and icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        SynthContext context = getContext(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        FontMetrics fm = context.getComponent().getFontMetrics(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            context.getStyle().getFont(context));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        context.getStyle().getGraphicsUtils(context).layoutText(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            context, fm, b.getText(), b.getIcon(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            b.getHorizontalAlignment(), b.getVerticalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            b.getHorizontalTextPosition(), b.getVerticalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            viewRect, iconRect, textRect, b.getIconTextGap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        View view = (View)b.getClientProperty(BasicHTML.propertyKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        int baseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (view != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            baseline = BasicHTML.getHTMLBaseline(view, textRect.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                                 textRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            if (baseline >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                baseline += textRect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            baseline = textRect.y + fm.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return baseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    //          Paint Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   239
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   240
     * 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
   241
     * 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
   242
     * 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
   243
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   244
     * <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
   245
     * 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
   246
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   247
     * @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
   248
     * @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
   249
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   250
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   251
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        paintBackground(context, g, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   261
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   262
     * 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
   263
     * <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
   264
     * 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
   265
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   266
     * @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
   267
     * @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
   268
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   269
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   270
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   278
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   279
     * Paints the specified component.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   280
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   281
     * @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
   282
     * @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
   283
     * @see #update(Graphics,JComponent)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   284
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        AbstractButton b = (AbstractButton)context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        g.setColor(context.getStyle().getColor(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                                               ColorType.TEXT_FOREGROUND));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        g.setFont(style.getFont(context));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        context.getStyle().getGraphicsUtils(context).paintText(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            context, g, b.getText(), getIcon(b),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            b.getHorizontalAlignment(), b.getVerticalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            b.getHorizontalTextPosition(), b.getVerticalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            b.getIconTextGap(), b.getDisplayedMnemonicIndex(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            getTextShiftOffset(context));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    void paintBackground(SynthContext context, Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (((AbstractButton) c).isContentAreaFilled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            context.getPainter().paintButtonBackground(context, g, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                                       c.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                                       c.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   307
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 13037
diff changeset
   308
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   309
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   310
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        context.getPainter().paintButtonBorder(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   317
     * Returns the default icon. This should not callback
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * to the JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   320
     * @param b button the icon is associated with
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @return default icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    protected Icon getDefaultIcon(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        SynthContext context = getContext(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        Icon icon = context.getStyle().getIcon(context, getPropertyPrefix() + "icon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   331
     * Returns the Icon to use for painting the button. The icon is chosen with
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   332
     * respect to the current state of the button.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   333
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   334
     * @param b button the icon is associated with
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   335
     * @return an icon
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    protected Icon getIcon(AbstractButton b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        Icon icon = b.getIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        if (!model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            icon = getSynthDisabledIcon(b, icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        } else if (model.isPressed() && model.isArmed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            icon = getPressedIcon(b, getSelectedIcon(b, icon));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        } else if (b.isRolloverEnabled() && model.isRollover()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            icon = getRolloverIcon(b, getSelectedIcon(b, icon));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        } else if (model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            icon = getSelectedIcon(b, icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            icon = getEnabledIcon(b, icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if(icon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            return getDefaultIcon(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * This method will return the icon that should be used for a button.  We
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * only want to use the synth icon defined by the style if the specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * icon has not been defined for the button state and the backup icon is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * UIResource (we set it, not the developer).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @param b button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @param specificIcon icon returned from the button for the specific state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @param defaultIcon fallback icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @param state the synth state of the button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    private Icon getIcon(AbstractButton b, Icon specificIcon, Icon defaultIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        Icon icon = specificIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        if (icon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            if (defaultIcon instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                icon = getSynthIcon(b, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                if (icon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    icon = defaultIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                icon = defaultIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    private Icon getSynthIcon(AbstractButton b, int synthConstant) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        return style.getIcon(getContext(b, synthConstant), getPropertyPrefix() + "icon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    private Icon getEnabledIcon(AbstractButton b, Icon defaultIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (defaultIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            defaultIcon = getSynthIcon(b, SynthConstants.ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return defaultIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    private Icon getSelectedIcon(AbstractButton b, Icon defaultIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return getIcon(b, b.getSelectedIcon(), defaultIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                SynthConstants.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    private Icon getRolloverIcon(AbstractButton b, Icon defaultIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        Icon icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        if (model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            icon = getIcon(b, b.getRolloverSelectedIcon(), defaultIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    SynthConstants.MOUSE_OVER | SynthConstants.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            icon = getIcon(b, b.getRolloverIcon(), defaultIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    SynthConstants.MOUSE_OVER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    private Icon getPressedIcon(AbstractButton b, Icon defaultIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        return getIcon(b, b.getPressedIcon(), defaultIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                SynthConstants.PRESSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    private Icon getSynthDisabledIcon(AbstractButton b, Icon defaultIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        Icon icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        if (model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            icon = getIcon(b, b.getDisabledSelectedIcon(), defaultIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    SynthConstants.DISABLED | SynthConstants.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            icon = getIcon(b, b.getDisabledIcon(), defaultIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                    SynthConstants.DISABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * Returns the amount to shift the text/icon when painting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   435
    private int getTextShiftOffset(SynthContext state) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        AbstractButton button = (AbstractButton)state.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        ButtonModel model = button.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        if (model.isArmed() && model.isPressed() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                               button.getPressedIcon() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            return state.getStyle().getInt(state, getPropertyPrefix() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                                           "textShiftOffset", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    // ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    //          Layout Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    // ********************************
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   450
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   451
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 13037
diff changeset
   452
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   453
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   454
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    public Dimension getMinimumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        if (c.getComponentCount() > 0 && c.getLayout() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        SynthContext ss = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        Dimension size = ss.getStyle().getGraphicsUtils(ss).getMinimumSize(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
               ss, ss.getStyle().getFont(ss), b.getText(), getSizingIcon(b),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
               b.getHorizontalAlignment(), b.getVerticalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
               b.getHorizontalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
               b.getVerticalTextPosition(), b.getIconTextGap(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
               b.getDisplayedMnemonicIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        ss.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   472
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 13037
diff changeset
   473
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   474
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   475
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (c.getComponentCount() > 0 && c.getLayout() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        SynthContext ss = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        Dimension size = ss.getStyle().getGraphicsUtils(ss).getPreferredSize(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
               ss, ss.getStyle().getFont(ss), b.getText(), getSizingIcon(b),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
               b.getHorizontalAlignment(), b.getVerticalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
               b.getHorizontalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
               b.getVerticalTextPosition(), b.getIconTextGap(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
               b.getDisplayedMnemonicIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        ss.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   493
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 13037
diff changeset
   494
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   495
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   496
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        if (c.getComponentCount() > 0 && c.getLayout() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        SynthContext ss = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        Dimension size = ss.getStyle().getGraphicsUtils(ss).getMaximumSize(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
               ss, ss.getStyle().getFont(ss), b.getText(), getSizingIcon(b),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
               b.getHorizontalAlignment(), b.getVerticalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
               b.getHorizontalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
               b.getVerticalTextPosition(), b.getIconTextGap(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
               b.getDisplayedMnemonicIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        ss.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    /**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   516
     * Returns the Icon used in calculating the
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   517
     * preferred/minimum/maximum size.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    protected Icon getSizingIcon(AbstractButton b) {
1296
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents: 2
diff changeset
   520
        Icon icon = getEnabledIcon(b, b.getIcon());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        if (icon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            icon = getDefaultIcon(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   527
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 13037
diff changeset
   528
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   529
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   530
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        if (SynthLookAndFeel.shouldUpdateStyle(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            updateStyle((AbstractButton)e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
}