KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > edit > ShapeDrawComponentEditPart


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * Project author: Daniel Mazurek <Daniel.Mazurek [at] nightlabs [dot] org> *
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 *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin St, Fifth Floor, *
20  * Boston, MA 02110-1301 USA *
21  * *
22  * Or get it online : *
23  * http://www.gnu.org/copyleft/lesser.html *
24  * *
25  * *
26  ******************************************************************************/

27
28 package org.nightlabs.editor2d.edit;
29
30 import java.beans.PropertyChangeEvent JavaDoc;
31
32 import org.eclipse.gef.DragTracker;
33 import org.eclipse.gef.Request;
34 import org.eclipse.ui.views.properties.IPropertySource;
35
36 import org.nightlabs.editor2d.EditorStateManager;
37 import org.nightlabs.editor2d.ShapeDrawComponent;
38 import org.nightlabs.editor2d.figures.ShapeFigure;
39 import org.nightlabs.editor2d.j2d.GeneralShape;
40 import org.nightlabs.editor2d.model.ShapeDrawComponentPropertySource;
41 import org.nightlabs.editor2d.request.EditorEditShapeRequest;
42 import org.nightlabs.editor2d.tools.ShapeEditTracker;
43
44
45 //public abstract class ShapeDrawComponentEditPart
46
public class ShapeDrawComponentEditPart
47 extends DrawComponentEditPart
48 {
49   /**
50    * @param drawComponent
51    */

52   public ShapeDrawComponentEditPart(ShapeDrawComponent shapeDrawComponent) {
53     super(shapeDrawComponent);
54   }
55
56 // /* (non-Javadoc)
57
// * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
58
// */
59
// protected IFigure createFigure()
60
// {
61
// AbstractShapeFigure shapeFigure = new ShapeFigureImpl();
62
// shapeFigure.setGeneralShape(getShapeDrawComponent().getGeneralShape());
63
// setShapeProperties(getShapeDrawComponent(), shapeFigure);
64
//
65
// if (getRoot() instanceof ScalableRootEditPart) {
66
// ((ScalableRootEditPart) getRoot()).getZoomManager().addZoomListener(shapeFigure.getZoomListener());
67
// }
68
//
69
// return shapeFigure;
70
// }
71

72 // protected Color defaultFillColor = ColorConstants.white;
73
// protected Color defaultLineColor = ColorConstants.black;
74

75 // protected void setShapeProperties(ShapeDrawComponent sdc, ShapeFigure s)
76
// {
77
// // TODO: Color should come from ConfigModule
78
// Color fillColor = J2DUtil.toSWTColor(sdc.getFillColor());
79
// Color lineColor = J2DUtil.toSWTColor(sdc.getLineColor());
80
//
81
// s.setBackgroundColor(fillColor);
82
// s.setForegroundColor(lineColor);
83
// s.setLineWidth(sdc.getLineWidth());
84
// s.setLineStyle(sdc.getLineStyle());
85
// s.setFill(sdc.isFill());
86
// }
87

88 // protected void refreshVisuals()
89
// {
90
// GeneralShape gs = (GeneralShape) getShapeDrawComponent().getGeneralShape().clone();
91
// getShapeFigure().setGeneralShape(gs);
92
//// setShapeProperties(getShapeDrawComponent(), getShapeFigure());
93
// super.refreshVisuals();
94
// }
95

96     protected void propertyChanged(PropertyChangeEvent JavaDoc evt)
97     {
98         super.propertyChanged(evt);
99         String JavaDoc propertyName = evt.getPropertyName();
100         if (propertyName.equals(ShapeDrawComponent.PROP_FILL_COLOR)) {
101             LOGGER.debug(propertyName +" changed!");
102             refreshVisuals();
103         }
104         else if (propertyName.equals(ShapeDrawComponent.PROP_LINE_COLOR)) {
105             LOGGER.debug(propertyName +" changed!");
106             refreshVisuals();
107         }
108         else if (propertyName.equals(ShapeDrawComponent.PROP_FILL)) {
109             LOGGER.debug(propertyName +" changed!");
110             refreshVisuals();
111         }
112         else if (propertyName.equals(ShapeDrawComponent.PROP_LINE_STYLE)) {
113             LOGGER.debug(propertyName +" changed!");
114             refreshVisuals();
115         }
116         else if (propertyName.equals(ShapeDrawComponent.PROP_LINE_WIDTH)) {
117             LOGGER.debug(propertyName +" changed!");
118             refreshVisuals();
119         }
120         else if (propertyName.equals(ShapeDrawComponent.PROP_GENERAL_SHAPE)) {
121             LOGGER.debug(propertyName +" changed!");
122             refreshVisuals();
123         }
124     }
125         
126   public ShapeDrawComponent getShapeDrawComponent() {
127     return (ShapeDrawComponent) getModel();
128   }
129  
130 // public ShapeFigure getShapeFigure() {
131
// return (ShapeFigure) getFigure();
132
// }
133

134   public GeneralShape getGeneralShape()
135   {
136     GeneralShape gs = getShapeDrawComponent().getGeneralShape();
137     if (gs == null) {
138       gs = ((ShapeFigure)getFigure()).getGeneralShape();
139       getShapeDrawComponent().setGeneralShape(gs);
140     }
141     return gs;
142   }
143     
144   /**
145    * Overridden to return a default <code>DragTracker</code> for GraphicalEditParts.
146    * @see org.eclipse.gef.EditPart#getDragTracker(Request)
147    */

148   public DragTracker getDragTracker(Request request)
149   {
150     if (request.getType().equals(REQ_EDIT_SHAPE)) {
151       EditorEditShapeRequest req = (EditorEditShapeRequest) request;
152       return new ShapeEditTracker(this, req.getPathSegmentIndex());
153     }
154           
155     return super.getDragTracker(request);
156   }
157     
158   public void performRequest(Request req)
159   {
160     // TODO: set somehow the EditShapeMode to the corresponding ShapeFigure
161
if (req.getType().equals(REQ_EDIT_SHAPE))
162     {
163       EditorEditShapeRequest request = (EditorEditShapeRequest) req;
164       EditorStateManager.setEditShapeMode(this);
165     }
166     
167     super.performRequest(req);
168   }
169           
170   public boolean understandsRequest(Request req)
171   {
172     if (req.getType().equals(REQ_EDIT_SHAPE))
173       return true;
174     
175     return super.understandsRequest(req);
176   }
177   
178   /* (non-Javadoc)
179    * @see com.ibm.itso.sal330r.gefdemo.edit.WorkflowElementEditPart#getPropertySource()
180    */

181   protected IPropertySource getPropertySource()
182   {
183     if (propertySource == null)
184     {
185       propertySource =
186         new ShapeDrawComponentPropertySource(getShapeDrawComponent());
187     }
188     return propertySource;
189   }
190 }
191
Popular Tags