001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.mail.gui.tree.util;
017:
018: /**
019: * @version 1.0
020: * @author
021: */
022: import java.awt.Color;
023: import java.awt.GradientPaint;
024: import java.awt.Graphics2D;
025: import java.awt.RenderingHints;
026: import java.awt.SystemColor;
027: import java.awt.geom.GeneralPath;
028: import java.awt.geom.Line2D;
029: import java.awt.image.BufferedImage;
030: import java.util.HashMap;
031: import java.util.Map;
032:
033: /**
034: * A BufferedImage of one of four types of arrow (up, down, left or right)
035: * drawn to the size specified on the constructor.
036: */
037: public class CArrowImage extends BufferedImage {
038: // Constants...
039: public static final int ARROW_UP = 0;
040: public static final int ARROW_DOWN = 1;
041: public static final int ARROW_LEFT = 2;
042: public static final int ARROW_RIGHT = 3;
043:
044: // Member variables...
045: private GeneralPath _pathArrow = new GeneralPath();
046:
047: // Constructor...
048: public CArrowImage(int nArrowDirection) {
049: this (15, 9, nArrowDirection);
050: }
051:
052: public CArrowImage(int nWidth, int nHeight, int nArrowDirection) {
053: super (nWidth, nHeight, TYPE_INT_ARGB_PRE);
054:
055: // Set the width, height and image type
056: Map map = new HashMap();
057: map.put(RenderingHints.KEY_ANTIALIASING,
058: RenderingHints.VALUE_ANTIALIAS_ON);
059: map.put(RenderingHints.KEY_RENDERING,
060: RenderingHints.VALUE_RENDER_QUALITY);
061:
062: RenderingHints hints = new RenderingHints(map);
063:
064: Graphics2D g2 = this .createGraphics();
065:
066: // Create a graphics context for this buffered image
067: g2.setRenderingHints(hints);
068:
069: float h = getHeight();
070: float w = getWidth();
071: float w13 = w / 3;
072: float w12 = w / 2;
073: float w23 = (w * 2) / 3;
074: float h13 = h / 3;
075: float h12 = h / 2;
076: float h23 = (h * 2) / 3;
077:
078: switch (nArrowDirection) {
079: case ARROW_UP:
080: _pathArrow.moveTo(w12, h12);
081: _pathArrow.lineTo(w12, 0);
082: _pathArrow.lineTo(w, h - 1);
083: _pathArrow.lineTo(0, h - 1);
084: _pathArrow.closePath();
085: g2.setPaint(new GradientPaint(w13, h13,
086: SystemColor.controlLtHighlight, w, h - 1,
087: SystemColor.controlShadow));
088:
089: g2.fill(_pathArrow);
090:
091: g2.setColor(SystemColor.controlDkShadow);
092: g2.draw(new Line2D.Float(0, h - 1, w, h - 1));
093: g2.setColor(SystemColor.controlShadow);
094: g2.draw(new Line2D.Float(w12, 0, w, h - 1));
095: g2.setColor(SystemColor.controlLtHighlight);
096: g2.draw(new Line2D.Float(0, h - 1, w12, 0));
097:
098: break;
099:
100: case ARROW_DOWN:
101: _pathArrow.moveTo(w12, h12);
102: _pathArrow.lineTo(w, 0);
103: _pathArrow.lineTo(w12, h - 1);
104: _pathArrow.closePath();
105: g2.setPaint(new GradientPaint(0, 0,
106: SystemColor.controlLtHighlight, w23, h23,
107: SystemColor.controlShadow));
108: g2.fill(_pathArrow);
109:
110: g2.setColor(SystemColor.controlDkShadow);
111: g2.draw(new Line2D.Float(w, 0, w12, h - 1));
112: g2.setColor(SystemColor.controlShadow);
113: g2.draw(new Line2D.Float(w12, h - 1, 0, 0));
114: g2.setColor(SystemColor.controlLtHighlight);
115: g2.draw(new Line2D.Float(0, 0, w, 0));
116:
117: break;
118:
119: case ARROW_LEFT:
120: _pathArrow.moveTo(w - 1, h13);
121: _pathArrow.lineTo(w13, h13);
122: _pathArrow.lineTo(w13, 0);
123: _pathArrow.lineTo(0, h12);
124: _pathArrow.lineTo(w13, h - 1);
125: _pathArrow.lineTo(w13, h23);
126: _pathArrow.lineTo(w - 1, h23);
127: _pathArrow.closePath();
128: g2.setPaint(new GradientPaint(0, 0, Color.white,
129: //SystemColor.controlLtHighlight,
130: 0, h, SystemColor.controlShadow));
131: g2.fill(_pathArrow);
132:
133: _pathArrow.reset();
134: _pathArrow.moveTo(w13, 0);
135: _pathArrow.lineTo(w13, h13);
136: _pathArrow.moveTo(w - 1, h13);
137: _pathArrow.lineTo(w - 1, h23);
138: _pathArrow.lineTo(w13, h23);
139: _pathArrow.lineTo(w13, h - 1);
140: g2.setColor(SystemColor.controlDkShadow);
141: g2.draw(_pathArrow);
142:
143: g2.setColor(SystemColor.controlShadow);
144: g2.draw(new Line2D.Float(0, h12, w13, h - 1));
145:
146: _pathArrow.reset();
147: _pathArrow.moveTo(0, h12);
148: _pathArrow.lineTo(w13, 0);
149: _pathArrow.moveTo(w13, h13);
150: _pathArrow.lineTo(w - 1, h13);
151: g2.setColor(SystemColor.controlLtHighlight);
152: g2.draw(_pathArrow);
153:
154: break;
155:
156: case ARROW_RIGHT:
157: default: {
158: _pathArrow.moveTo(0, h13);
159: _pathArrow.lineTo(w23, h13);
160: _pathArrow.lineTo(w23, 0);
161: _pathArrow.lineTo(w - 1, h12);
162: _pathArrow.lineTo(w23, h - 1);
163: _pathArrow.lineTo(w23, h23);
164: _pathArrow.lineTo(0, h23);
165: _pathArrow.closePath();
166: g2.setPaint(new GradientPaint(0, 0, Color.white,
167: //SystemColor.controlLtHighlight,
168: 0, h, SystemColor.controlShadow));
169: g2.fill(_pathArrow);
170:
171: _pathArrow.reset();
172: _pathArrow.moveTo(0, h23);
173: _pathArrow.lineTo(w23, h23);
174: _pathArrow.moveTo(w23, h - 1);
175: _pathArrow.lineTo(w - 1, h12);
176: g2.setColor(SystemColor.controlDkShadow);
177: g2.draw(_pathArrow);
178:
179: g2.setColor(SystemColor.controlShadow);
180: g2.draw(new Line2D.Float(w - 1, h12, w23, 0));
181:
182: _pathArrow.reset();
183: _pathArrow.moveTo(w23, 0);
184: _pathArrow.lineTo(w23, h13);
185: _pathArrow.lineTo(0, h13);
186: _pathArrow.lineTo(0, h23);
187: _pathArrow.moveTo(w23, h23);
188: _pathArrow.lineTo(w23, h - 1);
189: g2.setColor(SystemColor.controlLtHighlight);
190: g2.draw(_pathArrow);
191:
192: break;
193: }
194: }
195: }
196: }
|