java - Edge type changed to orthogonal, unable to click the edge -


i constructing directed edge using jung , changed edge type default setting orthogonal edge type. unable make edge clickable after changing edge type orthogonal. doing wrong ?

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.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 directedsparsegraph<string, string>();     graph.addedge("edge 1", "peer 1", "peer 2");     graph.addedge("edge 2", "peer 2", "peer 3");     graph.addedge("edge 3", "peer 3",  "peer 1");     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.orthogonal<>()); // 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() % 205);             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)) {                             graph newgraph = new directedsparsegraph<string, string>();                             newgraph.addedge("edge 5", "peer 1 ", "peer 2");                             newgraph.addedge("edge 6", "peer 2", "peer 3");                             newgraph.addedge("edge 7", "peer 3", "peer 1");                             layout<integer, string> graphlayout = new circlelayout(newgraph);                             visualizationviewer chartviewer = new visualizationviewer<>(graphlayout);                             jpanel temppanel = new jpanel();                             temppanel.add(chartviewer);                              jframe tempframe = new jframe("sample data ");                             tempframe.getcontentpane().add(temppanel);                             tempframe.pack();                             tempframe.setvisible(true);                                 }                     }                 }             });             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); }   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; } } 

i found mistake. problem defined orthogonal edgeshape generic <> operator. need define same define graph.

therefore, should have been:

tempviewer.getrendercontext().setedgeshapetransformer(new edgeshape.orthogonal<string, string>());  

here's complete edited code:

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 1", "peer 1", "peer 2"); graph.addedge("edge 2", "peer 2", "peer 3"); graph.addedge("edge 3", "peer 3",  "peer 1"); layout<string, string> layout = new circlelayout(graph); visualizationviewer<string, string> 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.orthogonal<string, string>()); // 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() % 205);         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)) {                         graph newgraph = new directedsparsegraph<string, string>();                         newgraph.addedge("edge 5", "peer 1 ", "peer 2");                         newgraph.addedge("edge 6", "peer 2", "peer 3");                         newgraph.addedge("edge 7", "peer 3", "peer 1");                         layout<string, string> graphlayout = new circlelayout(newgraph);                         visualizationviewer chartviewer = new visualizationviewer<>(graphlayout);                         jpanel temppanel = new jpanel();                         temppanel.add(chartviewer);                          jframe tempframe = new jframe("sample data ");                         tempframe.getcontentpane().add(temppanel);                         tempframe.pack();                         tempframe.setvisible(true);                             }                 }             }         });         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); }   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

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -