| View previous topic :: View next topic |
| Author |
Message |
Dieter Schicker Guest
|
Posted: Tue May 23, 2006 11:07 am Post subject: snap-to-grid functionality |
|
|
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
|
Posted: Wed May 24, 2006 3:07 pm Post subject: Re: snap-to-grid functionality |
|
|
| 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
|
Posted: Thu May 25, 2006 11:07 am Post subject: Re: snap-to-grid functionality |
|
|
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 |
|
 |
|