Results 1 to 8 of 8
  1. #1
    Mekonom is offline Member
    Join Date
    Nov 2009
    Posts
    71
    Rep Power
    0

    Default 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?

  2. #2
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

    Default

    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:
    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);
    		}
    	}
    The mouse movement event finds out which tree, if any, is near the mouse.
    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();
    	}

  3. #3
    Mekonom is offline Member
    Join Date
    Nov 2009
    Posts
    71
    Rep Power
    0

    Default

    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 :)

  4. #4
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

    Default

    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.

  5. #5
    Mekonom is offline Member
    Join Date
    Nov 2009
    Posts
    71
    Rep Power
    0

    Default

    yes.. it is Shape s = new Shape().... but it allways 0.0 point .strange :)

  6. #6
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

    Default

    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.

  7. #7
    Mekonom is offline Member
    Join Date
    Nov 2009
    Posts
    71
    Rep Power
    0

    Default

    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?

  8. #8
    Mekonom is offline Member
    Join Date
    Nov 2009
    Posts
    71
    Rep Power
    0

    Default

    I tryed to set corrdinates after creating and moving it with mouse but it adds new value then removes and 0.0

Similar Threads

  1. UML class diagram generator!
    By renegadeandy in forum Advanced Java
    Replies: 5
    Last Post: 04-11-2009, 07:08 AM
  2. UML Diagram creation!
    By renegadeandy in forum New To Java
    Replies: 16
    Last Post: 04-10-2009, 04:37 AM
  3. plz i need help ((ER diagram))
    By sweet angle in forum JDBC
    Replies: 9
    Last Post: 02-01-2009, 10:28 PM
  4. creating a RCP editor for external files
    By niretn in forum Eclipse
    Replies: 3
    Last Post: 11-11-2008, 08:45 PM
  5. UML diagram
    By jvasilj1 in forum New To Java
    Replies: 4
    Last Post: 03-08-2008, 06:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •