forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxGraphModel.java
More file actions
2637 lines (2290 loc) · 55.3 KB
/
mxGraphModel.java
File metadata and controls
2637 lines (2290 loc) · 55.3 KB
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (c) 2007, Gaudenz Alder
*/
package com.mxgraph.model;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.mxgraph.util.mxEvent;
import com.mxgraph.util.mxEventObject;
import com.mxgraph.util.mxEventSource;
import com.mxgraph.util.mxPoint;
import com.mxgraph.util.mxUndoableEdit;
/**
* Extends mxEventSource to implement a graph model. The graph model acts as
* a wrapper around the cells which are in charge of storing the actual graph
* datastructure. The model acts as a transactional wrapper with event
* notification for all changes, whereas the cells contain the atomic
* operations for updating the actual datastructure.
*
* Layers:
*
* The cell hierarchy in the model must have a top-level root cell which
* contains the layers (typically one default layer), which in turn contain the
* top-level cells of the layers. This means each cell is contained in a layer.
* If no layers are required, then all new cells should be added to the default
* layer.
*
* Layers are useful for hiding and showing groups of cells, or for placing
* groups of cells on top of other cells in the display. To identify a layer,
* the <isLayer> function is used. It returns true if the parent of the given
* cell is the root of the model.
*
* This class fires the following events:
*
* mxEvent.CHANGE fires when an undoable edit is dispatched. The <code>edit</code>
* property contains the mxUndoableEdit. The <code>changes</code> property
* contains the list of undoable changes inside the undoable edit. The changes
* property is deprecated, please use edit.getChanges() instead.
*
* mxEvent.EXECUTE fires between begin- and endUpdate and after an atomic
* change was executed in the model. The <code>change</code> property contains
* the atomic change that was executed.
*
* mxEvent.BEGIN_UPDATE fires after the updateLevel was incremented in
* beginUpdate. This event contains no properties.
*
* mxEvent.END_UPDATE fires after the updateLevel was decreased in endUpdate
* but before any notification or change dispatching. The <code>edit</code>
* property contains the current mxUndoableEdit.
*
* mxEvent.BEFORE_UNDO fires before the change is dispatched after the update
* level has reached 0 in endUpdate. The <code>edit</code> property contains
* the current mxUndoableEdit.
*
* mxEvent.UNDO fires after the change was dispatched in endUpdate. The
* <code>edit</code> property contains the current mxUndoableEdit.
*/
public class mxGraphModel extends mxEventSource implements mxIGraphModel,
Serializable
{
private static final Logger log = Logger.getLogger(mxGraphModel.class.getName());
/**
* Holds the root cell, which in turn contains the cells that represent the
* layers of the diagram as child cells. That is, the actual element of the
* diagram are supposed to live in the third generation of cells and below.
*/
protected mxICell root;
/**
* Maps from Ids to cells.
*/
protected Map<String, Object> cells;
/**
* Specifies if edges should automatically be moved into the nearest common
* ancestor of their terminals. Default is true.
*/
protected boolean maintainEdgeParent = true;
/**
* Specifies if the model should automatically create Ids for new cells.
* Default is true.
*/
protected boolean createIds = true;
/**
* Specifies the next Id to be created. Initial value is 0.
*/
protected int nextId = 0;
/**
* Holds the changes for the current transaction. If the transaction is
* closed then a new object is created for this variable using
* createUndoableEdit.
*/
protected transient mxUndoableEdit currentEdit;
/**
* Counter for the depth of nested transactions. Each call to beginUpdate
* increments this counter and each call to endUpdate decrements it. When
* the counter reaches 0, the transaction is closed and the respective
* events are fired. Initial value is 0.
*/
protected transient int updateLevel = 0;
/**
*
*/
protected transient boolean endingUpdate = false;
/**
* Constructs a new empty graph model.
*/
public mxGraphModel()
{
this(null);
}
/**
* Constructs a new graph model. If no root is specified
* then a new root mxCell with a default layer is created.
*
* @param root Cell that represents the root cell.
*/
public mxGraphModel(Object root)
{
currentEdit = createUndoableEdit();
if (root != null)
{
setRoot(root);
}
else
{
clear();
}
}
/**
* Sets a new root using createRoot.
*/
public void clear()
{
setRoot(createRoot());
}
/**
*
*/
public int getUpdateLevel()
{
return updateLevel;
}
/**
* Creates a new root cell with a default layer (child 0).
*/
public Object createRoot()
{
mxCell root = new mxCell();
root.insert(new mxCell());
return root;
}
/**
* Returns the internal lookup table that is used to map from Ids to cells.
*/
public Map<String, Object> getCells()
{
return cells;
}
/**
* Returns the cell for the specified Id or null if no cell can be
* found for the given Id.
*
* @param id A string representing the Id of the cell.
* @return Returns the cell for the given Id.
*/
public Object getCell(String id)
{
Object result = null;
if (cells != null)
{
result = cells.get(id);
}
return result;
}
/**
* Returns true if the model automatically update parents of edges so that
* the edge is contained in the nearest-common-ancestor of its terminals.
*
* @return Returns true if the model maintains edge parents.
*/
public boolean isMaintainEdgeParent()
{
return maintainEdgeParent;
}
/**
* Specifies if the model automatically updates parents of edges so that
* the edge is contained in the nearest-common-ancestor of its terminals.
*
* @param maintainEdgeParent Boolean indicating if the model should
* maintain edge parents.
*/
public void setMaintainEdgeParent(boolean maintainEdgeParent)
{
this.maintainEdgeParent = maintainEdgeParent;
}
/**
* Returns true if the model automatically creates Ids and resolves Id
* collisions.
*
* @return Returns true if the model creates Ids.
*/
public boolean isCreateIds()
{
return createIds;
}
/**
* Specifies if the model automatically creates Ids for new cells and
* resolves Id collisions.
*
* @param value Boolean indicating if the model should created Ids.
*/
public void setCreateIds(boolean value)
{
createIds = value;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#getRoot()
*/
public Object getRoot()
{
return root;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#setRoot(Object)
*/
public Object setRoot(Object root)
{
execute(new mxRootChange(this, root));
return root;
}
/**
* Inner callback to change the root of the model and update the internal
* datastructures, such as cells and nextId. Returns the previous root.
*/
protected Object rootChanged(Object root)
{
Object oldRoot = this.root;
this.root = (mxICell) root;
// Resets counters and datastructures
nextId = 0;
cells = null;
cellAdded(root);
return oldRoot;
}
/**
* Creates a new undoable edit.
*/
protected mxUndoableEdit createUndoableEdit()
{
return new mxUndoableEdit(this)
{
public void dispatch()
{
// LATER: Remove changes property (deprecated)
((mxGraphModel) source).fireEvent(new mxEventObject(
mxEvent.CHANGE, "edit", this, "changes", changes));
}
};
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#cloneCells(Object[], boolean)
*/
public Object[] cloneCells(Object[] cells, boolean includeChildren)
{
Map<Object, Object> mapping = new Hashtable<Object, Object>();
Object[] clones = new Object[cells.length];
for (int i = 0; i < cells.length; i++)
{
try
{
clones[i] = cloneCell(cells[i], mapping, includeChildren);
}
catch (CloneNotSupportedException e)
{
log.log(Level.SEVERE, "Failed to clone cells", e);
}
}
for (int i = 0; i < cells.length; i++)
{
restoreClone(clones[i], cells[i], mapping);
}
return clones;
}
/**
* Inner helper method for cloning cells recursively.
*/
protected Object cloneCell(Object cell, Map<Object, Object> mapping,
boolean includeChildren) throws CloneNotSupportedException
{
if (cell instanceof mxICell)
{
mxICell mxc = (mxICell) ((mxICell) cell).clone();
mapping.put(cell, mxc);
if (includeChildren)
{
int childCount = getChildCount(cell);
for (int i = 0; i < childCount; i++)
{
Object clone = cloneCell(getChildAt(cell, i), mapping, true);
mxc.insert((mxICell) clone);
}
}
return mxc;
}
return null;
}
/**
* Inner helper method for restoring the connections in
* a network of cloned cells.
*/
protected void restoreClone(Object clone, Object cell,
Map<Object, Object> mapping)
{
if (clone instanceof mxICell)
{
mxICell mxc = (mxICell) clone;
Object source = getTerminal(cell, true);
if (source instanceof mxICell)
{
mxICell tmp = (mxICell) mapping.get(source);
if (tmp != null)
{
tmp.insertEdge(mxc, true);
}
}
Object target = getTerminal(cell, false);
if (target instanceof mxICell)
{
mxICell tmp = (mxICell) mapping.get(target);
if (tmp != null)
{
tmp.insertEdge(mxc, false);
}
}
}
int childCount = getChildCount(clone);
for (int i = 0; i < childCount; i++)
{
restoreClone(getChildAt(clone, i), getChildAt(cell, i), mapping);
}
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#isAncestor(Object, Object)
*/
public boolean isAncestor(Object parent, Object child)
{
while (child != null && child != parent)
{
child = getParent(child);
}
return child == parent;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#contains(Object)
*/
public boolean contains(Object cell)
{
return isAncestor(getRoot(), cell);
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#getParent(Object)
*/
public Object getParent(Object child)
{
return (child instanceof mxICell) ? ((mxICell) child).getParent()
: null;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#add(Object, Object, int)
*/
public Object add(Object parent, Object child, int index)
{
if (child != parent && parent != null && child != null)
{
boolean parentChanged = parent != getParent(child);
execute(new mxChildChange(this, parent, child, index));
// Maintains the edges parents by moving the edges
// into the nearest common ancestor of its
// terminals
if (maintainEdgeParent && parentChanged)
{
updateEdgeParents(child);
}
}
return child;
}
/**
* Invoked after a cell has been added to a parent. This recursively
* creates an Id for the new cell and/or resolves Id collisions.
*
* @param cell Cell that has been added.
*/
protected void cellAdded(Object cell)
{
if (cell instanceof mxICell)
{
mxICell mxc = (mxICell) cell;
if (mxc.getId() == null && isCreateIds())
{
mxc.setId(createId(cell));
}
if (mxc.getId() != null)
{
Object collision = getCell(mxc.getId());
if (collision != cell)
{
while (collision != null)
{
mxc.setId(createId(cell));
collision = getCell(mxc.getId());
}
if (cells == null)
{
cells = new Hashtable<String, Object>();
}
cells.put(mxc.getId(), cell);
}
}
// Makes sure IDs of deleted cells are not reused
try
{
int id = Integer.parseInt(mxc.getId());
nextId = Math.max(nextId, id + 1);
}
catch (NumberFormatException e)
{
// most likely this just means a custom cell id and that it's
// not a simple number - should be safe to skip
log.log(Level.FINEST, "Failed to parse cell id", e);
}
int childCount = mxc.getChildCount();
for (int i = 0; i < childCount; i++)
{
cellAdded(mxc.getChildAt(i));
}
}
}
/**
* Creates a new Id for the given cell and increments the global counter
* for creating new Ids.
*
* @param cell Cell for which a new Id should be created.
* @return Returns a new Id for the given cell.
*/
public String createId(Object cell)
{
String id = String.valueOf(nextId);
nextId++;
return id;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#remove(Object)
*/
public Object remove(Object cell)
{
if (cell == root)
{
setRoot(null);
}
else if (getParent(cell) != null)
{
execute(new mxChildChange(this, null, cell));
}
return cell;
}
/**
* Invoked after a cell has been removed from the model. This recursively
* removes the cell from its terminals and removes the mapping from the Id
* to the cell.
*
* @param cell Cell that has been removed.
*/
protected void cellRemoved(Object cell)
{
if (cell instanceof mxICell)
{
mxICell mxc = (mxICell) cell;
int childCount = mxc.getChildCount();
for (int i = 0; i < childCount; i++)
{
cellRemoved(mxc.getChildAt(i));
}
if (cells != null && mxc.getId() != null)
{
cells.remove(mxc.getId());
}
}
}
/**
* Inner callback to update the parent of a cell using mxCell.insert
* on the parent and return the previous parent.
*/
protected Object parentForCellChanged(Object cell, Object parent, int index)
{
mxICell child = (mxICell) cell;
mxICell previous = (mxICell) getParent(cell);
if (parent != null)
{
if (parent != previous || previous.getIndex(child) != index)
{
((mxICell) parent).insert(child, index);
}
}
else if (previous != null)
{
int oldIndex = previous.getIndex(child);
previous.remove(oldIndex);
}
// Checks if the previous parent was already in the
// model and avoids calling cellAdded if it was.
if (!contains(previous) && parent != null)
{
cellAdded(cell);
}
else if (parent == null)
{
cellRemoved(cell);
}
return previous;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#getChildCount(Object)
*/
public int getChildCount(Object cell)
{
return (cell instanceof mxICell) ? ((mxICell) cell).getChildCount() : 0;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#getChildAt(Object, int)
*/
public Object getChildAt(Object parent, int index)
{
return (parent instanceof mxICell) ? ((mxICell) parent)
.getChildAt(index) : null;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#getTerminal(Object, boolean)
*/
public Object getTerminal(Object edge, boolean isSource)
{
return (edge instanceof mxICell) ? ((mxICell) edge)
.getTerminal(isSource) : null;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#setTerminal(Object, Object, boolean)
*/
public Object setTerminal(Object edge, Object terminal, boolean isSource)
{
boolean terminalChanged = terminal != getTerminal(edge, isSource);
execute(new mxTerminalChange(this, edge, terminal, isSource));
if (maintainEdgeParent && terminalChanged)
{
updateEdgeParent(edge, getRoot());
}
return terminal;
}
/**
* Inner helper function to update the terminal of the edge using
* mxCell.insertEdge and return the previous terminal.
*/
protected Object terminalForCellChanged(Object edge, Object terminal,
boolean isSource)
{
mxICell previous = (mxICell) getTerminal(edge, isSource);
if (terminal != null)
{
((mxICell) terminal).insertEdge((mxICell) edge, isSource);
}
else if (previous != null)
{
previous.removeEdge((mxICell) edge, isSource);
}
return previous;
}
/**
* Updates the parents of the edges connected to the given cell and all its
* descendants so that each edge is contained in the nearest common
* ancestor.
*
* @param cell Cell whose edges should be checked and updated.
*/
public void updateEdgeParents(Object cell)
{
updateEdgeParents(cell, getRoot());
}
/**
* Updates the parents of the edges connected to the given cell and all its
* descendants so that the edge is contained in the nearest-common-ancestor.
*
* @param cell Cell whose edges should be checked and updated.
* @param root Root of the cell hierarchy that contains all cells.
*/
public void updateEdgeParents(Object cell, Object root)
{
// Updates edges on children first
int childCount = getChildCount(cell);
for (int i = 0; i < childCount; i++)
{
Object child = getChildAt(cell, i);
updateEdgeParents(child, root);
}
// Updates the parents of all connected edges
int edgeCount = getEdgeCount(cell);
List<Object> edges = new ArrayList<Object>(edgeCount);
for (int i = 0; i < edgeCount; i++)
{
edges.add(getEdgeAt(cell, i));
}
Iterator<Object> it = edges.iterator();
while (it.hasNext())
{
Object edge = it.next();
// Updates edge parent if edge and child have
// a common root node (does not need to be the
// model root node)
if (isAncestor(root, edge))
{
updateEdgeParent(edge, root);
}
}
}
/**
* Inner helper method to update the parent of the specified edge to the
* nearest-common-ancestor of its two terminals.
*
* @param edge Specifies the edge to be updated.
* @param root Current root of the model.
*/
public void updateEdgeParent(Object edge, Object root)
{
Object source = getTerminal(edge, true);
Object target = getTerminal(edge, false);
Object cell = null;
// Uses the first non-relative descendants of the source terminal
while (source != null && !isEdge(source) &&
getGeometry(source) != null && getGeometry(source).isRelative())
{
source = getParent(source);
}
// Uses the first non-relative descendants of the target terminal
while (target != null && !isEdge(target) &&
getGeometry(target) != null && getGeometry(target).isRelative())
{
target = getParent(target);
}
if (isAncestor(root, source) && isAncestor(root, target))
{
if (source == target)
{
cell = getParent(source);
}
else
{
cell = getNearestCommonAncestor(source, target);
}
// Keeps the edge in the same layer
if (cell != null
&& (getParent(cell) != root || isAncestor(cell, edge))
&& getParent(edge) != cell)
{
mxGeometry geo = getGeometry(edge);
if (geo != null)
{
mxPoint origin1 = getOrigin(getParent(edge));
mxPoint origin2 = getOrigin(cell);
double dx = origin2.getX() - origin1.getX();
double dy = origin2.getY() - origin1.getY();
geo = (mxGeometry) geo.clone();
geo.translate(-dx, -dy);
setGeometry(edge, geo);
}
add(cell, edge, getChildCount(cell));
}
}
}
/**
* Returns the absolute, accumulated origin for the children inside the
* given parent.
*/
public mxPoint getOrigin(Object cell)
{
mxPoint result = null;
if (cell != null)
{
result = getOrigin(getParent(cell));
if (!isEdge(cell))
{
mxGeometry geo = getGeometry(cell);
if (geo != null)
{
result.setX(result.getX() + geo.getX());
result.setY(result.getY() + geo.getY());
}
}
}
else
{
result = new mxPoint();
}
return result;
}
/**
* Returns the nearest common ancestor for the specified cells.
*
* @param cell1 Cell that specifies the first cell in the tree.
* @param cell2 Cell that specifies the second cell in the tree.
* @return Returns the nearest common ancestor of the given cells.
*/
public Object getNearestCommonAncestor(Object cell1, Object cell2)
{
if (cell1 != null && cell2 != null)
{
// Creates the cell path for the second cell
String path = mxCellPath.create((mxICell) cell2);
if (path != null && path.length() > 0)
{
// Bubbles through the ancestors of the first
// cell to find the nearest common ancestor.
Object cell = cell1;
String current = mxCellPath.create((mxICell) cell);
while (cell != null)
{
Object parent = getParent(cell);
// Checks if the cell path is equal to the beginning
// of the given cell path
if (path.indexOf(current + mxCellPath.PATH_SEPARATOR) == 0
&& parent != null)
{
return cell;
}
current = mxCellPath.getParentPath(current);
cell = parent;
}
}
}
return null;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#getEdgeCount(Object)
*/
public int getEdgeCount(Object cell)
{
return (cell instanceof mxICell) ? ((mxICell) cell).getEdgeCount() : 0;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#getEdgeAt(Object, int)
*/
public Object getEdgeAt(Object parent, int index)
{
return (parent instanceof mxICell) ? ((mxICell) parent)
.getEdgeAt(index) : null;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#isVertex(Object)
*/
public boolean isVertex(Object cell)
{
return (cell instanceof mxICell) ? ((mxICell) cell).isVertex() : false;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#isEdge(Object)
*/
public boolean isEdge(Object cell)
{
return (cell instanceof mxICell) ? ((mxICell) cell).isEdge() : false;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#isConnectable(Object)
*/
public boolean isConnectable(Object cell)
{
return (cell instanceof mxICell) ? ((mxICell) cell).isConnectable()
: true;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#getValue(Object)
*/
public Object getValue(Object cell)
{
return (cell instanceof mxICell) ? ((mxICell) cell).getValue() : null;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#setValue(Object, Object)
*/
public Object setValue(Object cell, Object value)
{
execute(new mxValueChange(this, cell, value));
return value;
}
/**
* Inner callback to update the user object of the given mxCell
* using mxCell.setValue and return the previous value,
* that is, the return value of mxCell.getValue.
*/
protected Object valueForCellChanged(Object cell, Object value)
{
Object oldValue = ((mxICell) cell).getValue();
((mxICell) cell).setValue(value);
return oldValue;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#getGeometry(Object)
*/
public mxGeometry getGeometry(Object cell)
{
return (cell instanceof mxICell) ? ((mxICell) cell).getGeometry()
: null;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#setGeometry(Object, mxGeometry)
*/
public mxGeometry setGeometry(Object cell, mxGeometry geometry)
{
if (geometry != getGeometry(cell))
{
execute(new mxGeometryChange(this, cell, geometry));
}
return geometry;
}
/**
* Inner callback to update the mxGeometry of the given mxCell using
* mxCell.setGeometry and return the previous mxGeometry.
*/
protected mxGeometry geometryForCellChanged(Object cell, mxGeometry geometry)
{
mxGeometry previous = getGeometry(cell);
((mxICell) cell).setGeometry(geometry);
return previous;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#getStyle(Object)
*/
public String getStyle(Object cell)
{
return (cell instanceof mxICell) ? ((mxICell) cell).getStyle() : null;
}
/* (non-Javadoc)
* @see com.mxgraph.model.mxIGraphModel#setStyle(Object, String)
*/
public String setStyle(Object cell, String style)
{
if (style == null || !style.equals(getStyle(cell)))
{
execute(new mxStyleChange(this, cell, style));
}
return style;
}
/**
* Inner callback to update the style of the given mxCell
* using mxCell.setStyle and return the previous style.
*/
protected String styleForCellChanged(Object cell, String style)
{
String previous = getStyle(cell);
((mxICell) cell).setStyle(style);
return previous;