2010-10-29 4 views
3

J'utilise JGraphX ​​pour afficher des données (graphiques discrets simples) et je voudrais savoir comment faire les choses suivantes avec la bibliothèque JGraphX:Personnalisation JGraphX ​​

  • Faire tous les bords inamovibles mais toujours permettre à la utilisateur pour créer une arête entre deux sommets
  • Rendre tous les sommets et arêtes non modifiables (ils ne peuvent pas modifier ce qui est affiché sur eux)
  • Comment puis-je obtenir le sommet ou le bord sélectionné à un moment donné?
  • Rendre toutes les boîtes de vertex non-applicables à l'utilisateur
  • Comment modifier la couleur de la boîte de chaque vertex?

Merci, ExtremeCoder

Répondre

6

Voici un exemple:

mxGraph graph = new mxGraph() 
{ 
    // Make all edges unmovable 
    public boolean isCellMovable(Object cell) 
    { 
    return !getModel().isEdge(cell); 
    } 

    // Make all vertex boxes unresizable 
    public boolean isCellResizable(Object cell) 
    { 
    return !getModel().isVertex(cell); 
    } 
}; 

// Make all vertices and edges uneditable 
graph.setCellsEditable(false); 

// Make all edges unbendable 
graph.setCellsBendable(false); 

// Get the selected vertex or edge 
System.out.println(graph.getSelectionCell()); 

// To insert a vertex with a given color: 
Object v1 = graph.insertVertex(parent, null, "Hello", 
      20, 20, 80, 30, "fillColor=#FF0000;"); 

// To modify the color of a vertex: 
graph.setCellStyles(mxConstants.STYLE_FILLCOLOR, "#00FF00", new Object[]{v1});