Variable Diagram Size [message #1714508] |
Fri, 13 November 2015 04:59  |
Eclipse User |
|
|
|
Hi,
I implement a graphical editing tool with GEF.
It should be possible to adjust the diagram size and it should be prevented to drag new elements outside this size.
What I do is to override the createDefaultRoot method in ScrollingGraphicalViewer and write my own ScalableLayeredPane for which I override the createScaledLayers method, see below. Their I set the bounds for now on fixed size (200,200).
@Override
protected ScalableLayeredPane createScaledLayers() {
ScalableLayeredPane layer = new ScalableLayeredPane() {
@Override
public Rectangle getBounds() {
return new Rectangle(0, 0, 200, 200);
}
@Override
public Border getBorder() {
return new SchemeBorder(SCHEMES.BUTTON);
}
@Override
public void paint(Graphics graphics) {
super.paint(graphics);
graphics.setLineWidth(5);
graphics.setForegroundColor(red);
graphics.drawRectangle(new Rectangle(getBounds()));
graphics.scale(getScale());
}
protected void paintClientArea(Graphics graphics) {
if (getChildren().isEmpty())
return;
if (scale == 1.0) {
super.paintClientArea(graphics);
} else {
ScaledGraphics g = new ScaledGraphics(graphics);
boolean optimizeClip = getBorder() == null
|| getBorder().isOpaque();
if (!optimizeClip)
g.clipRect(getBounds().getCropped(getInsets()));
g.scale(scale);
g.pushState();
paintChildren(g);
g.dispose();
graphics.restoreState();
}
}
...
The current state after I made these changes:

After zoom:

1. What I want to achieve is that the diagram size should be adjustable and
2. in case of zooming it should be not zoomed inside the diagram, the zoom should affect the whole diagram, like this.

Could so. help please!
Attachment: 1.PNG
(Size: 3.77KB, Downloaded 360 times)
Attachment: 2.PNG
(Size: 3.54KB, Downloaded 367 times)
Attachment: 3.PNG
(Size: 4.58KB, Downloaded 356 times)
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02474 seconds