jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKIconFactory.java
author peterz
Mon, 06 Apr 2009 13:06:24 +0400
changeset 2495 3e32bdf43a35
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6635110: GTK problem when testing Sun Studio IDE on snv_77 with jdk1.6 using Gnome window manager Summary: GTKIconFactory icons should protect against null context passed in Reviewed-by: rupashka
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2002-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package com.sun.java.swing.plaf.gtk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.plaf.synth.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.reflect.*;
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 sun.swing.plaf.synth.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.java.swing.plaf.gtk.GTKConstants.ArrowType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.java.swing.plaf.gtk.GTKConstants.ExpanderStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.java.swing.plaf.gtk.GTKConstants.Orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
class GTKIconFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    static final int CHECK_ICON_EXTRA_INSET        = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static final int DEFAULT_ICON_SPACING          = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static final int DEFAULT_ICON_SIZE             = 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static final int DEFAULT_TOGGLE_MENU_ITEM_SIZE = 12; // For pre-gtk2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static final String RADIO_BUTTON_ICON    = "paintRadioButtonIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static final String CHECK_BOX_ICON       = "paintCheckBoxIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static final String MENU_ARROW_ICON      = "paintMenuArrowIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static final String CHECK_BOX_MENU_ITEM_CHECK_ICON =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                                      "paintCheckBoxMenuItemCheckIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static final String RADIO_BUTTON_MENU_ITEM_CHECK_ICON =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                                      "paintRadioButtonMenuItemCheckIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static final String TREE_EXPANDED_ICON = "paintTreeExpandedIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static final String TREE_COLLAPSED_ICON = "paintTreeCollapsedIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static final String ASCENDING_SORT_ICON = "paintAscendingSortIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static final String DESCENDING_SORT_ICON = "paintDescendingSortIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static final String TOOL_BAR_HANDLE_ICON = "paintToolBarHandleIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static Map<String, DelegatingIcon> iconsPool =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            Collections.synchronizedMap(new HashMap<String, DelegatingIcon>());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static DelegatingIcon getIcon(String methodName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        DelegatingIcon result = iconsPool.get(methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            if (methodName == TREE_COLLAPSED_ICON ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                methodName == TREE_EXPANDED_ICON)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                result = new SynthExpanderIcon(methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            } else if (methodName == TOOL_BAR_HANDLE_ICON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                result = new ToolBarHandleIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            } else if (methodName == MENU_ARROW_ICON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                result = new MenuArrowIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                result = new DelegatingIcon(methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            iconsPool.put(methodName, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    // Sort arrow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static Icon getAscendingSortIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return getIcon(ASCENDING_SORT_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public static Icon getDescendingSortIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        return getIcon(DESCENDING_SORT_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    // Tree methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public static SynthIcon getTreeExpandedIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return getIcon(TREE_EXPANDED_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public static SynthIcon getTreeCollapsedIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return getIcon(TREE_COLLAPSED_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    // Radio button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public static SynthIcon getRadioButtonIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return getIcon(RADIO_BUTTON_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    // CheckBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public static SynthIcon getCheckBoxIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return getIcon(CHECK_BOX_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    // Menus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public static SynthIcon getMenuArrowIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return getIcon(MENU_ARROW_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public static SynthIcon getCheckBoxMenuItemCheckIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return getIcon(CHECK_BOX_MENU_ITEM_CHECK_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public static SynthIcon getRadioButtonMenuItemCheckIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        return getIcon(RADIO_BUTTON_MENU_ITEM_CHECK_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    // ToolBar Handle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public static SynthIcon getToolBarHandleIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        return getIcon(TOOL_BAR_HANDLE_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    static void resetIcons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        synchronized (iconsPool) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            for (DelegatingIcon di: iconsPool.values()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                di.resetIconDimensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            }
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
    private static class DelegatingIcon extends SynthIcon implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                   UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        private static final Class[] PARAM_TYPES = new Class[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            SynthContext.class, Graphics.class, int.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            int.class, int.class, int.class, int.class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        private Object method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        int iconDimension = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        DelegatingIcon(String methodName ){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            this.method = methodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        public void paintIcon(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                              int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            if (context != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                GTKPainter.INSTANCE.paintIcon(context, g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                        getMethod(), x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        public int getIconWidth(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            return getIconDimension(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        public int getIconHeight(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            return getIconDimension(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        void resetIconDimensions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            iconDimension = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        protected Method getMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            if (method instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                method = resolveMethod((String)method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            return (Method)method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        protected Class[] getMethodParamTypes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            return PARAM_TYPES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        private Method resolveMethod(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                return GTKPainter.class.getMethod(name, getMethodParamTypes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            } catch (NoSuchMethodException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        int getIconDimension(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            if (iconDimension >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                return iconDimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                return DEFAULT_ICON_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            Region region = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            GTKStyle style = (GTKStyle) context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            iconDimension = style.getClassSpecificIntValue(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    "indicator-size",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    (region == Region.CHECK_BOX_MENU_ITEM ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                     region == Region.RADIO_BUTTON_MENU_ITEM) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                        DEFAULT_TOGGLE_MENU_ITEM_SIZE : DEFAULT_ICON_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            if (region == Region.CHECK_BOX || region == Region.RADIO_BUTTON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                iconDimension += 2 * style.getClassSpecificIntValue(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                        "indicator-spacing", DEFAULT_ICON_SPACING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            } else if (region == Region.CHECK_BOX_MENU_ITEM ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                       region == Region.RADIO_BUTTON_MENU_ITEM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                iconDimension += 2 * CHECK_ICON_EXTRA_INSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            return iconDimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    private static class SynthExpanderIcon extends DelegatingIcon {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        SynthExpanderIcon(String method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            super(method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        public void paintIcon(SynthContext context, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                              int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (context != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                super.paintIcon(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                updateSizeIfNecessary(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        int getIconDimension(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            updateSizeIfNecessary(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            return (iconDimension == -1) ? DEFAULT_ICON_SIZE :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                                           iconDimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        private void updateSizeIfNecessary(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            if (iconDimension == -1 && context != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                iconDimension = context.getStyle().getInt(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                        "Tree.expanderSize", 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
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
    // GTK has a separate widget for the handle box, to mirror this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    // we create a unique icon per ToolBar and lookup the style for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    // HandleBox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    private static class ToolBarHandleIcon extends DelegatingIcon {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        private static final Class[] PARAM_TYPES = new Class[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            SynthContext.class, Graphics.class, int.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            int.class, int.class, int.class, int.class, Orientation.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        private SynthStyle style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        public ToolBarHandleIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            super(TOOL_BAR_HANDLE_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        protected Class[] getMethodParamTypes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            return PARAM_TYPES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        public void paintIcon(SynthContext context, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                              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
   282
            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
   283
                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
   284
                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
   285
                        (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
   286
                            Orientation.HORIZONTAL : Orientation.VERTICAL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
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
   288
                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
   289
                    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
   290
                            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
   291
                }
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
                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
   293
                        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
   294
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
                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
   296
                        getMethod(), x, y, w, h, orientation);
2
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
        public int getIconWidth(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                return 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            if (((JToolBar)context.getComponent()).getOrientation() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    JToolBar.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                return 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                return context.getComponent().getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        public int getIconHeight(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                return 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            if (((JToolBar)context.getComponent()).getOrientation() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    JToolBar.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                return context.getComponent().getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                return 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            }
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
    private static class MenuArrowIcon extends DelegatingIcon {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        private static final Class[] PARAM_TYPES = new Class[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            SynthContext.class, Graphics.class, int.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            int.class, int.class, int.class, int.class, ArrowType.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        public MenuArrowIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            super(MENU_ARROW_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        protected Class[] getMethodParamTypes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            return PARAM_TYPES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        public void paintIcon(SynthContext context, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                              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
   341
            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
   342
                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
   343
                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
   344
                    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
   345
                }
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
                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
   347
                        getMethod(), x, y, w, h, arrowDir);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
}