001: /*
002: * Copyright (C) 2004 Giuseppe MANNA
003: *
004: * This file is part of FreeReportBuilder
005: *
006: * FreeReportBuilder is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package it.frb.tree.drag;
023:
024: import java.awt.RenderingHints;
025: import java.awt.SystemColor;
026: import java.awt.geom.Line2D.Float;
027:
028: /**
029: * A BufferedImage of one of four types of arrow (up, down, left or right)
030: * drawn to the size specified on the constructor.
031: */
032: public class CArrowImage extends java.awt.image.BufferedImage {
033: // Constants...
034: public static final int ARROW_UP = 0;
035: public static final int ARROW_DOWN = 1;
036: public static final int ARROW_LEFT = 2;
037: public static final int ARROW_RIGHT = 3;
038:
039: // Member variables...
040: private java.awt.geom.GeneralPath _pathArrow = new java.awt.geom.GeneralPath();
041:
042: // Constructor...
043: public CArrowImage(int nArrowDirection) {
044: this (15, 9, nArrowDirection);
045: }
046:
047: public CArrowImage(int nWidth, int nHeight, int nArrowDirection) {
048: super (nWidth, nHeight, TYPE_INT_ARGB_PRE); // Set the width, height and image type
049:
050: java.util.Map map = new java.util.HashMap();
051: map.put(RenderingHints.KEY_ANTIALIASING,
052: RenderingHints.VALUE_ANTIALIAS_ON);
053: map.put(RenderingHints.KEY_RENDERING,
054: RenderingHints.VALUE_RENDER_QUALITY);
055: RenderingHints hints = new RenderingHints(map);
056:
057: java.awt.Graphics2D g2 = this .createGraphics(); // Create a graphics context for this buffered image
058: g2.setRenderingHints(hints);
059:
060: float h = getHeight();
061: float w = getWidth();
062: float w13 = w / 3;
063: float w12 = w / 2;
064: float w23 = w * 2 / 3;
065: float h13 = h / 3;
066: float h12 = h / 2;
067: float h23 = h * 2 / 3;
068:
069: switch (nArrowDirection) {
070: case ARROW_UP:
071: _pathArrow.moveTo(w12, h12);
072: _pathArrow.lineTo(w12, 0);
073: _pathArrow.lineTo(w, h - 1);
074: _pathArrow.lineTo(0, h - 1);
075: _pathArrow.closePath();
076: g2.setPaint(new java.awt.GradientPaint(w13, h13,
077: SystemColor.controlLtHighlight, w, h - 1,
078: SystemColor.controlShadow));
079:
080: g2.fill(_pathArrow);
081:
082: g2.setColor(SystemColor.controlDkShadow);
083: g2.draw(new Float(0, h - 1, w, h - 1));
084: g2.setColor(SystemColor.controlShadow);
085: g2.draw(new Float(w12, 0, w, h - 1));
086: g2.setColor(SystemColor.controlLtHighlight);
087: g2.draw(new Float(0, h - 1, w12, 0));
088: break;
089:
090: case ARROW_DOWN:
091: _pathArrow.moveTo(w12, h12);
092: _pathArrow.lineTo(w, 0);
093: _pathArrow.lineTo(w12, h - 1);
094: _pathArrow.closePath();
095: g2.setPaint(new java.awt.GradientPaint(0, 0,
096: SystemColor.controlLtHighlight, w23, h23,
097: SystemColor.controlShadow));
098: g2.fill(_pathArrow);
099:
100: g2.setColor(SystemColor.controlDkShadow);
101: g2.draw(new Float(w, 0, w12, h - 1));
102: g2.setColor(SystemColor.controlShadow);
103: g2.draw(new Float(w12, h - 1, 0, 0));
104: g2.setColor(SystemColor.controlLtHighlight);
105: g2.draw(new Float(0, 0, w, 0));
106: break;
107:
108: case ARROW_LEFT:
109: _pathArrow.moveTo(w - 1, h13);
110: _pathArrow.lineTo(w13, h13);
111: _pathArrow.lineTo(w13, 0);
112: _pathArrow.lineTo(0, h12);
113: _pathArrow.lineTo(w13, h - 1);
114: _pathArrow.lineTo(w13, h23);
115: _pathArrow.lineTo(w - 1, h23);
116: _pathArrow.closePath();
117: g2.setPaint(new java.awt.GradientPaint(0, 0,
118: java.awt.Color.white, //SystemColor.controlLtHighlight,
119: 0, h, SystemColor.controlShadow));
120: g2.fill(_pathArrow);
121:
122: _pathArrow.reset();
123: _pathArrow.moveTo(w13, 0);
124: _pathArrow.lineTo(w13, h13);
125: _pathArrow.moveTo(w - 1, h13);
126: _pathArrow.lineTo(w - 1, h23);
127: _pathArrow.lineTo(w13, h23);
128: _pathArrow.lineTo(w13, h - 1);
129: g2.setColor(SystemColor.controlDkShadow);
130: g2.draw(_pathArrow);
131:
132: g2.setColor(SystemColor.controlShadow);
133: g2.draw(new Float(0, h12, w13, h - 1));
134:
135: _pathArrow.reset();
136: _pathArrow.moveTo(0, h12);
137: _pathArrow.lineTo(w13, 0);
138: _pathArrow.moveTo(w13, h13);
139: _pathArrow.lineTo(w - 1, h13);
140: g2.setColor(SystemColor.controlLtHighlight);
141: g2.draw(_pathArrow);
142: break;
143:
144: case ARROW_RIGHT:
145: default: {
146: _pathArrow.moveTo(0, h13);
147: _pathArrow.lineTo(w23, h13);
148: _pathArrow.lineTo(w23, 0);
149: _pathArrow.lineTo(w - 1, h12);
150: _pathArrow.lineTo(w23, h - 1);
151: _pathArrow.lineTo(w23, h23);
152: _pathArrow.lineTo(0, h23);
153: _pathArrow.closePath();
154: g2.setPaint(new java.awt.GradientPaint(0, 0,
155: java.awt.Color.white, //SystemColor.controlLtHighlight,
156: 0, h, SystemColor.controlShadow));
157: g2.fill(_pathArrow);
158:
159: _pathArrow.reset();
160: _pathArrow.moveTo(0, h23);
161: _pathArrow.lineTo(w23, h23);
162: _pathArrow.moveTo(w23, h - 1);
163: _pathArrow.lineTo(w - 1, h12);
164: g2.setColor(SystemColor.controlDkShadow);
165: g2.draw(_pathArrow);
166:
167: g2.setColor(SystemColor.controlShadow);
168: g2.draw(new Float(w - 1, h12, w23, 0));
169:
170: _pathArrow.reset();
171: _pathArrow.moveTo(w23, 0);
172: _pathArrow.lineTo(w23, h13);
173: _pathArrow.lineTo(0, h13);
174: _pathArrow.lineTo(0, h23);
175: _pathArrow.moveTo(w23, h23);
176: _pathArrow.lineTo(w23, h - 1);
177: g2.setColor(SystemColor.controlLtHighlight);
178: g2.draw(_pathArrow);
179: break;
180: }
181: }
182: }
183: }
|