Commits

Anonymous committed 89a5ae4

Tried to solve a graphical problem, not yet successful, but files are reordered

Comments (0)

Files changed (7)

src/nl/tudelft/lime/edit/editpart/ComponentEditPart.java

  *******************************************************************************/
 package nl.tudelft.lime.edit.editpart;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
+
 import nl.tudelft.lime.edit.policy.ContainerHighlightEditPolicy;
 import nl.tudelft.lime.edit.policy.LimeXYLayoutEditPolicy;
 import nl.tudelft.lime.figures.ComponentFigure;
 import org.eclipse.draw2d.XYLayout;
 import org.eclipse.draw2d.geometry.Point;
 import org.eclipse.draw2d.geometry.Rectangle;
-
 import org.eclipse.gef.AccessibleAnchorProvider;
 import org.eclipse.gef.AutoexposeHelper;
 import org.eclipse.gef.EditPolicy;
 import org.eclipse.gef.editparts.ViewportExposeHelper;
 import org.eclipse.gef.editparts.ViewportMouseWheelHelper;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Vector;
-
 
 /**
  * Holds a circuit, which is a container capable of
      * @return  Figure representing the circuit.
      */
     protected IFigure createFigure() {
-        return FigureFactory.createNewCircuit();
+        return FigureFactory.createNewComponent();
     }
 
     public Object getAdapter(Class key) {
     public IFigure getContentPane() {
         return getComponentFigure().getContentsPane();
     }
+
+    
 }

src/nl/tudelft/lime/edit/policy/ContainerHighlightEditPolicy.java

 package nl.tudelft.lime.edit.policy;
 
+import nl.tudelft.lime.edit.editpart.ComponentEditPart;
 import nl.tudelft.lime.figures.LimeColorConstants;
 
 import org.eclipse.draw2d.IFigure;
 import org.eclipse.gef.EditPart;
-import org.eclipse.gef.GraphicalEditPart;
 import org.eclipse.gef.Request;
 import org.eclipse.gef.RequestConstants;
 import org.eclipse.swt.graphics.Color;
      * @return the figure specified for this container
      */
     private IFigure getContainerFigure() {
-        return ((GraphicalEditPart) getHost()).getFigure();
+        return ((ComponentEditPart) getHost()).getFigure();
     }
 
     /**

src/nl/tudelft/lime/edit/policy/WhileDraggingEditPolicy.java

 
 import java.util.List;
 
-import nl.tudelft.lime.figures.ComponentBorder;
 import nl.tudelft.lime.figures.ComponentFigure;
 import nl.tudelft.lime.figures.InputPortFigure;
 import nl.tudelft.lime.figures.LabelFeedbackFigure;
             ((NodeFigure) figure).setBeingDragged(true);
         }
 
-        if (figure instanceof ComponentBorder) {
-            ((ComponentBorder) figure).setBeingDragged(true);
-        }
-
         return figure;
     }
 

src/nl/tudelft/lime/figures/ComponentBorder.java

-package nl.tudelft.lime.figures;
-
-import org.eclipse.draw2d.AbstractBorder;
-import org.eclipse.draw2d.Graphics;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Insets;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.swt.SWT;
-
-
-public class ComponentBorder extends AbstractBorder {
-    //defines margins for the shape
-    private Integer splitterLineHeight = 50;
-
-    //it is the default value
-    protected Insets insets = new Insets(1, 1, 1, 1);
-    protected boolean isBeingDragged = false;
-
-    /**
-    * This method is called while painting a dragged object on the diagram,
-    * it can be used to change the diagram painting style
-    * @return
-    */
-    public boolean isBeingDragged() {
-        return isBeingDragged;
-    }
-
-    /**
-     * @param isBeingDragged the isBeingDragged to set
-     */
-    public void setBeingDragged(boolean isBeingDragged) {
-        this.isBeingDragged = isBeingDragged;
-    }
-
-    public Insets getInsets(IFigure figure) {
-        return insets;
-    }
-
-    /**
-         * @param splitterLineHeight the splitterLineHeight to set
-         */
-    public void setSplitterLineHeight(Integer splitterLineHeight) {
-        this.splitterLineHeight = splitterLineHeight;
-        insets.top = this.splitterLineHeight;
-    }
-
-    /**
-     * @return the splitterLineHeight
-     */
-    public Integer getSplitterLineHeight() {
-        return splitterLineHeight;
-    }
-
-    public void paint(IFigure figure, Graphics g, Insets in) {
-        if (isBeingDragged()) {
-            g.setAlpha(150);
-        }
-
-        g.setForegroundColor(LimeColorConstants.black);
-        g.setBackgroundColor(LimeColorConstants.componentBorder);
-
-        Rectangle r = figure.getBounds().getCropped(in);
-
-        //Outline the border
-        r.shrink(1, 0);
-        g.setForegroundColor(LimeColorConstants.black);
-        //draw the border line
-        g.setLineWidth(2);
-        g.setLineStyle(SWT.LINE_SOLID);
-        g.drawLine(r.x, r.y + splitterLineHeight, r.right(),
-            r.y + splitterLineHeight);
-
-        g.drawLine(r.x, r.y, r.right(), r.y);
-        g.drawLine(r.x, r.bottom() - 1, r.right(), r.bottom() - 1);
-        g.drawLine(r.x, r.y, r.x, r.bottom() - 1);
-        g.drawLine(r.right(), r.bottom() - 1, r.right(), r.y);
-
-        //r.crop(new Insets(5, 0, 5, 0));
-        //r.expand(0, 6);
-        //r.crop(getInsets(figure));
-
-        //drawConnectors(g, figure.getBounds().getCropped(in));
-    }
-}

src/nl/tudelft/lime/figures/ComponentFigure.java

 import nl.tudelft.lime.constants.LimeMessages;
 
 import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.Figure;
+import org.eclipse.draw2d.FlowLayout;
 import org.eclipse.draw2d.FreeformLayer;
 import org.eclipse.draw2d.FreeformLayout;
 import org.eclipse.draw2d.FreeformViewport;
 import org.eclipse.draw2d.Graphics;
 import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.LightweightSystem;
+import org.eclipse.draw2d.LineBorder;
+import org.eclipse.draw2d.Polyline;
 import org.eclipse.draw2d.ScrollPane;
-import org.eclipse.draw2d.StackLayout;
+import org.eclipse.draw2d.ToolbarLayout;
+import org.eclipse.draw2d.XYLayout;
 import org.eclipse.draw2d.geometry.Dimension;
 import org.eclipse.draw2d.geometry.Insets;
 import org.eclipse.draw2d.geometry.Point;
 import org.eclipse.draw2d.geometry.Rectangle;
 import org.eclipse.gef.handles.HandleBounds;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
 
 
 public class ComponentFigure extends NodeFigure implements HandleBounds {
-    private IFigure pane;
+//    private IFigure pane;
     protected static final Dimension SIZE = new Dimension(200, 200);
+    //we want to have a label which has a line at the bottom
+    protected ComponentLabel componentLabel = new ComponentLabel();
+    private IFigure contentsFigure = new FreeformLayer(){
+    	@Override
+    	public void paintFigure(Graphics graphics){
+    		graphics.setBackgroundColor(ColorConstants.red);
+    		graphics.fillRectangle(getBounds());
+    		super.paintFigure(graphics);
+    	}
+    };
 
+
+    
     public ComponentFigure() {
-        setBorder(new ComponentBorder());
+	    ToolbarLayout layout = new ToolbarLayout();
+	    setLayoutManager(layout);
+	    setBorder(new LineBorder(2));
+	    
+        componentLabel.setFont(FigureUtility.LARGE_FONT);
+	    FreeformLayer labelLayer = new FreeformLayer();
+	    labelLayer.setLayoutManager(new ToolbarLayout());
+	    
+	    labelLayer.add(componentLabel);
+	    add(labelLayer);
 
-        ScrollPane scrollpane = new ScrollPane();
-        pane = new FreeformLayer();
-        pane.setLayoutManager(new FreeformLayout());
-        setLayoutManager(new StackLayout());
-        add(scrollpane);
+	    contentsFigure.setLayoutManager(new FreeformLayout());
+	    ScrollPane scrollpane = new ScrollPane();
         scrollpane.setViewport(new FreeformViewport());
-        scrollpane.setContents(pane);
-        setSize(SIZE);
-        //pane.setSize(scrollpane.getSize().width, scrollpane.getSize().height /2 );
-        
+        scrollpane.setContents(contentsFigure);
+	    add(scrollpane);
+	    setSize(SIZE);
+    }
+    
+    public static void main(String[] args) {
+    	Display d = new Display();
+    	final Shell shell = new Shell(d);
+    	shell.setSize(400, 400);
+    	shell.setText("UMLClassFigure Test");
+    	LightweightSystem lws = new LightweightSystem(shell);
+    	Figure contents = new Figure();
+    	XYLayout contentsLayout = new XYLayout();
+    	contents.setLayoutManager(contentsLayout);
+    	final ComponentFigure classFigure = new ComponentFigure();
+    	classFigure.setName("hello");
+    	contents.add(classFigure);
+    	lws.setContents(contents);
+    	shell.open();
+    	while (!shell.isDisposed())
+    		while (!d.readAndDispatch())
+    			d.sleep();
+	}
+    
+	/**
+	 * @return the contentsFigure
+	 */
+	public IFigure getContentsFigure() {
+		return contentsFigure;
+	}
 
-    }
-   
-    /* (non-Javadoc)
+
+	/* (non-Javadoc)
+	 * @see nl.tudelft.lime.figures.NodeFigure#setName(java.lang.String)
+	 */
+	@Override
+	public void setName(String name) {
+		componentLabel.setText(name);
+		super.setName(name);
+	}
+
+
+
+	/* (non-Javadoc)
 	 * @see org.eclipse.draw2d.Figure#setSize(int, int)
 	 */
 	@Override
 	public Dimension getPreferredSize(int w, int h) {
 		return SIZE.union(getSize());
 	}
+	
+	/**
+	 * @see IFigure#setSize(int, int)
+	 */
+	@Override
+	public void setSize(int w, int h) {
+		Dimension minimumSize = SIZE.union(new Dimension(w, h));
+		super.setSize(minimumSize.width, minimumSize.height); 
+	}
+	
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.draw2d.Figure#setSize(int, int)
+	 */
+	@Override
+	public Dimension getMinimumSize(int w, int h) {
+		return SIZE;
+	}
 
 	public IFigure getContentsPane() {
-        return pane;
+        return contentsFigure;
     }
     
     
 	 * this method :{@link ComponentBorder#getInsets(IFigure)}
      * @see org.eclipse.draw2d.Figure#paintFigure(Graphics)
      */
-    @SuppressWarnings("unchecked")
     protected void paintFigure(Graphics g) {
         if (isBeingDragged()) {
             g.setAlpha(150);
         }
-
-        g.setBackgroundColor(ColorConstants.white);
-        Rectangle rect = getBounds().getCopy();
-//        Rectangle biggestRectangle = getBounds().getCopy();
-//        //getting component -> scrollpane
-//        Figure scrollPane = (Figure) getChildren().get(0);
-//        //getting scrollpane -> FreeformViewPort
-//        Figure freeFormViewport= (Figure) scrollPane.getChildren().get(0);
-//        //getting FreeformViewPort -> FreeformLayer
-//        Figure freeFormLayer= (Figure) freeFormViewport.getChildren().get(0);
-//        
-//        List<Figure> children = (List<Figure>) freeFormLayer.getChildren(); 
-//        for (Figure child : children){
-//        	biggestRectangle = biggestRectangle.union(child.getBounds());
-//    	}
-//        
-//        setBounds(biggestRectangle);
-
-        g.fillRectangle(rect);
-        if (!isBeingDragged()) {
-            g.setFont(FigureUtility.LARGE_FONT);
-            Point p = FigureUtility.centeredTextLocation(g, rect,
-                    getName().length());
-            ((ComponentBorder)getBorder()).setSplitterLineHeight(rect.height / 5);
-            g.drawString(getName(), p.x, rect.y + ((ComponentBorder)getBorder()).getSplitterLineHeight() / 2);
-            
-        }        
+//        Rectangle rect = getBounds().getCopy();
+//        g.setBackgroundColor(ColorConstants.white);
+//        g.fillRectangle(rect);
     }
 
     

src/nl/tudelft/lime/figures/ComponentLabel.java

+/**
+ * 
+ */
+package nl.tudelft.lime.figures;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.Label;
+import org.eclipse.draw2d.geometry.Rectangle;
+
+/**
+ * Draws a line under the label of the component
+ * @author af08018
+ */
+public class ComponentLabel extends Label{
+        public void paintFigure(Graphics graphics) {
+        	Rectangle rect = getBounds().getCopy();
+        	graphics.setBackgroundColor(ColorConstants.gray);
+        	graphics.setForegroundColor(ColorConstants.white);
+        	graphics.fillRectangle(rect);
+            super.paintFigure(graphics);
+        }
+}

src/nl/tudelft/lime/figures/FigureFactory.java

         return conn;
     }
 
-    public static IFigure createNewCircuit() {
+    public static IFigure createNewComponent() {
         ComponentFigure f = new ComponentFigure();
 
         return f;