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