001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Sergey Burlak
020: * @version $Revision$
021: */package javax.swing.plaf.basic;
022:
023: import java.awt.Color;
024: import java.awt.Component;
025: import java.awt.Graphics;
026: import java.io.Serializable;
027:
028: import javax.swing.AbstractButton;
029: import javax.swing.Icon;
030: import javax.swing.SwingConstants;
031: import javax.swing.plaf.UIResource;
032:
033: import org.apache.harmony.x.swing.Utilities;
034:
035: public class BasicIconFactory implements Serializable {
036: private static RadioButtonMenuItemIcon radioButtonMenuItemIcon;
037: private static RadioButtonIcon radioButtonIcon;
038: private static MenuItemCheckIcon menuItemCheckIcon;
039: private static MenuItemArrowIcon menuItemArrowIcon;
040: private static MenuArrowIcon menuArrowIcon;
041: private static CheckBoxMenuItemIcon checkBoxMenuItemIcon;
042: private static CheckBoxIcon checkBoxIcon;
043: private static EmptyFrameIcon emptyFrameIcon;
044:
045: public static Icon getRadioButtonMenuItemIcon() {
046: if (radioButtonMenuItemIcon == null) {
047: radioButtonMenuItemIcon = new RadioButtonMenuItemIcon();
048: }
049: return radioButtonMenuItemIcon;
050: }
051:
052: public static Icon getRadioButtonIcon() {
053: if (radioButtonIcon == null) {
054: radioButtonIcon = new RadioButtonIcon();
055: }
056: return radioButtonIcon;
057: }
058:
059: public static Icon getMenuItemCheckIcon() {
060: if (menuItemCheckIcon == null) {
061: menuItemCheckIcon = new MenuItemCheckIcon();
062: }
063: return menuItemCheckIcon;
064: }
065:
066: public static Icon getMenuItemArrowIcon() {
067: if (menuItemArrowIcon == null) {
068: menuItemArrowIcon = new MenuItemArrowIcon();
069: }
070: return menuItemArrowIcon;
071: }
072:
073: public static Icon getMenuArrowIcon() {
074: if (menuArrowIcon == null) {
075: menuArrowIcon = new MenuArrowIcon();
076: }
077: return menuArrowIcon;
078: }
079:
080: public static Icon getCheckBoxMenuItemIcon() {
081: if (checkBoxMenuItemIcon == null) {
082: checkBoxMenuItemIcon = new CheckBoxMenuItemIcon();
083: }
084: return checkBoxMenuItemIcon;
085: }
086:
087: public static Icon getCheckBoxIcon() {
088: if (checkBoxIcon == null) {
089: checkBoxIcon = new CheckBoxIcon();
090: }
091: return checkBoxIcon;
092: }
093:
094: public static Icon createEmptyFrameIcon() {
095: if (emptyFrameIcon == null) {
096: emptyFrameIcon = new EmptyFrameIcon();
097: }
098: return emptyFrameIcon;
099: }
100:
101: private static class RadioButtonIcon implements Icon {
102: public int getIconHeight() {
103: return 13;
104: }
105:
106: public int getIconWidth() {
107: return 13;
108: }
109:
110: public void paintIcon(final Component c, final Graphics g,
111: final int x, final int y) {
112: // this method paints nothing
113: }
114: }
115:
116: private static class RadioButtonMenuItemIcon implements Icon {
117: private static final int SIZE = 6;
118:
119: public int getIconHeight() {
120: return SIZE;
121: }
122:
123: public int getIconWidth() {
124: return SIZE;
125: }
126:
127: public void paintIcon(final Component c, final Graphics g,
128: final int x, final int y) {
129: AbstractButton b = (AbstractButton) c;
130: if (b.isSelected()) {
131: g.setColor(b.getForeground());
132: g.fillRoundRect(x, y + 1, SIZE, SIZE, SIZE / 2,
133: SIZE / 2);
134: }
135: }
136: }
137:
138: private static class CheckBoxIcon implements Icon {
139: public int getIconHeight() {
140: return 13;
141: }
142:
143: public int getIconWidth() {
144: return 13;
145: }
146:
147: public void paintIcon(final Component c, final Graphics g,
148: final int x, final int y) {
149: // this method paints nothing
150: }
151: }
152:
153: private static class CheckBoxMenuItemIcon implements Icon {
154: private static final int SIZE = 9;
155:
156: public int getIconHeight() {
157: return SIZE;
158: }
159:
160: public int getIconWidth() {
161: return SIZE;
162: }
163:
164: public void paintIcon(final Component c, final Graphics g,
165: final int x, final int y) {
166: AbstractButton b = (AbstractButton) c;
167: if (b.isSelected()) {
168: g.setColor(b.getForeground());
169: g.drawLine(x + 3, y + SIZE / 2, x + 3, y + SIZE - 2);
170: g.drawLine(x + 4, y + SIZE / 2, x + 4, y + SIZE - 2);
171: int lineLength = SIZE - SIZE / 2 - 2;
172: g.drawLine(x + 4, y + SIZE - 3, x + 4 + lineLength, y
173: + SIZE - 3 - lineLength);
174: }
175: }
176: }
177:
178: private static class MenuArrowIcon implements Icon {
179: private int iconHeight = 8;
180: private int iconWidth = 4;
181:
182: public int getIconHeight() {
183: return iconHeight;
184: }
185:
186: public int getIconWidth() {
187: return iconWidth;
188: }
189:
190: public void paintIcon(final Component c, final Graphics g,
191: final int x, final int y) {
192: final boolean leftToRight = c.getComponentOrientation()
193: .isLeftToRight();
194: final int direction = leftToRight ? SwingConstants.EAST
195: : SwingConstants.WEST;
196: final Color color = c.isEnabled() ? c.getForeground() : c
197: .getBackground().darker();
198: Utilities.fillArrow(g, x, y + 1, direction, 8, true, color);
199: }
200: }
201:
202: private static class MenuItemCheckIcon implements Icon {
203: public int getIconHeight() {
204: return 9;
205: }
206:
207: public int getIconWidth() {
208: return 9;
209: }
210:
211: public void paintIcon(final Component c, final Graphics g,
212: final int x, final int y) {
213: }
214: }
215:
216: private static class MenuItemArrowIcon implements Icon {
217: public int getIconHeight() {
218: return 8;
219: }
220:
221: public int getIconWidth() {
222: return 4;
223: }
224:
225: public void paintIcon(final Component c, final Graphics g,
226: final int x, final int y) {
227: }
228: }
229:
230: private static class EmptyFrameIcon implements Icon, UIResource {
231: public int getIconHeight() {
232: return 16;
233: }
234:
235: public int getIconWidth() {
236: return 14;
237: }
238:
239: public void paintIcon(final Component c, final Graphics g,
240: final int x, final int y) {
241: // does nothing
242: }
243: }
244: }
|