Changing the color of an edge using JGraphXAdapter

I'm using the JGraphT library, in particular JGraphXAdapter to display graphs using JGraphX. I would like to change the color of a few edges (not all of them). My question is, how can that be accomplished? (I know how to change the default style for all edges, but not how to change a single edge.) Please see the code below.

I'm using jgrapht-ext-0.9.1-uber.jar from the JGraphT 0.9.1 package.

package org.jgrapht.demo;

import java.awt.EventQueue;
import java.util.ArrayList;
import java.util.Collections;

import javax.swing.JFrame;

import org.jgrapht.ListenableGraph;
import org.jgrapht.ext.JGraphXAdapter;
import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.graph.ListenableDirectedGraph;

import com.mxgraph.layout.mxCircleLayout;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.util.mxConstants;

public class FiveSort extends JFrame {

  private static final long serialVersionUID = 1L;

  private JGraphXAdapter<Node, DefaultEdge> jgxAdapter;

  private static final int ARRAY_SIZE = 25;
  private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

  class Node {
    String label;
    int value;
    Node(String label, int value) {
      this.label = label;
      this.value = value;
    }
    @Override
    public String toString() {
      return label + ": " + value;
    }
  }

  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      @Override
      public void run() {
        new FiveSort();
      }
    });
  }

  public FiveSort() {
    initGUI();
    setLocationRelativeTo(null);
    setTitle("Five Sort");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setVisible(true);
  }

  public void initGUI() {
    ListenableGraph<Node, DefaultEdge> g =
        new ListenableDirectedGraph<Node, DefaultEdge>(DefaultEdge.class);

    jgxAdapter = new JGraphXAdapter<Node, DefaultEdge>(g);
    jgxAdapter.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_NOLABEL, "1");
    add(new mxGraphComponent(jgxAdapter));

    ArrayList<Integer> shuffle = new ArrayList<Integer>();
    for (int i = 0; i < ARRAY_SIZE; ++i) {
      shuffle.add(i);
    }
    Collections.shuffle(shuffle);

    Node[] n = new Node[ARRAY_SIZE];
    for (int i = 0; i < ARRAY_SIZE; ++i) {
      n[i] = new Node(ALPHABET.substring(i, i+1), shuffle.get(i));
      g.addVertex(n[i]);
      for (int j = 0; j < i; ++j) {
        g.addEdge(n[i], n[j]);
        g.addEdge(n[j], n[i]);
      }
    }

    mxCircleLayout layout = new mxCircleLayout(jgxAdapter);
    layout.execute(jgxAdapter.getDefaultParent());

    for (int i = 1; i < ARRAY_SIZE; ++i) {
      g.removeEdge(n[0],n[i]);
      // instead of removing the edge below I would like to change its color
      g.removeEdge(n[i],n[0]);
    }
  }

}


ANSWERS:


I found the answer to my question. Like this:

// set up a mapping between JGraphT edges and JGraphX cells
HashMap<DefaultEdge,com.mxgraph.model.mxICell> edgeToCellMap
  = jgxAdapter.getEdgeToCellMap();
// we can also set up a mapping between JGraphT vertices and JGraphX cells
HashMap<Node,com.mxgraph.model.mxICell> vertexToCellMap
  = jgxAdapter.getVertexToCellMap();

...

Object[] edgeCellArray = new Object[ARRAY_SIZE-1];

for (int i = 1; i < ARRAY_SIZE; ++i) {
  g.removeEdge(n[0],n[i]);
  edgeCellArray[i-1] = (Object)(edgeToCellMap.get(g.getEdge(n[i], n[0])));
}

// the following two lines are for learning the format of style strings
Map<String,Object> edgeCellStyle = jgxAdapter.getCellStyle(edgeCellArray[0]);
System.out.println(edgeCellStyle);

jgxAdapter.setCellStyle("strokeColor=#CCCC00", edgeCellArray);

// we can do something similar for vertices    
Object[] vertexCellArray = new Object[ARRAY_SIZE/2];

for (int i = 0; i < ARRAY_SIZE/2; ++i) {
  vertexCellArray[i] = (Object)(vertexToCellMap.get(n[i]));
}

// the following two lines are for learning the format of style strings    
Map<String,Object> vertexCellStyle = jgxAdapter.getCellStyle(vertexCellArray[0]);
System.out.println(vertexCellStyle);

jgxAdapter.setCellStyle("fillColor=#00CC00", vertexCellArray);

There may be a set of string constants including "strokeColor" and "fillColor" somewhere in the library but I haven't found them.



 MORE:


 ? Define if statement conditions by pairs, and on only one parameter of an object
 ? How to change color of selected connection in jgrapht or jgraphx?
 ? Reach n-th successor of a vertex in a branch
 ? JGraphT throws NoSuchMethodException when initializing case classes through ClassBasedVertexFactory
 ? Automatically create objects based on a list's elements
 ? Retrieve "n-1" and "n+1" element of each position in a for loop
 ? Return number of edges of each vertex in a digraph (jgrapht)
 ? Error "illegalArgumentException: no such vertex in graph" but vertexSet() returns the vertex
 ? Error when changing method parameter to an object (jgrapht library)
 ? Path beween tree nodes, cost between edges differs in direction of traversal