001: /*
002: JOpenChart Java Charting Library and Toolkit
003: Copyright (C) 2001 Sebastian Müller
004: http://jopenchart.sourceforge.net
005:
006: This library is free software; you can redistribute it and/or
007: modify it under the terms of the GNU Lesser General Public
008: License as published by the Free Software Foundation; either
009: version 2.1 of the License, or (at your option) any later version.
010:
011: This library 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 GNU
014: Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public
017: License along with this library; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019:
020: Diamond2D.java
021: Created on 11. September 2002, 22:01
022: */
023:
024: package de.progra.charting.render.shape;
025:
026: import java.awt.geom.RectangularShape;
027: import java.awt.geom.Rectangle2D;
028: import java.awt.geom.PathIterator;
029: import java.awt.geom.AffineTransform;
030:
031: /**
032: * This class implements a diamond like Shape object.
033: * @author mueller
034: * @version 1.0
035: */
036: public class Diamond2D extends RectangularShape {
037:
038: protected double x, y, width, height;
039:
040: /** Creates a Diamond shape with the specified coordinates. */
041: public Diamond2D(double x, double y, double width, double height) {
042: this .x = x;
043: this .y = y;
044: this .width = width;
045: this .height = height;
046: }
047:
048: /** Returns the height. */
049: public double getHeight() {
050: return height;
051: }
052:
053: /** Returns the width. */
054: public double getWidth() {
055: return width;
056: }
057:
058: /** Returns the x-coordinate. */
059: public double getX() {
060: return x;
061: }
062:
063: /** Returns the y-coordinate. */
064: public double getY() {
065: return y;
066: }
067:
068: /** Returns true if the bounding box is empty. */
069: public boolean isEmpty() {
070: return (width <= 0.0) || (height <= 0.0);
071: }
072:
073: /** Sets the framing rectangle. */
074: public void setFrame(double x, double y, double width, double height) {
075: this .x = x;
076: this .y = y;
077: this .width = width;
078: this .height = height;
079: }
080:
081: public Rectangle2D getBounds2D() {
082: return new Rectangle2D.Double(x, y, height, width);
083: }
084:
085: /** Returns the object's PathIterator. */
086: public PathIterator getPathIterator(AffineTransform at) {
087: return new PathIterator() {
088: int state = 0;
089: int maxstate = 4;
090: float[][] fcurrentSegment = {
091: { (float) (x + width / 2), (float) y, 0f, 0f, 0f,
092: 0f },
093: { (float) x, (float) (y + height / 2), 0f, 0f, 0f,
094: 0f },
095: { (float) (x + width / 2), (float) (y + height),
096: 0f, 0f, 0f, 0f },
097: { (float) (x + width), (float) (y + height / 2),
098: 0f, 0f, 0f, 0f },
099: { 0f, 0f, 0f, 0f, 0f, 0f } };
100:
101: double[][] dcurrentSegment = {
102: { x + width / 2, y, 0.0, 0.0, 0.0, 0.0 },
103: { x, y + height / 2, 0.0, 0.0, 0.0, 0.0 },
104: { x + width / 2, y + height, 0.0, 0.0, 0.0, 0.0 },
105: { x + width, y + height / 2, 0.0, 0.0, 0.0, 0.0 },
106: { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
107:
108: int[] segment = { PathIterator.SEG_MOVETO,
109: PathIterator.SEG_LINETO, PathIterator.SEG_LINETO,
110: PathIterator.SEG_LINETO, PathIterator.SEG_CLOSE };
111:
112: public int currentSegment(double[] coords) {
113: coords[0] = dcurrentSegment[state][0];
114: coords[1] = dcurrentSegment[state][1];
115: return segment[state];
116: }
117:
118: public int currentSegment(float[] coords) {
119: coords[0] = fcurrentSegment[state][0];
120: coords[1] = fcurrentSegment[state][1];
121: return segment[state];
122: }
123:
124: public int getWindingRule() {
125: return PathIterator.WIND_NON_ZERO;
126: }
127:
128: public boolean isDone() {
129: return (state == maxstate);
130: }
131:
132: public void next() {
133: state++;
134: }
135: };
136: }
137:
138: public boolean contains(double x, double y, double w, double h) {
139: return false;
140: }
141:
142: public boolean contains(double x, double y) {
143: return false;
144: }
145:
146: public boolean intersects(double x, double y, double w, double h) {
147: return false;
148: }
149:
150: }
|