Bonjour, j'utilise l'api JGraph pour dessiner un graphe et je dois dessiner des liens dynamiques entre mes cellules. C'est à dire je selectionne une cellule source, je clicke sur le bouton pour la création de liens, je drague et lors du relachement sur la cellule cible, je crée mon lien.
J'arrive à créer mes liens (lignes) mais ca me fait un affichage bizarre lorsque je drague. J'utilise la méthode drawLine pour dessiner mon lien.
Je mets un exemple de mon code des méthodes mousePressed, mouseDragged et de mouseReleased:
Est ce que quelqu'un pourrait m'aider svp?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 @Override public void mousePressed(MouseEvent arg0) { // TODO Auto-generated method stub JGraph graph = getGraphForEvent(arg0); if (graph != null){ DefaultGraphCell cell = (DefaultGraphCell)graph.getSelectionCell(); graph.setMoveable(false); this.startport = graph.getDefaultPortForCell(cell); this.start = this.startport.getLocation(); } super.mousePressed(arg0); } @Override public void mouseDragged(MouseEvent arg0) { // TODO Auto-generated method stub JGraph graph = getGraphForEvent(arg0); Point2D current = arg0.getPoint(); Graphics g = graph.getGraphics(); if( graph != null) { //paintConnector(Color.RED, Color.BLACK, g ,graph, arg0.getPoint()); g.drawLine((int) start.getX(), (int) start.getY(), (int) current.getX(), (int) current.getY()); } super.mouseDragged(arg0); } @Override public void mouseReleased(MouseEvent arg0) { // TODO Auto-generated method stub JGraph graph = getGraphForEvent(arg0); if( graph != null) { DefaultGraphCell cell = (DefaultGraphCell)graph.getFirstCellForLocation(arg0.getX(), arg0.getY()); if( cell != null) { this.endport = graph.getDefaultPortForCell(cell); DefaultEdge edge = new DefaultEdge(); int arrow = GraphConstants.ARROW_CLASSIC; GraphConstants.setLineEnd(edge.getAttributes(), arrow); GraphConstants.setLineColor(edge.getAttributes(), Color.GREEN); GraphConstants.setLineWidth(edge.getAttributes(), 2); GraphConstants.setEndFill(edge.getAttributes(), true); edge.setSource(this.startport.getCell()); edge.setTarget(this.endport.getCell()); graph.getGraphLayoutCache().insertEdge(edge, this.startport.getCell(), this.endport.getCell()); } } graph.setMoveable(true); graph.setMarqueeHandler(previousMarqueeHandler); super.mouseReleased(arg0); }
Est ce que j'ai loupé qq chose?
Partager