jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKIconFactory.java
author alexsch
Wed, 18 Nov 2015 19:13:42 +0400
changeset 34407 2b40f400a30b
parent 25859 3317bb8137f4
child 34408 ab286f70dd5e
permissions -rw-r--r--
8081411: Add an API for painting an icon with a SynthContext Reviewed-by: serb, azvegint
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 5506
diff changeset
     2
 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2495
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: 2495
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: 2495
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2495
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2495
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package com.sun.java.swing.plaf.gtk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
34407
2b40f400a30b 8081411: Add an API for painting an icon with a SynthContext
alexsch
parents: 25859
diff changeset
    27
import javax.swing.plaf.synth.SynthIcon;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.plaf.synth.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.swing.plaf.synth.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.java.swing.plaf.gtk.GTKConstants.ArrowType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.java.swing.plaf.gtk.GTKConstants.ExpanderStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.java.swing.plaf.gtk.GTKConstants.Orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
class GTKIconFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static final int CHECK_ICON_EXTRA_INSET        = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static final int DEFAULT_ICON_SPACING          = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static final int DEFAULT_ICON_SIZE             = 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static final int DEFAULT_TOGGLE_MENU_ITEM_SIZE = 12; // For pre-gtk2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static final String RADIO_BUTTON_ICON    = "paintRadioButtonIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static final String CHECK_BOX_ICON       = "paintCheckBoxIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static final String MENU_ARROW_ICON      = "paintMenuArrowIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static final String CHECK_BOX_MENU_ITEM_CHECK_ICON =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                                      "paintCheckBoxMenuItemCheckIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static final String RADIO_BUTTON_MENU_ITEM_CHECK_ICON =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                                      "paintRadioButtonMenuItemCheckIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static final String TREE_EXPANDED_ICON = "paintTreeExpandedIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static final String TREE_COLLAPSED_ICON = "paintTreeCollapsedIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static final String ASCENDING_SORT_ICON = "paintAscendingSortIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static final String DESCENDING_SORT_ICON = "paintDescendingSortIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static final String TOOL_BAR_HANDLE_ICON = "paintToolBarHandleIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static Map<String, DelegatingIcon> iconsPool =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            Collections.synchronizedMap(new HashMap<String, DelegatingIcon>());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static DelegatingIcon getIcon(String methodName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        DelegatingIcon result = iconsPool.get(methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            if (methodName == TREE_COLLAPSED_ICON ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                methodName == TREE_EXPANDED_ICON)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                result = new SynthExpanderIcon(methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            } else if (methodName == TOOL_BAR_HANDLE_ICON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                result = new ToolBarHandleIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            } else if (methodName == MENU_ARROW_ICON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                result = new MenuArrowIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                result = new DelegatingIcon(methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            iconsPool.put(methodName, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    // Sort arrow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static Icon getAscendingSortIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        return getIcon(ASCENDING_SORT_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public static Icon getDescendingSortIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        return getIcon(DESCENDING_SORT_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    // Tree methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public static SynthIcon getTreeExpandedIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return getIcon(TREE_EXPANDED_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public static SynthIcon getTreeCollapsedIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return getIcon(TREE_COLLAPSED_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    // Radio button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public static SynthIcon getRadioButtonIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        return getIcon(RADIO_BUTTON_ICON);
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
    // CheckBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public static SynthIcon getCheckBoxIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return getIcon(CHECK_BOX_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    // Menus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public static SynthIcon getMenuArrowIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        return getIcon(MENU_ARROW_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public static SynthIcon getCheckBoxMenuItemCheckIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return getIcon(CHECK_BOX_MENU_ITEM_CHECK_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public static SynthIcon getRadioButtonMenuItemCheckIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return getIcon(RADIO_BUTTON_MENU_ITEM_CHECK_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    // ToolBar Handle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public static SynthIcon getToolBarHandleIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return getIcon(TOOL_BAR_HANDLE_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    static void resetIcons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        synchronized (iconsPool) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            for (DelegatingIcon di: iconsPool.values()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                di.resetIconDimensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    private static class DelegatingIcon extends SynthIcon implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                   UIResource {
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 5506
diff changeset
   155
        private static final Class<?>[] PARAM_TYPES = new Class<?>[] {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            SynthContext.class, Graphics.class, int.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            int.class, int.class, int.class, int.class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        private Object method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        int iconDimension = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        DelegatingIcon(String methodName ){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            this.method = methodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        public void paintIcon(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                              int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            if (context != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                GTKPainter.INSTANCE.paintIcon(context, g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                        getMethod(), x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        public int getIconWidth(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            return getIconDimension(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        public int getIconHeight(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            return getIconDimension(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        void resetIconDimensions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            iconDimension = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        protected Method getMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            if (method instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                method = resolveMethod((String)method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            return (Method)method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 5506
diff changeset
   194
        protected Class<?>[] getMethodParamTypes() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            return PARAM_TYPES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        private Method resolveMethod(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                return GTKPainter.class.getMethod(name, getMethodParamTypes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            } catch (NoSuchMethodException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        int getIconDimension(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            if (iconDimension >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                return iconDimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                return DEFAULT_ICON_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            Region region = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            GTKStyle style = (GTKStyle) context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            iconDimension = style.getClassSpecificIntValue(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    "indicator-size",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    (region == Region.CHECK_BOX_MENU_ITEM ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                     region == Region.RADIO_BUTTON_MENU_ITEM) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                        DEFAULT_TOGGLE_MENU_ITEM_SIZE : DEFAULT_ICON_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            if (region == Region.CHECK_BOX || region == Region.RADIO_BUTTON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                iconDimension += 2 * style.getClassSpecificIntValue(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                        "indicator-spacing", DEFAULT_ICON_SPACING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            } else if (region == Region.CHECK_BOX_MENU_ITEM ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                       region == Region.RADIO_BUTTON_MENU_ITEM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                iconDimension += 2 * CHECK_ICON_EXTRA_INSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            return iconDimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    private static class SynthExpanderIcon extends DelegatingIcon {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        SynthExpanderIcon(String method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            super(method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        public void paintIcon(SynthContext context, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                              int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            if (context != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                super.paintIcon(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                updateSizeIfNecessary(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        int getIconDimension(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            updateSizeIfNecessary(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            return (iconDimension == -1) ? DEFAULT_ICON_SIZE :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                           iconDimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        private void updateSizeIfNecessary(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            if (iconDimension == -1 && context != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                iconDimension = context.getStyle().getInt(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                        "Tree.expanderSize", 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    // GTK has a separate widget for the handle box, to mirror this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    // we create a unique icon per ToolBar and lookup the style for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    // HandleBox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    private static class ToolBarHandleIcon extends DelegatingIcon {
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 5506
diff changeset
   266
        private static final Class<?>[] PARAM_TYPES = new Class<?>[] {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            SynthContext.class, Graphics.class, int.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            int.class, int.class, int.class, int.class, Orientation.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        private SynthStyle style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        public ToolBarHandleIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            super(TOOL_BAR_HANDLE_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 5506
diff changeset
   277
        protected Class<?>[] getMethodParamTypes() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            return PARAM_TYPES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        public void paintIcon(SynthContext context, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                              int w, int h) {
2495
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   283
            if (context != null) {
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   284
                JToolBar toolbar = (JToolBar)context.getComponent();
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   285
                Orientation orientation =
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   286
                        (toolbar.getOrientation() == JToolBar.HORIZONTAL ?
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   287
                            Orientation.HORIZONTAL : Orientation.VERTICAL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
2495
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   289
                if (style == null) {
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   290
                    style = SynthLookAndFeel.getStyleFactory().getStyle(
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   291
                            context.getComponent(), GTKRegion.HANDLE_BOX);
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   292
                }
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   293
                context = new SynthContext(toolbar, GTKRegion.HANDLE_BOX,
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   294
                        style, SynthConstants.ENABLED);
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   295
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   296
                GTKPainter.INSTANCE.paintIcon(context, g,
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   297
                        getMethod(), x, y, w, h, orientation);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        public int getIconWidth(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                return 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            if (((JToolBar)context.getComponent()).getOrientation() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    JToolBar.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                return 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                return context.getComponent().getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        public int getIconHeight(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                return 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            if (((JToolBar)context.getComponent()).getOrientation() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    JToolBar.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                return context.getComponent().getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                return 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    private static class MenuArrowIcon extends DelegatingIcon {
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 5506
diff changeset
   327
        private static final Class<?>[] PARAM_TYPES = new Class<?>[] {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            SynthContext.class, Graphics.class, int.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            int.class, int.class, int.class, int.class, ArrowType.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        public MenuArrowIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            super(MENU_ARROW_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 5506
diff changeset
   336
        protected Class<?>[] getMethodParamTypes() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            return PARAM_TYPES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        public void paintIcon(SynthContext context, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                              int w, int h) {
2495
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   342
            if (context != null) {
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   343
                ArrowType arrowDir = ArrowType.RIGHT;
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   344
                if (!context.getComponent().getComponentOrientation().isLeftToRight()) {
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   345
                    arrowDir = ArrowType.LEFT;
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   346
                }
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   347
                GTKPainter.INSTANCE.paintIcon(context, g,
3e32bdf43a35 6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager
peterz
parents: 2
diff changeset
   348
                        getMethod(), x, y, w, h, arrowDir);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
}