AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

snap-to-grid functionality

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits
View previous topic :: View next topic  
Author Message
Dieter Schicker
Guest





PostPosted: Tue May 23, 2006 11:07 am    Post subject: snap-to-grid functionality Reply with quote



Hi,

I want to develop something like an editor application. It should be a
MDI application with a toolbox from which the user can drag elements to
the edit window. In this window there should be a grid with snap-to-grid
functionality.
Does someone know of a library/API that helps me getting the job done?

Many thanks in advance

Didi
Back to top
Andrey Kuznetsov
Guest





PostPosted: Wed May 24, 2006 3:07 pm    Post subject: Re: snap-to-grid functionality Reply with quote



Quote:
I want to develop something like an editor application. It should be a
MDI application with a toolbox from which the user can drag elements to
the edit window. In this window there should be a grid with snap-to-grid
functionality.
Does someone know of a library/API that helps me getting the job done?

you don't need any lib for snap-to-grid.
This is very easy to implement:

class GridMouseListener extends MouseAdapter {
int gridW = 50;
int gridH = 50;

public void mouseDragged(MouseEvent e) {
int x = (e.getX() / gridW) * gridW;
int y = (e.getY() / gridH) * gridH;

//further processing here
}
}

Andrey

--
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
Back to top
Dieter Schicker
Guest





PostPosted: Thu May 25, 2006 11:07 am    Post subject: Re: snap-to-grid functionality Reply with quote



Thank you for the code snippet! It's very easy indeed.

Didi


Andrey Kuznetsov wrote:
Quote:
I want to develop something like an editor application. It should be a
MDI application with a toolbox from which the user can drag elements to
the edit window. In this window there should be a grid with snap-to-grid
functionality.
Does someone know of a library/API that helps me getting the job done?


you don't need any lib for snap-to-grid.
This is very easy to implement:

class GridMouseListener extends MouseAdapter {
int gridW = 50;
int gridH = 50;

public void mouseDragged(MouseEvent e) {
int x = (e.getX() / gridW) * gridW;
int y = (e.getY() / gridH) * gridH;

//further processing here
}
}

Andrey
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.