java - JUNG - one edge never get's picked -


i using edge picking event see edge clicked. observed, see 1 edge never gets picked though edge being displayed. 1 click edge, display edge picked.

in code below, 1 edge never picked after have tried clicking of them (its either 1 of them 3 edges). why so, or 1 experiencing ? also, edge seems appear correctly if rotate graph 180 degrees.

package test;  import edu.uci.ics.jung.algorithms.layout.circlelayout; import edu.uci.ics.jung.algorithms.layout.layout; import edu.uci.ics.jung.graph.directedsparsegraph; import edu.uci.ics.jung.graph.directedsparsemultigraph; import edu.uci.ics.jung.graph.graph; import edu.uci.ics.jung.visualization.visualizationviewer; import edu.uci.ics.jung.visualization.control.crossoverscalingcontrol; import edu.uci.ics.jung.visualization.control.defaultmodalgraphmouse; import edu.uci.ics.jung.visualization.control.modalgraphmouse; import edu.uci.ics.jung.visualization.control.scalingcontrol; import edu.uci.ics.jung.visualization.decorators.edgeshape; import edu.uci.ics.jung.visualization.decorators.tostringlabeller; import edu.uci.ics.jung.visualization.picking.pickedstate; import java.awt.borderlayout; import java.awt.color; import java.awt.dimension; import java.awt.graphics; import java.awt.gridlayout; import java.awt.paint; import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.awt.event.itemevent; import java.awt.event.itemlistener; import java.util.collection; import javax.swing.borderfactory; import javax.swing.jbutton; import javax.swing.jcombobox; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel; import org.apache.commons.collections15.transformer; import org.apache.commons.collections15.functors.constanttransformer;  public class test2 { public static void main(string args[]) { graph graph = new directedsparsemultigraph<string, string>();                         graph.addedge("edge 5", "peer 1", "peer 2");                         graph.addedge("edge 6", "peer 1", "peer 2");                         graph.addedge("edge 7", "peer 1", "peer 2"); layout<integer, string> layout = new circlelayout(graph); visualizationviewer tempviewer = new visualizationviewer<>(layout); tempviewer.setpreferredsize(new dimension(700,700)); tempviewer.getrendercontext().setvertexlabeltransformer(new tostringlabeller()); tempviewer.setvertextooltiptransformer(new tostringlabeller()); tempviewer.getrendercontext().setarrowfillpainttransformer(new constanttransformer(color.lightgray)); defaultmodalgraphmouse graphmouse = new defaultmodalgraphmouse(); tempviewer.getrendercontext().setedgeshapetransformer(new edgeshape.bentline<>()); // if comment line, program works fine graphmouse.setmode(modalgraphmouse.mode.picking); transformer<string, paint> edgepaint = new transformer<string, paint>() {      @override     public paint transform(string graphedge) {         int redvalue = math.abs(graphedge.hashcode() % 235);         int greenvalue = math.abs(graphedge.hashcode() % 200);         int bluevalue = math.abs(graphedge.hashcode() % 175);          return new color(redvalue, greenvalue, bluevalue);      } }; tempviewer.getrendercontext().setedgedrawpainttransformer(edgepaint); tempviewer.setgraphmouse(graphmouse);  final pickedstate<string> pickedstate = tempviewer.getpickededgestate();         pickedstate.additemlistener(new itemlistener() {             @override             public void itemstatechanged(itemevent e) {                 object subject = e.getitem();                 if (subject instanceof string) {                     string edgepicked = (string) subject;                     if (pickedstate.ispicked(edgepicked)) {                         system.out.println("edge picked"  + edgepicked);                         }                 }             }         });         jpanel graphpanel = new jpanel(new borderlayout());         graphpanel.add(tempviewer, borderlayout.center);         jpanel controlpanel = addlegendcontrols(tempviewer, graph);         graphpanel.add(controlpanel, borderlayout.south);          jframe masterframe = new jframe();         masterframe.add(graphpanel);         masterframe.pack();         masterframe.setvisible(true);         masterframe.setdefaultcloseoperation(jframe.exit_on_close); }   static jpanel addlegendcontrols(visualizationviewer chartviewer, graph tempgraph) { jpanel masterpanel = new jpanel(new borderlayout()); jpanel secondpanel = new jpanel(new gridlayout(1, 2)); defaultmodalgraphmouse graphmouse = new defaultmodalgraphmouse(); chartviewer.setgraphmouse(graphmouse); jcombobox modebox = graphmouse.getmodecombobox(); modebox.additemlistener(graphmouse.getmodelistener()); graphmouse.setmode(modalgraphmouse.mode.transforming);  final scalingcontrol scalergraph = new crossoverscalingcontrol(); jbutton zoomplus = new jbutton("+"); zoomplus.addactionlistener(new actionlistener() {     public void actionperformed(actionevent e) {         scalergraph.scale(chartviewer, 1.1f, chartviewer.getcenter());     } }); jbutton zoomminus = new jbutton("-"); zoomminus.addactionlistener(new actionlistener() {     public void actionperformed(actionevent e) {         scalergraph.scale(chartviewer, 1 / 1.1f, chartviewer.getcenter());     } });  final int defaultrowsize = 10; jpanel legendbox = new jpanel(new gridlayout(defaultrowsize, 1)); int borderthickness = 2; legendbox.setborder(borderfactory.createlineborder(color.black, borderthickness)); jlabel legendlabel = new jlabel("    legend     "); legendbox.add(legendlabel); collection<string> graphedges = tempgraph.getedges(); ( string graphlabel : graphedges) {     color edgecolor = (color)chartviewer.getrendercontext().getedgedrawpainttransformer().transform(graphlabel);     jpanel circlepanel = new jpanel() {         protected void paintcomponent(graphics g) {              super.paintcomponent(g);              g.setcolor(edgecolor);             g.filloval(2, 9, 10, 10);          }      };      jlabel edgelabel = new jlabel("      " + graphlabel + "   sent from: " + tempgraph.getsource(graphlabel) + "  : " + tempgraph.getdest(graphlabel));     circlepanel.add(edgelabel);     legendbox.add(circlepanel);  }  jpanel modepanel = new jpanel(new gridlayout(1, 1)); modepanel.setborder(borderfactory.createtitledborder("mouse mode")); modepanel.add(modebox); secondpanel.add(modepanel); jpanel zoompanel = new jpanel(new gridlayout(1, 2)); zoompanel.setborder(borderfactory.createtitledborder("manual zoom controls")); zoompanel.add(zoomplus); zoompanel.add(zoomminus); secondpanel.add(zoompanel); masterpanel.add(secondpanel, borderlayout.south); masterpanel.add(legendbox, borderlayout.east); return masterpanel; } } 


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -