KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > impl > EllipseDrawComponentImpl


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * *
5  * This library is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or (at your option) any later version. *
9  * *
10  * This library is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13  * Lesser General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU Lesser General Public *
16  * License along with this library; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin St, Fifth Floor, *
19  * Boston, MA 02110-1301 USA *
20  * *
21  * Or get it online : *
22  * http://www.gnu.org/copyleft/lesser.html *
23  * *
24  * *
25  ******************************************************************************/

26
27 package org.nightlabs.editor2d.impl;
28
29 import java.awt.Rectangle JavaDoc;
30 import java.awt.geom.AffineTransform JavaDoc;
31 import java.awt.geom.Arc2D JavaDoc;
32 import java.util.Iterator JavaDoc;
33
34 import org.nightlabs.editor2d.DrawComponent;
35 import org.nightlabs.editor2d.DrawComponentContainer;
36 import org.nightlabs.editor2d.EllipseDrawComponent;
37 import org.nightlabs.editor2d.j2d.GeneralShape;
38
39 public class EllipseDrawComponentImpl
40 extends ShapeDrawComponentImpl
41 implements EllipseDrawComponent
42 {
43   protected static final int START_ANGLE_EDEFAULT = 0;
44   protected int startAngle = START_ANGLE_EDEFAULT;
45
46   protected static final int END_ANGLE_EDEFAULT = 360;
47   protected int endAngle = END_ANGLE_EDEFAULT;
48
49   protected static final boolean CONNECT_EDEFAULT = false;
50   protected boolean connect = CONNECT_EDEFAULT;
51
52   public EllipseDrawComponentImpl() {
53         super();
54     }
55
56   public boolean isConnect() {
57         return connect;
58     }
59   public void setConnect(boolean newConnect)
60   {
61         boolean oldConnect = connect;
62         connect = newConnect;
63         generalShape = createEllipse();
64         generalShape.transform(affineTransform);
65         bounds = null;
66         firePropertyChange(PROP_CONNECT, oldConnect, connect);
67     }
68
69   public int getStartAngle() {
70         return startAngle;
71     }
72   public void setStartAngle(int newStartAngle)
73   {
74         int oldStartAngle = startAngle;
75         startAngle = newStartAngle;
76         generalShape = createEllipse();
77         generalShape.transform(affineTransform);
78         bounds = null;
79         firePropertyChange(PROP_START_ANGLE, oldStartAngle, startAngle);
80     }
81
82   public int getEndAngle() {
83         return endAngle;
84     }
85   public void setEndAngle(int newEndAngle) {
86         int oldEndAngle = endAngle;
87         endAngle = newEndAngle;
88         generalShape = createEllipse();
89     generalShape.transform(affineTransform);
90         bounds = null;
91         firePropertyChange(PROP_END_ANGLE, oldEndAngle, endAngle);
92     }
93
94   public String JavaDoc toString()
95   {
96         StringBuffer JavaDoc result = new StringBuffer JavaDoc(super.toString());
97         result.append(" (startAngle: ");
98         result.append(startAngle);
99         result.append(", endAngle: ");
100         result.append(endAngle);
101         result.append(", connect: ");
102         result.append(connect);
103         result.append(')');
104         return result.toString();
105     }
106
107 // public String getTypeName() {
108
// return ModelPlugin.getResourceString("type.ellipse");
109
// }
110
public String JavaDoc getTypeName() {
111     return "Ellipse";
112   }
113   
114   protected GeneralShape createEllipse()
115   {
116     Rectangle JavaDoc originalBounds = originalShape.getBounds();
117     int type = connect ? Arc2D.PIE : Arc2D.OPEN;
118     Arc2D JavaDoc arc = new Arc2D.Double JavaDoc(originalBounds.x, originalBounds.y,
119             originalBounds.width, originalBounds.height, getStartAngle(), getEndAngle()-getStartAngle(), type);
120     
121     GeneralShape originalEllipse = new GeneralShape(arc);
122     return originalEllipse;
123   }
124   
125   public void transform(AffineTransform JavaDoc at, boolean fromParent)
126   {
127     Rectangle JavaDoc oldBounds = getBounds();
128     if (generalShape != null) {
129         super.transform(at, fromParent);
130       generalShape = createEllipse();
131       generalShape.transform(affineTransform);
132     }
133     
134     if (!fromParent && getParent() != null)
135       getParent().notifyChildTransform(this);
136
137     bounds = null;
138   }
139   
140 // public Object clone()
141
// {
142
// EllipseDrawComponentImpl ellipse = (EllipseDrawComponentImpl) super.clone();
143
// return ellipse;
144
// }
145

146   public Object JavaDoc clone(DrawComponentContainer parent)
147   {
148     EllipseDrawComponentImpl ellipse = (EllipseDrawComponentImpl) super.clone(parent);
149     ellipse.connect = connect;
150     ellipse.endAngle = endAngle;
151     ellipse.startAngle = startAngle;
152     return ellipse;
153   }
154     
155 // public DrawComponent clone()
156
// {
157
// EllipseDrawComponent ellipse = new EllipseDrawComponentImpl();
158
// ellipse = (EllipseDrawComponent) assign(ellipse);
159
// return ellipse;
160
// }
161
//
162
// protected DrawComponent assign(DrawComponent dc)
163
// {
164
// super.assign(dc);
165
// if (dc instanceof EllipseDrawComponent) {
166
// EllipseDrawComponent ellipse = (EllipseDrawComponent) dc;
167
// ellipse.setConnect(isConnect());
168
// ellipse.setEndAngle(getEndAngle());
169
// ellipse.setStartAngle(getStartAngle());
170
// }
171
// return dc;
172
// }
173
} //EllipseDrawComponentImpl
174
Popular Tags