Dessigner des diagrammes UML avec JGraph

Résolu
soumairi Messages postés 3 Date d'inscription mercredi 9 juillet 2008 Statut Membre Dernière intervention 6 juin 2011 - 26 mai 2011 à 12:57
 Utilisateur anonyme - 27 mai 2011 à 18:47
salam
je souhaite realiser un outil d'aide à l'édition de diagramme de séquence codage en java (framework jgraph) et j'ai jamais utiliser jgraph
qlq un peut m'aider svp
merci

3 réponses

Utilisateur anonyme
26 mai 2011 à 19:03
Huumm...Même s'il est puissant, JGraph n'est pas un outil très simple à aborder. Il ne sera pas très facile de trouver de la code en français.

Regarde sur ces liens :
Javalobby
JGraphX
Freshmeat
forum JGraph

Par ailleurs, il faut que tu trouves un jar de l'application. J'en possède un avec un PDF en anglais qui m'a aidé. Contact moi par MP pour que je te transmette ça.

Sinon, voici le code basique ("Hello World !") :

 
import java.awt.Color;
import java.awt.geom.Rectangle2D;
 
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
 
import org.jgraph.JGraph;
import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.DefaultPort;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphModel;
 
public class HelloWorld {
public static void main(String[] args) {
// Construct Model and Graph
GraphModel model = new DefaultGraphModel();
JGraph graph = new JGraph(model);
 
// Control-drag should clone selection
graph.setCloneable(false);
// Enable edit without final RETURN keystroke
 
graph.setInvokesStopCellEditing(true);
// When over a cell, jump to its default port (we only have one, anyway)
 
graph.setJumpToDefaultPort(true);
 
// Insert all three cells in one call, so we need an array to store them
DefaultGraphCell[] cells = new DefaultGraphCell[5];
 
// Create Hello Vertex
cells[0] = createVertex("Hello", 20, 20, 40, 20, Color.BLUE, false);
 
// Create World Vertex
cells[1] = createVertex("World", 20, 80, 40, 20, Color.ORANGE, true);
cells[2] = createVertex("ess", 20, 140, 40, 20, Color.RED, true);
 
// Create Edge
DefaultEdge edge1 = new DefaultEdge();
DefaultEdge edge2 = new DefaultEdge();
 
// Fetch the ports from the new vertices, and connect them with the edge
 
edge1.setSource(cells[0].getChildAt(0));
edge1.setTarget(cells[1].getChildAt(0));
 
edge2.setSource(cells[0].getChildAt(0));
edge2.setTarget(cells[2].getChildAt(0));
 
cells[3] = edge1;
cells[4] = edge2;
 
// Set Arrow Style for edge
int arrow = GraphConstants.ARROW_CLASSIC;
GraphConstants.setLineEnd(edge1.getAttributes(), arrow);
GraphConstants.setEndFill(edge1.getAttributes(), true);
 
GraphConstants.setLineEnd(edge2.getAttributes(), arrow);
GraphConstants.setEndFill(edge2.getAttributes(), true);
 
// Insert the cells via the cache, so they get selected
graph.getGraphLayoutCache().insert(cells);
 
// Show in Frame
JFrame frame = new JFrame();
frame.getContentPane().add(new JScrollPane(graph));
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
 
public static DefaultGraphCell createVertex(String name, double x,
double y, double w, double h, Color bg, boolean raised) {
 
// Create vertex with the given name
DefaultGraphCell cell = new DefaultGraphCell(name);
 
// Set bounds
GraphConstants.setBounds(cell.getAttributes(), new Rectangle2D.Double(x, y, w, h));
 
// Set fill color
if (bg != null) {
GraphConstants.setGradientColor(cell.getAttributes(), Color.orange);
GraphConstants.setOpaque(cell.getAttributes(), true);
}
 
// Set raised border
if (raised)
GraphConstants.setBorder(cell.getAttributes(), BorderFactory.createRaisedBevelBorder());
else
// Set black border
GraphConstants.setBorderColor(cell.getAttributes(), Color.black);
// Add a Port
DefaultPort port = new DefaultPort();
cell.add(port);
port.setParent(cell);
 
return cell;
}
}


Quelques explications qui ne seront pas du luxe :
JGraph : l'objet JGraph comme son nom l'indique. Peut contenir un graphe ou pas.
DefaultGraphCell[] cells : le tableau qui va contenir toutes les cellules de ton graphe
createVertex() : méthode qui crée une cellule nommée "vertex"
DefaultEdge : un arc de ton graphe

Si tu as des questions, n'hésite pas. Tu peux les poster ici (c'est mieux pour tout le monde) ou par MP.
Lorsque j'aurais pas mal de temps devant moi, je pourrais surement faire un p'tit tuto dessus.

Bon courage !

--
Pylouq (actuellement jongleur de clavier AZERTY et de clavier QWERTZ)
3
soumairi Messages postés 3 Date d'inscription mercredi 9 juillet 2008 Statut Membre Dernière intervention 6 juin 2011
26 mai 2011 à 21:47
Merci
connaissez-vous un autre framework plus facile que jgraph ?
et merci
0
Utilisateur anonyme
27 mai 2011 à 18:47
Nop pas à ma connaissance. Cela ne t'empêche pas de chercher sur Google et je suis curieux de savoir s'il y a autre chose :D

Sinon, au pire, tu peux tout faire en Swing. Cela est moins complexe à aborder mais plus long d'implémentation.

--
Pylouq (actuellement jongleur de clavier AZERTY et de clavier QWERTZ)
0
Rejoignez-nous