forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxCellState.java
More file actions
593 lines (523 loc) · 11 KB
/
mxCellState.java
File metadata and controls
593 lines (523 loc) · 11 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
/**
* Copyright (c) 2007, Gaudenz Alder
*/
package com.mxgraph.view;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.mxgraph.util.mxPoint;
import com.mxgraph.util.mxRectangle;
/**
* Represents the current state of a cell in a given graph view.
*/
public class mxCellState extends mxRectangle
{
/**
*
*/
private static final long serialVersionUID = 7588335615324083354L;
/**
* Reference to the enclosing graph view.
*/
protected mxGraphView view;
/**
* Reference to the cell that is represented by this state.
*/
protected Object cell;
/**
* Holds the current label value, including newlines which result from
* word wrapping.
*/
protected String label;
/**
* Contains an array of key, value pairs that represent the style of the
* cell.
*/
protected Map<String, Object> style;
/**
* Holds the origin for all child cells.
*/
protected mxPoint origin = new mxPoint();
/**
* List of mxPoints that represent the absolute points of an edge.
*/
protected List<mxPoint> absolutePoints;
/**
* Holds the absolute offset. For edges, this is the absolute coordinates
* of the label position. For vertices, this is the offset of the label
* relative to the top, left corner of the vertex.
*/
protected mxPoint absoluteOffset = new mxPoint();
/**
* Caches the distance between the end points and the length of an edge.
*/
protected double terminalDistance, length;
/**
* Array of numbers that represent the cached length of each segment of the
* edge.
*/
protected double[] segments;
/**
* Holds the rectangle which contains the label.
*/
protected mxRectangle labelBounds;
/**
* Holds the largest rectangle which contains all rendering for this cell.
*/
protected mxRectangle boundingBox;
/**
* Specifies if the state is invalid. Default is true.
*/
protected boolean invalid = true;
/**
* Caches the visible source and target terminal states.
*/
protected mxCellState visibleSourceState, visibleTargetState;
/**
* Constructs an empty cell state.
*/
public mxCellState()
{
this(null, null, null);
}
/**
* Constructs a new object that represents the current state of the given
* cell in the specified view.
*
* @param view Graph view that contains the state.
* @param cell Cell that this state represents.
* @param style Array of key, value pairs that constitute the style.
*/
public mxCellState(mxGraphView view, Object cell, Map<String, Object> style)
{
setView(view);
setCell(cell);
setStyle(style);
}
/**
* Returns true if the state is invalid.
*/
public boolean isInvalid()
{
return invalid;
}
/**
* Sets the invalid state.
*/
public void setInvalid(boolean invalid)
{
this.invalid = invalid;
}
/**
* Returns the enclosing graph view.
*
* @return the view
*/
public mxGraphView getView()
{
return view;
}
/**
* Sets the enclosing graph view.
*
* @param view the view to set
*/
public void setView(mxGraphView view)
{
this.view = view;
}
/**
* Returns the current label.
*/
public String getLabel()
{
return label;
}
/**
* Returns the current label.
*/
public void setLabel(String value)
{
label = value;
}
/**
* Returns the cell that is represented by this state.
*
* @return the cell
*/
public Object getCell()
{
return cell;
}
/**
* Sets the cell that this state represents.
*
* @param cell the cell to set
*/
public void setCell(Object cell)
{
this.cell = cell;
}
/**
* Returns the cell style as a map of key, value pairs.
*
* @return the style
*/
public Map<String, Object> getStyle()
{
return style;
}
/**
* Sets the cell style as a map of key, value pairs.
*
* @param style the style to set
*/
public void setStyle(Map<String, Object> style)
{
this.style = style;
}
/**
* Returns the origin for the children.
*
* @return the origin
*/
public mxPoint getOrigin()
{
return origin;
}
/**
* Sets the origin for the children.
*
* @param origin the origin to set
*/
public void setOrigin(mxPoint origin)
{
this.origin = origin;
}
/**
* Returns the absolute point at the given index.
*
* @return the mxPoint at the given index
*/
public mxPoint getAbsolutePoint(int index)
{
return absolutePoints.get(index);
}
/**
* Returns the absolute point at the given index.
*
* @return the mxPoint at the given index
*/
public mxPoint setAbsolutePoint(int index, mxPoint point)
{
return absolutePoints.set(index, point);
}
/**
* Returns the number of absolute points.
*
* @return the absolutePoints
*/
public int getAbsolutePointCount()
{
return (absolutePoints != null) ? absolutePoints.size() : 0;
}
/**
* Returns the absolute points.
*
* @return the absolutePoints
*/
public List<mxPoint> getAbsolutePoints()
{
return absolutePoints;
}
/**
* Returns the absolute points.
*
* @param absolutePoints the absolutePoints to set
*/
public void setAbsolutePoints(List<mxPoint> absolutePoints)
{
this.absolutePoints = absolutePoints;
}
/**
* Returns the absolute offset.
*
* @return the absoluteOffset
*/
public mxPoint getAbsoluteOffset()
{
return absoluteOffset;
}
/**
* Returns the absolute offset.
*
* @param absoluteOffset the absoluteOffset to set
*/
public void setAbsoluteOffset(mxPoint absoluteOffset)
{
this.absoluteOffset = absoluteOffset;
}
/**
* Returns the terminal distance.
*
* @return the terminalDistance
*/
public double getTerminalDistance()
{
return terminalDistance;
}
/**
* Sets the terminal distance.
*
* @param terminalDistance the terminalDistance to set
*/
public void setTerminalDistance(double terminalDistance)
{
this.terminalDistance = terminalDistance;
}
/**
* Returns the length.
*
* @return the length
*/
public double getLength()
{
return length;
}
/**
* Sets the length.
*
* @param length the length to set
*/
public void setLength(double length)
{
this.length = length;
}
/**
* Returns the length of the segments.
*
* @return the segments
*/
public double[] getSegments()
{
return segments;
}
/**
* Sets the length of the segments.
*
* @param segments the segments to set
*/
public void setSegments(double[] segments)
{
this.segments = segments;
}
/**
* Returns the label bounds.
*
* @return Returns the label bounds for this state.
*/
public mxRectangle getLabelBounds()
{
return labelBounds;
}
/**
* Sets the label bounds.
*
* @param labelBounds
*/
public void setLabelBounds(mxRectangle labelBounds)
{
this.labelBounds = labelBounds;
}
/**
* Returns the bounding box.
*
* @return Returns the bounding box for this state.
*/
public mxRectangle getBoundingBox()
{
return boundingBox;
}
/**
* Sets the bounding box.
*
* @param boundingBox
*/
public void setBoundingBox(mxRectangle boundingBox)
{
this.boundingBox = boundingBox;
}
/**
* Returns the rectangle that should be used as the perimeter of the cell.
* This implementation adds the perimeter spacing to the rectangle
* defined by this cell state.
*
* @return Returns the rectangle that defines the perimeter.
*/
public mxRectangle getPerimeterBounds()
{
return getPerimeterBounds(0);
}
/**
* Returns the rectangle that should be used as the perimeter of the cell.
*
* @return Returns the rectangle that defines the perimeter.
*/
public mxRectangle getPerimeterBounds(double border)
{
mxRectangle bounds = new mxRectangle(getRectangle());
if (border != 0)
{
bounds.grow(border);
}
return bounds;
}
/**
* Sets the first or last point in the list of points depending on isSource.
*
* @param point Point that represents the terminal point.
* @param isSource Boolean that specifies if the first or last point should
* be assigned.
*/
public void setAbsoluteTerminalPoint(mxPoint point, boolean isSource)
{
if (isSource)
{
if (absolutePoints == null)
{
absolutePoints = new ArrayList<mxPoint>();
}
if (absolutePoints.size() == 0)
{
absolutePoints.add(point);
}
else
{
absolutePoints.set(0, point);
}
}
else
{
if (absolutePoints == null)
{
absolutePoints = new ArrayList<mxPoint>();
absolutePoints.add(null);
absolutePoints.add(point);
}
else if (absolutePoints.size() == 1)
{
absolutePoints.add(point);
}
else
{
absolutePoints.set(absolutePoints.size() - 1, point);
}
}
}
/**
* Returns the visible source or target terminal cell.
*
* @param source Boolean that specifies if the source or target cell should be
* returned.
*/
public Object getVisibleTerminal(boolean source)
{
mxCellState tmp = getVisibleTerminalState(source);
return (tmp != null) ? tmp.getCell() : null;
}
/**
* Returns the visible source or target terminal state.
*
* @param Boolean that specifies if the source or target state should be
* returned.
*/
public mxCellState getVisibleTerminalState(boolean source)
{
return (source) ? visibleSourceState : visibleTargetState;
}
/**
* Sets the visible source or target terminal state.
*
* @param terminalState Cell state that represents the terminal.
* @param source Boolean that specifies if the source or target state should be set.
*/
public void setVisibleTerminalState(mxCellState terminalState,
boolean source)
{
if (source)
{
visibleSourceState = terminalState;
}
else
{
visibleTargetState = terminalState;
}
}
/**
* Returns a clone of this state where all members are deeply cloned
* except the view and cell references, which are copied with no
* cloning to the new instance.
*/
public Object clone()
{
mxCellState clone = new mxCellState(view, cell, style);
if (label != null)
{
clone.label = label;
}
if (absolutePoints != null)
{
clone.absolutePoints = new ArrayList<mxPoint>();
for (int i = 0; i < absolutePoints.size(); i++)
{
clone.absolutePoints.add((mxPoint) absolutePoints.get(i)
.clone());
}
}
if (origin != null)
{
clone.origin = (mxPoint) origin.clone();
}
if (absoluteOffset != null)
{
clone.absoluteOffset = (mxPoint) absoluteOffset.clone();
}
if (labelBounds != null)
{
clone.labelBounds = (mxRectangle) labelBounds.clone();
}
if (boundingBox != null)
{
clone.boundingBox = (mxRectangle) boundingBox.clone();
}
clone.terminalDistance = terminalDistance;
clone.segments = segments;
clone.length = length;
clone.x = x;
clone.y = y;
clone.width = width;
clone.height = height;
return clone;
}
@Override
public String toString()
{
StringBuilder builder = new StringBuilder(64);
builder.append(getClass().getSimpleName());
builder.append(" [");
builder.append("cell=");
builder.append(cell);
builder.append(", label=");
builder.append(label);
builder.append(", x=");
builder.append(x);
builder.append(", y=");
builder.append(y);
builder.append(", width=");
builder.append(width);
builder.append(", height=");
builder.append(height);
builder.append("]");
return builder.toString();
}
}