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(およびEclipse全般)の初心者です。