1 8 package com.nightlabs.editor2d.edit; 9 10 import java.beans.PropertyChangeEvent ; 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 class ShapeDrawComponentEditPart 27 extends DrawComponentEditPart 28 { 29 32 public ShapeDrawComponentEditPart(ShapeDrawComponent shapeDrawComponent) { 33 super(shapeDrawComponent); 34 } 35 36 52 55 68 76 protected void propertyChanged(PropertyChangeEvent evt) 77 { 78 super.propertyChanged(evt); 79 String 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 145 public ShapeDrawComponent getShapeDrawComponent() { 146 return (ShapeDrawComponent) getModel(); 147 } 148 149 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 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 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 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 |