jdk/src/share/classes/javax/swing/plaf/basic/BasicIconFactory.java
author darcy
Wed, 02 Jul 2014 23:03:27 -0700
changeset 25565 ce603b34c98d
parent 22574 7f8ce0c8c20a
child 25761 c408b10ef757
permissions -rw-r--r--
8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.* 8042849: Fix raw and unchecked warnings in com.sun.java.swing Reviewed-by: pchelko, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
     2
 * Copyright (c) 1997, 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: 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
/**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
    38
 * Factory object that can vend Icons appropriate for the basic L & F.
2
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
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20169
diff changeset
    45
 * of all JavaBeans&trade;
2
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
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    52
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class BasicIconFactory implements Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static Icon frame_icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static Icon checkBoxIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static Icon radioButtonIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static Icon checkBoxMenuItemIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static Icon radioButtonMenuItemIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static Icon menuItemCheckIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static Icon menuItemArrowIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static Icon menuArrowIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public static Icon getMenuItemCheckIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        if (menuItemCheckIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            menuItemCheckIcon = new MenuItemCheckIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        return menuItemCheckIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public static Icon getMenuItemArrowIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        if (menuItemArrowIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            menuItemArrowIcon = new MenuItemArrowIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        return menuItemArrowIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static Icon getMenuArrowIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if (menuArrowIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            menuArrowIcon = new MenuArrowIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        return menuArrowIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public static Icon getCheckBoxIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (checkBoxIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            checkBoxIcon = new CheckBoxIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        return checkBoxIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public static Icon getRadioButtonIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (radioButtonIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            radioButtonIcon = new RadioButtonIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        return radioButtonIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public static Icon getCheckBoxMenuItemIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (checkBoxMenuItemIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            checkBoxMenuItemIcon = new CheckBoxMenuItemIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return checkBoxMenuItemIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public static Icon getRadioButtonMenuItemIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if (radioButtonMenuItemIcon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            radioButtonMenuItemIcon = new RadioButtonMenuItemIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return radioButtonMenuItemIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public static Icon createEmptyFrameIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        if(frame_icon == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            frame_icon = new EmptyFrameIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return frame_icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private static class EmptyFrameIcon implements Icon, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        int height = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        int width = 14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        public int getIconWidth() { return width; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        public int getIconHeight() { return height; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private static class CheckBoxIcon implements Icon, Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        final static int csize = 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        public void paintIcon(Component c, Graphics g, int x, int y) {
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 int getIconWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            return csize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        public int getIconHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            return csize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private static class RadioButtonIcon implements Icon, UIResource, Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        public int getIconWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            return 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        public int getIconHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            return 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    } // end class RadioButtonIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private static class CheckBoxMenuItemIcon implements Icon, UIResource, Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            AbstractButton b = (AbstractButton) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            boolean isSelected = model.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            if (isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                g.drawLine(x+7, y+1, x+7, y+3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                g.drawLine(x+6, y+2, x+6, y+4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                g.drawLine(x+5, y+3, x+5, y+5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                g.drawLine(x+4, y+4, x+4, y+6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                g.drawLine(x+3, y+5, x+3, y+7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                g.drawLine(x+2, y+4, x+2, y+6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                g.drawLine(x+1, y+3, x+1, y+5);
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() { return 9; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        public int getIconHeight() { return 9; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    } // End class CheckBoxMenuItemIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    private static class RadioButtonMenuItemIcon implements Icon, UIResource, Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            AbstractButton b = (AbstractButton) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            if (b.isSelected() == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                g.fillOval(x+1, y+1, getIconWidth(), getIconHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        public int getIconWidth() { return 6; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        public int getIconHeight() { return 6; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    } // End class RadioButtonMenuItemIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    private static class MenuItemCheckIcon implements Icon, UIResource, Serializable{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        public int getIconWidth() { return 9; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        public int getIconHeight() { return 9; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    } // End class MenuItemCheckIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    private static class MenuItemArrowIcon implements Icon, UIResource, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        public int getIconWidth() { return 4; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        public int getIconHeight() { return 8; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    } // End class MenuItemArrowIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    private static class MenuArrowIcon implements Icon, UIResource, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            Polygon p = new Polygon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            p.addPoint(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            p.addPoint(x+getIconWidth(), y+getIconHeight()/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            p.addPoint(x, y+getIconHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            g.fillPolygon(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        public int getIconWidth() { return 4; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        public int getIconHeight() { return 8; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    } // End class MenuArrowIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
}