为什么在删除容器的绝对大小时没有绘制 GEF 子项?
我尝试获得一个简单的 GEF 编辑器。我有一个 GraphicalEditorWithPalette
来创建我的示例模型。我有一个 RootEditPart
,它覆盖 createFigure
和 getModelChildren
,如下所示:
public class RootEditPart extends AbstractGraphicalEditPart {
@Override
protected IFigure createFigure() {
Figure figure = new Figure();
figure.setOpaque(true);
figure.setLayoutManager(new XYLayout());
figure.setSize(1000, 1000);
return figure;
}
@Override
protected List<Positionable> getModelChildren() {
return getModel().getChildren();
}
// More methods ...
}
我有一个 ChildEditPart,它创建标签并覆盖 refreshVisuals
> 像这样:
public class ChildEditPart extends AbstractGraphicalEditPart {
@Override
protected void refreshVisuals() {
RDC rdc = getModel();
Label nameLabel = (Label) getFigure();
nameLabel.setText(rdc.getName());
Point position = rdc.getPosition();
Rectangle r = new Rectangle(position.x, position.y, -1,-1);
((GraphicalEditPart) getParent()).setLayoutConstraint(this, nameLabel, r);
}
// More methods ...
}
这按预期工作。但我不想让容器有固定的大小。相反,我尝试让容器的大小适应孩子们的需要。如果我删除 figure.setSize(1000, 1000);
则不再绘制子项。我的错误是什么?
编辑: 也许重要的是要知道我的编辑器像这样配置根编辑部分:viewer.setRootEditPart(new ScalableFreeformRootEditPart());
Edit2: 看起来实际上调用 viewer.setRootEditPart(new ScalableFreeformRootEditPart());
是问题所在。如果我删除它,它将按预期工作。目前我不完全明白为什么......如果有人能解释一下那就太好了。
I try to get a simple working GEF editor. I have a GraphicalEditorWithPalette
that creates my example model. I have a RootEditPart
that overrides createFigure
and getModelChildren
like this:
public class RootEditPart extends AbstractGraphicalEditPart {
@Override
protected IFigure createFigure() {
Figure figure = new Figure();
figure.setOpaque(true);
figure.setLayoutManager(new XYLayout());
figure.setSize(1000, 1000);
return figure;
}
@Override
protected List<Positionable> getModelChildren() {
return getModel().getChildren();
}
// More methods ...
}
I have a ChildEditPart that creates a label and override refreshVisuals
like this:
public class ChildEditPart extends AbstractGraphicalEditPart {
@Override
protected void refreshVisuals() {
RDC rdc = getModel();
Label nameLabel = (Label) getFigure();
nameLabel.setText(rdc.getName());
Point position = rdc.getPosition();
Rectangle r = new Rectangle(position.x, position.y, -1,-1);
((GraphicalEditPart) getParent()).setLayoutConstraint(this, nameLabel, r);
}
// More methods ...
}
This works as expected. But I don't want to have a fixed size for the container. Instead I try to achieve that the containers size adapts to the children. If I remove the figure.setSize(1000, 1000);
the children are not drawn any more. What is my mistake?
Edit:
Maybe it is important to know that my editor configures the root edit part like this: viewer.setRootEditPart(new ScalableFreeformRootEditPart());
Edit2:
Seems like in fact the call viewer.setRootEditPart(new ScalableFreeformRootEditPart());
is the problem. If I remove this it works as expected. Currently I don't fully understand why ... would be great if someone could explain.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须在需要时手动设置父母身材的大小。
图形代表计算其首选大小而不是其布局(如果存在)。
XYLayout 将计算表示内容的最小尺寸。
我认为插入此代码的最佳位置是父 EditPart 的 setLayoutConstraint。
You have to set size of parent's figure manually when it needed.
figure delegates computing it's prefer size to it's layout(if exist).
XYLayout will compute minimal size to represent contents.
I think best place to insert this code is setLayoutConstraint of parent EditPart.