001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026: package org.cougaar.glm.execution.eg;
027:
028: import java.awt.RenderingHints;
029: import java.awt.Color;
030: import java.awt.Component;
031: import java.awt.Graphics;
032: import java.awt.Graphics2D;
033: import java.awt.Shape;
034: import java.awt.geom.GeneralPath;
035: import javax.swing.Icon;
036:
037: public class DrawnIcon implements Icon {
038: static RenderingHints antialiasingHint = new RenderingHints(
039: RenderingHints.KEY_ANTIALIASING,
040: RenderingHints.VALUE_ANTIALIAS_ON);
041:
042: private static final Color ENABLED_COLOR = Color.black;
043: private static final Color SHADOW_COLOR = Color.white;
044: private static final Color DISABLED_COLOR = Color.gray;
045:
046: public static Icon getPlayIcon(boolean enabled) {
047: GeneralPath playShape = new GeneralPath(
048: GeneralPath.WIND_EVEN_ODD, 4);
049: playShape.moveTo(1f, 1f);
050: playShape.lineTo(11f, 5f);
051: playShape.lineTo(1f, 9f);
052: playShape.closePath();
053: Color fillColor;
054: GeneralPath shadowShape = null;
055: if (enabled) {
056: fillColor = ENABLED_COLOR;
057: } else {
058: shadowShape = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2);
059: shadowShape.moveTo(12f, 6f);
060: shadowShape.lineTo(2f, 10f);
061: fillColor = DISABLED_COLOR;
062: }
063: return new DrawnIcon(playShape, fillColor, shadowShape,
064: SHADOW_COLOR);
065: }
066:
067: public static Icon getStopIcon(boolean enabled) {
068: GeneralPath stopShape = new GeneralPath(
069: GeneralPath.WIND_EVEN_ODD, 5);
070: stopShape.moveTo(1f, 1f);
071: stopShape.lineTo(9f, 1f);
072: stopShape.lineTo(9f, 9f);
073: stopShape.lineTo(1f, 9f);
074: stopShape.closePath();
075: Color fillColor;
076: GeneralPath shadowShape = null;
077: if (enabled) {
078: fillColor = ENABLED_COLOR;
079: } else {
080: shadowShape = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3);
081: shadowShape.moveTo(2f, 10f);
082: shadowShape.lineTo(10f, 10f);
083: shadowShape.lineTo(10f, 2f);
084: fillColor = DISABLED_COLOR;
085: }
086: return new DrawnIcon(stopShape, fillColor, shadowShape,
087: SHADOW_COLOR);
088: }
089:
090: public static Icon getPauseIcon(boolean enabled) {
091: GeneralPath pauseShape = new GeneralPath(
092: GeneralPath.WIND_EVEN_ODD, 8);
093: pauseShape.moveTo(1f, 1f);
094: pauseShape.lineTo(4f, 1f);
095: pauseShape.lineTo(4f, 9f);
096: pauseShape.lineTo(1f, 9f);
097: pauseShape.closePath();
098: pauseShape.moveTo(7f, 1f);
099: pauseShape.lineTo(10f, 1f);
100: pauseShape.lineTo(10f, 9f);
101: pauseShape.lineTo(7f, 9f);
102: pauseShape.closePath();
103: Color fillColor;
104: GeneralPath shadowShape = null;
105: if (enabled) {
106: fillColor = ENABLED_COLOR;
107: } else {
108: shadowShape = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 6);
109: shadowShape.moveTo(5f, 2f);
110: shadowShape.lineTo(5f, 10f);
111: shadowShape.lineTo(2f, 10f);
112: shadowShape.moveTo(11f, 2f);
113: shadowShape.lineTo(11f, 10f);
114: shadowShape.lineTo(8f, 10f);
115: fillColor = DISABLED_COLOR;
116: }
117: return new DrawnIcon(pauseShape, fillColor, shadowShape,
118: SHADOW_COLOR);
119: }
120:
121: private Shape fillShape, shadowShape;
122: private Color fillColor, shadowColor;
123:
124: public DrawnIcon(Shape fillShape, Color fillColor,
125: Shape shadowShape, Color shadowColor) {
126: this .fillShape = fillShape;
127: this .fillColor = fillColor;
128: this .shadowShape = shadowShape;
129: this .shadowColor = shadowColor;
130: }
131:
132: public int getIconHeight() {
133: return 12;
134: }
135:
136: public int getIconWidth() {
137: return 12;
138: }
139:
140: public void paintIcon(Component c, Graphics g, int x, int y) {
141: Graphics2D g2d = ((Graphics2D) g);
142: Color base = g.getColor();
143: g2d.translate(x, y);
144: g2d.addRenderingHints(antialiasingHint);
145: if (shadowShape != null) {
146: g2d.setColor(shadowColor);
147: g2d.draw(shadowShape);
148: }
149: g2d.setColor(fillColor);
150: g2d.fill(fillShape);
151: g2d.translate(-x, -y);
152: g.setColor(base);
153: }
154: }
|