author | ddehaven |
Tue, 19 Aug 2014 10:32:16 -0700 | |
changeset 26037 | 508779ce6619 |
parent 26004 | jdk/src/share/classes/javax/swing/event/SwingPropertyChangeSupport.java@7507a1b93f67 |
parent 25859 | jdk/src/share/classes/javax/swing/event/SwingPropertyChangeSupport.java@3317bb8137f4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.swing.event; |
|
27 |
||
28 |
import java.beans.PropertyChangeSupport; |
|
29 |
import java.beans.PropertyChangeEvent; |
|
30 |
||
31 |
import javax.swing.SwingUtilities; |
|
32 |
||
33 |
/** |
|
34 |
* This subclass of {@code java.beans.PropertyChangeSupport} is almost |
|
35 |
* identical in functionality. The only difference is if constructed with |
|
36 |
* {@code SwingPropertyChangeSupport(sourceBean, true)} it ensures |
|
37 |
* listeners are only ever notified on the <i>Event Dispatch Thread</i>. |
|
38 |
* |
|
39 |
* @author Igor Kushnirskiy |
|
40 |
*/ |
|
41 |
||
42 |
public final class SwingPropertyChangeSupport extends PropertyChangeSupport { |
|
43 |
||
44 |
/** |
|
45 |
* Constructs a SwingPropertyChangeSupport object. |
|
46 |
* |
|
47 |
* @param sourceBean The bean to be given as the source for any |
|
48 |
* events. |
|
49 |
* @throws NullPointerException if {@code sourceBean} is |
|
50 |
* {@code null} |
|
51 |
*/ |
|
52 |
public SwingPropertyChangeSupport(Object sourceBean) { |
|
53 |
this(sourceBean, false); |
|
54 |
} |
|
55 |
||
56 |
/** |
|
57 |
* Constructs a SwingPropertyChangeSupport object. |
|
58 |
* |
|
59 |
* @param sourceBean the bean to be given as the source for any events |
|
60 |
* @param notifyOnEDT whether to notify listeners on the <i>Event |
|
61 |
* Dispatch Thread</i> only |
|
62 |
* |
|
63 |
* @throws NullPointerException if {@code sourceBean} is |
|
64 |
* {@code null} |
|
65 |
* @since 1.6 |
|
66 |
*/ |
|
67 |
public SwingPropertyChangeSupport(Object sourceBean, boolean notifyOnEDT) { |
|
68 |
super(sourceBean); |
|
69 |
this.notifyOnEDT = notifyOnEDT; |
|
70 |
} |
|
71 |
||
72 |
/** |
|
73 |
* {@inheritDoc} |
|
74 |
* |
|
75 |
* <p> |
|
76 |
* If {@link #isNotifyOnEDT} is {@code true} and called off the |
|
77 |
* <i>Event Dispatch Thread</i> this implementation uses |
|
78 |
* {@code SwingUtilities.invokeLater} to send out the notification |
|
79 |
* on the <i>Event Dispatch Thread</i>. This ensures listeners |
|
80 |
* are only ever notified on the <i>Event Dispatch Thread</i>. |
|
81 |
* |
|
82 |
* @throws NullPointerException if {@code evt} is |
|
83 |
* {@code null} |
|
84 |
* @since 1.6 |
|
85 |
*/ |
|
86 |
public void firePropertyChange(final PropertyChangeEvent evt) { |
|
87 |
if (evt == null) { |
|
88 |
throw new NullPointerException(); |
|
89 |
} |
|
90 |
if (! isNotifyOnEDT() |
|
91 |
|| SwingUtilities.isEventDispatchThread()) { |
|
92 |
super.firePropertyChange(evt); |
|
93 |
} else { |
|
94 |
SwingUtilities.invokeLater( |
|
95 |
new Runnable() { |
|
96 |
public void run() { |
|
97 |
firePropertyChange(evt); |
|
98 |
} |
|
99 |
}); |
|
100 |
} |
|
101 |
} |
|
102 |
||
103 |
/** |
|
104 |
* Returns {@code notifyOnEDT} property. |
|
105 |
* |
|
106 |
* @return {@code notifyOnEDT} property |
|
107 |
* @see #SwingPropertyChangeSupport(Object sourceBean, boolean notifyOnEDT) |
|
108 |
* @since 1.6 |
|
109 |
*/ |
|
26004
7507a1b93f67
6521783: Unnecessary final modifier for a method in a final class
serb
parents:
5506
diff
changeset
|
110 |
public boolean isNotifyOnEDT() { |
2 | 111 |
return notifyOnEDT; |
112 |
} |
|
113 |
||
114 |
// Serialization version ID |
|
115 |
static final long serialVersionUID = 7162625831330845068L; |
|
116 |
||
117 |
/** |
|
118 |
* whether to notify listeners on EDT |
|
119 |
* |
|
120 |
* @serial |
|
121 |
* @since 1.6 |
|
122 |
*/ |
|
123 |
private final boolean notifyOnEDT; |
|
124 |
} |