gef开发,为什么自定义的Ifigure后UML图展示不出来?

jcreatorqijiashe 2017-01-31 07:25:40
拖动出来后是空的?也没报错,什么都显示不出来,大神门帮忙看看 代码哪里有问题?多谢!。我自定义了一个UML的图(参考 http://blog.csdn.net/niujiabinbin/article/details/51302847 里面的UMLClassFigure),每一个NodePart 中
 
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);
}


NodeFigure中构造函数如下:
 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);

}


UMLClassFigure.java

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());
}
}
}
...全文
241 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
jcreatorqijiashe 2017-02-11
  • 打赏
  • 举报
回复
提前!!!!

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧