Bonjour,

j'ai une structure de données avec des relations parent/enfants, j'ai implémenté le modèle de Treemodel sans mention explicite des l'insertion de nœud parent et enfant, mais en utilisant seulement un lieu d'afficher mon modèle de données comme un jtree (MonTreeModel implements TreeModel), et ça marche bien. Il m’affiche bien mes données, je peux naviguer facilement.

J'ai essayé de faire ça pour afficher mes données comme un jgraph sans mention explicité des l'insertion des sommets, des arêtes ni des ports, mais seulement en utilisant un modèle (MonGraphModel implements GraphModel). J’ai essayé d’implémenter ma classe MonGraphModel mais, avec graphe plusieurs problèmes se présentent :
1. comment puis-je définir la méthodes isEdge , IsPort de moment que j’ai que la relation parent/enfant.
2. Es-ce que je dois faire l’insertion dans mon modèle ( MonGraphModel) pour qu’il créé les graphcell ( vertex , edge , Port ).
3. …etc


Je serais très heureux si vous pouviez m’aider à trouver un indice ou un exemple.

Merci ,

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
 
public class MonGraphModel implements GraphModel {
    MForm form ; 
    private Vector<GraphModelListener> graphModelListeners;
    private Vector<UndoableEditListener> undoableEditListeners;
    protected AttributeMap attributes;
    protected HashMap<Object, AttributeMap> Hashattributes; 
    protected int updateLevel;
        protected CompoundEdit compoundEdit;
        protected Collection currentUpdate;
        protected int x = -80; 
 
    public MonGraphModel(MForm f) {
 
        Mform = f;
        Hashattributes = new HashMap();
        graphModelListeners = new Vector<GraphModelListener>();
        undoableEditListeners = new Vector<UndoableEditListener>();
        updateLevel= 0;
        compoundEdit = null;
        currentUpdate = new ArrayList();
 
    }
    public boolean acceptsSource(Object edge, Object port) {
        return null;// reste à faire 
    }
    public boolean acceptsTarget(Object edge, Object port) {
        return null;// reste à faire 
    }
    public void addGraphModelListener(GraphModelListener l) {
        graphModelListeners.addElement(l);
    }
    public void addUndoableEditListener(UndoableEditListener listener) {
        undoableEditListeners.add( listener);
    }
    public void beginUpdate() {
        if (updateLevel == 0) {
            compoundEdit = createCompoundEdit();
        }
        updateLevel++;
    }
        protected CompoundEdit createCompoundEdit()
    {
            return new CompoundEdit();
        }
    public Map cloneCells(Object[] cells) {
 
        MComponent [] comp = ( MComponent[]) cells; 
        Map map = new Hashtable(); 
        for ( int i = 0 ; i < comp.length ; i ++){
            map.put(comp[i], comp[i].clone()) ;        
        }
        Iterator it = map.entrySet().iterator();
        Object obj, cell, parent ; 
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            obj = entry.getValue();
            cell = entry.getKey();
 
            // Replaces the cloned cell's parent with the parent's clone
            parent = getParent(cell);
            if (parent != null)
                parent = map.get(parent);
            if (parent != null)
                ((DefaultMutableTreeNode) parent)
                        .add((DefaultMutableTreeNode) obj);
 
            // Replaces the anchors for ports
            if (obj instanceof Port) {
                Object anchor = ((Port) obj).getAnchor();
                if (anchor != null)
                    ((Port) obj).setAnchor((Port) map.get(anchor));
            }
        }    
 
        return map;    
        }    
    public boolean contains(Object node) {
        MComponent comp = (MComponent) node;
        Component parentNode = null;
        while ((parentNode = ((MComponent) comp ).getParent()) != null){
            comp = parentNode;
        }
        return    form.contains(comp);
    }
    public Iterator edges(Object port) {
        ArrayList<MRoute> routes = form.getRoutes();
        Iterator<MRoute> it = routes.iterator();
        return it ;
    }
    public void edit(Map attributes, ConnectionSet cs, ParentMap pm,UndoableEdit[] e) {
        // TODO Auto-generated method stub
    }
    public void endUpdate() {
        updateLevel--;
        if (updateLevel == 0) {
            compoundEdit.end();
            _postEdit(compoundEdit);
            compoundEdit = null;
        }
    }
        protected void _postEdit(UndoableEdit e){
            UndoableEditEvent ev = new UndoableEditEvent(form, e);
            Enumeration cursor = ((Vector)undoableEditListeners.clone()).elements();
            while (cursor.hasMoreElements()) {
                ((UndoableEditListener)cursor.nextElement()).undoableEditHappened(ev);        
            }
        }
    public void execute(ExecutableChange change) {
        change.execute();
        beginUpdate();
        currentUpdate.add(change);
        endUpdate();
    }
    public AttributeMap getAttributes(Object cell) {
        if (Hashattributes.containsKey(cell)){
            attributes = Hashattributes.get(cell);    
        } else {
            x += 90; 
            attributes = new AttributeMap(); 
            int arrow = GraphConstants.ARROW_CLASSIC;
            GraphConstants.setBounds(attributes,  new Rectangle2D.Double
                    ( 20 , x , 80, 30));
            GraphConstants.setBackground(attributes,Color.green);
            GraphConstants.setGradientColor(attributes,Color.darkGray);
            GraphConstants.setOpaque(attributes, true);
            GraphConstants.setLineEnd(attributes, arrow);
            GraphConstants.setEndFill(attributes, true);
            Hashattributes.put( cell, attributes);
        }
        return      attributes ;    
    }
    public Object getChild(Object parent, int index) {
        MComponent comp = (MComponent) parent;
        return comp.getChild(index);
    }
    public int getChildCount(Object parent) {
        if (parent instanceof MComponent){
                return ((MComponent) parent).getChildCount();
        }else {
            return 0;
        }
    }
    public int getIndexOfChild(Object parent, Object child) {
        if (parent == null || child == null){
            return -1;
        }else {
            return ((MComponent) parent).getIndexOfChild((MComponent) child);
        }    
    }
    public int getIndexOfRoot(Object root) {
        if (root == null ) {
            return - 1; 
        } else {
            return 0; 
        }
 
    }
    public Object getParent(Object child) {
        if ((child != null && child instanceof MComponent)){
            if ( child != form ){
                return ((MComponent) child).getParent();
            } else {
                return null; 
            }    
        }else {
            return null;
        }            
    }
    public Object getRootAt(int index) {
        if ( index == 0 ){
            return form;    
        } 
        else {
            return form ; 
        }
    }
    public Object getRootAt() {
            return form ; 
    }
    public int getRootCount() {
        return 1;
    }
    public Object getSource(Object edge) {
        return null ; //???????????????????????????
    }
    public Object getTarget(Object edge) {
        return null; //??????????????????????????
    }
    public Object getValue(Object node) {
        if ( node instanceof MComponent){
            return node ; 
        }else {
            return null; 
        }
    }
    public void insert(Object[] roots, Map attributes, ConnectionSet cs, ParentMap pm, UndoableEdit[] edits) {
        ??????????????????????
    }
    public boolean isEdge(Object edge) {
        //?????????????????????????
    }
    public boolean isLeaf(Object component) {
        //???????????????????????????
    }
    public boolean isPort(Object port) {
        return false; //??????????????????????
    }
    public void remove(Object[] roots) {
        // TODO Auto-generated method stub
    }
    public void removeGraphModelListener(GraphModelListener l) {
        graphModelListeners.remove(l);;
    }
    public void removeUndoableEditListener(UndoableEditListener listener) {
        undoableEditListeners.remove(listener);
    }
    public void toBack(Object[] cells) {
    }
    public void toFront(Object[] cells) {
    }
    public Object valueForCellChanged(Object cell, Object newValue) {
        return null; 
    }
    protected void fireGraphChanged(Object source ,GraphModelEvent.GraphModelChange edit){
        GraphModelEvent e = new GraphModelEvent(source, edit);
 
        for (GraphModelListener gml : graphModelListeners) {
 
            gml.graphChanged(e);
 
        }    
    }
 
 
Merci