Results 1 to 8 of 8
Thread: creating diagram editor
- 11-09-2009, 12:33 AM #1
Member
- Join Date
- Nov 2009
- Posts
- 71
- Rep Power
- 0
creating diagram editor
Hi all.. I want to create diagram editor ..there will be rectaangles and I will connect them with clikcing each of them . I cerated something but on scren I can not choose rectangles ..It creates but not recognıze previous one or some one whic ı clicked whit mouse..any idea to correct this? or other way to creat such project?
- 11-10-2009, 07:06 PM #2
Senior Member
- Join Date
- Aug 2009
- Location
- Pittsburgh, PA
- Posts
- 282
- Rep Power
- 4
If your code just draws rectangles,
then there will indeed be no way to select one with the mouse.
Your code must keep track of what rectangle have been drawn
and then check this list when a mouse click arrives.
In one application, there is a list of trees, each represented as an object.
Each object has an associated hotSpot -- that is,
a Shape (circle) at a particular coordinate location.
One particular tree is the value of the global variable hotTree.
This tree is drawn in a different color.
Drawing the diagram and trees looks like this:
The mouse movement event finds out which tree, if any, is near the mouse.Java Code:@Override public void paint(Graphics g) { g.drawImage(diagram, 0, 0, this); // draw all the items on the Tree list for (Tree t : trees) { gOff.setColor((t==hotTree) ? hotColor : treeColor); gOff.fill(t.hotSpot); } }
That tree becomes the value of hotTree.
Java Code:public void mouseMoved(MouseEvent e) { TreeInfo oldHot = hotTree; hotTree = null; // if we are in range of one of 'trees', set hotTree for (Tree t : trees) { if (t.hotSpot.contains(1.0 * e.getX(), 1.0 * e.getY())) { hotTree = tree; break; } } if (oldHot != hotTree) repaint(); }
- 11-10-2009, 08:58 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 71
- Rep Power
- 0
Thans for reply but I try to reach object lıke creatıng array lıst and addıng them . then usıng Poınt p = e.getpoint and compareing if(s.contains(p)). but here problem is getlocation allways return 0.0 it isthe top left of window .when I am creating object it creates on screen but when I ask its location it says me that is on 0.0 point.But it works when I used Rectangle2d class from library .it gaves real corrdinates and choosing work.BUt I want to create my own object and rectangle :)
- 11-10-2009, 11:45 PM #4
Senior Member
- Join Date
- Aug 2009
- Location
- Pittsburgh, PA
- Posts
- 282
- Rep Power
- 4
You can create your own objects with four rectangle coordinates.
Or you might create a subclass of Rectangle.
The previous post mentions "if(s.contains(p))",
but fails to say what s is.
It would have to be a Shape or rectangle
describing where the rectange was drawn in the window.
- 11-11-2009, 12:48 AM #5
Member
- Join Date
- Nov 2009
- Posts
- 71
- Rep Power
- 0
yes.. it is Shape s = new Shape().... but it allways 0.0 point .strange :)
- 11-11-2009, 01:02 AM #6
Senior Member
- Join Date
- Aug 2009
- Location
- Pittsburgh, PA
- Posts
- 282
- Rep Power
- 4
The default location for a Shape is 0,0.
If the code draws it at x,y, then the Shape origin is still 0,0.
Only if the code sets the x,y value in the Shape will it have some other origin.
- 11-11-2009, 01:26 AM #7
Member
- Join Date
- Nov 2009
- Posts
- 71
- Rep Power
- 0
but ı am movıng ıt whıt mouse .. Whıt button creatıng lots of shape and movıng ıt wıth mouse. how orgın can be 0.0?
- 11-11-2009, 01:29 AM #8
Member
- Join Date
- Nov 2009
- Posts
- 71
- Rep Power
- 0
Similar Threads
-
UML class diagram generator!
By renegadeandy in forum Advanced JavaReplies: 5Last Post: 04-11-2009, 07:08 AM -
UML Diagram creation!
By renegadeandy in forum New To JavaReplies: 16Last Post: 04-10-2009, 04:37 AM -
plz i need help ((ER diagram))
By sweet angle in forum JDBCReplies: 9Last Post: 02-01-2009, 10:28 PM -
creating a RCP editor for external files
By niretn in forum EclipseReplies: 3Last Post: 11-11-2008, 08:45 PM -
UML diagram
By jvasilj1 in forum New To JavaReplies: 4Last Post: 03-08-2008, 06:29 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks