Results 1 to 4 of 4

Thread: Diagram editor in java

  1. #1
    Join Date
    Nov 2009
    Posts
    583

    Diagram editor in java

    Hi
    I have done some programs in java. Now I want to create a diagram editor. My idea is , there will be a rectangle and I will connect them with clicking each of them. I created a rectangle on the screen but I can not choose rectangles. It creates but not recognıze previous one or some one which I clicked with the mouse. Any idea to correct this problem or nay other way round to create such a project. any help will be appreciated. Thanks in advance.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Diagram editor in java

    You said 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 the example there is a list of trees, each represented as an object. Each object has an associated hotsp i.e. a Shape (circle) at a particular coordinate location. One particular tree is the value of the global variable hottr. This tree is drawn in a different color.
    Code:
    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.hotsp);
    		}
    	}
    Code:
    public void mouseMoved(MouseEvent e) {
    		TreeInfo oldHot = hottr;
    		hottr = null;
    		// if we are in range of one of 'trees', set hottr
    		for (Tree t : trees) {
    			if (t.hotSpot.contains(1.0 * e.getX(), 1.0 * e.getY())) {
    				hottr = tree;
    				break;
    			}
    		}
    		if (oldHot != hottr) repaint();
    	}

  3. #3
    Join Date
    Nov 2009
    Posts
    583

    Re: Diagram editor in java

    Thanks for your reply.
    I tried to create object like creating array list and adding them, then usıng Poınt p = e.getpoint and compareing if(s.contains(p)). But the problem is getlocation always return 0.0 it is located at the top left of the 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 gave real coordinates and choosing work.But I want to create my own object and rectangle

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Diagram editor in java

    Hi
    The best idea is to 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 rectangle was drawn in the window. Check your program for the same and if any problem then post by your query.

Similar Threads

  1. Replies: 6
    Last Post: 20-12-2011, 07:04 PM
  2. Java editor for palm device!
    By Honey Singh in forum Software Development
    Replies: 4
    Last Post: 15-09-2010, 05:17 AM
  3. Best editor for java
    By HardWeaR in forum Windows Software
    Replies: 3
    Last Post: 24-11-2009, 09:47 AM
  4. Gliffy Online Diagram Editor
    By Jeffrey in forum Reviews
    Replies: 3
    Last Post: 11-11-2009, 10:45 AM
  5. JAVA WYSIWYG Editor information
    By WeezY in forum Software Development
    Replies: 4
    Last Post: 08-11-2009, 02:09 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,900,070.98601 seconds with 17 queries