author | serb |
Fri, 17 Apr 2015 16:54:13 +0300 | |
changeset 30469 | bac0a7ff7e1e |
parent 25859 | 3317bb8137f4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
18178
diff
changeset
|
2 |
* Copyright (c) 2000, 2013, 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 sun.awt; |
|
27 |
||
28 |
import java.awt.IllegalComponentStateException; |
|
29 |
import java.util.Collections; |
|
30 |
import java.util.Iterator; |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
31 |
import java.util.HashMap; |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
32 |
import java.util.HashSet; |
2 | 33 |
import java.util.Map; |
34 |
import java.util.Set; |
|
35 |
import java.util.WeakHashMap; |
|
36 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
37 |
import sun.util.logging.PlatformLogger; |
2 | 38 |
|
39 |
/** |
|
40 |
* This class is used to aid in keeping track of DisplayChangedListeners and |
|
41 |
* notifying them when a display change has taken place. DisplayChangedListeners |
|
42 |
* are notified when the display's bit depth is changed, or when a top-level |
|
43 |
* window has been dragged onto another screen. |
|
44 |
* |
|
45 |
* It is safe for a DisplayChangedListener to be added while the list is being |
|
46 |
* iterated. |
|
47 |
* |
|
48 |
* The displayChanged() call is propagated after some occurrence (either |
|
49 |
* due to user action or some other application) causes the display mode |
|
50 |
* (e.g., depth or resolution) to change. All heavyweight components need |
|
51 |
* to know when this happens because they need to create new surfaceData |
|
52 |
* objects based on the new depth. |
|
53 |
* |
|
54 |
* displayChanged() is also called on Windows when they are moved from one |
|
55 |
* screen to another on a system equipped with multiple displays. |
|
56 |
*/ |
|
57 |
public class SunDisplayChanger { |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
58 |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
59 |
private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.multiscreen.SunDisplayChanger"); |
2 | 60 |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
61 |
// Create a new synchronized map with initial capacity of one listener. |
2 | 62 |
// It is asserted that the most common case is to have one GraphicsDevice |
63 |
// and one top-level Window. |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
64 |
private Map<DisplayChangedListener, Void> listeners = |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
65 |
Collections.synchronizedMap(new WeakHashMap<DisplayChangedListener, Void>(1)); |
2 | 66 |
|
67 |
public SunDisplayChanger() {} |
|
68 |
||
69 |
/* |
|
70 |
* Add a DisplayChangeListener to this SunDisplayChanger so that it is |
|
71 |
* notified when the display is changed. |
|
72 |
*/ |
|
73 |
public void add(DisplayChangedListener theListener) { |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
11264
diff
changeset
|
74 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
2 | 75 |
if (theListener == null) { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
76 |
log.fine("Assertion (theListener != null) failed"); |
2 | 77 |
} |
78 |
} |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
11264
diff
changeset
|
79 |
if (log.isLoggable(PlatformLogger.Level.FINER)) { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
80 |
log.finer("Adding listener: " + theListener); |
2 | 81 |
} |
82 |
listeners.put(theListener, null); |
|
83 |
} |
|
84 |
||
85 |
/* |
|
86 |
* Remove the given DisplayChangeListener from this SunDisplayChanger. |
|
87 |
*/ |
|
88 |
public void remove(DisplayChangedListener theListener) { |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
11264
diff
changeset
|
89 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
2 | 90 |
if (theListener == null) { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
91 |
log.fine("Assertion (theListener != null) failed"); |
2 | 92 |
} |
93 |
} |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
11264
diff
changeset
|
94 |
if (log.isLoggable(PlatformLogger.Level.FINER)) { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
95 |
log.finer("Removing listener: " + theListener); |
2 | 96 |
} |
97 |
listeners.remove(theListener); |
|
98 |
} |
|
99 |
||
100 |
/* |
|
101 |
* Notify our list of DisplayChangedListeners that a display change has |
|
102 |
* taken place by calling their displayChanged() methods. |
|
103 |
*/ |
|
104 |
public void notifyListeners() { |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
11264
diff
changeset
|
105 |
if (log.isLoggable(PlatformLogger.Level.FINEST)) { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
106 |
log.finest("notifyListeners"); |
2 | 107 |
} |
108 |
// This method is implemented by making a clone of the set of listeners, |
|
109 |
// and then iterating over the clone. This is because during the course |
|
110 |
// of responding to a display change, it may be appropriate for a |
|
111 |
// DisplayChangedListener to add or remove itself from a SunDisplayChanger. |
|
112 |
// If the set itself were iterated over, rather than a clone, it is |
|
113 |
// trivial to get a ConcurrentModificationException by having a |
|
114 |
// DisplayChangedListener remove itself from its list. |
|
115 |
// Because all display change handling is done on the event thread, |
|
116 |
// synchronization provides no protection against modifying the listener |
|
117 |
// list while in the middle of iterating over it. -bchristi 7/10/2001 |
|
118 |
||
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
119 |
Set<DisplayChangedListener> cloneSet; |
2 | 120 |
|
121 |
synchronized(listeners) { |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
122 |
cloneSet = new HashSet<DisplayChangedListener>(listeners.keySet()); |
2 | 123 |
} |
124 |
||
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
125 |
Iterator<DisplayChangedListener> itr = cloneSet.iterator(); |
2 | 126 |
while (itr.hasNext()) { |
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
127 |
DisplayChangedListener current = itr.next(); |
2 | 128 |
try { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
11264
diff
changeset
|
129 |
if (log.isLoggable(PlatformLogger.Level.FINEST)) { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
130 |
log.finest("displayChanged for listener: " + current); |
2 | 131 |
} |
132 |
current.displayChanged(); |
|
133 |
} catch (IllegalComponentStateException e) { |
|
134 |
// This DisplayChangeListener is no longer valid. Most |
|
135 |
// likely, a top-level window was dispose()d, but its |
|
136 |
// Java objects have not yet been garbage collected. In any |
|
137 |
// case, we no longer need to track this listener, though we |
|
138 |
// do need to remove it from the original list, not the clone. |
|
139 |
listeners.remove(current); |
|
140 |
} |
|
141 |
} |
|
142 |
} |
|
143 |
||
144 |
/* |
|
145 |
* Notify our list of DisplayChangedListeners that a palette change has |
|
146 |
* taken place by calling their paletteChanged() methods. |
|
147 |
*/ |
|
148 |
public void notifyPaletteChanged() { |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
11264
diff
changeset
|
149 |
if (log.isLoggable(PlatformLogger.Level.FINEST)) { |
2 | 150 |
log.finest("notifyPaletteChanged"); |
151 |
} |
|
152 |
// This method is implemented by making a clone of the set of listeners, |
|
153 |
// and then iterating over the clone. This is because during the course |
|
154 |
// of responding to a display change, it may be appropriate for a |
|
155 |
// DisplayChangedListener to add or remove itself from a SunDisplayChanger. |
|
156 |
// If the set itself were iterated over, rather than a clone, it is |
|
157 |
// trivial to get a ConcurrentModificationException by having a |
|
158 |
// DisplayChangedListener remove itself from its list. |
|
159 |
// Because all display change handling is done on the event thread, |
|
160 |
// synchronization provides no protection against modifying the listener |
|
161 |
// list while in the middle of iterating over it. -bchristi 7/10/2001 |
|
162 |
||
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
163 |
Set<DisplayChangedListener> cloneSet; |
2 | 164 |
|
165 |
synchronized (listeners) { |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
166 |
cloneSet = new HashSet<DisplayChangedListener>(listeners.keySet()); |
2 | 167 |
} |
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
168 |
Iterator<DisplayChangedListener> itr = cloneSet.iterator(); |
2 | 169 |
while (itr.hasNext()) { |
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
5506
diff
changeset
|
170 |
DisplayChangedListener current = itr.next(); |
2 | 171 |
try { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
11264
diff
changeset
|
172 |
if (log.isLoggable(PlatformLogger.Level.FINEST)) { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
173 |
log.finest("paletteChanged for listener: " + current); |
2 | 174 |
} |
175 |
current.paletteChanged(); |
|
176 |
} catch (IllegalComponentStateException e) { |
|
177 |
// This DisplayChangeListener is no longer valid. Most |
|
178 |
// likely, a top-level window was dispose()d, but its |
|
179 |
// Java objects have not yet been garbage collected. In any |
|
180 |
// case, we no longer need to track this listener, though we |
|
181 |
// do need to remove it from the original list, not the clone. |
|
182 |
listeners.remove(current); |
|
183 |
} |
|
184 |
} |
|
185 |
} |
|
186 |
} |