KickJava   Java API By Example, From Geeks To Geeks.

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


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     Triangle2D.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 triangular shape.
33  * @author smueller
34  */

35 public class Triangle2D extends RectangularShape JavaDoc {
36     
37     protected double x = 0.0;
38     
39     protected double y = 0.0;
40     
41     protected double width = 0.0;
42     
43     protected double height = 0.0;
44     
45     protected boolean upsidedown = false;
46     
47     /** Creates a new instance of Triangle2D */
48     public Triangle2D(double x, double y, double width, double height, boolean upsidedown) {
49         setFrame(x, y, width, height);
50         this.upsidedown = upsidedown;
51     }
52     
53     public boolean contains(double param, double param1) {
54         return false;
55     }
56     
57     public boolean contains(double param, double param1, double param2, double param3) {
58         return false;
59     }
60     
61     public boolean intersects(double x, double y, double w, double h) {
62         return false;
63     }
64     
65     public Rectangle2D JavaDoc getBounds2D() {
66         return new Rectangle2D.Double JavaDoc(x, y, width, height);
67     }
68     
69     public double getHeight() {
70         return height;
71     }
72     
73     public PathIterator JavaDoc getPathIterator(AffineTransform JavaDoc affineTransform) {
74         return new PathIterator JavaDoc() {
75             int state = 0;
76             int maxstate = 3;
77             
78             double[][] dcurrentSegment = {{x + width/2, y},
79                                           {x, y + height},
80                                           {x + width, y + height},
81                                           {0.0, 0.0} };
82
83             
84             double[][] ddowncurrentSegment = {{x, y},
85                                               {x + width/2, y + height},
86                                               {x + width, y},
87                                               {0.0, 0.0} };
88                                           
89             int[] segment = { PathIterator.SEG_MOVETO, PathIterator.SEG_LINETO, PathIterator.SEG_LINETO, PathIterator.SEG_CLOSE};
90             
91             public int currentSegment(double[] coords) {
92                 if(!upsidedown) {
93                     coords[0] = dcurrentSegment[state][0];
94                     coords[1] = dcurrentSegment[state][1];
95                 } else {
96                     coords[0] = ddowncurrentSegment[state][0];
97                     coords[1] = ddowncurrentSegment[state][1];
98                 }
99                 return segment[state];
100             }
101             
102             public int currentSegment(float[] coords){
103                 if(!upsidedown) {
104                     coords[0] = (float)dcurrentSegment[state][0];
105                     coords[1] = (float)dcurrentSegment[state][1];
106                 } else {
107                     coords[0] = (float)ddowncurrentSegment[state][0];
108                     coords[1] = (float)ddowncurrentSegment[state][1];
109                 }
110                 return segment[state];
111             }
112             
113             public int getWindingRule() { return PathIterator.WIND_NON_ZERO; }
114             public boolean isDone() { return (state == maxstate); }
115             public void next() { state++ ; }
116         };
117     }
118     
119     public double getWidth() {
120         return width;
121     }
122     
123     public double getX() {
124         return x;
125     }
126     
127     public double getY() {
128         return y;
129     }
130     
131     public boolean isEmpty() {
132         return (width<= 0.0 || height <= 0.0);
133     }
134     
135     public void setFrame(double x, double y, double width, double height) {
136         this.x = x;
137         this.y = y;
138         this.width = width;
139         this.height = height;
140     }
141 }
142
Popular Tags