KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * <p> Project: com.nightlabs.editor2d </p>
3  * <p> Copyright: Copyright (c) 2004 </p>
4  * <p> Company: NightLabs GmbH (Germany) </p>
5  * <p> Creation Date: 08.12.2004 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

8 package com.nightlabs.editor2d.edit;
9
10 import java.beans.PropertyChangeEvent JavaDoc;
11
12 import org.eclipse.gef.DragTracker;
13 import org.eclipse.gef.Request;
14 import org.eclipse.ui.views.properties.IPropertySource;
15
16 import com.nightlabs.editor2d.EditorStateManager;
17 import com.nightlabs.editor2d.ShapeDrawComponent;
18 import com.nightlabs.editor2d.figures.ShapeFigure;
19 import com.nightlabs.editor2d.j2d.GeneralShape;
20 import com.nightlabs.editor2d.model.ShapeDrawComponentPropertySource;
21 import com.nightlabs.editor2d.request.EditorEditShapeRequest;
22 import com.nightlabs.editor2d.tools.ShapeEditTracker;
23
24
25 //public abstract class ShapeDrawComponentEditPart
26
public class ShapeDrawComponentEditPart
27 extends DrawComponentEditPart
28 {
29   /**
30    * @param drawComponent
31    */

32   public ShapeDrawComponentEditPart(ShapeDrawComponent shapeDrawComponent) {
33     super(shapeDrawComponent);
34   }
35
36 // /* (non-Javadoc)
37
// * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
38
// */
39
// protected IFigure createFigure()
40
// {
41
// AbstractShapeFigure shapeFigure = new ShapeFigureImpl();
42
// shapeFigure.setGeneralShape(getShapeDrawComponent().getGeneralShape());
43
// setShapeProperties(getShapeDrawComponent(), shapeFigure);
44
//
45
// if (getRoot() instanceof ScalableRootEditPart) {
46
// ((ScalableRootEditPart) getRoot()).getZoomManager().addZoomListener(shapeFigure.getZoomListener());
47
// }
48
//
49
// return shapeFigure;
50
// }
51

52 // protected Color defaultFillColor = ColorConstants.white;
53
// protected Color defaultLineColor = ColorConstants.black;
54

55 // protected void setShapeProperties(ShapeDrawComponent sdc, ShapeFigure s)
56
// {
57
// // TODO: Color should come from ConfigModule
58
// Color fillColor = J2DUtil.toSWTColor(sdc.getFillColor());
59
// Color lineColor = J2DUtil.toSWTColor(sdc.getLineColor());
60
//
61
// s.setBackgroundColor(fillColor);
62
// s.setForegroundColor(lineColor);
63
// s.setLineWidth(sdc.getLineWidth());
64
// s.setLineStyle(sdc.getLineStyle());
65
// s.setFill(sdc.isFill());
66
// }
67

68 // protected void refreshVisuals()
69
// {
70
// GeneralShape gs = (GeneralShape) getShapeDrawComponent().getGeneralShape().clone();
71
// getShapeFigure().setGeneralShape(gs);
72
//// setShapeProperties(getShapeDrawComponent(), getShapeFigure());
73
// super.refreshVisuals();
74
// }
75

76     protected void propertyChanged(PropertyChangeEvent JavaDoc evt)
77     {
78         super.propertyChanged(evt);
79         String JavaDoc propertyName = evt.getPropertyName();
80         if (propertyName.equals(ShapeDrawComponent.PROP_FILL_COLOR)) {
81             LOGGER.debug(propertyName +" changed!");
82             refreshVisuals();
83         }
84         else if (propertyName.equals(ShapeDrawComponent.PROP_LINE_COLOR)) {
85             LOGGER.debug(propertyName +" changed!");
86             refreshVisuals();
87         }
88         else if (propertyName.equals(ShapeDrawComponent.PROP_FILL)) {
89             LOGGER.debug(propertyName +" changed!");
90             refreshVisuals();
91         }
92         else if (propertyName.equals(ShapeDrawComponent.PROP_LINE_STYLE)) {
93             LOGGER.debug(propertyName +" changed!");
94             refreshVisuals();
95         }
96         else if (propertyName.equals(ShapeDrawComponent.PROP_LINE_WIDTH)) {
97             LOGGER.debug(propertyName +" changed!");
98             refreshVisuals();
99         }
100         else if (propertyName.equals(ShapeDrawComponent.PROP_GENERAL_SHAPE)) {
101             LOGGER.debug(propertyName +" changed!");
102             refreshVisuals();
103         }
104     }
105     
106 // public void notifyChanged(Notification notification)
107
// {
108
// int type = notification.getEventType();
109
// int featureId = notification.getFeatureID(Editor2DPackage.class);
110
//
111
// // TODO: add Notification method for setting PathSegments to model
112
// if (type == Notification.SET)
113
// {
114
// switch (featureId)
115
// {
116
// case Editor2DPackage.SHAPE_DRAW_COMPONENT__FILL_COLOR :
117
// LOGGER.debug("SHAPE_DRAW_COMPONENT__FILL_COLOR Notified!");
118
// refreshVisuals();
119
// break;
120
// case Editor2DPackage.SHAPE_DRAW_COMPONENT__LINE_COLOR :
121
// LOGGER.debug("SHAPE_DRAW_COMPONENT__LINE_COLOR Notified!");
122
// refreshVisuals();
123
// break;
124
// case Editor2DPackage.SHAPE_DRAW_COMPONENT__FILL :
125
// LOGGER.debug("SHAPE_DRAW_COMPONENT__FILL Notified!");
126
// refreshVisuals();
127
// break;
128
// case Editor2DPackage.SHAPE_DRAW_COMPONENT__LINE_STYLE :
129
// LOGGER.debug("SHAPE_DRAW_COMPONENT__LINE_STYLE Notified!");
130
// refreshVisuals();
131
// break;
132
// case Editor2DPackage.SHAPE_DRAW_COMPONENT__LINE_WIDTH :
133
// LOGGER.debug("SHAPE_DRAW_COMPONENT__LINE_WIDTH Notified!");
134
// refreshVisuals();
135
// break;
136
// case Editor2DPackage.SHAPE_DRAW_COMPONENT__GENERAL_SHAPE :
137
// LOGGER.debug("SHAPE_DRAW_COMPONENT__GENERAL_SHAPE Notified!");
138
// refreshVisuals();
139
// break;
140
// }
141
// }
142
// super.notifyChanged(notification);
143
// }
144

145   public ShapeDrawComponent getShapeDrawComponent() {
146     return (ShapeDrawComponent) getModel();
147   }
148  
149 // public ShapeFigure getShapeFigure() {
150
// return (ShapeFigure) getFigure();
151
// }
152

153   public GeneralShape getGeneralShape()
154   {
155     GeneralShape gs = getShapeDrawComponent().getGeneralShape();
156     if (gs == null) {
157       gs = ((ShapeFigure)getFigure()).getGeneralShape();
158       getShapeDrawComponent().setGeneralShape(gs);
159     }
160     return gs;
161   }
162     
163   /**
164    * Overridden to return a default <code>DragTracker</code> for GraphicalEditParts.
165    * @see org.eclipse.gef.EditPart#getDragTracker(Request)
166    */

167   public DragTracker getDragTracker(Request request)
168   {
169     if (request.getType().equals(REQ_EDIT_SHAPE)) {
170       EditorEditShapeRequest req = (EditorEditShapeRequest) request;
171       return new ShapeEditTracker(this, req.getPathSegmentIndex());
172     }
173           
174     return super.getDragTracker(request);
175   }
176     
177   public void performRequest(Request req)
178   {
179     // TODO: set somehow the EditShapeMode to the corresponding ShapeFigure
180
if (req.getType().equals(REQ_EDIT_SHAPE))
181     {
182       EditorEditShapeRequest request = (EditorEditShapeRequest) req;
183       EditorStateManager.setEditShapeMode(this);
184     }
185     
186     super.performRequest(req);
187   }
188           
189   public boolean understandsRequest(Request req)
190   {
191     if (req.getType().equals(REQ_EDIT_SHAPE))
192       return true;
193     
194     return super.understandsRequest(req);
195   }
196   
197   /* (non-Javadoc)
198    * @see com.ibm.itso.sal330r.gefdemo.edit.WorkflowElementEditPart#getPropertySource()
199    */

200   protected IPropertySource getPropertySource()
201   {
202     if (propertySource == null)
203     {
204       propertySource =
205         new ShapeDrawComponentPropertySource(getShapeDrawComponent());
206     }
207     return propertySource;
208   }
209 }
210
Popular Tags