58,454
社区成员
发帖
与我相关
我的任务
分享
public class NodePart extends AbstractGraphicalEditPart implements PropertyChangeListener, NodeEditPart {
protected IFigure createFigure() {
return new NodeFigure();
}
protected void refreshVisuals() {
Node node = (Node) getModel();
Point loc = node.getLocation();
Dimension size = new Dimension(150, 40);
Rectangle rectangle = new Rectangle(loc, size);
((NodeFigure) this.getFigure()).setName(((Node) this.getModel()).getName());
((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), rectangle);
}
public NodeFigure() {
IWorkbenchPart activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
Device d =activePage.getTitleImage().getDevice();
Figure contents = new Figure();
XYLayout contentsLayout = new XYLayout();
contents.setLayoutManager(contentsLayout);
Font classFont = new Font(null, "Arial", 12, SWT.BOLD);
Label classLabel1 = new Label("Table", new Image(d,("c:/class_obj.gif")));
classLabel1.setFont(classFont);
this.classFigure= new UMLClassFigure(classLabel1);
Label attribute1 = new Label("columns: Column[]", new Image(d,("c:/field_private_obj.gif")));
Label attribute2 = new Label("rows: Row[]", new Image(d,("c:/field_private_obj.gif")));
Label attribute3 = new Label("columnID: int", new Image(d,("c:/field_private_obj.gif")));
Label attribute4 = new Label("items: List", new Image(d,("c:/field_private_obj.gif")));
classFigure.getAttributesCompartment().add(attribute1);
classFigure.getAttributesCompartment().add(attribute2);
Label method1 = new Label("getColumns(): Column[]", new Image(d,("c:/methpub_obj.gif")));
Label method2 = new Label("getRows(): Row[]", new Image(d,("c:/methpub_obj.gif")));
Label method3 = new Label("getColumnID(): int", new Image(d,("c:/methpub_obj.gif")));
Label method4 = new Label("getItems(): List", new Image(d,("c:/methpub_obj.gif")));
classFigure.getMethodsCompartment().add(method1);
classFigure.getMethodsCompartment().add(method2);
contentsLayout.setConstraint(classFigure, new Rectangle(10,10,-1,-1));
contents.add(classFigure);
this.add(contents);
}
public class UMLClassFigure extends Figure {
public static Color classColor = new Color(null,255,255,206);
private CompartmentFigure attributeFigure = new CompartmentFigure();
private CompartmentFigure methodFigure = new CompartmentFigure();
public UMLClassFigure(Label name) {
ToolbarLayout layout = new ToolbarLayout();
setLayoutManager(layout);
setBorder(new LineBorder(ColorConstants.black,1));
setBackgroundColor(classColor);
setOpaque(true);
add(name);
add(attributeFigure);
add(methodFigure);
}
public CompartmentFigure getAttributesCompartment() {
return attributeFigure;
}
public CompartmentFigure getMethodsCompartment() {
return methodFigure;
}
}
public class CompartmentFigure extends Figure {
public CompartmentFigure() {
ToolbarLayout layout = new ToolbarLayout();
layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
layout.setStretchMinorAxis(false);
layout.setSpacing(2);
setLayoutManager(layout);
setBorder(new CompartmentFigureBorder());
}
public class CompartmentFigureBorder extends AbstractBorder {
public Insets getInsets(IFigure figure) {
return new Insets(1,0,0,0);
}
public void paint(IFigure figure, Graphics graphics, Insets insets) {
graphics.drawLine(getPaintRectangle(figure, insets).getTopLeft(),
tempRect.getTopRight());
}
}
}