KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > progra > charting > render > shape > Diamond2D


1 /*
2     JOpenChart Java Charting Library and Toolkit
3     Copyright (C) 2001 Sebastian Müller
4     http://jopenchart.sourceforge.net
5
6     This library is free software; you can redistribute it and/or
7     modify it under the terms of the GNU Lesser General Public
8     License as published by the Free Software Foundation; either
9     version 2.1 of the License, or (at your option) any later version.
10
11     This library is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14     Lesser General Public License for more details.
15
16     You should have received a copy of the GNU Lesser General Public
17     License along with this library; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20     Diamond2D.java
21     Created on 11. September 2002, 22:01
22 */

23
24 package de.progra.charting.render.shape;
25
26 import java.awt.geom.RectangularShape JavaDoc;
27 import java.awt.geom.Rectangle2D JavaDoc;
28 import java.awt.geom.PathIterator JavaDoc;
29 import java.awt.geom.AffineTransform JavaDoc;
30
31 /**
32  * This class implements a diamond like Shape object.
33  * @author mueller
34  * @version 1.0
35  */

36 public class Diamond2D extends RectangularShape JavaDoc {
37
38     protected double x, y, width, height;
39
40     /** Creates a Diamond shape with the specified coordinates. */
41     public Diamond2D(double x, double y, double width, double height) {
42         this.x = x;
43         this.y = y;
44         this.width = width;
45         this.height = height;
46     }
47     
48     /** Returns the height. */
49     public double getHeight() {
50         return height;
51     }
52     
53     /** Returns the width. */
54     public double getWidth() {
55         return width;
56     }
57     
58     /** Returns the x-coordinate. */
59     public double getX() {
60         return x;
61     }
62     
63     /** Returns the y-coordinate. */
64     public double getY() {
65         return y;
66     }
67     
68     /** Returns true if the bounding box is empty. */
69     public boolean isEmpty() {
70         return (width <= 0.0) || (height <= 0.0);
71     }
72     
73     /** Sets the framing rectangle. */
74     public void setFrame(double x, double y, double width, double height) {
75         this.x = x;
76         this.y = y;
77         this.width = width;
78         this.height = height;
79     }
80     
81     public Rectangle2D JavaDoc getBounds2D() {
82         return new Rectangle2D.Double JavaDoc(x, y, height, width);
83     }
84     
85     /** Returns the object's PathIterator. */
86     public PathIterator JavaDoc getPathIterator(AffineTransform JavaDoc at) {
87         return new PathIterator JavaDoc() {
88             int state = 0;
89             int maxstate = 4;
90             float[][] fcurrentSegment = { {(float)(x + width/2), (float)y, 0f, 0f, 0f, 0f},
91                                           {(float)x, (float)(y + height/2), 0f, 0f, 0f, 0f},
92                                           {(float)(x + width/2), (float)(y + height), 0f, 0f, 0f, 0f},
93                                           {(float)(x + width), (float)(y + height/2), 0f, 0f, 0f, 0f},
94                                           {0f, 0f, 0f, 0f, 0f, 0f} };
95                                           
96             
97             double[][] dcurrentSegment = {{x + width/2, y, 0.0, 0.0, 0.0, 0.0},
98                                           {x, y + height/2, 0.0, 0.0, 0.0, 0.0},
99                                           {x + width/2, y + height, 0.0, 0.0, 0.0, 0.0},
100                                           {x + width, y + height/2, 0.0, 0.0, 0.0, 0.0},
101                                           {0.0, 0.0, 0.0, 0.0, 0.0, 0.0} };
102
103             int[] segment = { PathIterator.SEG_MOVETO, PathIterator.SEG_LINETO, PathIterator.SEG_LINETO, PathIterator.SEG_LINETO, PathIterator.SEG_CLOSE};
104             
105             public int currentSegment(double[] coords) {
106                 coords[0] = dcurrentSegment[state][0];
107                 coords[1] = dcurrentSegment[state][1];
108                 return segment[state];
109             }
110             
111             public int currentSegment(float[] coords){
112                 coords[0] = fcurrentSegment[state][0];
113                 coords[1] = fcurrentSegment[state][1];
114                 return segment[state];
115             }
116             
117             public int getWindingRule() { return PathIterator.WIND_NON_ZERO; }
118             public boolean isDone() { return (state == maxstate); }
119             public void next() { state++ ; }
120         };
121     }
122     
123     public boolean contains(double x, double y, double w, double h) {
124         return false;
125     }
126     
127     public boolean contains(double x, double y) {
128         return false;
129     }
130     
131     public boolean intersects(double x, double y, double w, double h) {
132         return false;
133     }
134     
135 }
136
Popular Tags