【发布时间】:2013-01-05 05:58:33
【问题描述】:
我的意思是绘制一些简单的形状,如圆形、矩形图和折线Connectistrong。似乎必须在 Shell 等 Canvas 上构建 LightweightSystem。在 RCP 应用程序中,当我添加编辑器的扩展时,编辑器默认扩展 org.eclipse.ui.part.EditorPart。它有一个名为 createPartControl 的方法。该方法有一个参数(复合父级)。
所以我写了下面的代码,它给了我一个未处理的事件循环异常
public void createPartControl(Composite parent) {
Shell shell = parent.getShell();
shell.open();
Display display = shell.getDisplay();
LightweightSystem lws = new LightweightSystem(shell);
IFigure panel = new Figure();
lws.setContents(panel);
RectangleFigure node1 = new RectangleFigure();
RectangleFigure node2 = new RectangleFigure();
node1.setBackgroundColor(ColorConstants.red);
node1.setBounds(new Rectangle(30, 30, 64, 36));
node2.setBackgroundColor(ColorConstants.blue);
node2.setBounds(new Rectangle(100, 100, 64, 36));
PolylineConnection conn = new PolylineConnection();
conn.setSourceAnchor(new ChopboxAnchor(node1));
conn.setTargetAnchor(new ChopboxAnchor(node2));
conn.setTargetDecoration(new PolygonDecoration());
Label label = new Label("Midpoint");
label.setOpaque(true);
label.setBackgroundColor(ColorConstants.buttonLightest);
label.setBorder(new LineBorder());
conn.add(label, new MidpointLocator(conn, 0));
panel.add(node1);
panel.add(node2);
panel.add(conn);
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ())
display.sleep ();
}
}
那么如何解决这个问题以及如何在编辑器上绘制这些图形呢?
【问题讨论】:
-
您似乎复制并粘贴了一个 swt 示例,该示例在 jface 编辑器类中显示了一个带有画布的窗口
-
是的,这个示例在一个带有 main 方法的类中成功运行。我希望它可以在作为插件扩展的 Editor 中使用。
-
使用父级创建一个画布,然后将该画布传递给 LightweightSystem。删除所有不需要的外壳/显示代码
-
干得好。它的工作原理!非常感谢!好人。
-
欢迎;我将评论转换为您接受的答案。
标签: eclipse-plugin eclipse-rcp eclipse-gef draw2d