Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Centered, fixed-sized diagram with correctly positioned grid and rulers
Centered, fixed-sized diagram with correctly positioned grid and rulers [message #227382] Mon, 04 December 2006 20:01 Go to next message
Eric Heiker is currently offline Eric HeikerFriend
Messages: 2
Registered: July 2009
Junior Member
Hi, I am making a graphics editing program using GEF and I need to be
able to edit a fixed size (like 640x480), centered diagram. It needs to
be zoomable and have a grid that has its origin in the upper-left corner
of the diagram figure. Ideally it would also have rulers that are fitted
to the diagram, but its not entirely necessary.

This is a picture of what I'm trying to achieve:
http://mediacraftlabs.com/eric/gef-layout.jpg

Here are my current results:
http://mediacraftlabs.com/eric/gef-bad-layout.jpg

At the moment I am extending a ScalableRootEditPart and overriding the
createLayers() method. There I move the scaled layers into a new layer
called centerPane. A FlowLayout is applied to centerPane to try to make
it centered, but for some reason it is only vertically centered and
horizontally it is left-aligned.

LayeredPane scaledLayers = getScaledLayers();
layeredPane.remove(scaledLayers);
Layer centerPane = new Layer();
centerPane.add(scaledLayers);
FlowLayout layout = new FlowLayout(false);
layout.setMinorAlignment(FlowLayout.ALIGN_CENTER);
layout.setMajorAlignment(FlowLayout.ALIGN_CENTER);
layeredPane.addLayerAfter(centerPane, CENTER_LAYER,
getLayer(HANDLE_LAYER));

New layer structure:

Root Layered Pane
├ Guide Layer
├ Feedback Layer
├ Handle Layer
├ centerPane <=======
├ Scalable Layers (ScalableLayeredPane)
├ Scaled Feedback Layer
├ Printable Layers
├ Connection Layer
└ Primary Layer
├ DiagramFigure <========
└ Grid Layer


Then I made a new figure called DiagramFigure which serves as the
container for all of the shapes and other figures. The DiagramFigure
has an XYLayout and I set its preferred size (640,480) and its color
(yellow) in DiagramEditPart.

This makes the diagram the right size and color but the problem is that
all of the other layers, including grid, feedback, and rulers, are all
drawn starting at (0,0) of the viewport layer and not the DiagramFigure.
If you look at the 2nd image I posted you can see that the grid layer
is slightly off. Also, when moving child figures in the diagram the
feedback layer is also drawn starting at (0,0) of the viewport so the
gray "move" square is also off. Its not just a drawing issue as
snapping to the grid is also calculated from the viewport.

I assume the solution has something to do with layouts but I can't
figure it out. Any help would be appreciated.
Re: Centered, fixed-sized diagram with correctly positioned grid and rulers [message #227663 is a reply to message #227382] Fri, 08 December 2006 22:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.unknown.com

An easy hack is to give the layer a border.

Otherwise you could add a separate figure (page) to the layer with a stack
layout or something. That page then becomes the content pane for your
editpart and would have the XYLayout.

"Eric Heiker" <eric.heiker@gmail.com> wrote in message
news:el1uqr$2h2$1@utils.eclipse.org...
> Hi, I am making a graphics editing program using GEF and I need to be able
> to edit a fixed size (like 640x480), centered diagram. It needs to be
> zoomable and have a grid that has its origin in the upper-left corner of
> the diagram figure. Ideally it would also have rulers that are fitted to
> the diagram, but its not entirely necessary.
>
> This is a picture of what I'm trying to achieve:
> http://mediacraftlabs.com/eric/gef-layout.jpg
>
> Here are my current results:
> http://mediacraftlabs.com/eric/gef-bad-layout.jpg
>
> At the moment I am extending a ScalableRootEditPart and overriding the
> createLayers() method. There I move the scaled layers into a new layer
> called centerPane. A FlowLayout is applied to centerPane to try to make
> it centered, but for some reason it is only vertically centered and
> horizontally it is left-aligned.
>
> LayeredPane scaledLayers = getScaledLayers();
> layeredPane.remove(scaledLayers);
> Layer centerPane = new Layer();
> centerPane.add(scaledLayers);
> FlowLayout layout = new FlowLayout(false);
> layout.setMinorAlignment(FlowLayout.ALIGN_CENTER);
> layout.setMajorAlignment(FlowLayout.ALIGN_CENTER);
> layeredPane.addLayerAfter(centerPane, CENTER_LAYER,
> getLayer(HANDLE_LAYER));
>
> New layer structure:
>
> Root Layered Pane
>
Re: Centered, fixed-sized diagram with correctly positioned grid and rulers [message #227820 is a reply to message #227663] Mon, 11 December 2006 17:33 Go to previous messageGo to next message
Eric Heiker is currently offline Eric HeikerFriend
Messages: 2
Registered: July 2009
Junior Member
Hi, thanks for your response.

Which layer are you referring to?

Also, I already have a separate figure as the content pane with a
XYLayout. The problem is that the figure is not centered and the
feedback and grid layers do not have their origin at the (0,0) point on
the figure but the (0,0) point of the viewport.

Pratik Shah wrote:
> An easy hack is to give the layer a border.
>
> Otherwise you could add a separate figure (page) to the layer with a stack
> layout or something. That page then becomes the content pane for your
> editpart and would have the XYLayout.
>
> "Eric Heiker" <eric.heiker@gmail.com> wrote in message
> news:el1uqr$2h2$1@utils.eclipse.org...
>> Hi, I am making a graphics editing program using GEF and I need to be able
>> to edit a fixed size (like 640x480), centered diagram. It needs to be
>> zoomable and have a grid that has its origin in the upper-left corner of
>> the diagram figure. Ideally it would also have rulers that are fitted to
>> the diagram, but its not entirely necessary.
>>
>> This is a picture of what I'm trying to achieve:
>> http://mediacraftlabs.com/eric/gef-layout.jpg
>>
>> Here are my current results:
>> http://mediacraftlabs.com/eric/gef-bad-layout.jpg
>>
>> At the moment I am extending a ScalableRootEditPart and overriding the
>> createLayers() method. There I move the scaled layers into a new layer
>> called centerPane. A FlowLayout is applied to centerPane to try to make
>> it centered, but for some reason it is only vertically centered and
>> horizontally it is left-aligned.
>>
>> LayeredPane scaledLayers = getScaledLayers();
>> layeredPane.remove(scaledLayers);
>> Layer centerPane = new Layer();
>> centerPane.add(scaledLayers);
>> FlowLayout layout = new FlowLayout(false);
>> layout.setMinorAlignment(FlowLayout.ALIGN_CENTER);
>> layout.setMajorAlignment(FlowLayout.ALIGN_CENTER);
>> layeredPane.addLayerAfter(centerPane, CENTER_LAYER,
>> getLayer(HANDLE_LAYER));
>>
>> New layer structure:
>>
>> Root Layered Pane
>> â"o Guide Layer
>> â"o Feedback Layer
>> â"o Handle Layer
>> â"o centerPane <=======
>> â"o Scalable Layers (ScalableLayeredPane)
>> â"o Scaled Feedback Layer
>> â"o Printable Layers
>> â"o Connection Layer
>> â"" Primary Layer
>> â"o DiagramFigure <========
>> â"" Grid Layer
>>
>>
>> Then I made a new figure called DiagramFigure which serves as the
>> container for all of the shapes and other figures. The DiagramFigure has
>> an XYLayout and I set its preferred size (640,480) and its color (yellow)
>> in DiagramEditPart.
>>
>> This makes the diagram the right size and color but the problem is that
>> all of the other layers, including grid, feedback, and rulers, are all
>> drawn starting at (0,0) of the viewport layer and not the DiagramFigure.
>> If you look at the 2nd image I posted you can see that the grid layer is
>> slightly off. Also, when moving child figures in the diagram the feedback
>> layer is also drawn starting at (0,0) of the viewport so the gray "move"
>> square is also off. Its not just a drawing issue as snapping to the grid
>> is also calculated from the viewport.
>>
>> I assume the solution has something to do with layouts but I can't figure
>> it out. Any help would be appreciated.
>
>
Re: Centered, fixed-sized diagram with correctly positioned grid and rulers [message #227903 is a reply to message #227820] Tue, 12 December 2006 19:11 Go to previous message
Eclipse UserFriend
Originally posted by: none.unknown.com

I was referring to the layer being created in your content editpart, also
sometimes referred to as the diagram editpart. Looking at your first post
in detail, it seems you're not creating a layer in your DiagramEditPart.

If you want to go with the two figure strategy, in your DiagramEditPart you
need to first create a Figure (or layer) and give it a shaded border (the
size of empty space all around). Give that figure a stack layout and add to
it another figure that is your content pane (which is what should be
returned in DiagramEditPart's getContentPane() method). The content pane's
layout manager should be an XYLayout.

SnapToGrid has a property so you can change its origin. You don't need to
change the feedback layer's origin. Just make sure all coordinates are
being translated properly. Your post said something about moving the
feedback layer, but you don't need to do that either.

"Eric Heiker" <eric.heiker@gmail.com> wrote in message
news:elk4om$kon$1@utils.eclipse.org...
> Hi, thanks for your response.
>
> Which layer are you referring to?
>
> Also, I already have a separate figure as the content pane with a
> XYLayout. The problem is that the figure is not centered and the feedback
> and grid layers do not have their origin at the (0,0) point on the figure
> but the (0,0) point of the viewport.
>
> Pratik Shah wrote:
>> An easy hack is to give the layer a border.
>>
>> Otherwise you could add a separate figure (page) to the layer with a
>> stack layout or something. That page then becomes the content pane for
>> your editpart and would have the XYLayout.
>>
>> "Eric Heiker" <eric.heiker@gmail.com> wrote in message
>> news:el1uqr$2h2$1@utils.eclipse.org...
>>> Hi, I am making a graphics editing program using GEF and I need to be
>>> able to edit a fixed size (like 640x480), centered diagram. It needs to
>>> be zoomable and have a grid that has its origin in the upper-left corner
>>> of the diagram figure. Ideally it would also have rulers that are fitted
>>> to the diagram, but its not entirely necessary.
>>>
>>> This is a picture of what I'm trying to achieve:
>>> http://mediacraftlabs.com/eric/gef-layout.jpg
>>>
>>> Here are my current results:
>>> http://mediacraftlabs.com/eric/gef-bad-layout.jpg
>>>
>>> At the moment I am extending a ScalableRootEditPart and overriding the
>>> createLayers() method. There I move the scaled layers into a new layer
>>> called centerPane. A FlowLayout is applied to centerPane to try to make
>>> it centered, but for some reason it is only vertically centered and
>>> horizontally it is left-aligned.
>>>
>>> LayeredPane scaledLayers = getScaledLayers();
>>> layeredPane.remove(scaledLayers);
>>> Layer centerPane = new Layer();
>>> centerPane.add(scaledLayers);
>>> FlowLayout layout = new FlowLayout(false);
>>> layout.setMinorAlignment(FlowLayout.ALIGN_CENTER);
>>> layout.setMajorAlignment(FlowLayout.ALIGN_CENTER);
>>> layeredPane.addLayerAfter(centerPane, CENTER_LAYER,
>>> getLayer(HANDLE_LAYER));
>>>
>>> New layer structure:
>>>
>>> Root Layered Pane
>>>
Previous Topic:SnapTo : How to find nearest snap to point
Next Topic:DnD enablement
Goto Forum:
  


Current Time: Tue Apr 16 15:04:01 GMT 2024

Powered by FUDForum. Page generated in 0.15148 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top