The MindFusion Forums
Flow Diagramming Components >> Java Swing >> Diagram Link without destination
https://mindfusion.eu/Forum/YaBB.pl?num=1485445795

Message started by Gaurav Dubey on Jan 26th, 2017 at 3:49pm

Title: Diagram Link without destination
Post by Gaurav Dubey on Jan 26th, 2017 at 3:49pm
In our application, we are supporting different types of dynamic link creation using context menu, However it is 3 step process for us right now, first user have to select link type from context menu and then he has to again select component to draw the link.

Is it possible to raise DiagramLink option as soon as user select option from context menu, so that he only needs to select destination.

Currently DiagramLink api only create link if we have source and destination points.

Please suggest

Title: Re: Diagram Link without destination
Post by Slavcho on Jan 26th, 2017 at 5:29pm
You can create a link connected only to origin node like this -

Code (]
DiagramLink currentLink;
...
createLinkMenuItem.addActionListener(new ActionListener()
{
     public void actionPerformed(ActionEvent e)
     {
           DiagramNode origin = (DiagramNode)diagram.getActiveItem();
           currentLink = diagram.getFactory().createDiagramLink(origin, origin.getCenter());
           currentLink.setPen(new Pen(0, Color.gray, DashStyle.Dot));
     }
});[/code):



then update its end point position from mouseMoved event handler -
[code]
diagramView.addMouseMotionListener(new MouseAdapter()
{
    public void mouseMoved(MouseEvent e)
    {
        Point2D.Float diagramPoint = diagramView.deviceToDoc(e.getPoint());
        if (currentLink != null)
        {
             currentLink.setEndPoint(diagramPoint);
             currentLink.updateFromPoints();
             diagramView.repaint();
        }
    }
});


and connect it to destination node from nodeClicked handler -
[code]
public void nodeClicked(NodeEvent e)
{
     if (currentLink != null)
     {
           currentLink.setDestination(e.getNode());
           currentLink.setPen(new Pen(0, Color.black));
           currentLink = null;
     }
}[/code]

Regards,
Slavcho
Mindfusion

Title: Re: Diagram Link without destination
Post by Gaurav Dubey on Jan 27th, 2017 at 1:51pm
Thanks a lot for quick solution, it solves the problem

The MindFusion Forums » Powered by YaBB 2.6.11!
YaBB Forum Software © 2000-2024. All Rights Reserved.