Eclipse gefのスクロールグラフィカルビューターの可視領域のサイズの決定

StackOverflow https://stackoverflow.com/questions/2763553

  •  02-10-2019
  •  | 
  •  

質問

ScrollingGraphicalViewer内に図を表示するEclipse GEFを使用して、簡単なアプリケーションを作成しようとしています。起動時には、図を視聴者の内側に集中させたいと思います(星の中心がビューの中心にある星のレイアウトを想像してください)。

関連するコードセクションは次のとおりです。

私の見解:

public class View extends ViewPart {
    public static final String ID = "GEFProofOfConcept.view";

...         

    public void createPartControl(Composite parent) {
        viewer.createControl(parent);

        viewer.setRootEditPart(rootEditPart);
        viewer.setEditPartFactory(editPartFactory);

        viewer.setContents(DummyModelCreator.generateModel());          
    }

編集部品コード:

@Override
protected void refreshVisuals() {
    Project project = (Project) getModel();

    // This is where the actual drawing is done,
    // Simply a rectangle with text
    Rectangle bounds = new Rectangle(50, 50, 75, 50);
    getFigure().setBounds(bounds);
    Label label = new Label(project.getName());
    projectFont = new Font(null, "Arial", 6, SWT.NORMAL);
    label.setFont(projectFont);
    label.setTextAlignment(PositionConstants.CENTER);
    label.setBounds(bounds.crop(IFigure.NO_INSETS));

    getFigure().add(label);

    setLocation();
}

private void setLocation() {
    Project project = (Project) getModel();

    if (project.isRoot()) {
        // Place in centre of the layout
        Point centrePoint = new Point(0, 0); // This is where I need the center of the view
        getFigure().setLocation(centrePoint);
    } else {
        ...
    }       
}

そして、上記の編集パーツの親:

public class ProjectDependencyModelEditPart extends AbstractGraphicalEditPart {

@Override
protected IFigure createFigure() {
    Figure f = new FreeformLayer();
    f.setLayoutManager(new XYLayout());

    return f;
}
...

問題の代替ソリューションも歓迎します。私は間違いなくGEF(そして一般的に日食)の初心者です。

役に立ちましたか?

解決

興味のある人のために、それを解決しました:

        Dimension viewSize = (((FigureCanvas) getViewer().getControl()).getViewport().getSize());
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top