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 *
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.
24 */
25 package com.sun.java.swing.plaf.windows;
26
27 import java.awt.*;
28 import java.beans.*;
29 import java.lang.ref.*;
30 import javax.swing.*;
31 import javax.swing.plaf.*;
32
33 /**
34 * Wrapper for a value from the desktop. The value is lazily looked up, and
35 * can be accessed using the <code>UIManager.ActiveValue</code> method
36 * <code>createValue</code>. If the underlying desktop property changes this
37 * will force the UIs to update all known Frames. You can invoke
38 * <code>invalidate</code> to force the value to be fetched again.
39 *
40 */
41 // NOTE: Don't rely on this class staying in this location. It is likely
42 // to move to a different package in the future.
43 public class DesktopProperty implements UIDefaults.ActiveValue {
44 /**
45 * Indicates if an updateUI call is pending.
46 */
47 private static boolean updatePending;
48
49 /**
50 * ReferenceQueue of unreferenced WeakPCLs.
51 */
52 private static final ReferenceQueue<DesktopProperty> queue = new ReferenceQueue<DesktopProperty>();
53
54 /**
55 * PropertyChangeListener attached to the Toolkit.
56 */
57 private WeakPCL pcl;
58 /**
174 }
175
176 /**
177 * Returns the value to use if the desktop property is null.
178 */
179 protected Object getDefaultValue() {
180 return fallback;
181 }
182
183 /**
184 * Invalidates the current value.
185 *
186 * @param laf the LookAndFeel this DesktopProperty was created with
187 */
188 public void invalidate(LookAndFeel laf) {
189 invalidate();
190 }
191
192 /**
193 * Invalides the current value so that the next invocation of
194 * <code>createValue</code> will ask for the property again.
195 */
196 public void invalidate() {
197 value = null;
198 }
199
200 /**
201 * Requests that all components in the GUI hierarchy be updated
202 * to reflect dynamic changes in this {@literal look&feel}. This update occurs
203 * by uninstalling and re-installing the UI objects. Requests are
204 * batched and collapsed into a single update pass because often
205 * many desktop properties will change at once.
206 */
207 protected void updateUI() {
208 if (!isUpdatePending()) {
209 setUpdatePending(true);
210 Runnable uiUpdater = new Runnable() {
211 public void run() {
212 updateAllUIs();
213 setUpdatePending(false);
214 }
|
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 *
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.
24 */
25 package com.sun.java.swing.plaf.windows;
26
27 import java.awt.*;
28 import java.beans.*;
29 import java.lang.ref.*;
30 import javax.swing.*;
31 import javax.swing.plaf.*;
32
33 /**
34 * Wrapper for a value from the desktop. The value is lazily looked up, and
35 * can be accessed using the {@code UIManager.ActiveValue} method
36 * {@code createValue}. If the underlying desktop property changes this
37 * will force the UIs to update all known Frames. You can invoke
38 * {@code invalidate} to force the value to be fetched again.
39 *
40 */
41 // NOTE: Don't rely on this class staying in this location. It is likely
42 // to move to a different package in the future.
43 public class DesktopProperty implements UIDefaults.ActiveValue {
44 /**
45 * Indicates if an updateUI call is pending.
46 */
47 private static boolean updatePending;
48
49 /**
50 * ReferenceQueue of unreferenced WeakPCLs.
51 */
52 private static final ReferenceQueue<DesktopProperty> queue = new ReferenceQueue<DesktopProperty>();
53
54 /**
55 * PropertyChangeListener attached to the Toolkit.
56 */
57 private WeakPCL pcl;
58 /**
174 }
175
176 /**
177 * Returns the value to use if the desktop property is null.
178 */
179 protected Object getDefaultValue() {
180 return fallback;
181 }
182
183 /**
184 * Invalidates the current value.
185 *
186 * @param laf the LookAndFeel this DesktopProperty was created with
187 */
188 public void invalidate(LookAndFeel laf) {
189 invalidate();
190 }
191
192 /**
193 * Invalides the current value so that the next invocation of
194 * {@code createValue} will ask for the property again.
195 */
196 public void invalidate() {
197 value = null;
198 }
199
200 /**
201 * Requests that all components in the GUI hierarchy be updated
202 * to reflect dynamic changes in this {@literal look&feel}. This update occurs
203 * by uninstalling and re-installing the UI objects. Requests are
204 * batched and collapsed into a single update pass because often
205 * many desktop properties will change at once.
206 */
207 protected void updateUI() {
208 if (!isUpdatePending()) {
209 setUpdatePending(true);
210 Runnable uiUpdater = new Runnable() {
211 public void run() {
212 updateAllUIs();
213 setUpdatePending(false);
214 }
|