Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » how to snap to grid
how to snap to grid [message #117725] Mon, 16 February 2004 10:39 Go to next message
Eclipse UserFriend
Originally posted by: tranfy.hotmail.com

I have drawn a background grid by realize a customer figure named
sectionfigure as following:
protected void paintFigure(Graphics graphics) {
Rectangle rect = getBounds();
for (int r = rect.y + 10; r < rect.height + rect.y; r+=10) {
for (int c = rect.x + 10; c < rect.width + rect.x; c+=10) {
graphics.drawLine(c, r, c, r);
}
}
}

The sectionfigure is a container.Now I want to draw a element in the
container and make the element snap to grid when I drawing it . how I can
snap to grid ?
Thanks a lot!
Waiting for your answer.
Re: how to snap to grid [message #117749 is a reply to message #117725] Mon, 16 February 2004 12:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nospam.gmx.net

Hi Sunny,

there a many ways to implement a snap-to-grid.

One is, you create your own ChangeConstraintCommand.
The Command receives the desired coordinates,
transforms them into the snapped coordinates
and then applies them to the model element.

An other way is to extend a layoutmanager (Freeform) which
transforms the coodinates.
Perhaps in the setConstraint or layout method.

Regards, Ingo





"sunny" <tranfy@hotmail.com> wrote in message
news:c0q6kq$vtu$1@eclipse.org...
>
> I have drawn a background grid by realize a customer figure named
> sectionfigure as following:
> protected void paintFigure(Graphics graphics) {
> Rectangle rect = getBounds();
> for (int r = rect.y + 10; r < rect.height + rect.y; r+=10) {
> for (int c = rect.x + 10; c < rect.width + rect.x; c+=10) {
> graphics.drawLine(c, r, c, r);
> }
> }
> }
>
> The sectionfigure is a container.Now I want to draw a element in the
> container and make the element snap to grid when I drawing it . how I can
> snap to grid ?
> Thanks a lot!
> Waiting for your answer.
>
Re: how to snap to grid [message #117808 is a reply to message #117725] Mon, 16 February 2004 18:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Open the Logic editor.
From View menu, enable snap-to-grid.
voila.

See the new class SnapToGrid

"sunny" <tranfy@hotmail.com> wrote in message
news:c0q6kq$vtu$1@eclipse.org...
>
> I have drawn a background grid by realize a customer figure named
> sectionfigure as following:
> protected void paintFigure(Graphics graphics) {
> Rectangle rect = getBounds();
> for (int r = rect.y + 10; r < rect.height + rect.y; r+=10) {
> for (int c = rect.x + 10; c < rect.width + rect.x; c+=10) {
> graphics.drawLine(c, r, c, r);
> }
> }
> }
>
> The sectionfigure is a container.Now I want to draw a element in the
> container and make the element snap to grid when I drawing it . how I can
> snap to grid ?
> Thanks a lot!
> Waiting for your answer.
>
Re: how to snap to grid [message #117907 is a reply to message #117808] Tue, 17 February 2004 04:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tranfy.hotmail.com

My gef logic exmaple's version is 2.1.1 and when I run it ,I can not find
snap-to-grid option in the View menu.
Why?




Randy Hudson wrote:

> Open the Logic editor.
> From View menu, enable snap-to-grid.
> voila.

> See the new class SnapToGrid

> "sunny" <tranfy@hotmail.com> wrote in message
> news:c0q6kq$vtu$1@eclipse.org...
> >
> > I have drawn a background grid by realize a customer figure named
> > sectionfigure as following:
> > protected void paintFigure(Graphics graphics) {
> > Rectangle rect = getBounds();
> > for (int r = rect.y + 10; r < rect.height + rect.y; r+=10) {
> > for (int c = rect.x + 10; c < rect.width + rect.x; c+=10) {
> > graphics.drawLine(c, r, c, r);
> > }
> > }
> > }
> >
> > The sectionfigure is a container.Now I want to draw a element in the
> > container and make the element snap to grid when I drawing it . how I can
> > snap to grid ?
> > Thanks a lot!
> > Waiting for your answer.
> >
Re: how to snap to grid [message #117919 is a reply to message #117749] Tue, 17 February 2004 04:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tranfy.hotmail.com

My puzzle is that in my sectionfigure , I realize the background grid by
drawing line and these lines are actual some dots. When I draw a new
element ,I don't know how to get these dots coordinates , so I can not set
new location for the element.
How I can get the dot(background grid) coordinate?
Please give me some advice.
Thanks very much!



Ingo Koch wrote:

> Hi Sunny,

> there a many ways to implement a snap-to-grid.

> One is, you create your own ChangeConstraintCommand.
> The Command receives the desired coordinates,
> transforms them into the snapped coordinates
> and then applies them to the model element.

> An other way is to extend a layoutmanager (Freeform) which
> transforms the coodinates.
> Perhaps in the setConstraint or layout method.

> Regards, Ingo





> "sunny" <tranfy@hotmail.com> wrote in message
> news:c0q6kq$vtu$1@eclipse.org...
> >
> > I have drawn a background grid by realize a customer figure named
> > sectionfigure as following:
> > protected void paintFigure(Graphics graphics) {
> > Rectangle rect = getBounds();
> > for (int r = rect.y + 10; r < rect.height + rect.y; r+=10) {
> > for (int c = rect.x + 10; c < rect.width + rect.x; c+=10) {
> > graphics.drawLine(c, r, c, r);
> > }
> > }
> > }
> >
> > The sectionfigure is a container.Now I want to draw a element in the
> > container and make the element snap to grid when I drawing it . how I can
> > snap to grid ?
> > Thanks a lot!
> > Waiting for your answer.
> >
Re: how to snap to grid [message #117956 is a reply to message #117919] Tue, 17 February 2004 09:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nospam.gmx.net

If you insist on implementing your own snap to grid, since
2.1.1 doesn?t support it (but the latest integration builds do),
a little hint:

int newX = GRIDSIZE * (int)Math.round ( (double) oldX / (double)
GRIDSIZE ) + OFFSET;

Also a good point to implement this is in your editpolicy?s
#getChangeConstraintCommand().

Regards, Ingo





"sunny" <tranfy@hotmail.com> wrote in message
news:c0s4th$be1$1@eclipse.org...
>
> My puzzle is that in my sectionfigure , I realize the background grid by
> drawing line and these lines are actual some dots. When I draw a new
> element ,I don't know how to get these dots coordinates , so I can not set
> new location for the element.
> How I can get the dot(background grid) coordinate?
> Please give me some advice.
> Thanks very much!
>
>
>
> Ingo Koch wrote:
>
> > Hi Sunny,
>
> > there a many ways to implement a snap-to-grid.
>
> > One is, you create your own ChangeConstraintCommand.
> > The Command receives the desired coordinates,
> > transforms them into the snapped coordinates
> > and then applies them to the model element.
>
> > An other way is to extend a layoutmanager (Freeform) which
> > transforms the coodinates.
> > Perhaps in the setConstraint or layout method.
>
> > Regards, Ingo
>
>
>
>
>
> > "sunny" <tranfy@hotmail.com> wrote in message
> > news:c0q6kq$vtu$1@eclipse.org...
> > >
> > > I have drawn a background grid by realize a customer figure named
> > > sectionfigure as following:
> > > protected void paintFigure(Graphics graphics) {
> > > Rectangle rect = getBounds();
> > > for (int r = rect.y + 10; r < rect.height + rect.y; r+=10) {
> > > for (int c = rect.x + 10; c < rect.width + rect.x; c+=10) {
> > > graphics.drawLine(c, r, c, r);
> > > }
> > > }
> > > }
> > >
> > > The sectionfigure is a container.Now I want to draw a element in the
> > > container and make the element snap to grid when I drawing it . how I
can
> > > snap to grid ?
> > > Thanks a lot!
> > > Waiting for your answer.
> > >
>
>
Re: how to snap to grid [message #118045 is a reply to message #117907] Tue, 17 February 2004 15:38 Go to previous message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Because it is only in 3.0.

"sunny" <tranfy@hotmail.com> wrote in message
news:c0s460$aqc$1@eclipse.org...
>
> My gef logic exmaple's version is 2.1.1 and when I run it ,I can not find
> snap-to-grid option in the View menu.
> Why?
>
>
>
>
> Randy Hudson wrote:
>
> > Open the Logic editor.
> > From View menu, enable snap-to-grid.
> > voila.
>
> > See the new class SnapToGrid
>
> > "sunny" <tranfy@hotmail.com> wrote in message
> > news:c0q6kq$vtu$1@eclipse.org...
> > >
> > > I have drawn a background grid by realize a customer figure named
> > > sectionfigure as following:
> > > protected void paintFigure(Graphics graphics) {
> > > Rectangle rect = getBounds();
> > > for (int r = rect.y + 10; r < rect.height + rect.y; r+=10) {
> > > for (int c = rect.x + 10; c < rect.width + rect.x; c+=10) {
> > > graphics.drawLine(c, r, c, r);
> > > }
> > > }
> > > }
> > >
> > > The sectionfigure is a container.Now I want to draw a element in the
> > > container and make the element snap to grid when I drawing it . how I
can
> > > snap to grid ?
> > > Thanks a lot!
> > > Waiting for your answer.
> > >
>
>
Previous Topic:bendpoints command
Next Topic:Getting the active editor
Goto Forum:
  


Current Time: Sun Nov 03 06:57:44 GMT 2024

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

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

Back to the top