1

円、rectangleFigure、polylineConnectistrongなどの単純な形状を描画することを意味します。LightweightSystemはシェルなどのキャンバス上に構築する必要があるようです。RCPアプリケーションでは、エディターの拡張機能を追加すると、エディターは組織を拡張します。 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 (); 
    }
}

では、この問題を解決する方法と、エディターでこれらの図を描く方法は?

4

1 に答える 1

1

エディター内に描画するため、スタンドアロンSWTアプリケーションの場合のように、新しいシェルを作成したり、イベントキューからイベントをディスパッチしたりする必要はありません。キャンバスを作成して描画するだけです。これはあなたを助けるはずです:

public void createPartControl(Composite parent) {
    Canvas canvas = new Canvas(parent, SWT.NONE);
    LightweightSystem lws = new LightweightSystem(canvas);
    IFigure panel = new Figure();
    lws.setContents(panel);
    [...]
    panel.add(node1);
    panel.add(node2);
    panel.add(conn);
}
于 2013-01-23T05:11:22.133 に答える