Eclipse Gef Tutorial • Ultimate
public abstract class Shape public static final String LOCATION_PROP = "location"; public static final String SIZE_PROP = "size";
org.eclipse.core.runtime org.eclipse.ui org.eclipse.draw2d org.eclipse.gef org.eclipse.jface org.eclipse.swt org.eclipse.ui.ide Define the data structure.
@Override public void setBounds(Rectangle rect) super.setBounds(rect); // any custom layout logic
public class DiagramEditPart extends AbstractGraphicalEditPart @Override protected IFigure createFigure() Layer lay = new FreeformLayer(); lay.setLayoutManager(new FreeformLayout()); return lay; @Override protected void createEditPolicies() installEditPolicy(EditPolicy.LAYOUT_ROLE, new FreeformLayoutEditPolicy()); eclipse gef tutorial
public abstract void accept(ShapeVisitor visitor);
package com.example.shapeditor.parts; import org.eclipse.draw2d. ; import org.eclipse.gef. ; import org.eclipse.gef.editparts.AbstractGraphicalEditPart; import com.example.shapeditor.figures.RectangleFigure; import com.example.shapeditor.model.Shape;
public class ShapeEditor extends GraphicalEditorWithFlyoutPalette private Diagram diagram; public ShapeEditor() setEditDomain(new DefaultEditDomain(this)); public abstract class Shape public static final String
package com.example.shapeditor.figures; import org.eclipse.draw2d.ColorConstants; import org.eclipse.draw2d.RectangleFigure; import org.eclipse.draw2d.geometry.Rectangle;
– Base class for all shapes:
Bridges model ↔ figure.
private PropertyChangeSupport listeners = new PropertyChangeSupport(this); private int x, y, width, height;
// similarly for y, width, height...
public class ShapeEditPart extends AbstractGraphicalEditPart ; import org
public void removePropertyChangeListener(PropertyChangeListener listener) listeners.removePropertyChangeListener(listener);