0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */
0017:
0018: /**
0019: * @author Sergey Burlak, Anton Avtamonov, Vadim Bogdanov
0020: * @version $Revision$
0021: */package javax.swing.plaf.metal;
0022:
0023: import java.awt.Color;
0024: import java.awt.Component;
0025: import java.awt.Graphics;
0026: import java.io.Serializable;
0027:
0028: import javax.swing.AbstractButton;
0029: import javax.swing.Icon;
0030: import javax.swing.JSlider;
0031: import javax.swing.JTree;
0032: import javax.swing.SwingConstants;
0033: import javax.swing.plaf.UIResource;
0034:
0035: import org.apache.harmony.x.swing.Utilities;
0036:
0037: public class MetalIconFactory implements Serializable {
0038: public static class FileIcon16 implements Icon, Serializable {
0039: private static final Color FILE_COLOR = new Color(240, 240, 255);
0040:
0041: public void paintIcon(final Component c, final Graphics g,
0042: final int x, final int y) {
0043: Color oldColor = g.getColor();
0044:
0045: int[] envelopeXs = new int[] { x + 2, x + 7, x + 14,
0046: x + 14, x + 2, x + 2 };
0047: int[] envelopeYs = new int[] { y + 7, y + 2, y + 2, y + 16,
0048: y + 16, y + 7 };
0049: g.setColor(FILE_COLOR);
0050: g.fillPolygon(envelopeXs, envelopeYs, 6);
0051: g.setColor(Color.GRAY);
0052: g.drawPolygon(envelopeXs, envelopeYs, 6);
0053:
0054: int[] cornerXs = new int[] { x + 2, x + 7, x + 7, x + 2 };
0055: int[] cornerYs = new int[] { y + 7, y + 2, y + 7, y + 7 };
0056: g.setColor(Color.LIGHT_GRAY);
0057: g.fillPolygon(cornerXs, cornerYs, 4);
0058: g.setColor(Color.GRAY);
0059: g.drawPolygon(cornerXs, cornerYs, 4);
0060:
0061: g.setColor(oldColor);
0062: }
0063:
0064: public int getShift() {
0065: return 0;
0066: }
0067:
0068: public int getIconWidth() {
0069: return 16;
0070: }
0071:
0072: public int getIconHeight() {
0073: return 16;
0074: }
0075:
0076: public int getAdditionalHeight() {
0077: return 0;
0078: }
0079: }
0080:
0081: public static class FolderIcon16 implements Icon, Serializable {
0082: public void paintIcon(final Component c, final Graphics g,
0083: final int x, final int y) {
0084: Color oldColor = g.getColor();
0085:
0086: int[] folderXs = new int[] { x + 2, x + 7, x + 8, x + 14,
0087: x + 14, x + 2, x + 2 };
0088: int[] folderYs = new int[] { y + 3, y + 3, y + 5, y + 5,
0089: y + 13, y + 13, y + 3 };
0090: g.setColor(Color.YELLOW);
0091: g.fillPolygon(folderXs, folderYs, 7);
0092: g.setColor(Color.GRAY);
0093: g.drawPolygon(folderXs, folderYs, 7);
0094:
0095: int[] cornerXs = new int[] { x + 2, x + 7, x + 8, x + 2,
0096: x + 2 };
0097: int[] cornerYs = new int[] { y + 3, y + 3, y + 5, y + 5,
0098: y + 3 };
0099: g.setColor(Color.LIGHT_GRAY);
0100: g.fillPolygon(cornerXs, cornerYs, 5);
0101: g.setColor(Color.GRAY);
0102: g.drawPolygon(cornerXs, cornerYs, 5);
0103:
0104: g.setColor(oldColor);
0105: }
0106:
0107: public int getShift() {
0108: return 0;
0109: }
0110:
0111: public int getIconWidth() {
0112: return 16;
0113: }
0114:
0115: public int getIconHeight() {
0116: return 16;
0117: }
0118:
0119: public int getAdditionalHeight() {
0120: return 0;
0121: }
0122:
0123: }
0124:
0125: public static class PaletteCloseIcon implements Icon, UIResource,
0126: Serializable {
0127: private static final int size = 8;
0128:
0129: public int getIconWidth() {
0130: return size;
0131: }
0132:
0133: public int getIconHeight() {
0134: return size;
0135: }
0136:
0137: public void paintIcon(final Component c, final Graphics g,
0138: final int x, final int y) {
0139: AbstractButton b = (AbstractButton) c;
0140: Color saveColor = g.getColor();
0141: Color shadow = MetalLookAndFeel.getControlDarkShadow();
0142: Color highlight = MetalLookAndFeel.getControlHighlight();
0143: Color foreground = b.getModel().isArmed() ? shadow
0144: : highlight;
0145: Color background = !b.getModel().isArmed() ? shadow
0146: : highlight;
0147:
0148: g.setColor(foreground);
0149: g.drawPolyline(new int[] { 0, 1, size / 2 - 1, size / 2,
0150: size - 2, size - 1 }, new int[] { 0, 0,
0151: size / 2 - 2, size / 2 - 2, 0, 0 }, 6);
0152: g.drawLine(0, size - 2, size / 2 - 2, size / 2);
0153: g.drawLine(size / 2 + 1, size / 2, size - 1, size - 2);
0154: g.setColor(background);
0155: g.drawPolyline(new int[] { 0, 1, size / 2 - 1, size / 2,
0156: size - 2, size - 1 }, new int[] { size - 1,
0157: size - 1, size / 2 + 1, size / 2 + 1, size - 1,
0158: size - 1 }, 6);
0159: g.drawLine(0, 1, size / 2 - 2, size / 2 - 1);
0160: g.drawLine(size / 2 + 1, size / 2 - 1, size - 1, 1);
0161: g.setColor(saveColor);
0162: }
0163: }
0164:
0165: public static class TreeControlIcon implements Icon, Serializable {
0166: protected boolean isLight;
0167:
0168: public TreeControlIcon(final boolean isCollapsed) {
0169: this .isLight = isCollapsed;
0170: }
0171:
0172: public void paintMe(final Component c, final Graphics g,
0173: final int x, final int y) {
0174: JTree tree = (JTree) c;
0175: g.setColor(tree.getBackground());
0176: g.fillRect(x + getIconWidth() / 4, y + getIconHeight() / 4
0177: + 1, getIconWidth() / 2 - 1,
0178: getIconHeight() / 2 - 1);
0179: g.setColor(tree.getForeground());
0180: g.drawRect(x + getIconWidth() / 4, y + getIconHeight() / 4
0181: + 1, getIconWidth() / 2 - 1,
0182: getIconHeight() / 2 - 1);
0183: g.drawLine(x + getIconWidth() / 2 - 3, y + getIconWidth()
0184: / 2, x + getIconWidth() / 2 + 1, y + getIconWidth()
0185: / 2);
0186: if (isLight) {
0187: g.drawLine(x + getIconWidth() / 2 - 1, y
0188: + getIconWidth() / 2 - 2, x + getIconWidth()
0189: / 2 - 1, y + getIconWidth() / 2 + 2);
0190: }
0191: }
0192:
0193: public void paintIcon(final Component c, final Graphics g,
0194: final int x, final int y) {
0195: paintMe(c, g, x, y);
0196: }
0197:
0198: public int getIconWidth() {
0199: return 18;
0200: }
0201:
0202: public int getIconHeight() {
0203: return 18;
0204: }
0205: }
0206:
0207: public static class TreeFolderIcon extends
0208: MetalIconFactory.FolderIcon16 {
0209: public int getShift() {
0210: return -1;
0211: }
0212:
0213: public int getAdditionalHeight() {
0214: return 2;
0215: }
0216:
0217: public int getIconHeight() {
0218: return 18;
0219: }
0220: }
0221:
0222: public static class TreeLeafIcon extends
0223: MetalIconFactory.FileIcon16 {
0224: public int getShift() {
0225: return 2;
0226: }
0227:
0228: public int getAdditionalHeight() {
0229: return 4;
0230: }
0231:
0232: public int getIconHeight() {
0233: return 20;
0234: }
0235: }
0236:
0237: private static class InternalFrameAltMaximizeIcon implements Icon,
0238: UIResource {
0239: private int size;
0240:
0241: public InternalFrameAltMaximizeIcon(final int size) {
0242: this .size = size;
0243: }
0244:
0245: public int getIconHeight() {
0246: return size;
0247: }
0248:
0249: public int getIconWidth() {
0250: return size;
0251: }
0252:
0253: public void paintIcon(final Component c, final Graphics g,
0254: final int x, final int y) {
0255: AbstractButton b = (AbstractButton) c;
0256: Color saveColor = g.getColor();
0257: Color shadow = MetalLookAndFeel.getControlDarkShadow();
0258: Color highlight = MetalLookAndFeel.getControlHighlight();
0259: Utilities.draw3DRect(g, x, y + 5, size - 6, size - 6,
0260: shadow, highlight, !b.getModel().isArmed());
0261: Utilities.draw3DRect(g, x + 1, y + 6, size - 8, size - 8,
0262: shadow, highlight, b.getModel().isArmed());
0263: Utilities.draw3DRect(g, x + 5, y, size - 6, size - 6,
0264: shadow, highlight, !b.getModel().isArmed());
0265: Utilities.draw3DRect(g, x + 6, y + 1, size - 8, size - 8,
0266: shadow, highlight, b.getModel().isArmed());
0267:
0268: g.setColor(saveColor);
0269: }
0270: }
0271:
0272: private static class InternalFrameMinimizeIcon implements Icon,
0273: UIResource {
0274: private int size;
0275:
0276: public InternalFrameMinimizeIcon(final int size) {
0277: this .size = size;
0278: }
0279:
0280: public int getIconHeight() {
0281: return size;
0282: }
0283:
0284: public int getIconWidth() {
0285: return size;
0286: }
0287:
0288: public void paintIcon(final Component c, final Graphics g,
0289: final int x, final int y) {
0290: AbstractButton b = (AbstractButton) c;
0291: Color shadow = MetalLookAndFeel.getControlDarkShadow();
0292: Color highlight = MetalLookAndFeel.getControlHighlight();
0293: Utilities.draw3DRect(g, x, y + size - 6, size - 1, 5,
0294: shadow, highlight, !b.getModel().isArmed());
0295: }
0296: }
0297:
0298: private static class InternalFrameCloseIcon implements Icon,
0299: UIResource {
0300: private final int size;
0301:
0302: public InternalFrameCloseIcon(final int size) {
0303: this .size = size & -2;
0304: }
0305:
0306: public int getIconHeight() {
0307: return size;
0308: }
0309:
0310: public int getIconWidth() {
0311: return size;
0312: }
0313:
0314: public void paintIcon(final Component c, final Graphics g,
0315: final int x, final int y) {
0316: AbstractButton b = (AbstractButton) c;
0317: Color saveColor = g.getColor();
0318: Color shadow = MetalLookAndFeel.getControlDarkShadow();
0319: Color highlight = MetalLookAndFeel.getControlHighlight();
0320: Color foreground = b.getModel().isArmed() ? shadow
0321: : highlight;
0322: Color background = !b.getModel().isArmed() ? shadow
0323: : highlight;
0324:
0325: g.setColor(foreground);
0326: g.drawPolyline(new int[] { 0, 2, size / 2 - 1, size / 2,
0327: size - 3, size - 2 }, new int[] { 2, 0,
0328: size / 2 - 3, size / 2 - 3, 0, 1 }, 6);
0329: g.drawLine(0, size - 3, size / 2 - 3, size / 2);
0330: g.drawLine(size / 2 + 2, size / 2, size - 2, size - 4);
0331: g.setColor(background);
0332: g.drawPolyline(new int[] { 1, 2, size / 2 - 1, size / 2,
0333: size - 3, size - 1 }, new int[] { size - 2,
0334: size - 1, size / 2 + 2, size / 2 + 2, size - 1,
0335: size - 3 }, 6);
0336: g.drawLine(1, 3, size / 2 - 3, size / 2 - 1);
0337: g.drawLine(size / 2 + 2, size / 2 - 1, size - 1, 2);
0338: g.setColor(saveColor);
0339: }
0340: }
0341:
0342: private static class InternalFrameMaximizeIcon implements Icon,
0343: UIResource {
0344: private int size;
0345:
0346: public InternalFrameMaximizeIcon(final int size) {
0347: this .size = size;
0348: }
0349:
0350: public int getIconHeight() {
0351: return size;
0352: }
0353:
0354: public int getIconWidth() {
0355: return size;
0356: }
0357:
0358: public void paintIcon(final Component c, final Graphics g,
0359: final int x, final int y) {
0360: AbstractButton b = (AbstractButton) c;
0361: Color shadow = MetalLookAndFeel.getControlDarkShadow();
0362: Color highlight = MetalLookAndFeel.getControlHighlight();
0363: Utilities.draw3DRect(g, x, y, size - 1, size - 1, shadow,
0364: highlight, !b.getModel().isArmed());
0365: Utilities.draw3DRect(g, x + 1, y + 1, size - 3, size - 3,
0366: shadow, highlight, b.getModel().isArmed());
0367: }
0368: }
0369:
0370: private static class TreeHardDriveIcon implements Icon, UIResource {
0371: public int getIconHeight() {
0372: return 16;
0373: }
0374:
0375: public int getIconWidth() {
0376: return 16;
0377: }
0378:
0379: public void paintIcon(final Component c, final Graphics g,
0380: final int x, final int y) {
0381: Color oldColor = g.getColor();
0382:
0383: g.setColor(Color.LIGHT_GRAY);
0384: g.fillOval(x + 2, y + 8, 12, 6);
0385: g.setColor(Color.DARK_GRAY);
0386: g.drawOval(x + 2, y + 8, 12, 6);
0387:
0388: g.setColor(Color.LIGHT_GRAY);
0389: g.fillOval(x + 2, y + 5, 12, 6);
0390: g.setColor(Color.DARK_GRAY);
0391: g.drawOval(x + 2, y + 5, 12, 6);
0392:
0393: g.setColor(Color.LIGHT_GRAY);
0394: g.fillOval(x + 2, y + 2, 12, 6);
0395: g.setColor(Color.DARK_GRAY);
0396: g.drawOval(x + 2, y + 2, 12, 6);
0397:
0398: g.setColor(oldColor);
0399: }
0400: }
0401:
0402: private static class TreeFloppyDriveIcon implements Icon,
0403: UIResource {
0404: private static final Color FLOPPY_COLOR = new Color(200, 200,
0405: 255);
0406:
0407: public int getIconHeight() {
0408: return 16;
0409: }
0410:
0411: public int getIconWidth() {
0412: return 16;
0413: }
0414:
0415: public void paintIcon(final Component c, final Graphics g,
0416: final int x, final int y) {
0417: Color oldColor = g.getColor();
0418:
0419: int[] floppyXs = new int[] { x + 2, x + 3, x + 13, x + 14,
0420: x + 14, x + 13, x + 3, x + 2, x + 2 };
0421: int[] floppyYs = new int[] { y + 2, y + 1, y + 1, y + 2,
0422: y + 12, y + 13, y + 13, y + 13, y + 2 };
0423: g.setColor(FLOPPY_COLOR);
0424: g.fillPolygon(floppyXs, floppyYs, 9);
0425: g.setColor(Color.GRAY);
0426: g.drawPolygon(floppyXs, floppyYs, 9);
0427:
0428: int[] labelXs = new int[] { x + 4, x + 12, x + 12, x + 4,
0429: x + 4 };
0430: int[] labelYs = new int[] { y + 1, y + 1, y + 8, y + 8,
0431: y + 1 };
0432: g.setColor(Color.WHITE);
0433: g.fillPolygon(labelXs, labelYs, 5);
0434: g.setColor(Color.GRAY);
0435: g.drawPolygon(labelXs, labelYs, 5);
0436:
0437: int[] bootXs = new int[] { x + 5, x + 12, x + 12, x + 5,
0438: x + 5 };
0439: int[] bootYs = new int[] { y + 10, y + 10, y + 13, y + 13,
0440: y + 10 };
0441: g.setColor(Color.BLUE);
0442: g.fillPolygon(bootXs, bootYs, 5);
0443:
0444: g.setColor(oldColor);
0445: }
0446: }
0447:
0448: private static class TreeComputerIcon implements Icon, UIResource {
0449: private static final Color SCREEN_COLOR = new Color(176, 221,
0450: 244);
0451:
0452: public int getIconHeight() {
0453: return 16;
0454: }
0455:
0456: public int getIconWidth() {
0457: return 16;
0458: }
0459:
0460: public void paintIcon(final Component c, final Graphics g,
0461: final int x, final int y) {
0462: Color oldColor = g.getColor();
0463:
0464: g.setColor(SCREEN_COLOR);
0465: g.fillRect(x + 2, y + 2, 12, 8);
0466: g.setColor(Color.DARK_GRAY);
0467: g.drawRect(x + 2, y + 2, 11, 8);
0468:
0469: g.setColor(Color.CYAN);
0470: g.drawRect(x + 4, y + 5, 2, 1);
0471:
0472: g.setColor(Color.DARK_GRAY);
0473: g.fillRect(x + 7, y + 10, 2, 2);
0474: g.fillRect(x + 2, y + 12, 12, 2);
0475:
0476: g.setColor(oldColor);
0477: }
0478: }
0479:
0480: private static class InternalFrameDefaultMenuIcon implements Icon,
0481: UIResource {
0482: public int getIconHeight() {
0483: return 16;
0484: }
0485:
0486: public int getIconWidth() {
0487: return 16;
0488: }
0489:
0490: public void paintIcon(final Component c, final Graphics g,
0491: final int x, final int y) {
0492: Color highlight = MetalLookAndFeel.getControlHighlight();
0493: Color shadow = MetalLookAndFeel.getControlDarkShadow();
0494: Utilities.draw3DRect(g, x, y, 16, 16, shadow, highlight,
0495: true);
0496: Utilities.draw3DRect(g, x + 1, y + 1, 14, 14, shadow,
0497: highlight, false);
0498: Color oldColor = g.getColor();
0499: g.setColor(MetalLookAndFeel.getControlHighlight());
0500: g.fillRect(x + 2, y + 2, 12, 12);
0501: g.setColor(oldColor);
0502: }
0503: }
0504:
0505: private static class HorizontalSliderThumbIcon implements Icon,
0506: UIResource {
0507: public int getIconHeight() {
0508: return 16;
0509: }
0510:
0511: public int getIconWidth() {
0512: return 15;
0513: }
0514:
0515: public void paintIcon(final Component c, final Graphics g,
0516: final int x, final int y) {
0517: int bottom = y + getIconHeight() - 1;
0518: int right = x + getIconWidth() - 1;
0519: g.fillPolygon(new int[] { x, right, right,
0520: x + getIconWidth() / 2, x }, new int[] { y, y,
0521: bottom - getIconHeight() / 2, bottom,
0522: bottom - getIconHeight() / 2 }, 5);
0523:
0524: Color shadow = Color.gray;
0525: Color highlight = Color.white;
0526:
0527: g.setColor(highlight);
0528: g.drawLine(x, y, right, y);
0529: g.drawLine(right, y, right, bottom - getIconHeight() / 2
0530: + 1);
0531: g.drawLine(right, bottom - getIconHeight() / 2 + 1, x
0532: + getIconWidth() / 2, bottom);
0533:
0534: g.setColor(shadow);
0535: g.drawLine(x, y, x, bottom - getIconHeight() / 2 + 1);
0536: g.drawLine(x, bottom - getIconHeight() / 2 + 1, x
0537: + getIconWidth() / 2, bottom);
0538: }
0539: }
0540:
0541: private static class VerticalSliderThumbIcon implements Icon,
0542: UIResource {
0543: public int getIconHeight() {
0544: return 15;
0545: }
0546:
0547: public int getIconWidth() {
0548: return 16;
0549: }
0550:
0551: public void paintIcon(final Component c, final Graphics g,
0552: final int x, final int y) {
0553: JSlider slider = (JSlider) c;
0554: int bottom = y + getIconHeight() - 1;
0555: int right = x + getIconWidth() - 1;
0556: if (slider.getComponentOrientation().isLeftToRight()) {
0557: g.fillPolygon(new int[] { x, x + getIconWidth() / 2,
0558: right, x + getIconWidth() / 2, x }, new int[] {
0559: y, y, bottom - getIconHeight() / 2, bottom,
0560: bottom }, 5);
0561:
0562: Color shadow = Color.gray;
0563: Color highlight = Color.white;
0564:
0565: g.setColor(highlight);
0566: g.drawLine(x, y, x + getIconWidth() / 2, y);
0567: g.drawLine(x + getIconWidth() / 2, y, right, bottom
0568: - getIconHeight() / 2);
0569:
0570: g.setColor(shadow);
0571: g.drawLine(x, y, x, bottom);
0572: g.drawLine(x, bottom, x + getIconWidth() / 2, bottom);
0573: g.drawLine(x + getIconWidth() / 2, bottom, right,
0574: bottom - getIconHeight() / 2);
0575: } else {
0576: g.fillPolygon(new int[] { x, x + getIconWidth() / 2,
0577: right, right, x + getIconWidth() / 2, x },
0578: new int[] { bottom - getIconHeight() / 2, y, y,
0579: bottom, bottom,
0580: bottom - getIconHeight() / 2 }, 5);
0581:
0582: Color shadow = Color.gray;
0583: Color highlight = Color.white;
0584:
0585: g.setColor(highlight);
0586: g.drawLine(x + getIconWidth() / 2 - 1, bottom, right,
0587: bottom);
0588: g.drawLine(right, bottom, right, y);
0589:
0590: g.setColor(shadow);
0591: g.drawLine(right, y, x + getIconWidth() / 2 - 1, y);
0592: g.drawLine(x + getIconWidth() / 2 - 1, y, x, bottom
0593: - getIconHeight() / 2);
0594: g.drawLine(x, bottom - getIconHeight() / 2, x
0595: + getIconWidth() / 2 - 1, bottom);
0596: }
0597: }
0598: }
0599:
0600: private static class FileChooserUpFolderIcon implements Icon,
0601: UIResource {
0602: public int getIconHeight() {
0603: return 18;
0604: }
0605:
0606: public int getIconWidth() {
0607: return 18;
0608: }
0609:
0610: public void paintIcon(final Component c, final Graphics g,
0611: final int x, final int y) {
0612: Color oldColor = g.getColor();
0613:
0614: int[] folderXs = new int[] { x + 2, x + 9, x + 10, x + 16,
0615: x + 16, x + 2, x + 2 };
0616: int[] folderYs = new int[] { y + 3, y + 3, y + 5, y + 5,
0617: y + 13, y + 13, y + 3 };
0618: g.setColor(Color.YELLOW);
0619: g.fillPolygon(folderXs, folderYs, 7);
0620: g.setColor(Color.GRAY);
0621: g.drawPolygon(folderXs, folderYs, 7);
0622:
0623: int[] cornerXs = new int[] { x + 2, x + 9, x + 10, x + 2,
0624: x + 2 };
0625: int[] cornerYs = new int[] { y + 3, y + 3, y + 5, y + 5,
0626: y + 3 };
0627: g.setColor(Color.LIGHT_GRAY);
0628: g.fillPolygon(cornerXs, cornerYs, 5);
0629: g.setColor(Color.GRAY);
0630: g.drawPolygon(cornerXs, cornerYs, 5);
0631:
0632: g.setColor(Color.GREEN.darker());
0633: int[] arrowXs = new int[] { x + 9, x + 13, x + 17, x + 9 };
0634: int[] arrowYs = new int[] { y + 6, y + 2, y + 6, y + 6 };
0635: g.fillPolygon(arrowXs, arrowYs, 4);
0636: g.drawPolygon(arrowXs, arrowYs, 4);
0637: g.drawLine(x + 12, y + 6, x + 12, y + 11);
0638: g.drawLine(x + 13, y + 6, x + 13, y + 11);
0639: g.drawLine(x + 14, y + 6, x + 14, y + 11);
0640:
0641: g.setColor(oldColor);
0642: }
0643: }
0644:
0645: private static class FileChooserNewFolderIcon implements Icon,
0646: UIResource {
0647: private static final Color STAR_COLOR = new Color(191, 62, 6);
0648:
0649: public int getIconHeight() {
0650: return 18;
0651: }
0652:
0653: public int getIconWidth() {
0654: return 18;
0655: }
0656:
0657: public void paintIcon(final Component c, final Graphics g,
0658: final int x, final int y) {
0659: Color oldColor = g.getColor();
0660:
0661: int[] folderXs = new int[] { x + 2, x + 9, x + 10, x + 16,
0662: x + 16, x + 2, x + 2 };
0663: int[] folderYs = new int[] { y + 3, y + 3, y + 5, y + 5,
0664: y + 13, y + 13, y + 3 };
0665: g.setColor(Color.YELLOW);
0666: g.fillPolygon(folderXs, folderYs, 7);
0667: g.setColor(Color.GRAY);
0668: g.drawPolygon(folderXs, folderYs, 7);
0669:
0670: int[] cornerXs = new int[] { x + 2, x + 9, x + 10, x + 2,
0671: x + 2 };
0672: int[] cornerYs = new int[] { y + 3, y + 3, y + 5, y + 5,
0673: y + 3 };
0674: g.setColor(Color.LIGHT_GRAY);
0675: g.fillPolygon(cornerXs, cornerYs, 5);
0676: g.setColor(Color.GRAY);
0677: g.drawPolygon(cornerXs, cornerYs, 5);
0678:
0679: g.setColor(STAR_COLOR);
0680: g.drawLine(x, y + 12, x + 6, y + 12);
0681: g.drawLine(x + 3, y + 9, x + 3, y + 15);
0682: g.drawLine(x + 1, y + 10, x + 5, y + 14);
0683: g.drawLine(x + 1, y + 14, x + 5, y + 10);
0684:
0685: g.setColor(oldColor);
0686: }
0687: }
0688:
0689: private static class FileChooserListViewIcon implements Icon,
0690: UIResource {
0691: private static final Color ICON_COLOR = new Color(50, 100, 250);
0692:
0693: public int getIconHeight() {
0694: return 18;
0695: }
0696:
0697: public int getIconWidth() {
0698: return 18;
0699: }
0700:
0701: public void paintIcon(final Component c, final Graphics g,
0702: final int x, final int y) {
0703: Color oldColor = g.getColor();
0704:
0705: drawItem(g, x + 1, y + 4);
0706: drawItem(g, x + 10, y + 4);
0707: drawItem(g, x + 1, y + 10);
0708: drawItem(g, x + 10, y + 10);
0709:
0710: g.setColor(oldColor);
0711: }
0712:
0713: private void drawItem(final Graphics g, final int x, final int y) {
0714: g.setColor(Color.LIGHT_GRAY);
0715: g.fillRect(x, y, 3, 3);
0716: g.setColor(ICON_COLOR);
0717: g.drawRect(x, y, 3, 3);
0718:
0719: g.setColor(Color.BLACK);
0720: g.drawLine(x + 5, y + 1, x + 7, y + 1);
0721: g.setColor(Color.GRAY);
0722: g.drawLine(x + 6, y + 2, x + 8, y + 2);
0723: }
0724: }
0725:
0726: private static class FileChooserHomeFolderIcon implements Icon,
0727: UIResource {
0728: private static final Color ROOF_COLOR = new Color(191, 62, 6);
0729:
0730: public int getIconHeight() {
0731: return 18;
0732: }
0733:
0734: public int getIconWidth() {
0735: return 18;
0736: }
0737:
0738: public void paintIcon(final Component c, final Graphics g,
0739: final int x, final int y) {
0740: Color oldColor = g.getColor();
0741:
0742: int[] roofXs = new int[] { x + 1, x + 9, x + 17, x + 2 };
0743: int[] roofYs = new int[] { y + 9, y + 1, y + 9, y + 9 };
0744: g.setColor(ROOF_COLOR);
0745: g.fillPolygon(roofXs, roofYs, 4);
0746: g.setColor(Color.DARK_GRAY);
0747: g.drawPolygon(roofXs, roofYs, 4);
0748:
0749: g.setColor(Color.YELLOW);
0750: g.fillRect(x + 3, y + 8, 12, 8);
0751: g.setColor(Color.DARK_GRAY);
0752: g.drawRect(x + 3, y + 8, 12, 8);
0753:
0754: g.setColor(Color.DARK_GRAY);
0755: g.fillRect(x + 5, y + 11, 3, 5);
0756:
0757: g.setColor(Color.DARK_GRAY);
0758: g.fillRect(x + 10, y + 11, 3, 3);
0759:
0760: g.setColor(oldColor);
0761: }
0762: }
0763:
0764: private static class FileChooserDetailViewIcon implements Icon,
0765: UIResource {
0766: private static final Color ICON_COLOR = new Color(50, 100, 250);
0767:
0768: public int getIconHeight() {
0769: return 18;
0770: }
0771:
0772: public int getIconWidth() {
0773: return 18;
0774: }
0775:
0776: public void paintIcon(final Component c, final Graphics g,
0777: final int x, final int y) {
0778: Color oldColor = g.getColor();
0779:
0780: drawItem(g, x + 1, y + 4);
0781: drawItem(g, x + 1, y + 10);
0782:
0783: g.setColor(oldColor);
0784: }
0785:
0786: private void drawItem(final Graphics g, final int x, final int y) {
0787: g.setColor(Color.LIGHT_GRAY);
0788: g.fillRect(x, y, 3, 3);
0789: g.setColor(ICON_COLOR);
0790: g.drawRect(x, y, 3, 3);
0791:
0792: g.setColor(Color.BLACK);
0793: g.drawLine(x + 5, y + 1, x + 7, y + 1);
0794: g.drawLine(x + 9, y + 1, x + 11, y + 1);
0795: g.drawLine(x + 13, y + 1, x + 15, y + 1);
0796: g.setColor(Color.GRAY);
0797: g.drawLine(x + 6, y + 2, x + 8, y + 2);
0798: g.drawLine(x + 10, y + 2, x + 12, y + 2);
0799: g.drawLine(x + 14, y + 2, x + 16, y + 2);
0800: }
0801: }
0802:
0803: private static class RadioButtonIcon implements Icon, UIResource {
0804: private static final int SIZE = 13;
0805:
0806: public void paintIcon(final Component c, final Graphics g,
0807: final int x, final int y) {
0808: Color selectionColor = c.isEnabled() ? c.getForeground()
0809: : MetalLookAndFeel.getControlDisabled();
0810: drawRadioButtonIcon(g, (AbstractButton) c, selectionColor,
0811: MetalLookAndFeel.getControlDisabled(), c
0812: .getBackground(), x, y, SIZE, SIZE);
0813: }
0814:
0815: public int getIconWidth() {
0816: return SIZE;
0817: }
0818:
0819: public int getIconHeight() {
0820: return SIZE;
0821: }
0822: }
0823:
0824: private static class RadioButtonMenuItemIcon implements Icon,
0825: UIResource {
0826: private static final int SIZE = 10;
0827:
0828: public void paintIcon(final Component c, final Graphics g,
0829: final int x, final int y) {
0830:
0831: AbstractButton ab = (AbstractButton) c;
0832: Color selectionColor = c.isEnabled() ? ab.isSelected() ? MetalLookAndFeel
0833: .getMenuSelectedForeground()
0834: : c.getForeground()
0835: : MetalLookAndFeel.getMenuDisabledForeground();
0836: Color backgroundColor = ab.getModel().isArmed() ? MetalLookAndFeel
0837: .getMenuSelectedBackground()
0838: : c.getBackground();
0839:
0840: drawRadioButtonIcon(g, ab, selectionColor, MetalLookAndFeel
0841: .getMenuDisabledForeground(), backgroundColor, x,
0842: y, SIZE, SIZE);
0843: }
0844:
0845: public int getIconWidth() {
0846: return SIZE;
0847: }
0848:
0849: public int getIconHeight() {
0850: return SIZE;
0851: }
0852: }
0853:
0854: private static class CheckBoxIcon implements Icon, UIResource {
0855: private static final int SIZE = 13;
0856:
0857: public void paintIcon(final Component c, final Graphics g,
0858: final int x, final int y) {
0859: Color selectionColor = c.isEnabled() ? c.getForeground()
0860: : MetalLookAndFeel.getControlDisabled();
0861: drawCheckBoxIcon(g, (AbstractButton) c, selectionColor,
0862: MetalLookAndFeel.getControlDisabled(), x, y, SIZE,
0863: SIZE);
0864: }
0865:
0866: public int getIconWidth() {
0867: return SIZE;
0868: }
0869:
0870: public int getIconHeight() {
0871: return SIZE;
0872: }
0873: }
0874:
0875: private static class CheckBoxMenuItemIcon implements Icon,
0876: UIResource {
0877: private static final int SIZE = 10;
0878:
0879: public void paintIcon(final Component c, final Graphics g,
0880: final int x, final int y) {
0881: Color selectionColor = c.isEnabled() ? ((AbstractButton) c)
0882: .isSelected() ? MetalLookAndFeel
0883: .getMenuSelectedForeground() : c.getForeground()
0884: : MetalLookAndFeel.getMenuDisabledForeground();
0885: drawCheckBoxIcon(g, (AbstractButton) c, selectionColor,
0886: MetalLookAndFeel.getMenuDisabledForeground(), x, y,
0887: SIZE, SIZE);
0888: }
0889:
0890: public int getIconWidth() {
0891: return SIZE;
0892: }
0893:
0894: public int getIconHeight() {
0895: return SIZE;
0896: }
0897: }
0898:
0899: private static class MenuArrowIcon implements Icon, UIResource {
0900: public void paintIcon(final Component c, final Graphics g,
0901: final int x, final int y) {
0902: final boolean leftToRight = c.getComponentOrientation()
0903: .isLeftToRight();
0904: final int direction = leftToRight ? SwingConstants.EAST
0905: : SwingConstants.WEST;
0906: final Color color = c.isEnabled() ? c.getForeground() : c
0907: .getBackground().darker();
0908: Utilities.fillArrow(g, x, y + 1, direction, 8, true, color);
0909: }
0910:
0911: public int getIconWidth() {
0912: return 4;
0913: }
0914:
0915: public int getIconHeight() {
0916: return 8;
0917: }
0918: }
0919:
0920: private static class MenuItemArrowIcon implements Icon, UIResource {
0921: public void paintIcon(final Component c, final Graphics g,
0922: final int x, final int y) {
0923: }
0924:
0925: public int getIconWidth() {
0926: return 4;
0927: }
0928:
0929: public int getIconHeight() {
0930: return 8;
0931: }
0932: }
0933:
0934: public static final boolean DARK = false;
0935: public static final boolean LIGHT = true;
0936:
0937: private static Icon treeHardDriveIcon;
0938: private static Icon treeFloppyDriveIcon;
0939: private static Icon treeComputerIcon;
0940: private static Icon radioButtonMenuItemIcon;
0941: private static Icon radioButtonIcon;
0942: private static Icon menuItemArrowIcon;
0943: private static Icon menuArrowIcon;
0944: private static Icon internalFrameDefaultMenuIcon;
0945: private static Icon fileChooserUpFolderIcon;
0946: private static Icon fileChooserNewFolderIcon;
0947: private static Icon fileChooserListViewIcon;
0948: private static Icon fileChooserHomeFolderIcon;
0949: private static Icon fileChooserDetailViewIcon;
0950: private static Icon checkBoxMenuItemIcon;
0951: private static Icon checkBoxIcon;
0952: private static Icon verticalSliderThumbIcon;
0953: private static Icon horizontalSliderThumbIcon;
0954:
0955: public static Icon getTreeControlIcon(final boolean isLight) {
0956: return new TreeControlIcon(isLight);
0957: }
0958:
0959: public static Icon getInternalFrameMinimizeIcon(final int size) {
0960: return new InternalFrameMinimizeIcon(size);
0961: }
0962:
0963: public static Icon getInternalFrameMaximizeIcon(final int size) {
0964: return new InternalFrameMaximizeIcon(size);
0965: }
0966:
0967: public static Icon getInternalFrameCloseIcon(final int size) {
0968: return new InternalFrameCloseIcon(size);
0969: }
0970:
0971: public static Icon getInternalFrameAltMaximizeIcon(final int size) {
0972: return new InternalFrameAltMaximizeIcon(size);
0973: }
0974:
0975: public static Icon getVerticalSliderThumbIcon() {
0976: if (verticalSliderThumbIcon == null) {
0977: verticalSliderThumbIcon = new VerticalSliderThumbIcon();
0978: }
0979: return verticalSliderThumbIcon;
0980: }
0981:
0982: public static Icon getTreeLeafIcon() {
0983: return new TreeLeafIcon();
0984: }
0985:
0986: public static Icon getTreeHardDriveIcon() {
0987: if (treeHardDriveIcon == null) {
0988: treeHardDriveIcon = new TreeHardDriveIcon();
0989: }
0990: return treeHardDriveIcon;
0991: }
0992:
0993: public static Icon getTreeFolderIcon() {
0994: return new TreeFolderIcon();
0995: }
0996:
0997: public static Icon getTreeFloppyDriveIcon() {
0998: if (treeFloppyDriveIcon == null) {
0999: treeFloppyDriveIcon = new TreeFloppyDriveIcon();
1000: }
1001: return treeFloppyDriveIcon;
1002: }
1003:
1004: public static Icon getTreeComputerIcon() {
1005: if (treeComputerIcon == null) {
1006: treeComputerIcon = new TreeComputerIcon();
1007: }
1008: return treeComputerIcon;
1009: }
1010:
1011: public static Icon getRadioButtonMenuItemIcon() {
1012: if (radioButtonMenuItemIcon == null) {
1013: radioButtonMenuItemIcon = new RadioButtonMenuItemIcon();
1014: }
1015: return radioButtonMenuItemIcon;
1016: }
1017:
1018: public static Icon getRadioButtonIcon() {
1019: if (radioButtonIcon == null) {
1020: radioButtonIcon = new RadioButtonIcon();
1021: }
1022: return radioButtonIcon;
1023: }
1024:
1025: public static Icon getMenuItemCheckIcon() {
1026: return null;
1027: }
1028:
1029: public static Icon getMenuItemArrowIcon() {
1030: if (menuItemArrowIcon == null) {
1031: menuItemArrowIcon = new MenuItemArrowIcon();
1032: }
1033: return menuItemArrowIcon;
1034: }
1035:
1036: public static Icon getMenuArrowIcon() {
1037: if (menuArrowIcon == null) {
1038: menuArrowIcon = new MenuArrowIcon();
1039: }
1040: return menuArrowIcon;
1041: }
1042:
1043: public static Icon getInternalFrameDefaultMenuIcon() {
1044: if (internalFrameDefaultMenuIcon == null) {
1045: internalFrameDefaultMenuIcon = new InternalFrameDefaultMenuIcon();
1046: }
1047: return internalFrameDefaultMenuIcon;
1048: }
1049:
1050: public static Icon getHorizontalSliderThumbIcon() {
1051: if (horizontalSliderThumbIcon == null) {
1052: horizontalSliderThumbIcon = new HorizontalSliderThumbIcon();
1053: }
1054: return horizontalSliderThumbIcon;
1055: }
1056:
1057: public static Icon getFileChooserUpFolderIcon() {
1058: if (fileChooserUpFolderIcon == null) {
1059: fileChooserUpFolderIcon = new FileChooserUpFolderIcon();
1060: }
1061: return fileChooserUpFolderIcon;
1062: }
1063:
1064: public static Icon getFileChooserNewFolderIcon() {
1065: if (fileChooserNewFolderIcon == null) {
1066: fileChooserNewFolderIcon = new FileChooserNewFolderIcon();
1067: }
1068: return fileChooserNewFolderIcon;
1069: }
1070:
1071: public static Icon getFileChooserListViewIcon() {
1072: if (fileChooserListViewIcon == null) {
1073: fileChooserListViewIcon = new FileChooserListViewIcon();
1074: }
1075: return fileChooserListViewIcon;
1076: }
1077:
1078: public static Icon getFileChooserHomeFolderIcon() {
1079: if (fileChooserHomeFolderIcon == null) {
1080: fileChooserHomeFolderIcon = new FileChooserHomeFolderIcon();
1081: }
1082: return fileChooserHomeFolderIcon;
1083: }
1084:
1085: public static Icon getFileChooserDetailViewIcon() {
1086: if (fileChooserDetailViewIcon == null) {
1087: fileChooserDetailViewIcon = new FileChooserDetailViewIcon();
1088: }
1089: return fileChooserDetailViewIcon;
1090: }
1091:
1092: public static Icon getCheckBoxMenuItemIcon() {
1093: if (checkBoxMenuItemIcon == null) {
1094: checkBoxMenuItemIcon = new CheckBoxMenuItemIcon();
1095: }
1096: return checkBoxMenuItemIcon;
1097: }
1098:
1099: public static Icon getCheckBoxIcon() {
1100: if (checkBoxIcon == null) {
1101: checkBoxIcon = new CheckBoxIcon();
1102: }
1103: return checkBoxIcon;
1104: }
1105:
1106: private static void drawRadioButtonIcon(final Graphics g,
1107: final AbstractButton rb, final Color selectionColor,
1108: final Color disableColor, final Color backgroundColor,
1109: final int x, final int y, final int w, final int h) {
1110:
1111: Color oldColor = g.getColor();
1112:
1113: if (rb.isEnabled()) {
1114: if (rb.getModel().isArmed()) {
1115: g.setColor(MetalLookAndFeel.getControlShadow());
1116: g.fillRoundRect(x, y + 1, w - 1, h - 1, w - 1, h - 1);
1117: }
1118: g.setColor(MetalLookAndFeel.getControlHighlight());
1119: g.drawRoundRect(x + 1, y + 2, w - 2, h - 2, w - 2, h - 2);
1120: g.setColor(MetalLookAndFeel.getControlDarkShadow());
1121: g.drawRoundRect(x, y + 1, w - 2, h - 2, w - 2, h - 2);
1122: } else {
1123: g.setColor(disableColor);
1124: g.drawRoundRect(x, y + 1, w - 2, h - 2, w - 2, h - 2);
1125: }
1126:
1127: if (rb.isSelected()) {
1128: g.setColor(rb.isEnabled() ? selectionColor : disableColor);
1129: g.fillRoundRect(x + w / 4, y + w / 4 + 1, w / 2, h / 2,
1130: w / 4, h / 4);
1131: }
1132:
1133: g.setColor(oldColor);
1134: }
1135:
1136: private static void drawCheckBoxIcon(final Graphics g,
1137: final AbstractButton cb, final Color selectionColor,
1138: final Color disableColor, final int x, final int y,
1139: final int w, final int h) {
1140:
1141: Color oldColor = g.getColor();
1142:
1143: if (cb.isEnabled()) {
1144: g.setColor(MetalLookAndFeel.getControlHighlight());
1145: g.drawRect(x + 1, y + 2, w - 2, h - 2);
1146: }
1147:
1148: if (cb.getModel().isArmed()) {
1149: g.setColor(MetalLookAndFeel.getControlShadow());
1150: g.fillRect(x, y + 1, w - 2, h - 2);
1151: }
1152:
1153: g.setColor(cb.isEnabled() ? MetalLookAndFeel
1154: .getControlDarkShadow() : disableColor);
1155: g.drawRect(x, y + 1, w - 2, h - 2);
1156:
1157: if (cb.isSelected()) {
1158: g.setColor(cb.isEnabled() ? selectionColor : disableColor);
1159: g.drawLine(x + 3, y + h / 2, x + 3, y + h - 2);
1160: g.drawLine(x + 4, y + h / 2, x + 4, y + h - 2);
1161: int lineLength = h - h / 2 - 2;
1162: g.drawLine(x + 4, y + h - 3, x + 4 + lineLength, y + h - 3
1163: - lineLength);
1164: }
1165:
1166: g.setColor(oldColor);
1167: }
1168: }
|