src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKStyle.java
author pbansal
Sat, 03 Aug 2019 13:53:19 +0530
changeset 57648 2b38409a336e
parent 53801 2a3bc7e69b31
permissions -rw-r--r--
8226964: [Yaru] GTK L&F: There is no difference between menu selected and de-selected Reviewed-by: prr, kcr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
44655
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 42218
diff changeset
     2
 * Copyright (c) 2002, 2017, 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: 715
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: 715
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: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
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 com.sun.java.swing.plaf.gtk;
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.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.plaf.synth.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.awt.AppContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.awt.UNIXToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.swing.SwingUtilities2;
34407
2b40f400a30b 8081411: Add an API for painting an icon with a SynthContext
alexsch
parents: 32485
diff changeset
    39
import javax.swing.plaf.synth.SynthIcon;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import com.sun.java.swing.plaf.gtk.GTKEngine.WidgetType;
32485
e00f713e6103 6302464: Allow programmatic enabling of subpixel anti-aliasing in Swing on ANY platform
alexsch
parents: 25859
diff changeset
    42
import static java.awt.RenderingHints.KEY_TEXT_ANTIALIASING;
e00f713e6103 6302464: Allow programmatic enabling of subpixel anti-aliasing in Swing on ANY platform
alexsch
parents: 25859
diff changeset
    43
import static java.awt.RenderingHints.KEY_TEXT_LCD_CONTRAST;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @author Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
class GTKStyle extends SynthStyle implements GTKConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static native int nativeGetXThickness(int widgetType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static native int nativeGetYThickness(int widgetType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static native int nativeGetColorForState(int widgetType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                                                     int state, int typeID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static native Object nativeGetClassValue(int widgetType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                                                     String key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static native String nativeGetPangoFontName(int widgetType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static final String ICON_PROPERTY_PREFIX = "gtk.icon.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    static final Color BLACK_COLOR = new ColorUIResource(Color.BLACK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    static final Color WHITE_COLOR = new ColorUIResource(Color.WHITE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    static final Font DEFAULT_FONT = new FontUIResource("sansserif",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                                                        Font.PLAIN, 10  );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    static final Insets BUTTON_DEFAULT_BORDER_INSETS = new Insets(1, 1, 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private static final GTKGraphicsUtils GTK_GRAPHICS = new GTKGraphicsUtils();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Maps from a key that is passed to Style.get to the equivalent class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * specific key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static final Map<String,String> CLASS_SPECIFIC_MAP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Backing style properties that are used if the style does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * defined the property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private static final Map<String,GTKStockIcon> ICONS_MAP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * The font used for this particular style, as determined at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * construction time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private final Font font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /** Widget type used when looking up class specific values. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private final int widgetType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /** The x/y thickness values for this particular style. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private final int xThickness, yThickness;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    GTKStyle(Font userFont, WidgetType widgetType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        this.widgetType = widgetType.ordinal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        String pangoFontName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        synchronized (sun.awt.UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            xThickness = nativeGetXThickness(this.widgetType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            yThickness = nativeGetYThickness(this.widgetType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            pangoFontName = nativeGetPangoFontName(this.widgetType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        Font pangoFont = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (pangoFontName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            pangoFont = PangoFonts.lookupFont(pangoFontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (pangoFont != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            this.font = pangoFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        } else if (userFont != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            this.font = userFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            this.font = DEFAULT_FONT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public void installDefaults(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        super.installDefaults(context);
32485
e00f713e6103 6302464: Allow programmatic enabling of subpixel anti-aliasing in Swing on ANY platform
alexsch
parents: 25859
diff changeset
   120
        Map<Object, Object> aaTextInfo = GTKLookAndFeel.aaTextInfo;
e00f713e6103 6302464: Allow programmatic enabling of subpixel anti-aliasing in Swing on ANY platform
alexsch
parents: 25859
diff changeset
   121
        if (aaTextInfo != null && !context.getRegion().isSubregion()) {
e00f713e6103 6302464: Allow programmatic enabling of subpixel anti-aliasing in Swing on ANY platform
alexsch
parents: 25859
diff changeset
   122
            context.getComponent().putClientProperty(KEY_TEXT_ANTIALIASING,
e00f713e6103 6302464: Allow programmatic enabling of subpixel anti-aliasing in Swing on ANY platform
alexsch
parents: 25859
diff changeset
   123
                    aaTextInfo.get(KEY_TEXT_ANTIALIASING));
e00f713e6103 6302464: Allow programmatic enabling of subpixel anti-aliasing in Swing on ANY platform
alexsch
parents: 25859
diff changeset
   124
            context.getComponent().putClientProperty(KEY_TEXT_LCD_CONTRAST,
e00f713e6103 6302464: Allow programmatic enabling of subpixel anti-aliasing in Swing on ANY platform
alexsch
parents: 25859
diff changeset
   125
                    aaTextInfo.get(KEY_TEXT_LCD_CONTRAST));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public SynthGraphicsUtils getGraphicsUtils(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return GTK_GRAPHICS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Returns a <code>SynthPainter</code> that will route the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * calls to a <code>GTKEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   138
     * @param state SynthContext identifying requestor
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @return SynthPainter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public SynthPainter getPainter(SynthContext state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        return GTKPainter.INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    protected Color getColorForState(SynthContext context, ColorType type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (type == ColorType.FOCUS || type == GTKColorType.BLACK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            return BLACK_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        else if (type == GTKColorType.WHITE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            return WHITE_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        int state = context.getComponentState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        state = GTKLookAndFeel.synthStateToGTKState(id, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (type == ColorType.TEXT_FOREGROUND &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
               (id == Region.BUTTON ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                id == Region.CHECK_BOX ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                id == Region.CHECK_BOX_MENU_ITEM ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                id == Region.MENU ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                id == Region.MENU_ITEM ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                id == Region.RADIO_BUTTON ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                id == Region.RADIO_BUTTON_MENU_ITEM ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                id == Region.TABBED_PANE_TAB ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                id == Region.TOGGLE_BUTTON ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                id == Region.TOOL_TIP ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                id == Region.MENU_ITEM_ACCELERATOR ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                id == Region.TABBED_PANE_TAB)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            type = ColorType.FOREGROUND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        } else if (id == Region.TABLE ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                   id == Region.LIST ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                   id == Region.TREE ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                   id == Region.TREE_CELL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            if (type == ColorType.FOREGROUND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                type = ColorType.TEXT_FOREGROUND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                if (state == SynthConstants.PRESSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    state = SynthConstants.SELECTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            } else if (type == ColorType.BACKGROUND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                type = ColorType.TEXT_BACKGROUND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return getStyleSpecificColor(context, state, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Returns color specific to the current style. This method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * invoked when other variants don't fit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private Color getStyleSpecificColor(SynthContext context, int state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                                        ColorType type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        synchronized (sun.awt.UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            int rgb = nativeGetColorForState(widgetType, state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                                             type.getID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            return new ColorUIResource(rgb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    Color getGTKColor(int state, ColorType type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return getGTKColor(null, state, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
57648
2b38409a336e 8226964: [Yaru] GTK L&F: There is no difference between menu selected and de-selected
pbansal
parents: 53801
diff changeset
   208
    Color getGTKColor(int widgetType, int state, int colorType) {
2b38409a336e 8226964: [Yaru] GTK L&F: There is no difference between menu selected and de-selected
pbansal
parents: 53801
diff changeset
   209
        synchronized (sun.awt.UNIXToolkit.GTK_LOCK) {
2b38409a336e 8226964: [Yaru] GTK L&F: There is no difference between menu selected and de-selected
pbansal
parents: 53801
diff changeset
   210
            int rgb = nativeGetColorForState(widgetType, state,
2b38409a336e 8226964: [Yaru] GTK L&F: There is no difference between menu selected and de-selected
pbansal
parents: 53801
diff changeset
   211
                    colorType);
2b38409a336e 8226964: [Yaru] GTK L&F: There is no difference between menu selected and de-selected
pbansal
parents: 53801
diff changeset
   212
            return new ColorUIResource(rgb);
2b38409a336e 8226964: [Yaru] GTK L&F: There is no difference between menu selected and de-selected
pbansal
parents: 53801
diff changeset
   213
        }
2b38409a336e 8226964: [Yaru] GTK L&F: There is no difference between menu selected and de-selected
pbansal
parents: 53801
diff changeset
   214
    }
2b38409a336e 8226964: [Yaru] GTK L&F: There is no difference between menu selected and de-selected
pbansal
parents: 53801
diff changeset
   215
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Returns the color for the specified state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   219
     * @param context SynthContext identifying requestor
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param state to get the color for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @param type of the color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @return Color to render with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    Color getGTKColor(SynthContext context, int state, ColorType type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (context != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            JComponent c = context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            state = GTKLookAndFeel.synthStateToGTKState(id, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            if (!id.isSubregion() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                (state & SynthConstants.ENABLED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                if (type == ColorType.BACKGROUND ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    type == ColorType.TEXT_BACKGROUND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    Color bg = c.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    if (!(bg instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                        return bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                else if (type == ColorType.FOREGROUND ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                         type == ColorType.TEXT_FOREGROUND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    Color fg = c.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    if (!(fg instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                        return fg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return getStyleSpecificColor(context, state, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public Color getColor(SynthContext context, ColorType type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        JComponent c = context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        int state = context.getComponentState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (c.getName() == "Table.cellRenderer") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
             if (type == ColorType.BACKGROUND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                 return c.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
             if (type == ColorType.FOREGROUND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                 return c.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (id == Region.LABEL && type == ColorType.TEXT_FOREGROUND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            type = ColorType.FOREGROUND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        // For the enabled state, prefer the widget's colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if (!id.isSubregion() && (state & SynthConstants.ENABLED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            if (type == ColorType.BACKGROUND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                return c.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            else if (type == ColorType.FOREGROUND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                return c.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            else if (type == ColorType.TEXT_FOREGROUND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                // If getForeground returns a non-UIResource it means the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                // developer has explicitly set the foreground, use it over
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                // that of TEXT_FOREGROUND as that is typically the expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                // behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                Color color = c.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                if (color != null && !(color instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                    return color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return getColorForState(context, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
41008
726399082620 8160054: The FileChooser didn't displayed large font with GTK LAF option.
ssadetsky
parents: 39845
diff changeset
   293
    Font getDefaultFont() {
726399082620 8160054: The FileChooser didn't displayed large font with GTK LAF option.
ssadetsky
parents: 39845
diff changeset
   294
        return font;
726399082620 8160054: The FileChooser didn't displayed large font with GTK LAF option.
ssadetsky
parents: 39845
diff changeset
   295
    }
726399082620 8160054: The FileChooser didn't displayed large font with GTK LAF option.
ssadetsky
parents: 39845
diff changeset
   296
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    protected Font getFontForState(SynthContext context) {
41008
726399082620 8160054: The FileChooser didn't displayed large font with GTK LAF option.
ssadetsky
parents: 39845
diff changeset
   298
        Font propFont = UIManager
726399082620 8160054: The FileChooser didn't displayed large font with GTK LAF option.
ssadetsky
parents: 39845
diff changeset
   299
                              .getFont(context.getRegion().getName() + ".font");
726399082620 8160054: The FileChooser didn't displayed large font with GTK LAF option.
ssadetsky
parents: 39845
diff changeset
   300
        if (propFont != null) {
726399082620 8160054: The FileChooser didn't displayed large font with GTK LAF option.
ssadetsky
parents: 39845
diff changeset
   301
            // if font property got a value then return it
726399082620 8160054: The FileChooser didn't displayed large font with GTK LAF option.
ssadetsky
parents: 39845
diff changeset
   302
            return propFont;
726399082620 8160054: The FileChooser didn't displayed large font with GTK LAF option.
ssadetsky
parents: 39845
diff changeset
   303
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Returns the X thickness to use for this GTKStyle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @return x thickness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    int getXThickness() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return xThickness;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Returns the Y thickness to use for this GTKStyle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @return y thickness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    int getYThickness() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return yThickness;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * Returns the Insets. If <code>insets</code> is non-null the resulting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * insets will be placed in it, otherwise a new Insets object will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * created and returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
44655
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 42218
diff changeset
   330
     * @param state SynthContext identifying requestor
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @param insets Where to place Insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @return Insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public Insets getInsets(SynthContext state, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        Region id = state.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        JComponent component = state.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        String name = (id.isSubregion()) ? null : component.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        if (insets == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            insets = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            insets.top = insets.bottom = insets.left = insets.right = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if (id == Region.ARROW_BUTTON || id == Region.BUTTON ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                id == Region.TOGGLE_BUTTON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            if ("Spinner.previousButton" == name ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    "Spinner.nextButton" == name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                return getSimpleInsets(state, insets, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                return getButtonInsets(state, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        else if (id == Region.CHECK_BOX || id == Region.RADIO_BUTTON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            return getRadioInsets(state, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        else if (id == Region.MENU_BAR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            return getMenuBarInsets(state, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        else if (id == Region.MENU ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                 id == Region.MENU_ITEM ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                 id == Region.CHECK_BOX_MENU_ITEM ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                 id == Region.RADIO_BUTTON_MENU_ITEM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            return getMenuItemInsets(state, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        else if (id == Region.FORMATTED_TEXT_FIELD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            return getTextFieldInsets(state, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        else if (id == Region.INTERNAL_FRAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            insets = Metacity.INSTANCE.getBorderInsets(state, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        else if (id == Region.LABEL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            if ("TableHeader.renderer" == name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                return getButtonInsets(state, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            else if (component instanceof ListCellRenderer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                return getTextFieldInsets(state, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            else if ("Tree.cellRenderer" == name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                return getSimpleInsets(state, insets, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        else if (id == Region.OPTION_PANE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            return getSimpleInsets(state, insets, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        else if (id == Region.POPUP_MENU) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            return getSimpleInsets(state, insets, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        else if (id == Region.PROGRESS_BAR || id == Region.SLIDER ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                 id == Region.TABBED_PANE  || id == Region.TABBED_PANE_CONTENT ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                 id == Region.TOOL_BAR     ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                 id == Region.TOOL_BAR_DRAG_WINDOW ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                 id == Region.TOOL_TIP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            return getThicknessInsets(state, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        else if (id == Region.SCROLL_BAR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            return getScrollBarInsets(state, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        else if (id == Region.SLIDER_TRACK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            return getSliderTrackInsets(state, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        else if (id == Region.TABBED_PANE_TAB) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            return getTabbedPaneTabInsets(state, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        else if (id == Region.TEXT_FIELD || id == Region.PASSWORD_FIELD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            if (name == "Tree.cellEditor") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                return getSimpleInsets(state, insets, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            return getTextFieldInsets(state, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        } else if (id == Region.SEPARATOR ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                   id == Region.POPUP_MENU_SEPARATOR ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                   id == Region.TOOL_BAR_SEPARATOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            return getSeparatorInsets(state, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        } else if (id == GTKEngine.CustomRegion.TITLED_BORDER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            return getThicknessInsets(state, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    private Insets getButtonInsets(SynthContext context, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        // The following calculations are derived from gtkbutton.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        // (GTK+ version 2.8.20), gtk_button_size_allocate() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        int CHILD_SPACING = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        int focusSize = getClassSpecificIntValue(context, "focus-line-width",1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        int focusPad = getClassSpecificIntValue(context, "focus-padding", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        int xThickness = getXThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        int yThickness = getYThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        int w = focusSize + focusPad + xThickness + CHILD_SPACING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        int h = focusSize + focusPad + yThickness + CHILD_SPACING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        insets.left = insets.right = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        insets.top = insets.bottom = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        Component component = context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        if ((component instanceof JButton) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            !(component.getParent() instanceof JToolBar) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            ((JButton)component).isDefaultCapable())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            // Include the default border insets, but only for JButtons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            // that are default capable.  Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            // JButton.getDefaultCapable() returns true by default, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            // GtkToolButtons are never default capable, so we skip this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            // step if the button is contained in a toolbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            Insets defaultInsets = getClassSpecificInsetsValue(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                          "default-border", BUTTON_DEFAULT_BORDER_INSETS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            insets.left += defaultInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            insets.right += defaultInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            insets.top += defaultInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            insets.bottom += defaultInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * This is used for both RADIO_BUTTON and CHECK_BOX.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    private Insets getRadioInsets(SynthContext context, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        // The following calculations are derived from gtkcheckbutton.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        // (GTK+ version 2.8.20), gtk_check_button_size_allocate() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        int focusSize =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            getClassSpecificIntValue(context, "focus-line-width", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        int focusPad =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            getClassSpecificIntValue(context, "focus-padding", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        int totalFocus = focusSize + focusPad;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        // Note: GTKIconFactory.DelegateIcon will have already included the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        // "indicator-spacing" value in the size of the indicator icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        // which explains why we use zero as the left inset (or right inset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        // in the RTL case); see 6489585 for more details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        insets.top    = totalFocus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        insets.bottom = totalFocus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        if (context.getComponent().getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            insets.left  = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            insets.right = totalFocus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            insets.left  = totalFocus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            insets.right = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    private Insets getMenuBarInsets(SynthContext context, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        // The following calculations are derived from gtkmenubar.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        // (GTK+ version 2.8.20), gtk_menu_bar_size_allocate() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        int internalPadding = getClassSpecificIntValue(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                                                       "internal-padding", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        int xThickness = getXThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        int yThickness = getYThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        insets.left = insets.right = xThickness + internalPadding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        insets.top = insets.bottom = yThickness + internalPadding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    private Insets getMenuItemInsets(SynthContext context, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        // The following calculations are derived from gtkmenuitem.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        // (GTK+ version 2.8.20), gtk_menu_item_size_allocate() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        int horizPadding = getClassSpecificIntValue(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                                                    "horizontal-padding", 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        int xThickness = getXThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        int yThickness = getYThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        insets.left = insets.right = xThickness + horizPadding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        insets.top = insets.bottom = yThickness;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    private Insets getThicknessInsets(SynthContext context, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        insets.left = insets.right = getXThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        insets.top = insets.bottom = getYThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    private Insets getSeparatorInsets(SynthContext context, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        int horizPadding = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        if (context.getRegion() == Region.POPUP_MENU_SEPARATOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            horizPadding =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                getClassSpecificIntValue(context, "horizontal-padding", 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        insets.right = insets.left = getXThickness() + horizPadding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        insets.top = insets.bottom = getYThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    private Insets getSliderTrackInsets(SynthContext context, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        int focusSize = getClassSpecificIntValue(context, "focus-line-width", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        int focusPad = getClassSpecificIntValue(context, "focus-padding", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        insets.top = insets.bottom =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                insets.left = insets.right = focusSize + focusPad;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    private Insets getSimpleInsets(SynthContext context, Insets insets, int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        insets.top = insets.bottom = insets.right = insets.left = n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    private Insets getTabbedPaneTabInsets(SynthContext context, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        int xThickness = getXThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        int yThickness = getYThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        int focusSize = getClassSpecificIntValue(context, "focus-line-width",1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        int pad = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        insets.left = insets.right = focusSize + pad + xThickness;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        insets.top = insets.bottom = focusSize + pad + yThickness;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    // NOTE: this is called for ComboBox, and FormattedTextField also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    private Insets getTextFieldInsets(SynthContext context, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        insets = getClassSpecificInsetsValue(context, "inner-border",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                                    getSimpleInsets(context, insets, 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        int xThickness = getXThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        int yThickness = getYThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        boolean interiorFocus =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                getClassSpecificBoolValue(context, "interior-focus", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        int focusSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        if (!interiorFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            focusSize = getClassSpecificIntValue(context, "focus-line-width",1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        insets.left   += focusSize + xThickness;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        insets.right  += focusSize + xThickness;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        insets.top    += focusSize + yThickness;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        insets.bottom += focusSize + yThickness;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    private Insets getScrollBarInsets(SynthContext context, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        int troughBorder =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            getClassSpecificIntValue(context, "trough-border", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        insets.left = insets.right = insets.top = insets.bottom = troughBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        JComponent c = context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        if (c.getParent() instanceof JScrollPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            // This scrollbar is part of a scrollpane; use only the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            // "scrollbar-spacing" style property to determine the padding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            // between the scrollbar and its parent scrollpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            int spacing =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                getClassSpecificIntValue(WidgetType.SCROLL_PANE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                                         "scrollbar-spacing", 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            if (((JScrollBar)c).getOrientation() == JScrollBar.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                insets.top += spacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                if (c.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    insets.left += spacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                    insets.right += spacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            // This is a standalone scrollbar; leave enough room for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            // focus line in addition to the trough border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            if (c.isFocusable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                int focusSize =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                    getClassSpecificIntValue(context, "focus-line-width", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                int focusPad =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    getClassSpecificIntValue(context, "focus-padding", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                int totalFocus = focusSize + focusPad;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                insets.left   += totalFocus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                insets.right  += totalFocus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                insets.top    += totalFocus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                insets.bottom += totalFocus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * Returns the value for a class specific property for a particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * WidgetType.  This method is useful in those cases where we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * fetch a value for a Region that is not associated with the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * currently in use (e.g. we need to figure out the insets for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * SCROLL_BAR, but certain values can only be extracted from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * SCROLL_PANE region).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * @param wt WidgetType for which to fetch the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * @param key Key identifying class specific value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * @return Value, or null if one has not been defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    private static Object getClassSpecificValue(WidgetType wt, String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            return nativeGetClassValue(wt.ordinal(), key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * Convenience method to get a class specific integer value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * a particular WidgetType.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * @param wt WidgetType for which to fetch the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * @param key Key identifying class specific value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * @param defaultValue Returned if there is no value for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     *        type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * @return Value, or defaultValue if <code>key</code> is not defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    private static int getClassSpecificIntValue(WidgetType wt, String key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                                                int defaultValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        Object value = getClassSpecificValue(wt, key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        if (value instanceof Number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            return ((Number)value).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * Returns the value for a class specific property. A class specific value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * is a value that will be picked up based on class hierarchy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * @param key Key identifying class specific value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @return Value, or null if one has not been defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    Object getClassSpecificValue(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        synchronized (sun.awt.UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            return nativeGetClassValue(widgetType, key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * Convenience method to get a class specific integer value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   665
     * @param context SynthContext identifying requestor
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @param key Key identifying class specific value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * @param defaultValue Returned if there is no value for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     *        type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * @return Value, or defaultValue if <code>key</code> is not defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    int getClassSpecificIntValue(SynthContext context, String key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                                 int defaultValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        Object value = getClassSpecificValue(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        if (value instanceof Number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            return ((Number)value).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * Convenience method to get a class specific Insets value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   685
     * @param context SynthContext identifying requestor
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * @param key Key identifying class specific value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * @param defaultValue Returned if there is no value for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     *        type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * @return Value, or defaultValue if <code>key</code> is not defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    Insets getClassSpecificInsetsValue(SynthContext context, String key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                                       Insets defaultValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        Object value = getClassSpecificValue(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        if (value instanceof Insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            return (Insets)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * Convenience method to get a class specific Boolean value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   705
     * @param context SynthContext identifying requestor
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @param key Key identifying class specific value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * @param defaultValue Returned if there is no value for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     *        type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * @return Value, or defaultValue if <code>key</code> is not defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    boolean getClassSpecificBoolValue(SynthContext context, String key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                                      boolean defaultValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        Object value = getClassSpecificValue(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        if (value instanceof Boolean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            return ((Boolean)value).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * Returns the value to initialize the opacity property of the Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * to. A Style should NOT assume the opacity will remain this value, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * developer may reset it or override it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   727
     * @param context SynthContext identifying requestor
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * @return opaque Whether or not the JComponent is opaque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    public boolean isOpaque(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        Region region = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        if (region == Region.COMBO_BOX ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
              region == Region.DESKTOP_PANE ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
              region == Region.DESKTOP_ICON ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
              region == Region.INTERNAL_FRAME ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
              region == Region.LIST ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
              region == Region.MENU_BAR ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
              region == Region.PANEL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
              region == Region.POPUP_MENU ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
              region == Region.PROGRESS_BAR ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
              region == Region.ROOT_PANE ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
              region == Region.SCROLL_PANE ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
              region == Region.SPLIT_PANE_DIVIDER ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
              region == Region.TABLE ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
              region == Region.TEXT_AREA ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
              region == Region.TOOL_BAR_DRAG_WINDOW ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
              region == Region.TOOL_TIP ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
              region == Region.TREE ||
53801
2a3bc7e69b31 8218479: JTextPane display issue with GTKLookAndFeel
ssadetsky
parents: 53800
diff changeset
   750
              region == Region.VIEWPORT ||
2a3bc7e69b31 8218479: JTextPane display issue with GTKLookAndFeel
ssadetsky
parents: 53800
diff changeset
   751
              region == Region.TEXT_PANE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        }
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37688
diff changeset
   754
        if (!GTKLookAndFeel.is3()) {
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37688
diff changeset
   755
            if (region == Region.EDITOR_PANE ||
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37688
diff changeset
   756
                  region == Region.FORMATTED_TEXT_FIELD ||
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37688
diff changeset
   757
                  region == Region.PASSWORD_FIELD ||
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37688
diff changeset
   758
                  region == Region.SPINNER ||
53801
2a3bc7e69b31 8218479: JTextPane display issue with GTKLookAndFeel
ssadetsky
parents: 53800
diff changeset
   759
                  region == Region.TEXT_FIELD) {
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37688
diff changeset
   760
                return true;
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37688
diff changeset
   761
            }
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37688
diff changeset
   762
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        Component c = context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        String name = c.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        if (name == "ComboBox.renderer" || name == "ComboBox.listRenderer") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    public Object get(SynthContext context, Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        // See if this is a class specific value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        String classKey = CLASS_SPECIFIC_MAP.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        if (classKey != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            Object value = getClassSpecificValue(classKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            if (value != null) {
53800
76668d618a99 8218469: JSlider display issue with slider for GTKLookAndFeel
pbansal
parents: 53667
diff changeset
   778
                //This is a workaround as the "slider-length" property has been
76668d618a99 8218469: JSlider display issue with slider for GTKLookAndFeel
pbansal
parents: 53667
diff changeset
   779
                //deprecated for GtkScale from gtk 3.20, so default value of 31
76668d618a99 8218469: JSlider display issue with slider for GTKLookAndFeel
pbansal
parents: 53667
diff changeset
   780
                //is used and makes redering of slider wrong. Value 14 is being
76668d618a99 8218469: JSlider display issue with slider for GTKLookAndFeel
pbansal
parents: 53667
diff changeset
   781
                //used as default value for Slider.thumbHeight is 14 and making
76668d618a99 8218469: JSlider display issue with slider for GTKLookAndFeel
pbansal
parents: 53667
diff changeset
   782
                //width 14 as well makes slider thumb render in proper shape
76668d618a99 8218469: JSlider display issue with slider for GTKLookAndFeel
pbansal
parents: 53667
diff changeset
   783
                if ("Slider.thumbWidth".equals(key) && value.equals(31)) {
76668d618a99 8218469: JSlider display issue with slider for GTKLookAndFeel
pbansal
parents: 53667
diff changeset
   784
                    return 14;
76668d618a99 8218469: JSlider display issue with slider for GTKLookAndFeel
pbansal
parents: 53667
diff changeset
   785
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        // Is it a specific value ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        if (key == "ScrollPane.viewportBorderInsets") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            return getThicknessInsets(context, new Insets(0, 0, 0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        else if (key == "Slider.tickColor") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            return getColorForState(context, ColorType.FOREGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        else if (key == "ScrollBar.minimumThumbSize") {
53800
76668d618a99 8218469: JSlider display issue with slider for GTKLookAndFeel
pbansal
parents: 53667
diff changeset
   798
            //This is a workaround as the "min-slider-length" property has been
76668d618a99 8218469: JSlider display issue with slider for GTKLookAndFeel
pbansal
parents: 53667
diff changeset
   799
            //deprecated for GtkScrollBar from gtk 3.20, so default value of 21
76668d618a99 8218469: JSlider display issue with slider for GTKLookAndFeel
pbansal
parents: 53667
diff changeset
   800
            //is used and makes ScrollBar thumb very small. Value 40 is being
76668d618a99 8218469: JSlider display issue with slider for GTKLookAndFeel
pbansal
parents: 53667
diff changeset
   801
            //used as this is the value mentioned in css files
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            int len =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                getClassSpecificIntValue(context, "min-slider-length", 21);
53800
76668d618a99 8218469: JSlider display issue with slider for GTKLookAndFeel
pbansal
parents: 53667
diff changeset
   804
            if (len == 21) {
76668d618a99 8218469: JSlider display issue with slider for GTKLookAndFeel
pbansal
parents: 53667
diff changeset
   805
                len = 40;
76668d618a99 8218469: JSlider display issue with slider for GTKLookAndFeel
pbansal
parents: 53667
diff changeset
   806
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            JScrollBar sb = (JScrollBar)context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            if (sb.getOrientation() == JScrollBar.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                return new DimensionUIResource(len, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                return new DimensionUIResource(0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        else if (key == "Separator.thickness") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            JSeparator sep = (JSeparator)context.getComponent();
37688
e5cd9e00a669 8153351: GTK Menu's have no border
ssadetsky
parents: 34408
diff changeset
   816
            if (getClassSpecificBoolValue(context, "wide-separators", false)) {
e5cd9e00a669 8153351: GTK Menu's have no border
ssadetsky
parents: 34408
diff changeset
   817
                if (sep.getOrientation() == JSeparator.HORIZONTAL) {
e5cd9e00a669 8153351: GTK Menu's have no border
ssadetsky
parents: 34408
diff changeset
   818
                    return getClassSpecificIntValue(context,
e5cd9e00a669 8153351: GTK Menu's have no border
ssadetsky
parents: 34408
diff changeset
   819
                            "separator-height", 0);
e5cd9e00a669 8153351: GTK Menu's have no border
ssadetsky
parents: 34408
diff changeset
   820
                } else {
e5cd9e00a669 8153351: GTK Menu's have no border
ssadetsky
parents: 34408
diff changeset
   821
                    return getClassSpecificIntValue(context,
e5cd9e00a669 8153351: GTK Menu's have no border
ssadetsky
parents: 34408
diff changeset
   822
                            "separator-width", 0);
e5cd9e00a669 8153351: GTK Menu's have no border
ssadetsky
parents: 34408
diff changeset
   823
                }
e5cd9e00a669 8153351: GTK Menu's have no border
ssadetsky
parents: 34408
diff changeset
   824
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            if (sep.getOrientation() == JSeparator.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                return getYThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                return getXThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        else if (key == "ToolBar.separatorSize") {
37688
e5cd9e00a669 8153351: GTK Menu's have no border
ssadetsky
parents: 34408
diff changeset
   832
            if (getClassSpecificBoolValue(context, "wide-separators", false)) {
e5cd9e00a669 8153351: GTK Menu's have no border
ssadetsky
parents: 34408
diff changeset
   833
                return new DimensionUIResource(
e5cd9e00a669 8153351: GTK Menu's have no border
ssadetsky
parents: 34408
diff changeset
   834
                    getClassSpecificIntValue(context, "separator-width", 2),
e5cd9e00a669 8153351: GTK Menu's have no border
ssadetsky
parents: 34408
diff changeset
   835
                    getClassSpecificIntValue(context, "separator-height", 2)
e5cd9e00a669 8153351: GTK Menu's have no border
ssadetsky
parents: 34408
diff changeset
   836
                );
e5cd9e00a669 8153351: GTK Menu's have no border
ssadetsky
parents: 34408
diff changeset
   837
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            int size = getClassSpecificIntValue(WidgetType.TOOL_BAR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                                                "space-size", 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            return new DimensionUIResource(size, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        else if (key == "ScrollBar.buttonSize") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            JScrollBar sb = (JScrollBar)context.getComponent().getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            boolean horiz = (sb.getOrientation() == JScrollBar.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            WidgetType wt = horiz ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                WidgetType.HSCROLL_BAR : WidgetType.VSCROLL_BAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            int sliderWidth = getClassSpecificIntValue(wt, "slider-width", 14);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            int stepperSize = getClassSpecificIntValue(wt, "stepper-size", 14);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            return horiz ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                new DimensionUIResource(stepperSize, sliderWidth) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                new DimensionUIResource(sliderWidth, stepperSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        else if (key == "ArrowButton.size") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            String name = context.getComponent().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            if (name != null && name.startsWith("Spinner")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                // Believe it or not, the size of a spinner arrow button is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                // dependent upon the size of the spinner's font.  These
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                // calculations come from gtkspinbutton.c (version 2.8.20),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                // spin_button_get_arrow_size() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                String pangoFontName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                synchronized (sun.awt.UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                    pangoFontName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                        nativeGetPangoFontName(WidgetType.SPINNER.ordinal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                int arrowSize = (pangoFontName != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                    PangoFonts.getFontSize(pangoFontName) : 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                return (arrowSize + (getXThickness() * 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            // For all other kinds of arrow buttons (e.g. combobox arrow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            // buttons), we will simply fall back on the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            // ArrowButton.size as defined in the UIDefaults for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            // GTKLookAndFeel when we call UIManager.get() below...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        else if ("CheckBox.iconTextGap".equals(key) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                 "RadioButton.iconTextGap".equals(key))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            // The iconTextGap value needs to include "indicator-spacing"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            // and it also needs to leave enough space for the focus line,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            // which falls between the indicator icon and the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            // See getRadioInsets() and 6489585 for more details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            int indicatorSpacing =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                getClassSpecificIntValue(context, "indicator-spacing", 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            int focusSize =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                getClassSpecificIntValue(context, "focus-line-width", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            int focusPad =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                getClassSpecificIntValue(context, "focus-padding", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            return indicatorSpacing + focusSize + focusPad;
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37688
diff changeset
   888
        } else if (GTKLookAndFeel.is3() && "ComboBox.forceOpaque".equals(key)) {
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37688
diff changeset
   889
            return true;
39845
9a6e55dd0aeb 8152968: JTree Collapse Buttons Clipped Off Under GTK
ssadetsky
parents: 37711
diff changeset
   890
        } else if ("Tree.expanderSize".equals(key)) {
9a6e55dd0aeb 8152968: JTree Collapse Buttons Clipped Off Under GTK
ssadetsky
parents: 37711
diff changeset
   891
            Object value = getClassSpecificValue("expander-size");
9a6e55dd0aeb 8152968: JTree Collapse Buttons Clipped Off Under GTK
ssadetsky
parents: 37711
diff changeset
   892
            if (value instanceof Integer) {
9a6e55dd0aeb 8152968: JTree Collapse Buttons Clipped Off Under GTK
ssadetsky
parents: 37711
diff changeset
   893
                return (Integer)value + 4;
9a6e55dd0aeb 8152968: JTree Collapse Buttons Clipped Off Under GTK
ssadetsky
parents: 37711
diff changeset
   894
            }
9a6e55dd0aeb 8152968: JTree Collapse Buttons Clipped Off Under GTK
ssadetsky
parents: 37711
diff changeset
   895
            return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        // Is it a stock icon ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        GTKStockIcon stockIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        synchronized (ICONS_MAP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            stockIcon = ICONS_MAP.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        if (stockIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            return stockIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        // Is it another kind of value ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        if (key != "engine") {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   910
            // For backward compatibility we'll fallback to the UIManager.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            // We don't go to the UIManager for engine as the engine is GTK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            // specific.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            Object value = UIManager.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            if (key == "Table.rowHeight") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                int focusLineWidth = getClassSpecificIntValue(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                        "focus-line-width", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                if (value == null && focusLineWidth > 0) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   918
                    value = Integer.valueOf(16 + 2 * focusLineWidth);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        // Don't call super, we don't want to pick up defaults from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        // SynthStyle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    private Icon getStockIcon(SynthContext context, String key, int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        TextDirection direction = TextDirection.LTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        if (context != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            ComponentOrientation co = context.getComponent().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                                              getComponentOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            if (co != null && !co.isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                direction = TextDirection.RTL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        // First try loading a theme-specific icon using the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        // GTK libraries (native GTK handles the resizing for us).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        Icon icon = getStyleSpecificIcon(key, direction, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        // In a failure case where native GTK (unexpectedly) returns a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        // null icon, we can try loading a default icon as a fallback.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        String propName = ICON_PROPERTY_PREFIX + key + '.' + type + '.' +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                          (direction == TextDirection.RTL ? "rtl" : "ltr");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        Image img = (Image)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            Toolkit.getDefaultToolkit().getDesktopProperty(propName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        if (img != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            return new ImageIcon(img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        // In an extreme failure situation, just return null (callers are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        // already prepared to handle a null icon, so the worst that can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        // happen is that an icon won't be included in the button/dialog).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    private Icon getStyleSpecificIcon(String key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                                      TextDirection direction, int type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        UNIXToolkit tk = (UNIXToolkit)Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        Image img =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            tk.getStockIcon(widgetType, key, type, direction.ordinal(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        return (img != null) ? new ImageIcon(img) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    static class GTKStockIconInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        private static Map<String,Integer> ICON_TYPE_MAP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        private static final Object ICON_SIZE_KEY = new StringBuffer("IconSize");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        private static Dimension[] getIconSizesMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            AppContext appContext = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            Dimension[] iconSizes = (Dimension[])appContext.get(ICON_SIZE_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            if (iconSizes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                iconSizes = new Dimension[7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                iconSizes[0] = null;                  // GTK_ICON_SIZE_INVALID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                iconSizes[1] = new Dimension(16, 16); // GTK_ICON_SIZE_MENU
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                iconSizes[2] = new Dimension(18, 18); // GTK_ICON_SIZE_SMALL_TOOLBAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                iconSizes[3] = new Dimension(24, 24); // GTK_ICON_SIZE_LARGE_TOOLBAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                iconSizes[4] = new Dimension(20, 20); // GTK_ICON_SIZE_BUTTON
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                iconSizes[5] = new Dimension(32, 32); // GTK_ICON_SIZE_DND
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                iconSizes[6] = new Dimension(48, 48); // GTK_ICON_SIZE_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                appContext.put(ICON_SIZE_KEY, iconSizes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            return iconSizes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
         * Return the size of a particular icon type (logical size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
         * @param type icon type (GtkIconSize value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
         * @return a Dimension object, or null if lsize is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        public static Dimension getIconSize(int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            Dimension[] iconSizes = getIconSizesMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            return type >= 0 && type < iconSizes.length ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                iconSizes[type] : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
         * Change icon size in a type to size mapping. This is called by code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
         * that parses the gtk-icon-sizes setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
         * @param type icon type (GtkIconSize value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
         * @param w the new icon width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
         * @param h the new icon height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        public static void setIconSize(int type, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            Dimension[] iconSizes = getIconSizesMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            if (type >= 0 && type < iconSizes.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                iconSizes[type] = new Dimension(w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
         * Return icon type (GtkIconSize value) given a symbolic name which can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
         * occur in a theme file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
         * @param size symbolic name, e.g. gtk-button
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
         * @return icon type. Valid types are 1 to 6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        public static int getIconType(String size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            if (size == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                return UNDEFINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            if (ICON_TYPE_MAP == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                initIconTypeMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            Integer n = ICON_TYPE_MAP.get(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            return n != null ? n.intValue() : UNDEFINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        private static void initIconTypeMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            ICON_TYPE_MAP = new HashMap<String,Integer>();
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1042
            ICON_TYPE_MAP.put("gtk-menu", Integer.valueOf(1));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1043
            ICON_TYPE_MAP.put("gtk-small-toolbar", Integer.valueOf(2));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1044
            ICON_TYPE_MAP.put("gtk-large-toolbar", Integer.valueOf(3));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1045
            ICON_TYPE_MAP.put("gtk-button", Integer.valueOf(4));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1046
            ICON_TYPE_MAP.put("gtk-dnd", Integer.valueOf(5));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1047
            ICON_TYPE_MAP.put("gtk-dialog", Integer.valueOf(6));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * An Icon that is fetched using getStockIcon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     */
34408
ab286f70dd5e 8143256: The build is broken after JDK-8081411
serb
parents: 34407
diff changeset
  1055
    private static class GTKStockIcon implements SynthIcon {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        private String key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        private int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        private boolean loadedLTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        private boolean loadedRTL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        private Icon ltrIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        private Icon rtlIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        private SynthStyle style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        GTKStockIcon(String key, int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            this.key = key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            this.size = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        public void paintIcon(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                              int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            Icon icon = getIcon(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                    icon.paintIcon(null, g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                    icon.paintIcon(context.getComponent(), g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        public int getIconWidth(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            Icon icon = getIcon(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                return icon.getIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        public int getIconHeight(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            Icon icon = getIcon(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            if (icon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                return icon.getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        private Icon getIcon(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            if (context != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                ComponentOrientation co = context.getComponent().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                                                  getComponentOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                SynthStyle style = context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                if (style != this.style) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                    this.style = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                    loadedLTR = loadedRTL = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                if (co == null || co.isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                    if (!loadedLTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                        loadedLTR = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                        ltrIcon = ((GTKStyle)context.getStyle()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                                  getStockIcon(context, key, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                    return ltrIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                else if (!loadedRTL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                    loadedRTL = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                    rtlIcon = ((GTKStyle)context.getStyle()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                              getStockIcon(context, key,size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                return rtlIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            return ltrIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * GTKLazyValue is a slimmed down version of <code>ProxyLaxyValue</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * The code is duplicate so that it can get at the package private
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * classes in gtk.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    static class GTKLazyValue implements UIDefaults.LazyValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
         * Name of the class to create.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        private String className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        private String methodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        GTKLazyValue(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            this(name, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        GTKLazyValue(String name, String methodName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            this.className = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            this.methodName = methodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
42218
35e0972b2533 8169887: javax/swing/JEditorPane/8080972/TestJEditor.java, javax/swing/text/View/8080972/TestObjectView.java are failing
prr
parents: 42208
diff changeset
  1151
        @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        public Object createValue(UIDefaults table) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            try {
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 23010
diff changeset
  1154
                Class<?> c = Class.forName(className, true,Thread.currentThread().
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 23010
diff changeset
  1155
                                           getContextClassLoader());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                if (methodName == null) {
42218
35e0972b2533 8169887: javax/swing/JEditorPane/8080972/TestJEditor.java, javax/swing/text/View/8080972/TestObjectView.java are failing
prr
parents: 42208
diff changeset
  1158
                    return c.newInstance();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                }
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 23010
diff changeset
  1160
                Method m = c.getMethod(methodName, (Class<?>[])null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                return m.invoke(c, (Object[])null);
42208
7c1017f0ade5 8155874: Fix java.desktop deprecation warnings about Class.newInstance
prr
parents: 41008
diff changeset
  1163
            } catch (ReflectiveOperationException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        CLASS_SPECIFIC_MAP = new HashMap<String,String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        CLASS_SPECIFIC_MAP.put("Slider.thumbHeight", "slider-width");
37711
972001566d66 8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents: 37688
diff changeset
  1172
        CLASS_SPECIFIC_MAP.put("Slider.thumbWidth", "slider-length");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        CLASS_SPECIFIC_MAP.put("Slider.trackBorder", "trough-border");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        CLASS_SPECIFIC_MAP.put("SplitPane.size", "handle-size");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        CLASS_SPECIFIC_MAP.put("ScrollBar.thumbHeight", "slider-width");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        CLASS_SPECIFIC_MAP.put("ScrollBar.width", "slider-width");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        CLASS_SPECIFIC_MAP.put("TextArea.caretForeground", "cursor-color");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        CLASS_SPECIFIC_MAP.put("TextArea.caretAspectRatio", "cursor-aspect-ratio");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        CLASS_SPECIFIC_MAP.put("TextField.caretForeground", "cursor-color");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        CLASS_SPECIFIC_MAP.put("TextField.caretAspectRatio", "cursor-aspect-ratio");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        CLASS_SPECIFIC_MAP.put("PasswordField.caretForeground", "cursor-color");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        CLASS_SPECIFIC_MAP.put("PasswordField.caretAspectRatio", "cursor-aspect-ratio");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        CLASS_SPECIFIC_MAP.put("FormattedTextField.caretForeground", "cursor-color");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        CLASS_SPECIFIC_MAP.put("FormattedTextField.caretAspectRatio", "cursor-aspect-");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        CLASS_SPECIFIC_MAP.put("TextPane.caretForeground", "cursor-color");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        CLASS_SPECIFIC_MAP.put("TextPane.caretAspectRatio", "cursor-aspect-ratio");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        CLASS_SPECIFIC_MAP.put("EditorPane.caretForeground", "cursor-color");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        CLASS_SPECIFIC_MAP.put("EditorPane.caretAspectRatio", "cursor-aspect-ratio");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        ICONS_MAP = new HashMap<String, GTKStockIcon>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        ICONS_MAP.put("FileChooser.cancelIcon", new GTKStockIcon("gtk-cancel", 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        ICONS_MAP.put("FileChooser.okIcon",     new GTKStockIcon("gtk-ok",     4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        ICONS_MAP.put("OptionPane.yesIcon", new GTKStockIcon("gtk-yes", 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        ICONS_MAP.put("OptionPane.noIcon", new GTKStockIcon("gtk-no", 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        ICONS_MAP.put("OptionPane.cancelIcon", new GTKStockIcon("gtk-cancel", 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        ICONS_MAP.put("OptionPane.okIcon", new GTKStockIcon("gtk-ok", 4));
53667
6dae74bb8a43 8214111: There is no icon in all JOptionPane target image
pbansal
parents: 47216
diff changeset
  1197
6dae74bb8a43 8214111: There is no icon in all JOptionPane target image
pbansal
parents: 47216
diff changeset
  1198
        //check whether the gtk version is >= 3.10 as the Icon names were
6dae74bb8a43 8214111: There is no icon in all JOptionPane target image
pbansal
parents: 47216
diff changeset
  1199
        //changed from this version
6dae74bb8a43 8214111: There is no icon in all JOptionPane target image
pbansal
parents: 47216
diff changeset
  1200
        UNIXToolkit tk = (UNIXToolkit)Toolkit.getDefaultToolkit();
6dae74bb8a43 8214111: There is no icon in all JOptionPane target image
pbansal
parents: 47216
diff changeset
  1201
        if (tk.checkGtkVersion(3, 10, 0)) {
6dae74bb8a43 8214111: There is no icon in all JOptionPane target image
pbansal
parents: 47216
diff changeset
  1202
            ICONS_MAP.put("OptionPane.errorIcon", new GTKStockIcon("dialog-error", 6));
6dae74bb8a43 8214111: There is no icon in all JOptionPane target image
pbansal
parents: 47216
diff changeset
  1203
            ICONS_MAP.put("OptionPane.informationIcon", new GTKStockIcon("dialog-information", 6));
6dae74bb8a43 8214111: There is no icon in all JOptionPane target image
pbansal
parents: 47216
diff changeset
  1204
            ICONS_MAP.put("OptionPane.warningIcon", new GTKStockIcon("dialog-warning", 6));
6dae74bb8a43 8214111: There is no icon in all JOptionPane target image
pbansal
parents: 47216
diff changeset
  1205
            ICONS_MAP.put("OptionPane.questionIcon", new GTKStockIcon("dialog-question", 6));
6dae74bb8a43 8214111: There is no icon in all JOptionPane target image
pbansal
parents: 47216
diff changeset
  1206
        } else {
6dae74bb8a43 8214111: There is no icon in all JOptionPane target image
pbansal
parents: 47216
diff changeset
  1207
            ICONS_MAP.put("OptionPane.errorIcon", new GTKStockIcon("gtk-dialog-error", 6));
6dae74bb8a43 8214111: There is no icon in all JOptionPane target image
pbansal
parents: 47216
diff changeset
  1208
            ICONS_MAP.put("OptionPane.informationIcon", new GTKStockIcon("gtk-dialog-info", 6));
6dae74bb8a43 8214111: There is no icon in all JOptionPane target image
pbansal
parents: 47216
diff changeset
  1209
            ICONS_MAP.put("OptionPane.warningIcon", new GTKStockIcon("gtk-dialog-warning", 6));
6dae74bb8a43 8214111: There is no icon in all JOptionPane target image
pbansal
parents: 47216
diff changeset
  1210
            ICONS_MAP.put("OptionPane.questionIcon", new GTKStockIcon("gtk-dialog-question", 6));
6dae74bb8a43 8214111: There is no icon in all JOptionPane target image
pbansal
parents: 47216
diff changeset
  1211
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
}