Results 1 to 4 of 4
Thread: Snapping algorithm
- 11-04-2008, 03:17 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 22
- Rep Power
- 0
Snapping algorithm
ok heres what i am trying to do.
i have a Jpanel is which i load an image. then the user presses 'generate' button to generate several instances of transparent JPanels with a white border. the user can drag these panels to position them over the image.
What i want to do is make a snap mode in which when activated will automatically snap these transparent panels to each others edges.
off the top of my head one idea that came was to x and y coordinate of all the 4 edges of each panel in an some sort of data structure and whenever the user drags a panel , constantly keep checking its x,y with the stored values and snap when required. however this seems like a not so elegant approach and with a lot of panels would be cumbersome.
Just wondering if anyone has any ideas/suggestions that could do it in a better way.
thanks
ankit
- 11-04-2008, 07:53 PM #2
Member
- Join Date
- Nov 2008
- Posts
- 22
- Rep Power
- 0
bumping....
anyone ?
- 11-04-2008, 08:04 PM #3
you could probably set it up so when the item being dragged is released it would only check then and move it to the closest edges. I'm not familiar with JPanel so I can't give too solid an example.
- 11-04-2008, 09:54 PM #4
What i want to do is make a snap mode in which when activated will automatically snap these transparent panels to each others edges.
There are always a lot of options in building something like this. Are these panels to be in a straight line or a rectangluar shape when snapped?
one idea that came was to x and y coordinate of all the 4 edges of each panel in an some sort of data structure and whenever the user drags a panel , constantly keep checking its x,y with the stored values and snap when required. however this seems like a not so elegant approach and with a lot of panels would be cumbersome.
Agreed. The components will keep the coordinates for you: you can call getBounds on each one and get the origin with the x, y fields. You can get the ne corner x value with either getMaxX or r.x + r.width (x and width fields of Rectangle).
The fun part is to design for fluid resizing. At the snap you could compute the size and location of the desired layout (line, rectangle of rows/columns or other layout) of the panels and adjust their locations relative to this rectangle with either the setBounds or the setLocation method called on each panel.
Similar Threads
-
Help of Thread and some Algorithm
By raghuylin in forum Threads and SynchronizationReplies: 1Last Post: 10-13-2008, 02:07 PM -
O(log n) algorithm help !!!!!!
By itseeker87 in forum New To JavaReplies: 8Last Post: 09-09-2008, 05:12 PM -
Help with algorithm
By susan in forum New To JavaReplies: 1Last Post: 07-13-2007, 10:26 PM -
Help me with this algorithm
By Marcus in forum Advanced JavaReplies: 3Last Post: 07-02-2007, 01:30 PM -
Help with Algorithm
By Daniel in forum Advanced JavaReplies: 2Last Post: 07-02-2007, 05:51 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks