Я пытаюсь создать простое приложение с использованием Eclipse GEF, которое отображает диаграмму внутри ScrollingGraphicalViewer. При запуске я хочу, чтобы диаграмма центрировалась внутри зрителя (представьте звездный макет, где центр звезды находится в центре вида).
Вот, что я думаю, соответствующие разделы кода:
Мой взгляд:
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 в целом).