-
Notifications
You must be signed in to change notification settings - Fork 48
/
Figure.java
2264 lines (2040 loc) · 52.7 KB
/
Figure.java
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) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
* Mike Marchand - fix for bug #472848
*******************************************************************************/
package org.eclipse.draw2d;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Display;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.draw2d.geometry.Translatable;
/**
* The base implementation for graphical figures.
*/
public class Figure implements IFigure {
private static final Rectangle PRIVATE_RECT = new Rectangle();
private static final Point PRIVATE_POINT = new Point();
private static final int FLAG_VALID = 1;
private static final int FLAG_OPAQUE = 1 << 1;
private static final int FLAG_VISIBLE = 1 << 2;
private static final int FLAG_FOCUSABLE = 1 << 3;
private static final int FLAG_ENABLED = 1 << 4;
private static final int FLAG_FOCUS_TRAVERSABLE = 1 << 5;
static final int FLAG_REALIZED = 1 << 31;
/**
* The largest flag defined in this class. If subclasses define flags, they
* should declare them as larger than this value and redefine MAX_FLAG to be
* their largest flag value.
* <P>
* This constant is evaluated at runtime and will not be inlined by the
* compiler.
*/
protected static int MAX_FLAG = FLAG_FOCUS_TRAVERSABLE;
/**
* The rectangular area that this Figure occupies.
*/
protected Rectangle bounds = new Rectangle(0, 0, 0, 0);
private LayoutManager layoutManager;
/**
* The flags for this Figure.
*/
protected int flags = FLAG_VISIBLE | FLAG_ENABLED;
private IFigure parent;
private IClippingStrategy clippingStrategy = null;
private Cursor cursor;
private PropertyChangeSupport propertyListeners;
private final EventListenerList eventListeners = new EventListenerList();
private List<IFigure> children = Collections.emptyList();
/**
* This Figure's preferred size.
*/
protected Dimension prefSize;
/**
* This Figure's minimum size.
*/
protected Dimension minSize;
/**
* This Figure's maximum size.
*/
protected Dimension maxSize;
/**
* @deprecated access using {@link #getLocalFont()}
*/
@Deprecated
protected Font font;
/**
* @deprecated access using {@link #getLocalBackgroundColor()}.
*/
@Deprecated
protected Color bgColor;
/**
* @deprecated access using {@link #getLocalForegroundColor()}.
*/
@Deprecated
protected Color fgColor;
/**
* @deprecated access using {@link #getBorder()}
*/
@Deprecated
protected Border border;
/**
* @deprecated access using {@link #getToolTip()}
*/
@Deprecated
protected IFigure toolTip;
private AncestorHelper ancestorHelper;
/**
* Calls {@link #add(IFigure, Object, int)} with -1 as the index.
*
* @see IFigure#add(IFigure, Object)
*/
@Override
public final void add(IFigure figure, Object constraint) {
add(figure, constraint, -1);
}
/**
* @see IFigure#add(IFigure, Object, int)
*/
@Override
public void add(IFigure figure, Object constraint, int index) {
if (children.equals(Collections.emptyList())) {
children = new ArrayList<>(2);
}
if (index < -1 || index > children.size()) {
throw new IndexOutOfBoundsException("Index does not exist"); //$NON-NLS-1$
}
// Check for Cycle in hierarchy
for (IFigure f = this; f != null; f = f.getParent()) {
if (figure == f) {
throw new IllegalArgumentException("Figure being added introduces cycle"); //$NON-NLS-1$
}
}
// Detach the child from previous parent
if (figure.getParent() != null) {
figure.getParent().remove(figure);
}
if (index == -1) {
children.add(figure);
} else {
children.add(index, figure);
}
figure.setParent(this);
if (layoutManager != null) {
layoutManager.setConstraint(figure, constraint);
}
revalidate();
if (getFlag(FLAG_REALIZED)) {
figure.addNotify();
}
figure.repaint();
}
/**
* Calls {@link #add(IFigure, Object, int)} with <code>null</code> as the
* constraint and -1 as the index.
*
* @see IFigure#add(IFigure)
*/
@Override
public final void add(IFigure figure) {
add(figure, null, -1);
}
/**
* Calls {@link #add(IFigure, Object, int)} with <code>null</code> as the
* constraint.
*
* @see IFigure#add(IFigure, int)
*/
@Override
public final void add(IFigure figure, int index) {
add(figure, null, index);
}
/**
* @see IFigure#addAncestorListener(AncestorListener)
*/
@Override
public void addAncestorListener(AncestorListener ancestorListener) {
if (ancestorHelper == null) {
ancestorHelper = new AncestorHelper(this);
}
ancestorHelper.addAncestorListener(ancestorListener);
}
/**
* @see IFigure#addCoordinateListener(CoordinateListener)
*/
@Override
public void addCoordinateListener(CoordinateListener listener) {
eventListeners.addListener(CoordinateListener.class, listener);
}
/**
* @see IFigure#addFigureListener(FigureListener)
*/
@Override
public void addFigureListener(FigureListener listener) {
eventListeners.addListener(FigureListener.class, listener);
}
/**
* @see IFigure#addFocusListener(FocusListener)
*/
@Override
public void addFocusListener(FocusListener listener) {
eventListeners.addListener(FocusListener.class, listener);
}
/**
* @see IFigure#addKeyListener(KeyListener)
*/
@Override
public void addKeyListener(KeyListener listener) {
eventListeners.addListener(KeyListener.class, listener);
}
/**
* Appends the given layout listener to the list of layout listeners.
*
* @since 3.1
* @param listener the listener being added
*/
@Override
public void addLayoutListener(LayoutListener listener) {
if (layoutManager instanceof LayoutNotifier notifier) {
notifier.listeners.add(listener);
} else {
layoutManager = new LayoutNotifier(layoutManager, listener);
}
}
/**
* Adds a listener of type <i>clazz</i> to this Figure's list of event
* listeners.
*
* @param clazz The listener type
* @param listener The listener
*/
protected <T> void addListener(Class<T> clazz, Object listener) {
eventListeners.addListener(clazz, listener);
}
/**
* @see IFigure#addMouseListener(MouseListener)
*/
@Override
public void addMouseListener(MouseListener listener) {
eventListeners.addListener(MouseListener.class, listener);
}
/**
* @see IFigure#addMouseMotionListener(MouseMotionListener)
*/
@Override
public void addMouseMotionListener(MouseMotionListener listener) {
eventListeners.addListener(MouseMotionListener.class, listener);
}
/**
* Called after the receiver's parent has been set and it has been added to its
* parent.
*
* @since 2.0
*/
@Override
public void addNotify() {
if (getFlag(FLAG_REALIZED)) {
throw new RuntimeException("addNotify() should not be called multiple times"); //$NON-NLS-1$
}
setFlag(FLAG_REALIZED, true);
children.forEach(IFigure::addNotify);
}
/**
* @see IFigure#addPropertyChangeListener(String, PropertyChangeListener)
*/
@Override
public void addPropertyChangeListener(String property, PropertyChangeListener listener) {
if (propertyListeners == null) {
propertyListeners = new PropertyChangeSupport(this);
}
propertyListeners.addPropertyChangeListener(property, listener);
}
/**
* @see IFigure#addPropertyChangeListener(PropertyChangeListener)
*/
@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
if (propertyListeners == null) {
propertyListeners = new PropertyChangeSupport(this);
}
propertyListeners.addPropertyChangeListener(listener);
}
/**
* This method is final. Override {@link #containsPoint(int, int)} if needed.
*
* @see IFigure#containsPoint(Point)
* @since 2.0
*/
@Override
public final boolean containsPoint(Point p) {
return containsPoint(p.x, p.y);
}
/**
* @see IFigure#containsPoint(int, int)
*/
@Override
public boolean containsPoint(int x, int y) {
return getBounds().contains(x, y);
}
/**
* @see IFigure#erase()
*/
@Override
public void erase() {
if (getParent() == null || !isVisible()) {
return;
}
Rectangle r = new Rectangle(getBounds());
getParent().translateToParent(r);
getParent().repaint(r.x, r.y, r.width, r.height);
}
/**
* Returns a descendant of this Figure such that the Figure returned contains
* the point (x, y), and is accepted by the given TreeSearch. Returns
* <code>null</code> if none found.
*
* @param x The X coordinate
* @param y The Y coordinate
* @param search the TreeSearch
* @return The descendant Figure at (x,y)
*/
protected IFigure findDescendantAtExcluding(int x, int y, TreeSearch search) {
PRIVATE_POINT.setLocation(x, y);
translateFromParent(PRIVATE_POINT);
if (!getClientArea(Rectangle.SINGLETON).contains(PRIVATE_POINT)) {
return null;
}
x = PRIVATE_POINT.x;
y = PRIVATE_POINT.y;
for (IFigure fig : getChildrenRevIterable()) {
if (fig.isVisible()) {
fig = fig.findFigureAt(x, y, search);
if (fig != null) {
return fig;
}
}
}
// No descendants were found
return null;
}
/**
* @see IFigure#findFigureAt(Point)
*/
@Override
public final IFigure findFigureAt(Point pt) {
return findFigureAtExcluding(pt.x, pt.y, Collections.emptyList());
}
/**
* @see IFigure#findFigureAt(int, int)
*/
@Override
public final IFigure findFigureAt(int x, int y) {
return findFigureAt(x, y, IdentitySearch.INSTANCE);
}
/**
* @see IFigure#findFigureAt(int, int, TreeSearch)
*/
@Override
public IFigure findFigureAt(int x, int y, TreeSearch search) {
if (!containsPoint(x, y)) {
return null;
}
if (search.prune(this)) {
return null;
}
IFigure child = findDescendantAtExcluding(x, y, search);
if (child != null) {
return child;
}
if (search.accept(this)) {
return this;
}
return null;
}
/**
* @see IFigure#findFigureAtExcluding(int, int, Collection)
*/
@Override
public final IFigure findFigureAtExcluding(int x, int y, Collection<IFigure> c) {
return findFigureAt(x, y, new ExclusionSearch(c));
}
/**
* Returns the deepest descendant for which {@link #isMouseEventTarget()}
* returns <code>true</code> or <code>null</code> if none found. The Parameters
* <i>x</i> and <i>y</i> are absolute locations. Any Graphics transformations
* applied by this Figure to its children during
* {@link #paintChildren(Graphics)} (thus causing the children to appear
* transformed to the user) should be applied inversely to the points <i>x</i>
* and <i>y</i> when called on the children.
*
* @param x The X coordinate
* @param y The Y coordinate
* @return The deepest descendant for which isMouseEventTarget() returns true
*/
@Override
public IFigure findMouseEventTargetAt(int x, int y) {
if (!containsPoint(x, y)) {
return null;
}
IFigure f = findMouseEventTargetInDescendantsAt(x, y);
if (f != null) {
return f;
}
if (isMouseEventTarget()) {
return this;
}
return null;
}
/**
* Searches this Figure's children for the deepest descendant for which
* {@link #isMouseEventTarget()} returns <code>true</code> and returns that
* descendant or <code>null</code> if none found.
*
* @see #findMouseEventTargetAt(int, int)
* @param x The X coordinate
* @param y The Y coordinate
* @return The deepest descendant for which isMouseEventTarget() returns true
*/
protected IFigure findMouseEventTargetInDescendantsAt(int x, int y) {
PRIVATE_POINT.setLocation(x, y);
translateFromParent(PRIVATE_POINT);
if (!getClientArea(Rectangle.SINGLETON).contains(PRIVATE_POINT)) {
return null;
}
for (IFigure fig : getChildrenRevIterable()) {
if (fig.isVisible() && fig.isEnabled() && fig.containsPoint(PRIVATE_POINT.x, PRIVATE_POINT.y)) {
fig = fig.findMouseEventTargetAt(PRIVATE_POINT.x, PRIVATE_POINT.y);
if (fig != null) {
return fig;
}
}
}
return null;
}
/**
* Notifies to all {@link CoordinateListener}s that this figure's local
* coordinate system has changed in a way which affects the absolute bounds of
* figures contained within.
*
* @since 3.1
*/
protected void fireCoordinateSystemChanged() {
if (!eventListeners.containsListener(CoordinateListener.class)) {
return;
}
eventListeners.getListenersIterable(CoordinateListener.class).forEach(lst -> lst.coordinateSystemChanged(this));
}
/**
* Notifies to all {@link FigureListener}s that this figure has moved. Moved
* means that the bounds have changed in some way, location and/or size.
*
* @since 3.1
*/
protected void fireFigureMoved() {
if (!eventListeners.containsListener(FigureListener.class)) {
return;
}
eventListeners.getListenersIterable(FigureListener.class).forEach(lst -> lst.figureMoved(this));
}
/**
* Fires both figuremoved and coordinate system changed. This method exists for
* compatibility. Some listeners which used to listen for figureMoved now listen
* for coordinates changed. So to be sure that those new listeners are notified,
* any client code which used called this method will also result in
* notification of coordinate changes.
*
* @since 2.0
* @deprecated call fireFigureMoved() or fireCoordinateSystemChanged() as
* appropriate
*/
@Deprecated
protected void fireMoved() {
fireFigureMoved();
fireCoordinateSystemChanged();
}
/**
* Notifies any {@link PropertyChangeListener PropertyChangeListeners} listening
* to this Figure that the boolean property with id <i>property</i> has changed.
*
* @param property The id of the property that changed
* @param old The old value of the changed property
* @param current The current value of the changed property
* @since 2.0
*/
protected void firePropertyChange(String property, boolean old, boolean current) {
if (propertyListeners == null) {
return;
}
propertyListeners.firePropertyChange(property, old, current);
}
/**
* Notifies any {@link PropertyChangeListener PropertyChangeListeners} listening
* to this figure that the Object property with id <i>property</i> has changed.
*
* @param property The id of the property that changed
* @param old The old value of the changed property
* @param current The current value of the changed property
* @since 2.0
*/
protected void firePropertyChange(String property, Object old, Object current) {
if (propertyListeners == null) {
return;
}
propertyListeners.firePropertyChange(property, old, current);
}
/**
* Notifies any {@link PropertyChangeListener PropertyChangeListeners} listening
* to this figure that the integer property with id <code>property</code> has
* changed.
*
* @param property The id of the property that changed
* @param old The old value of the changed property
* @param current The current value of the changed property
* @since 2.0
*/
protected void firePropertyChange(String property, int old, int current) {
if (propertyListeners == null) {
return;
}
propertyListeners.firePropertyChange(property, old, current);
}
/**
* Returns this Figure's background color. If this Figure's background color is
* <code>null</code> and its parent is not <code>null</code>, the background
* color is inherited from the parent.
*
* @see IFigure#getBackgroundColor()
*/
@Override
public Color getBackgroundColor() {
if (getLocalBackgroundColor() == null && getParent() != null) {
return getParent().getBackgroundColor();
}
return getLocalBackgroundColor();
}
/**
* @see IFigure#getBorder()
*/
@Override
public Border getBorder() {
return border;
}
/**
* Returns the smallest rectangle completely enclosing the figure. Implementors
* may return the Rectangle by reference. For this reason, callers of this
* method must not modify the returned Rectangle.
*
* @return The bounds of this Figure
*/
@Override
public Rectangle getBounds() {
return bounds;
}
/**
* @see IFigure#getChildren()
*/
@Override
public List<? extends IFigure> getChildren() {
return children;
}
/**
* Provide an iterable that will iterate in reverse over all children of this
* figure.
*
* @since 3.13
*/
public Iterable<IFigure> getChildrenRevIterable() {
return () -> new ReverseFigureChildrenIterator(Figure.this);
}
/**
* @see IFigure#getClientArea(Rectangle)
*/
@Override
public Rectangle getClientArea(Rectangle rect) {
rect.setBounds(getBounds());
rect.shrink(getInsets());
if (useLocalCoordinates()) {
rect.setLocation(0, 0);
}
return rect;
}
/**
* @see IFigure#getClientArea()
*/
@Override
public final Rectangle getClientArea() {
return getClientArea(new Rectangle());
}
/**
* Returns the IClippingStrategy used by this figure to clip its children
*
* @return the IClipppingStrategy used to clip this figure's children.
* @since 3.6
*/
@Override
public IClippingStrategy getClippingStrategy() {
return clippingStrategy;
}
/**
* @see IFigure#getCursor()
*/
@Override
public Cursor getCursor() {
if (cursor == null && getParent() != null) {
return getParent().getCursor();
}
return cursor;
}
/**
* Returns the value of the given flag.
*
* @param flag The flag to get
* @return The value of the given flag
*/
protected boolean getFlag(int flag) {
return (flags & flag) != 0;
}
/**
* @see IFigure#getFont()
*/
@Override
public Font getFont() {
if (getLocalFont() != null) {
return getLocalFont();
}
if (getParent() != null) {
return getParent().getFont();
}
return null;
}
/**
* @see IFigure#getForegroundColor()
*/
@Override
public Color getForegroundColor() {
if (getLocalForegroundColor() == null && getParent() != null) {
return getParent().getForegroundColor();
}
return getLocalForegroundColor();
}
/**
* Returns the border's Insets if the border is set. Otherwise returns
* NO_INSETS, an instance of Insets with all 0s. Returns Insets by reference. DO
* NOT Modify returned value. Cannot return null.
*
* @return This Figure's Insets
*/
@Override
public Insets getInsets() {
if (getBorder() != null) {
return getBorder().getInsets(this);
}
return NO_INSETS;
}
/**
* @see IFigure#getLayoutManager()
*/
@Override
public LayoutManager getLayoutManager() {
if (layoutManager instanceof LayoutNotifier layoutNotifier) {
return layoutNotifier.realLayout;
}
return layoutManager;
}
/**
* Returns an Iterator over the listeners of type <i>clazz</i> that are
* listening to this Figure. If there are no listeners of type <i>clazz</i>, an
* empty iterator is returned.
*
* @param clazz The type of listeners to get
* @return An Iterator over the requested listeners
* @since 2.0
*/
protected <T> Iterator<T> getListeners(Class<T> clazz) {
return eventListeners.getListeners(clazz);
}
/**
* * Returns an Iterator over the listeners of type <i>listenerType</i> that are
* listening to this Figure. If there are no listeners of type
* <i>listenerType</i>, an empty iterator is returned.
*
* @param listenerType The type of listeners to get
* @return an Iterable over the requested listeners <i>c</i>
* @since 3.13
*/
protected <T> Iterable<T> getListenersIterable(final Class<T> listenerType) {
return eventListeners.getListenersIterable(listenerType);
}
/**
* Returns <code>null</code> or the local background Color of this Figure. Does
* not inherit this Color from the parent.
*
* @return bgColor <code>null</code> or the local background Color
*/
@Override
public Color getLocalBackgroundColor() {
return bgColor;
}
/**
* Returns <code>null</code> or the local font setting for this figure. Does not
* return values inherited from the parent figure.
*
* @return <code>null</code> or the local font
* @since 3.1
*/
protected Font getLocalFont() {
return font;
}
/**
* Returns <code>null</code> or the local foreground Color of this Figure. Does
* not inherit this Color from the parent.
*
* @return fgColor <code>null</code> or the local foreground Color
*/
@Override
public Color getLocalForegroundColor() {
return fgColor;
}
/**
* Returns the top-left corner of this Figure's bounds.
*
* @return The top-left corner of this Figure's bounds
* @since 2.0
*/
@Override
public final Point getLocation() {
return IFigure.super.getLocation();
}
/**
* @see IFigure#getMaximumSize()
*/
@Override
public Dimension getMaximumSize() {
if (maxSize != null) {
return maxSize;
}
return MAX_DIMENSION;
}
/**
* @see IFigure#getMinimumSize()
*/
@Override
public final Dimension getMinimumSize() {
return getMinimumSize(-1, -1);
}
/**
* @see IFigure#getMinimumSize(int, int)
*/
@Override
public Dimension getMinimumSize(int wHint, int hHint) {
if (minSize != null) {
return minSize;
}
if (getLayoutManager() != null) {
Dimension d = getLayoutManager().getMinimumSize(this, wHint, hHint);
if (d != null) {
return d;
}
}
return getPreferredSize(wHint, hHint);
}
/**
* @see IFigure#getParent()
*/
@Override
public IFigure getParent() {
return parent;
}
/**
* @see IFigure#getPreferredSize()
*/
@Override
public final Dimension getPreferredSize() {
return getPreferredSize(-1, -1);
}
/**
* @see IFigure#getPreferredSize(int, int)
*/
@Override
public Dimension getPreferredSize(int wHint, int hHint) {
if (prefSize != null) {
return prefSize;
}
if (getLayoutManager() != null) {
Dimension d = getLayoutManager().getPreferredSize(this, wHint, hHint);
if (d != null) {
return d;
}
}
return getSize();
}
/**
* @see IFigure#getSize()
*/
@Override
public final Dimension getSize() {
return getBounds().getSize();
}
/**
* @see IFigure#getToolTip()
*/
@Override
public IFigure getToolTip() {
return toolTip;
}
/**
* @see IFigure#getUpdateManager()
*/
@Override
public UpdateManager getUpdateManager() {
if (getParent() != null) {
return getParent().getUpdateManager();
}
// Only happens when the figure has not been realized
return NO_MANAGER;
}
/**
* @see IFigure#handleFocusGained(FocusEvent)
*/
@Override
public void handleFocusGained(FocusEvent event) {
eventListeners.getListenersIterable(FocusListener.class).forEach(lst -> lst.focusGained(event));
}
/**
* @see IFigure#handleFocusLost(FocusEvent)
*/
@Override
public void handleFocusLost(FocusEvent event) {
eventListeners.getListenersIterable(FocusListener.class).forEach(lst -> lst.focusLost(event));
}
/**
* @see IFigure#handleKeyPressed(KeyEvent)
*/
@Override
public void handleKeyPressed(KeyEvent event) {
var iter = eventListeners.getListeners(KeyListener.class);
while (!event.isConsumed() && iter.hasNext()) {
iter.next().keyPressed(event);
}
}
/**
* @see IFigure#handleKeyReleased(KeyEvent)
*/
@Override
public void handleKeyReleased(KeyEvent event) {
var iter = eventListeners.getListeners(KeyListener.class);
while (!event.isConsumed() && iter.hasNext()) {
iter.next().keyReleased(event);
}
}
/**
* @see IFigure#handleMouseDoubleClicked(MouseEvent)
*/
@Override
public void handleMouseDoubleClicked(MouseEvent event) {
var iter = eventListeners.getListeners(MouseListener.class);
while (!event.isConsumed() && iter.hasNext()) {
iter.next().mouseDoubleClicked(event);
}
}
/**
* @see IFigure#handleMouseDragged(MouseEvent)
*/
@Override
public void handleMouseDragged(MouseEvent event) {
var iter = eventListeners.getListeners(MouseMotionListener.class);
while (!event.isConsumed() && iter.hasNext()) {
iter.next().mouseDragged(event);
}
}
/**
* @see IFigure#handleMouseEntered(MouseEvent)
*/
@Override
public void handleMouseEntered(MouseEvent event) {
var iter = eventListeners.getListeners(MouseMotionListener.class);
while (!event.isConsumed() && iter.hasNext()) {
iter.next().mouseEntered(event);
}
}
/**
* @see IFigure#handleMouseExited(MouseEvent)
*/
@Override
public void handleMouseExited(MouseEvent event) {
var iter = eventListeners.getListeners(MouseMotionListener.class);
while (!event.isConsumed() && iter.hasNext()) {
iter.next().mouseExited(event);
}
}
/**
* @see IFigure#handleMouseHover(MouseEvent)
*/
@Override
public void handleMouseHover(MouseEvent event) {