Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Allow arrow movement, but keep connection to node (Read 2698 times)
tronied
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 17
Joined: May 7th, 2008
Allow arrow movement, but keep connection to node
Sep 7th, 2009 at 9:21am
Print Post  
If I have three nodes (boxes), and I create an arrow to connect two of them, I can drag an arrows endpoint to another node. I want to stop this from happening, but don't want to stop the user having the ability to move the arrow around the nodes border using setAllowMoveStart/End(false). Is there any way I can do this? I don't think I want to use anchor points as that will mean it is stuck to a certain point on the node, and I want to allow the user to specify the location of the endpoint.

I tried writing some code to detect and prevent this from happening, but it doesn't seem to do anything:

Code
Select All
            @Override
            public void itemModifying(ValidationEvent e) {
                if (e.getItem() instanceof Arrow) {
                    Arrow oArrow = (Arrow)e.getItem();
                    java.awt.geom.Point2D.Float oSource = oArrow.getControlPoints().get(0);
                    java.awt.geom.Point2D.Float oDestination = oArrow.getControlPoints().get(oArrow.getControlPoints().size() -1);
                    Node oFrom = oArrow.getOrigin();
                    Node oTo = oArrow.getDestination();

                    if ((oSource.getX() >= oFrom.getBounds().getX() && oSource.getX() <= oFrom.getBounds().getX() + oFrom.getBounds().getWidth()) &&
                        (oSource.getY() >= oFrom.getBounds().getY() && oSource.getY() <= oFrom.getBounds().getY() + oFrom.getBounds().getHeight())) {
                        //Ignore
                    } else {
                        double dNewX = oSource.getX();
                        double dNewY = oSource.getY();
                        if (oSource.getX() < oFrom.getBounds().getX()) { dNewX = oFrom.getBounds().getX(); }
                        if (oSource.getX() > oFrom.getBounds().getX() + oFrom.getBounds().getWidth()) { dNewX = oFrom.getBounds().getX() + oFrom.getBounds().getWidth(); }
                        if (oSource.getY() < oFrom.getBounds().getY()) { dNewY = oFrom.getBounds().getY(); }
                        if (oSource.getY() > oFrom.getBounds().getY() + oFrom.getBounds().getHeight()) { dNewY = oFrom.getBounds().getY() + oFrom.getBounds().getHeight(); }
                        oSource.setLocation(dNewX, dNewY);
                    }
                    //java.awt.geom.Point2D.Float oTemp = oArrow.getControlPoints().get(0); //Debugging
                    oArrow.setSnapToNodeBorder(false);
                    oArrow.updateFromPoints();
                    oArrow.setSnapToNodeBorder(true);
                    //oTemp = oArrow.getControlPoints().get(0); //Debugging
                }
            } 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Allow arrow movement, but keep connection to n
Reply #1 - Sep 7th, 2009 at 2:09pm
Print Post  
The control updates the arrow points according to the current mouse position after this event is raised, so your changes do not have any effect. ItemModifying is a validation event and the control expect you only to confirm or cancel the operation, but not set the points positions.

You could call setCancel(true) when there is no node under the mouse pointer, or when the node there is not one of the arrow ends. This would display the stop cursor and prevent the arrow from being connected to another node. However, the user will be able to drag the end points around the screen.

Stoyan
  
Back to top
 
IP Logged
 
tronied
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 17
Joined: May 7th, 2008
Re: Allow arrow movement, but keep connection to n
Reply #2 - Sep 7th, 2009 at 3:08pm
Print Post  
The setValid(false) worked great Grin Thanks!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint