1

I am creating different type of Edges by changing the DefaultEdgeStyle. Each style depends on the button clicked in the UI and the edges are being added by dragging from one vertex to another and not the insert edge method.

My problem is that when I want to get the edge style a null is returned.

Why it is happening? I'm using JgraphX (v6)

private void applyEdgeNew2(mxStylesheet stylesheet) {
    // Settings for edges
    Map<String, Object> edge = new HashMap<String, Object>();
    edge.put(mxConstants.STYLE_ROUNDED, true);
    edge.put(mxConstants.STYLE_ORTHOGONAL, false);
    edge.put(mxConstants.STYLE_EDGE, "elbowEdgeStyle");
    edge.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_CONNECTOR);
    edge.put(mxConstants.STYLE_ENDARROW, mxConstants.ARROW_CLASSIC);
    edge.put(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE);
    edge.put(mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER);
    edge.put(mxConstants.STYLE_STROKECOLOR, "#FF0000"); // default is #6482B9
    edge.put(mxConstants.STYLE_FONTCOLOR, "#446299");
    stylesheet.putCellStyle("edge2", edge);
    stylesheet.setDefaultEdgeStyle(edge);   
}

private void applyEdgeNew3(mxStylesheet stylesheet) {
    // Settings for edges
    Map<String, Object> edge = new HashMap<String, Object>();
    edge.put(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_SEGMENT);
    edge.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_CONNECTOR);
    edge.put(mxConstants.STYLE_ENDARROW, mxConstants.ARROW_CLASSIC);
    edge.put(mxConstants.STYLE_STROKECOLOR, "#6482B9"); // default is #6482B9
    stylesheet.putCellStyle("edge3", edge);
    stylesheet.setDefaultEdgeStyle(edge);   

}


graphComponent.getGraphControl().addMouseListener(new MouseListener() {

    @Override
    public void mouseReleased(MouseEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mousePressed(MouseEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mouseExited(MouseEvent arg0) {
        // TODO Auto-generated method stub

    }
    @Override
    public void mouseClicked(MouseEvent e) {
      mxCell cell =(mxCell) graphComponent.getCellAt(e.getX(), e.getY());
      if(cell != null)
      {
         System.out.println("Edge:"+cell.isEdge());
         System.out.println("Vertex:"+cell.isVertex());
         if (cell.isEdge()){

         System.out.println(cell.getStyle()); //Here is the problem(It return null value)
         System.out.println(cell.getId());
         System.out.println(cell.getSource());
         System.out.println(cell.getTarget());
     }
     if (cell.isVertex()){
         System.out.println(cell.getStyle());
         System.out.println(cell.getId());
     }
}

}

danivare
  • 91
  • 1
  • 1
  • 3

1 Answers1

1

null is returned, because each edge uses the defaultEdgeStyle, defined in the mxStylesheet.

The earlier created edges simply didn't update in the view. If you mess around with them a bit, you will recognize they will change their style to the new defined defaultEdgeStyle.

If you want different styles, you have to create the edges and give them a style parameter. This can either be a key of an entry you added in the mxStylesheet object of your graph, or a totally new style, e.g. strokeColor=#0ff00f

F. Lumnitz
  • 688
  • 4
  • 11