1 27 28 package org.nightlabs.editor2d.edit; 29 30 import java.beans.PropertyChangeEvent ; 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 class ShapeDrawComponentEditPart 47 extends DrawComponentEditPart 48 { 49 52 public ShapeDrawComponentEditPart(ShapeDrawComponent shapeDrawComponent) { 53 super(shapeDrawComponent); 54 } 55 56 72 75 88 96 protected void propertyChanged(PropertyChangeEvent evt) 97 { 98 super.propertyChanged(evt); 99 String 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 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 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 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 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 |