jdk/src/share/classes/javax/swing/plaf/basic/BasicIconFactory.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 20169 d7fa6d7586c9
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2001, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.plaf.UIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Polygon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Factory object that can vend Icons appropriate for the basic L & F.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author David Kloba
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author Georges Saab
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class BasicIconFactory implements Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static Icon frame_icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static Icon checkBoxIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static Icon radioButtonIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static Icon checkBoxMenuItemIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static Icon radioButtonMenuItemIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static Icon menuItemCheckIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static Icon menuItemArrowIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static Icon menuArrowIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static Icon getMenuItemCheckIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        if (menuItemCheckIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            menuItemCheckIcon = new MenuItemCheckIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        return menuItemCheckIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public static Icon getMenuItemArrowIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        if (menuItemArrowIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            menuItemArrowIcon = new MenuItemArrowIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return menuItemArrowIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static Icon getMenuArrowIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if (menuArrowIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            menuArrowIcon = new MenuArrowIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        return menuArrowIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public static Icon getCheckBoxIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (checkBoxIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            checkBoxIcon = new CheckBoxIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return checkBoxIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public static Icon getRadioButtonIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (radioButtonIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            radioButtonIcon = new RadioButtonIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        return radioButtonIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static Icon getCheckBoxMenuItemIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (checkBoxMenuItemIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            checkBoxMenuItemIcon = new CheckBoxMenuItemIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return checkBoxMenuItemIcon;
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 Icon getRadioButtonMenuItemIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if (radioButtonMenuItemIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            radioButtonMenuItemIcon = new RadioButtonMenuItemIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return radioButtonMenuItemIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public static Icon createEmptyFrameIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        if(frame_icon == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            frame_icon = new EmptyFrameIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return frame_icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private static class EmptyFrameIcon implements Icon, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        int height = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        int width = 14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        public int getIconWidth() { return width; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        public int getIconHeight() { return height; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private static class CheckBoxIcon implements Icon, Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        final static int csize = 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        public void paintIcon(Component c, Graphics g, int x, int y) {
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 int getIconWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            return csize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        public int getIconHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            return csize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private static class RadioButtonIcon implements Icon, UIResource, Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        public int getIconWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            return 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        public int getIconHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            return 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    } // end class RadioButtonIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    private static class CheckBoxMenuItemIcon implements Icon, UIResource, Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            AbstractButton b = (AbstractButton) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            boolean isSelected = model.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            if (isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                g.drawLine(x+7, y+1, x+7, y+3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                g.drawLine(x+6, y+2, x+6, y+4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                g.drawLine(x+5, y+3, x+5, y+5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                g.drawLine(x+4, y+4, x+4, y+6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                g.drawLine(x+3, y+5, x+3, y+7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                g.drawLine(x+2, y+4, x+2, y+6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                g.drawLine(x+1, y+3, x+1, y+5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        public int getIconWidth() { return 9; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        public int getIconHeight() { return 9; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    } // End class CheckBoxMenuItemIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    private static class RadioButtonMenuItemIcon implements Icon, UIResource, Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            AbstractButton b = (AbstractButton) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (b.isSelected() == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                g.fillOval(x+1, y+1, getIconWidth(), getIconHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        public int getIconWidth() { return 6; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        public int getIconHeight() { return 6; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    } // End class RadioButtonMenuItemIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    private static class MenuItemCheckIcon implements Icon, UIResource, Serializable{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        public int getIconWidth() { return 9; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        public int getIconHeight() { return 9; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    } // End class MenuItemCheckIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    private static class MenuItemArrowIcon implements Icon, UIResource, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        public int getIconWidth() { return 4; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        public int getIconHeight() { return 8; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    } // End class MenuItemArrowIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    private static class MenuArrowIcon implements Icon, UIResource, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            Polygon p = new Polygon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            p.addPoint(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            p.addPoint(x+getIconWidth(), y+getIconHeight()/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            p.addPoint(x, y+getIconHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            g.fillPolygon(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        public int getIconWidth() { return 4; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        public int getIconHeight() { return 8; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    } // End class MenuArrowIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
}