1 8 package com.nightlabs.editor2d.util; 9 10 import java.util.Iterator ; 11 12 import org.eclipse.draw2d.ColorConstants; 13 14 import com.nightlabs.editor2d.DrawComponent; 15 import com.nightlabs.editor2d.DrawComponentContainer; 16 import com.nightlabs.editor2d.ImageDrawComponent; 17 import com.nightlabs.editor2d.ShapeDrawComponent; 18 import com.nightlabs.editor2d.figures.FeedbackShapeFigure; 19 import com.nightlabs.editor2d.figures.ShapeFigure; 20 import com.nightlabs.editor2d.j2d.GeneralShape; 21 import com.nightlabs.editor2d.j2d.GeneralShapeFactory; 22 23 24 public class FeedbackUtil 25 { 26 28 public FeedbackUtil() 29 { 30 super(); 31 } 38 39 public static ShapeFigure createCustomFeedbackFigure(Object modelPart) 40 { 41 GeneralShape gs = null; 42 if (modelPart instanceof ShapeDrawComponent) { 43 ShapeDrawComponent sdc = (ShapeDrawComponent) modelPart; 44 gs = (GeneralShape)sdc.getGeneralShape().clone(); 45 } 46 else if (modelPart instanceof ImageDrawComponent) { 47 ImageDrawComponent idc = (ImageDrawComponent) modelPart; 48 gs = (GeneralShape) idc.getImageShape().clone(); 49 } 50 else if (modelPart instanceof DrawComponentContainer) 51 { 52 DrawComponentContainer container = (DrawComponentContainer) modelPart; 53 ShapeFigure containerFigure = new FeedbackShapeFigure(); 54 GeneralShape containerShape = GeneralShapeFactory.createRectangle(1,1,1,1); 55 containerFigure.setGeneralShape(containerShape); 56 containerFigure.setXOR(true); 57 containerFigure.setFill(true); 58 containerFigure.setBackgroundColor(ColorConstants.darkGray); 59 containerFigure.setForegroundColor(ColorConstants.white); 60 for (Iterator it = container.getDrawComponents().iterator(); it.hasNext(); ) { 61 DrawComponent dc = (DrawComponent) it.next(); 62 ShapeFigure figure = createCustomFeedbackFigure(dc); 63 containerFigure.add(figure); 64 } 65 return containerFigure; 66 } 67 else { 68 gs = GeneralShapeFactory.createRectangle(0, 0, 10, 10); 69 } 70 ShapeFigure shapeFigure = new FeedbackShapeFigure(); 71 shapeFigure.setGeneralShape(gs); 72 shapeFigure.setXOR(true); 73 shapeFigure.setFill(true); 74 shapeFigure.setBackgroundColor(ColorConstants.darkGray); 75 shapeFigure.setForegroundColor(ColorConstants.white); 76 return shapeFigure; 77 } 78 79 113 } 121 | Popular Tags |