author | martin |
Thu, 30 Oct 2014 07:31:41 -0700 | |
changeset 28059 | e576535359cc |
parent 27265 | a6528e9ca83b |
child 29511 | 7c491ff8a5fc |
permissions | -rw-r--r-- |
3508 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
20158
diff
changeset
|
2 |
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
3733 | 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 |
3733 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
3733 | 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. |
|
3508 | 24 |
*/ |
25 |
||
26 |
package javax.swing; |
|
27 |
||
6647 | 28 |
import sun.awt.AWTAccessor; |
29 |
||
3508 | 30 |
import javax.swing.plaf.LayerUI; |
6647 | 31 |
import javax.swing.border.Border; |
6838
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
32 |
import javax.accessibility.*; |
3508 | 33 |
import java.awt.*; |
34 |
import java.awt.event.*; |
|
35 |
import java.beans.PropertyChangeEvent; |
|
36 |
import java.beans.PropertyChangeListener; |
|
37 |
import java.io.IOException; |
|
38 |
import java.io.ObjectInputStream; |
|
39 |
import java.util.ArrayList; |
|
40 |
import java.security.AccessController; |
|
41 |
import java.security.PrivilegedAction; |
|
42 |
||
43 |
/** |
|
44 |
* {@code JLayer} is a universal decorator for Swing components |
|
45 |
* which enables you to implement various advanced painting effects as well as |
|
46 |
* receive notifications of all {@code AWTEvent}s generated within its borders. |
|
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
47 |
* <p> |
3508 | 48 |
* {@code JLayer} delegates the handling of painting and input events to a |
49 |
* {@link javax.swing.plaf.LayerUI} object, which performs the actual decoration. |
|
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
50 |
* <p> |
3508 | 51 |
* The custom painting implemented in the {@code LayerUI} and events notification |
52 |
* work for the JLayer itself and all its subcomponents. |
|
53 |
* This combination enables you to enrich existing components |
|
54 |
* by adding new advanced functionality such as temporary locking of a hierarchy, |
|
55 |
* data tips for compound components, enhanced mouse scrolling etc and so on. |
|
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
56 |
* <p> |
3508 | 57 |
* {@code JLayer} is a good solution if you only need to do custom painting |
58 |
* over compound component or catch input events from its subcomponents. |
|
59 |
* <pre> |
|
3973
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
60 |
* import javax.swing.*; |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
61 |
* import javax.swing.plaf.LayerUI; |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
62 |
* import java.awt.*; |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
63 |
* |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
64 |
* public class JLayerSample { |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
65 |
* |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
66 |
* private static JLayer<JComponent> createLayer() { |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
67 |
* // This custom layerUI will fill the layer with translucent green |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
68 |
* // and print out all mouseMotion events generated within its borders |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
69 |
* LayerUI<JComponent> layerUI = new LayerUI<JComponent>() { |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
70 |
* |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
71 |
* public void paint(Graphics g, JComponent c) { |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
72 |
* // paint the layer as is |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
73 |
* super.paint(g, c); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
74 |
* // fill it with the translucent green |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
75 |
* g.setColor(new Color(0, 128, 0, 128)); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
76 |
* g.fillRect(0, 0, c.getWidth(), c.getHeight()); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
77 |
* } |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
78 |
* |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
79 |
* public void installUI(JComponent c) { |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
80 |
* super.installUI(c); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
81 |
* // enable mouse motion events for the layer's subcomponents |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
82 |
* ((JLayer) c).setLayerEventMask(AWTEvent.MOUSE_MOTION_EVENT_MASK); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
83 |
* } |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
84 |
* |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
85 |
* public void uninstallUI(JComponent c) { |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
86 |
* super.uninstallUI(c); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
87 |
* // reset the layer event mask |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
88 |
* ((JLayer) c).setLayerEventMask(0); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
89 |
* } |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
90 |
* |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
91 |
* // overridden method which catches MouseMotion events |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
92 |
* public void eventDispatched(AWTEvent e, JLayer<? extends JComponent> l) { |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
93 |
* System.out.println("AWTEvent detected: " + e); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
94 |
* } |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
95 |
* }; |
3508 | 96 |
* // create a component to be decorated with the layer |
3973
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
97 |
* JPanel panel = new JPanel(); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
98 |
* panel.add(new JButton("JButton")); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
99 |
* |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
100 |
* // create the layer for the panel using our custom layerUI |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
101 |
* return new JLayer<JComponent>(panel, layerUI); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
102 |
* } |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
103 |
* |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
104 |
* private static void createAndShowGUI() { |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
105 |
* final JFrame frame = new JFrame(); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
106 |
* frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
107 |
* |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
108 |
* // work with the layer as with any other Swing component |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
109 |
* frame.add(createLayer()); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
110 |
* |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
111 |
* frame.setSize(200, 200); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
112 |
* frame.setLocationRelativeTo(null); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
113 |
* frame.setVisible(true); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
114 |
* } |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
115 |
* |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
116 |
* public static void main(String[] args) throws Exception { |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
117 |
* SwingUtilities.invokeAndWait(new Runnable() { |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
118 |
* public void run() { |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
119 |
* createAndShowGUI(); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
120 |
* } |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
121 |
* }); |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
122 |
* } |
3bdd09958faf
6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents:
3748
diff
changeset
|
123 |
* } |
3508 | 124 |
* </pre> |
125 |
* |
|
126 |
* <b>Note:</b> {@code JLayer} doesn't support the following methods: |
|
127 |
* <ul> |
|
128 |
* <li>{@link Container#add(java.awt.Component)}</li> |
|
129 |
* <li>{@link Container#add(String, java.awt.Component)}</li> |
|
130 |
* <li>{@link Container#add(java.awt.Component, int)}</li> |
|
131 |
* <li>{@link Container#add(java.awt.Component, Object)}</li> |
|
132 |
* <li>{@link Container#add(java.awt.Component, Object, int)}</li> |
|
133 |
* </ul> |
|
28059
e576535359cc
8067377: My hobby: caning, then then canning, the the can-can
martin
parents:
27265
diff
changeset
|
134 |
* using any of them will cause {@code UnsupportedOperationException} to be thrown, |
3508 | 135 |
* to add a component to {@code JLayer} |
136 |
* use {@link #setView(Component)} or {@link #setGlassPane(JPanel)}. |
|
137 |
* |
|
138 |
* @param <V> the type of {@code JLayer}'s view component |
|
139 |
* |
|
140 |
* @see #JLayer(Component) |
|
141 |
* @see #setView(Component) |
|
142 |
* @see #getView() |
|
143 |
* @see javax.swing.plaf.LayerUI |
|
144 |
* @see #JLayer(Component, LayerUI) |
|
145 |
* @see #setUI(javax.swing.plaf.LayerUI) |
|
146 |
* @see #getUI() |
|
147 |
* @since 1.7 |
|
148 |
* |
|
149 |
* @author Alexander Potochkin |
|
150 |
*/ |
|
23697 | 151 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
3508 | 152 |
public final class JLayer<V extends Component> |
153 |
extends JComponent |
|
6838
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
154 |
implements Scrollable, PropertyChangeListener, Accessible { |
3508 | 155 |
private V view; |
156 |
// this field is necessary because JComponent.ui is transient |
|
157 |
// when layerUI is serializable |
|
158 |
private LayerUI<? super V> layerUI; |
|
159 |
private JPanel glassPane; |
|
160 |
private long eventMask; |
|
26029
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
161 |
private transient boolean isPaintCalling; |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
162 |
private transient boolean isPaintImmediatelyCalling; |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
163 |
private transient boolean isImageUpdateCalling; |
3508 | 164 |
|
165 |
private static final LayerEventController eventController = |
|
166 |
new LayerEventController(); |
|
167 |
||
168 |
/** |
|
169 |
* Creates a new {@code JLayer} object with a {@code null} view component |
|
6647 | 170 |
* and default {@link javax.swing.plaf.LayerUI}. |
3508 | 171 |
* |
172 |
* @see #setView |
|
173 |
* @see #setUI |
|
174 |
*/ |
|
175 |
public JLayer() { |
|
176 |
this(null); |
|
177 |
} |
|
178 |
||
179 |
/** |
|
180 |
* Creates a new {@code JLayer} object |
|
6647 | 181 |
* with default {@link javax.swing.plaf.LayerUI}. |
3508 | 182 |
* |
183 |
* @param view the component to be decorated by this {@code JLayer} |
|
184 |
* |
|
185 |
* @see #setUI |
|
186 |
*/ |
|
187 |
public JLayer(V view) { |
|
6647 | 188 |
this(view, new LayerUI<V>()); |
3508 | 189 |
} |
190 |
||
191 |
/** |
|
192 |
* Creates a new {@code JLayer} object with the specified view component |
|
193 |
* and {@link javax.swing.plaf.LayerUI} object. |
|
194 |
* |
|
195 |
* @param view the component to be decorated |
|
196 |
* @param ui the {@link javax.swing.plaf.LayerUI} delegate |
|
197 |
* to be used by this {@code JLayer} |
|
198 |
*/ |
|
199 |
public JLayer(V view, LayerUI<V> ui) { |
|
200 |
setGlassPane(createGlassPane()); |
|
201 |
setView(view); |
|
202 |
setUI(ui); |
|
203 |
} |
|
204 |
||
205 |
/** |
|
206 |
* Returns the {@code JLayer}'s view component or {@code null}. |
|
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
207 |
* <br>This is a bound property. |
3508 | 208 |
* |
209 |
* @return the {@code JLayer}'s view component |
|
210 |
* or {@code null} if none exists |
|
211 |
* |
|
3748
b88af44d77a8
6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents:
3743
diff
changeset
|
212 |
* @see #setView(Component) |
3508 | 213 |
*/ |
214 |
public V getView() { |
|
215 |
return view; |
|
216 |
} |
|
217 |
||
218 |
/** |
|
219 |
* Sets the {@code JLayer}'s view component, which can be {@code null}. |
|
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
220 |
* <br>This is a bound property. |
3508 | 221 |
* |
222 |
* @param view the view component for this {@code JLayer} |
|
223 |
* |
|
224 |
* @see #getView() |
|
225 |
*/ |
|
226 |
public void setView(V view) { |
|
227 |
Component oldView = getView(); |
|
228 |
if (oldView != null) { |
|
229 |
super.remove(oldView); |
|
230 |
} |
|
231 |
if (view != null) { |
|
232 |
super.addImpl(view, null, getComponentCount()); |
|
233 |
} |
|
234 |
this.view = view; |
|
235 |
firePropertyChange("view", oldView, view); |
|
236 |
revalidate(); |
|
237 |
repaint(); |
|
238 |
} |
|
239 |
||
240 |
/** |
|
241 |
* Sets the {@link javax.swing.plaf.LayerUI} which will perform painting |
|
242 |
* and receive input events for this {@code JLayer}. |
|
243 |
* |
|
244 |
* @param ui the {@link javax.swing.plaf.LayerUI} for this {@code JLayer} |
|
245 |
*/ |
|
246 |
public void setUI(LayerUI<? super V> ui) { |
|
247 |
this.layerUI = ui; |
|
248 |
super.setUI(ui); |
|
249 |
} |
|
250 |
||
251 |
/** |
|
252 |
* Returns the {@link javax.swing.plaf.LayerUI} for this {@code JLayer}. |
|
253 |
* |
|
254 |
* @return the {@code LayerUI} for this {@code JLayer} |
|
255 |
*/ |
|
256 |
public LayerUI<? super V> getUI() { |
|
257 |
return layerUI; |
|
258 |
} |
|
259 |
||
260 |
/** |
|
261 |
* Returns the {@code JLayer}'s glassPane component or {@code null}. |
|
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
262 |
* <br>This is a bound property. |
3508 | 263 |
* |
264 |
* @return the {@code JLayer}'s glassPane component |
|
265 |
* or {@code null} if none exists |
|
266 |
* |
|
267 |
* @see #setGlassPane(JPanel) |
|
268 |
*/ |
|
269 |
public JPanel getGlassPane() { |
|
270 |
return glassPane; |
|
271 |
} |
|
272 |
||
273 |
/** |
|
274 |
* Sets the {@code JLayer}'s glassPane component, which can be {@code null}. |
|
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
275 |
* <br>This is a bound property. |
3508 | 276 |
* |
277 |
* @param glassPane the glassPane component of this {@code JLayer} |
|
278 |
* |
|
279 |
* @see #getGlassPane() |
|
280 |
*/ |
|
281 |
public void setGlassPane(JPanel glassPane) { |
|
282 |
Component oldGlassPane = getGlassPane(); |
|
6647 | 283 |
boolean isGlassPaneVisible = false; |
3508 | 284 |
if (oldGlassPane != null) { |
6647 | 285 |
isGlassPaneVisible = oldGlassPane.isVisible(); |
3508 | 286 |
super.remove(oldGlassPane); |
287 |
} |
|
288 |
if (glassPane != null) { |
|
6647 | 289 |
AWTAccessor.getComponentAccessor().setMixingCutoutShape(glassPane, |
290 |
new Rectangle()); |
|
291 |
glassPane.setVisible(isGlassPaneVisible); |
|
3508 | 292 |
super.addImpl(glassPane, null, 0); |
293 |
} |
|
294 |
this.glassPane = glassPane; |
|
295 |
firePropertyChange("glassPane", oldGlassPane, glassPane); |
|
296 |
revalidate(); |
|
297 |
repaint(); |
|
298 |
} |
|
299 |
||
300 |
/** |
|
301 |
* Called by the constructor methods to create a default {@code glassPane}. |
|
302 |
* By default this method creates a new JPanel with visibility set to true |
|
303 |
* and opacity set to false. |
|
304 |
* |
|
305 |
* @return the default {@code glassPane} |
|
306 |
*/ |
|
307 |
public JPanel createGlassPane() { |
|
308 |
return new DefaultLayerGlassPane(); |
|
309 |
} |
|
310 |
||
311 |
/** |
|
6647 | 312 |
* Sets the layout manager for this container. This method is |
313 |
* overridden to prevent the layout manager from being set. |
|
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
314 |
* <p>Note: If {@code mgr} is non-{@code null}, this |
6647 | 315 |
* method will throw an exception as layout managers are not supported on |
316 |
* a {@code JLayer}. |
|
317 |
* |
|
318 |
* @param mgr the specified layout manager |
|
319 |
* @exception IllegalArgumentException this method is not supported |
|
320 |
*/ |
|
321 |
public void setLayout(LayoutManager mgr) { |
|
322 |
if (mgr != null) { |
|
323 |
throw new IllegalArgumentException("JLayer.setLayout() not supported"); |
|
324 |
} |
|
325 |
} |
|
326 |
||
327 |
/** |
|
27265
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
328 |
* Delegates its functionality to the {@code getView().setBorder(Border)} method, |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
329 |
* if the view component is an instance of {@code javax.swing.JComponent}, |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
330 |
* otherwise this method is a no-op. |
6647 | 331 |
* |
27265
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
332 |
* @param border the border to be rendered for the {@code view} component |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
333 |
* @see #getView() |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
334 |
* @see javax.swing.JComponent#setBorder(Border) |
6647 | 335 |
*/ |
336 |
public void setBorder(Border border) { |
|
27265
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
337 |
if (view instanceof JComponent) { |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
338 |
((JComponent)view).setBorder(border); |
6647 | 339 |
} |
340 |
} |
|
341 |
||
342 |
/** |
|
27265
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
343 |
* Delegates its functionality to the {@code getView().getBorder()} method, |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
344 |
* if the view component is an instance of {@code javax.swing.JComponent}, |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
345 |
* otherwise returns {@code null}. |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
346 |
* |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
347 |
* @return the border object for the {@code view} component |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
348 |
* @see #getView() |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
349 |
* @see #setBorder |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
350 |
* @see javax.swing.JComponent#getBorder() |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
351 |
*/ |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
352 |
public Border getBorder() { |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
353 |
if (view instanceof JComponent) { |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
354 |
return ((JComponent) view).getBorder(); |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
355 |
} |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
356 |
return null; |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
357 |
} |
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
358 |
|
a6528e9ca83b
8054543: Setting a border on a JLayer causes an Exceptions
alexp
parents:
26037
diff
changeset
|
359 |
/** |
3508 | 360 |
* This method is not supported by {@code JLayer} |
361 |
* and always throws {@code UnsupportedOperationException} |
|
362 |
* |
|
363 |
* @throws UnsupportedOperationException this method is not supported |
|
364 |
* |
|
365 |
* @see #setView(Component) |
|
3748
b88af44d77a8
6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents:
3743
diff
changeset
|
366 |
* @see #setGlassPane(JPanel) |
3508 | 367 |
*/ |
368 |
protected void addImpl(Component comp, Object constraints, int index) { |
|
369 |
throw new UnsupportedOperationException( |
|
370 |
"Adding components to JLayer is not supported, " + |
|
371 |
"use setView() or setGlassPane() instead"); |
|
372 |
} |
|
373 |
||
374 |
/** |
|
375 |
* {@inheritDoc} |
|
376 |
*/ |
|
377 |
public void remove(Component comp) { |
|
3975
097245f7db08
6875716: JLayer.remove((Component)null) should behave consistently in (not) throwing NPE
alexp
parents:
3973
diff
changeset
|
378 |
if (comp == null) { |
097245f7db08
6875716: JLayer.remove((Component)null) should behave consistently in (not) throwing NPE
alexp
parents:
3973
diff
changeset
|
379 |
super.remove(comp); |
097245f7db08
6875716: JLayer.remove((Component)null) should behave consistently in (not) throwing NPE
alexp
parents:
3973
diff
changeset
|
380 |
} else if (comp == getView()) { |
3508 | 381 |
setView(null); |
382 |
} else if (comp == getGlassPane()) { |
|
383 |
setGlassPane(null); |
|
384 |
} else { |
|
385 |
super.remove(comp); |
|
386 |
} |
|
387 |
} |
|
388 |
||
389 |
/** |
|
390 |
* {@inheritDoc} |
|
391 |
*/ |
|
392 |
public void removeAll() { |
|
7250
b16cad13bf2c
6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents:
7005
diff
changeset
|
393 |
if (view != null) { |
b16cad13bf2c
6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents:
7005
diff
changeset
|
394 |
setView(null); |
b16cad13bf2c
6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents:
7005
diff
changeset
|
395 |
} |
b16cad13bf2c
6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents:
7005
diff
changeset
|
396 |
if (glassPane != null) { |
b16cad13bf2c
6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents:
7005
diff
changeset
|
397 |
setGlassPane(null); |
b16cad13bf2c
6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents:
7005
diff
changeset
|
398 |
} |
3508 | 399 |
} |
400 |
||
401 |
/** |
|
6647 | 402 |
* Always returns {@code true} to cause painting to originate from {@code JLayer}, |
403 |
* or one of its ancestors. |
|
404 |
* |
|
405 |
* @return true |
|
406 |
* @see JComponent#isPaintingOrigin() |
|
407 |
*/ |
|
7005
5e6d24f4303b
6989617: Enable JComponent to control repaintings of its children
alexp
parents:
6838
diff
changeset
|
408 |
protected boolean isPaintingOrigin() { |
6647 | 409 |
return true; |
410 |
} |
|
411 |
||
412 |
/** |
|
8372
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
413 |
* Delegates its functionality to the |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
414 |
* {@link javax.swing.plaf.LayerUI#paintImmediately(int, int, int, int, JLayer)} method, |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
415 |
* if {@code LayerUI} is set. |
6647 | 416 |
* |
8372
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
417 |
* @param x the x value of the region to be painted |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
418 |
* @param y the y value of the region to be painted |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
419 |
* @param w the width of the region to be painted |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
420 |
* @param h the height of the region to be painted |
6647 | 421 |
*/ |
8372
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
422 |
public void paintImmediately(int x, int y, int w, int h) { |
26029
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
423 |
if (!isPaintImmediatelyCalling && getUI() != null) { |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
424 |
isPaintImmediatelyCalling = true; |
8372
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
425 |
try { |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
426 |
getUI().paintImmediately(x, y, w, h, this); |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
427 |
} finally { |
26029
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
428 |
isPaintImmediatelyCalling = false; |
8372
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
429 |
} |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
430 |
} else { |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
431 |
super.paintImmediately(x, y, w, h); |
6647 | 432 |
} |
433 |
} |
|
434 |
||
435 |
/** |
|
26029
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
436 |
* Delegates its functionality to the |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
437 |
* {@link javax.swing.plaf.LayerUI#imageUpdate(java.awt.Image, int, int, int, int, int, JLayer)} method, |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
438 |
* if the {@code LayerUI} is set. |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
439 |
* |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
440 |
* @param img the image being observed |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
441 |
* @param infoflags see {@code imageUpdate} for more information |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
442 |
* @param x the <i>x</i> coordinate |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
443 |
* @param y the <i>y</i> coordinate |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
444 |
* @param w the width |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
445 |
* @param h the height |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
446 |
* @return {@code false} if the infoflags indicate that the |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
447 |
* image is completely loaded; {@code true} otherwise. |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
448 |
*/ |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
449 |
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) { |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
450 |
if (!isImageUpdateCalling && getUI() != null) { |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
451 |
isImageUpdateCalling = true; |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
452 |
try { |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
453 |
return getUI().imageUpdate(img, infoflags, x, y, w, h, this); |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
454 |
} finally { |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
455 |
isImageUpdateCalling = false; |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
456 |
} |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
457 |
} else { |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
458 |
return super.imageUpdate(img, infoflags, x, y, w, h); |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
459 |
} |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
460 |
} |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
461 |
|
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
462 |
/** |
3508 | 463 |
* Delegates all painting to the {@link javax.swing.plaf.LayerUI} object. |
464 |
* |
|
465 |
* @param g the {@code Graphics} to render to |
|
466 |
*/ |
|
467 |
public void paint(Graphics g) { |
|
26029
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
468 |
if (!isPaintCalling) { |
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
469 |
isPaintCalling = true; |
8372
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
470 |
try { |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
471 |
super.paintComponent(g); |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
472 |
} finally { |
26029
730f9bc4b85e
8041982: Use of animated icon in JLayer causes CPU spin
alexp
parents:
26027
diff
changeset
|
473 |
isPaintCalling = false; |
8372
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
474 |
} |
3508 | 475 |
} else { |
476 |
super.paint(g); |
|
477 |
} |
|
478 |
} |
|
479 |
||
480 |
/** |
|
481 |
* This method is empty, because all painting is done by |
|
482 |
* {@link #paint(Graphics)} and |
|
483 |
* {@link javax.swing.plaf.LayerUI#update(Graphics, JComponent)} methods |
|
484 |
*/ |
|
485 |
protected void paintComponent(Graphics g) { |
|
486 |
} |
|
487 |
||
488 |
/** |
|
6647 | 489 |
* The {@code JLayer} overrides the default implementation of |
490 |
* this method (in {@code JComponent}) to return {@code false}. |
|
491 |
* This ensures |
|
492 |
* that the drawing machinery will call the {@code JLayer}'s |
|
493 |
* {@code paint} |
|
494 |
* implementation rather than messaging the {@code JLayer}'s |
|
495 |
* children directly. |
|
3508 | 496 |
* |
6647 | 497 |
* @return false |
3508 | 498 |
*/ |
499 |
public boolean isOptimizedDrawingEnabled() { |
|
6647 | 500 |
return false; |
3508 | 501 |
} |
502 |
||
503 |
/** |
|
504 |
* {@inheritDoc} |
|
505 |
*/ |
|
506 |
public void propertyChange(PropertyChangeEvent evt) { |
|
507 |
if (getUI() != null) { |
|
508 |
getUI().applyPropertyChange(evt, this); |
|
509 |
} |
|
510 |
} |
|
511 |
||
512 |
/** |
|
5451
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
513 |
* Enables the events from JLayer and <b>all its descendants</b> |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
514 |
* defined by the specified event mask parameter |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
515 |
* to be delivered to the |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
516 |
* {@link LayerUI#eventDispatched(AWTEvent, JLayer)} method. |
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
517 |
* <p> |
5451
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
518 |
* Events are delivered provided that {@code LayerUI} is set |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
519 |
* for this {@code JLayer} and the {@code JLayer} |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
520 |
* is displayable. |
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
521 |
* <p> |
8955 | 522 |
* The following example shows how to correctly use this method |
3508 | 523 |
* in the {@code LayerUI} implementations: |
524 |
* <pre> |
|
525 |
* public void installUI(JComponent c) { |
|
526 |
* super.installUI(c); |
|
527 |
* JLayer l = (JLayer) c; |
|
528 |
* // this LayerUI will receive only key and focus events |
|
529 |
* l.setLayerEventMask(AWTEvent.KEY_EVENT_MASK | AWTEvent.FOCUS_EVENT_MASK); |
|
530 |
* } |
|
531 |
* |
|
532 |
* public void uninstallUI(JComponent c) { |
|
533 |
* super.uninstallUI(c); |
|
534 |
* JLayer l = (JLayer) c; |
|
535 |
* // JLayer must be returned to its initial state |
|
536 |
* l.setLayerEventMask(0); |
|
537 |
* } |
|
538 |
* </pre> |
|
539 |
* |
|
5451
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
540 |
* By default {@code JLayer} receives no events and its event mask is {@code 0}. |
3508 | 541 |
* |
542 |
* @param layerEventMask the bitmask of event types to receive |
|
543 |
* |
|
544 |
* @see #getLayerEventMask() |
|
5451
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
545 |
* @see LayerUI#eventDispatched(AWTEvent, JLayer) |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
546 |
* @see Component#isDisplayable() |
3508 | 547 |
*/ |
548 |
public void setLayerEventMask(long layerEventMask) { |
|
549 |
long oldEventMask = getLayerEventMask(); |
|
550 |
this.eventMask = layerEventMask; |
|
551 |
firePropertyChange("layerEventMask", oldEventMask, layerEventMask); |
|
552 |
if (layerEventMask != oldEventMask) { |
|
553 |
disableEvents(oldEventMask); |
|
554 |
enableEvents(eventMask); |
|
3743 | 555 |
if (isDisplayable()) { |
556 |
eventController.updateAWTEventListener( |
|
557 |
oldEventMask, layerEventMask); |
|
558 |
} |
|
3508 | 559 |
} |
560 |
} |
|
561 |
||
562 |
/** |
|
563 |
* Returns the bitmap of event mask to receive by this {@code JLayer} |
|
564 |
* and its {@code LayerUI}. |
|
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
565 |
* <p> |
3508 | 566 |
* It means that {@link javax.swing.plaf.LayerUI#eventDispatched(AWTEvent, JLayer)} method |
567 |
* will only receive events that match the event mask. |
|
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
568 |
* <p> |
3508 | 569 |
* By default {@code JLayer} receives no events. |
570 |
* |
|
571 |
* @return the bitmask of event types to receive for this {@code JLayer} |
|
572 |
*/ |
|
573 |
public long getLayerEventMask() { |
|
574 |
return eventMask; |
|
575 |
} |
|
576 |
||
577 |
/** |
|
578 |
* Delegates its functionality to the {@link javax.swing.plaf.LayerUI#updateUI(JLayer)} method, |
|
579 |
* if {@code LayerUI} is set. |
|
580 |
*/ |
|
581 |
public void updateUI() { |
|
582 |
if (getUI() != null) { |
|
583 |
getUI().updateUI(this); |
|
584 |
} |
|
585 |
} |
|
586 |
||
587 |
/** |
|
588 |
* Returns the preferred size of the viewport for a view component. |
|
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
589 |
* <p> |
6647 | 590 |
* If the view component of this layer implements {@link Scrollable}, this method delegates its |
591 |
* implementation to the view component. |
|
3508 | 592 |
* |
593 |
* @return the preferred size of the viewport for a view component |
|
594 |
* |
|
595 |
* @see Scrollable |
|
596 |
*/ |
|
597 |
public Dimension getPreferredScrollableViewportSize() { |
|
6647 | 598 |
if (getView() instanceof Scrollable) { |
599 |
return ((Scrollable)getView()).getPreferredScrollableViewportSize(); |
|
3508 | 600 |
} |
601 |
return getPreferredSize(); |
|
602 |
} |
|
603 |
||
604 |
/** |
|
605 |
* Returns a scroll increment, which is required for components |
|
606 |
* that display logical rows or columns in order to completely expose |
|
607 |
* one block of rows or columns, depending on the value of orientation. |
|
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
608 |
* <p> |
6647 | 609 |
* If the view component of this layer implements {@link Scrollable}, this method delegates its |
610 |
* implementation to the view component. |
|
3508 | 611 |
* |
612 |
* @return the "block" increment for scrolling in the specified direction |
|
613 |
* |
|
614 |
* @see Scrollable |
|
615 |
*/ |
|
616 |
public int getScrollableBlockIncrement(Rectangle visibleRect, |
|
617 |
int orientation, int direction) { |
|
6647 | 618 |
if (getView() instanceof Scrollable) { |
619 |
return ((Scrollable)getView()).getScrollableBlockIncrement(visibleRect, |
|
3508 | 620 |
orientation, direction); |
621 |
} |
|
622 |
return (orientation == SwingConstants.VERTICAL) ? visibleRect.height : |
|
623 |
visibleRect.width; |
|
624 |
} |
|
625 |
||
626 |
/** |
|
627 |
* Returns {@code false} to indicate that the height of the viewport does not |
|
628 |
* determine the height of the layer, unless the preferred height |
|
629 |
* of the layer is smaller than the height of the viewport. |
|
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
630 |
* <p> |
6647 | 631 |
* If the view component of this layer implements {@link Scrollable}, this method delegates its |
632 |
* implementation to the view component. |
|
3508 | 633 |
* |
634 |
* @return whether the layer should track the height of the viewport |
|
635 |
* |
|
636 |
* @see Scrollable |
|
637 |
*/ |
|
638 |
public boolean getScrollableTracksViewportHeight() { |
|
6647 | 639 |
if (getView() instanceof Scrollable) { |
640 |
return ((Scrollable)getView()).getScrollableTracksViewportHeight(); |
|
3508 | 641 |
} |
642 |
return false; |
|
643 |
} |
|
644 |
||
645 |
/** |
|
646 |
* Returns {@code false} to indicate that the width of the viewport does not |
|
647 |
* determine the width of the layer, unless the preferred width |
|
648 |
* of the layer is smaller than the width of the viewport. |
|
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
649 |
* <p> |
6647 | 650 |
* If the view component of this layer implements {@link Scrollable}, this method delegates its |
651 |
* implementation to the view component. |
|
3508 | 652 |
* |
653 |
* @return whether the layer should track the width of the viewport |
|
654 |
* |
|
655 |
* @see Scrollable |
|
656 |
*/ |
|
657 |
public boolean getScrollableTracksViewportWidth() { |
|
6647 | 658 |
if (getView() instanceof Scrollable) { |
659 |
return ((Scrollable)getView()).getScrollableTracksViewportWidth(); |
|
3508 | 660 |
} |
661 |
return false; |
|
662 |
} |
|
663 |
||
664 |
/** |
|
665 |
* Returns a scroll increment, which is required for components |
|
666 |
* that display logical rows or columns in order to completely expose |
|
667 |
* one new row or column, depending on the value of orientation. |
|
668 |
* Ideally, components should handle a partially exposed row or column |
|
669 |
* by returning the distance required to completely expose the item. |
|
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
670 |
* <p> |
3508 | 671 |
* Scrolling containers, like {@code JScrollPane}, will use this method |
672 |
* each time the user requests a unit scroll. |
|
20158
1c5d22e5b898
8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents:
9050
diff
changeset
|
673 |
* <p> |
6647 | 674 |
* If the view component of this layer implements {@link Scrollable}, this method delegates its |
675 |
* implementation to the view component. |
|
3508 | 676 |
* |
677 |
* @return The "unit" increment for scrolling in the specified direction. |
|
678 |
* This value should always be positive. |
|
679 |
* |
|
680 |
* @see Scrollable |
|
681 |
*/ |
|
682 |
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, |
|
683 |
int direction) { |
|
6647 | 684 |
if (getView() instanceof Scrollable) { |
685 |
return ((Scrollable) getView()).getScrollableUnitIncrement( |
|
686 |
visibleRect, orientation, direction); |
|
3508 | 687 |
} |
688 |
return 1; |
|
689 |
} |
|
690 |
||
26027
f42f02a8666d
8054371: Need to suppress newly added unchecked cast and conversion in Swing code
prr
parents:
26001
diff
changeset
|
691 |
@SuppressWarnings("unchecked") |
3508 | 692 |
private void readObject(ObjectInputStream s) |
693 |
throws IOException, ClassNotFoundException { |
|
26001
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
694 |
ObjectInputStream.GetField f = s.readFields(); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
695 |
|
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
696 |
view = (V) f.get("view", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
697 |
glassPane = (JPanel) f.get("glassPane", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
698 |
eventMask = f.get("eventMask", 0l); |
3743 | 699 |
if (eventMask != 0) { |
700 |
eventController.updateAWTEventListener(0, eventMask); |
|
3508 | 701 |
} |
26001
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
702 |
LayerUI<V> newLayerUI = (LayerUI<V>) f.get("layerUI", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
703 |
if (newLayerUI != null) { |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
704 |
setUI(newLayerUI); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25568
diff
changeset
|
705 |
} |
3743 | 706 |
} |
707 |
||
3748
b88af44d77a8
6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents:
3743
diff
changeset
|
708 |
/** |
b88af44d77a8
6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents:
3743
diff
changeset
|
709 |
* {@inheritDoc} |
b88af44d77a8
6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents:
3743
diff
changeset
|
710 |
*/ |
3743 | 711 |
public void addNotify() { |
3748
b88af44d77a8
6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents:
3743
diff
changeset
|
712 |
super.addNotify(); |
3743 | 713 |
eventController.updateAWTEventListener(0, eventMask); |
714 |
} |
|
715 |
||
3748
b88af44d77a8
6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents:
3743
diff
changeset
|
716 |
/** |
b88af44d77a8
6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents:
3743
diff
changeset
|
717 |
* {@inheritDoc} |
b88af44d77a8
6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents:
3743
diff
changeset
|
718 |
*/ |
3743 | 719 |
public void removeNotify() { |
3748
b88af44d77a8
6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents:
3743
diff
changeset
|
720 |
super.removeNotify(); |
3743 | 721 |
eventController.updateAWTEventListener(eventMask, 0); |
3508 | 722 |
} |
723 |
||
724 |
/** |
|
6647 | 725 |
* Delegates its functionality to the {@link javax.swing.plaf.LayerUI#doLayout(JLayer)} method, |
726 |
* if {@code LayerUI} is set. |
|
727 |
*/ |
|
728 |
public void doLayout() { |
|
729 |
if (getUI() != null) { |
|
730 |
getUI().doLayout(this); |
|
731 |
} |
|
732 |
} |
|
733 |
||
734 |
/** |
|
6838
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
735 |
* Gets the AccessibleContext associated with this {@code JLayer}. |
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
736 |
* |
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
737 |
* @return the AccessibleContext associated with this {@code JLayer}. |
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
738 |
*/ |
23697 | 739 |
@SuppressWarnings("serial") // anonymous class |
6838
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
740 |
public AccessibleContext getAccessibleContext() { |
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
741 |
if (accessibleContext == null) { |
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
742 |
accessibleContext = new AccessibleJComponent() { |
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
743 |
public AccessibleRole getAccessibleRole() { |
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
744 |
return AccessibleRole.PANEL; |
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
745 |
} |
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
746 |
}; |
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
747 |
} |
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
748 |
return accessibleContext; |
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
749 |
} |
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
750 |
|
c101d59707f3
6986385: JLayer should implement accessible interface
alexp
parents:
6647
diff
changeset
|
751 |
/** |
3508 | 752 |
* static AWTEventListener to be shared with all AbstractLayerUIs |
753 |
*/ |
|
754 |
private static class LayerEventController implements AWTEventListener { |
|
3743 | 755 |
private ArrayList<Long> layerMaskList = |
756 |
new ArrayList<Long>(); |
|
3508 | 757 |
|
758 |
private long currentEventMask; |
|
759 |
||
5451
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
760 |
private static final long ACCEPTED_EVENTS = |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
761 |
AWTEvent.COMPONENT_EVENT_MASK | |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
762 |
AWTEvent.CONTAINER_EVENT_MASK | |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
763 |
AWTEvent.FOCUS_EVENT_MASK | |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
764 |
AWTEvent.KEY_EVENT_MASK | |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
765 |
AWTEvent.MOUSE_WHEEL_EVENT_MASK | |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
766 |
AWTEvent.MOUSE_MOTION_EVENT_MASK | |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
767 |
AWTEvent.MOUSE_EVENT_MASK | |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
768 |
AWTEvent.INPUT_METHOD_EVENT_MASK | |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
769 |
AWTEvent.HIERARCHY_EVENT_MASK | |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
770 |
AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK; |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
771 |
|
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23697
diff
changeset
|
772 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
3508 | 773 |
public void eventDispatched(AWTEvent event) { |
774 |
Object source = event.getSource(); |
|
775 |
if (source instanceof Component) { |
|
776 |
Component component = (Component) source; |
|
777 |
while (component != null) { |
|
778 |
if (component instanceof JLayer) { |
|
779 |
JLayer l = (JLayer) component; |
|
25568
b906a74c6882
8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents:
23697
diff
changeset
|
780 |
LayerUI<?> ui = l.getUI(); |
3508 | 781 |
if (ui != null && |
6647 | 782 |
isEventEnabled(l.getLayerEventMask(), event.getID()) && |
783 |
(!(event instanceof InputEvent) || !((InputEvent)event).isConsumed())) { |
|
3508 | 784 |
ui.eventDispatched(event, l); |
785 |
} |
|
786 |
} |
|
787 |
component = component.getParent(); |
|
788 |
} |
|
789 |
} |
|
790 |
} |
|
791 |
||
3743 | 792 |
private void updateAWTEventListener(long oldEventMask, long newEventMask) { |
793 |
if (oldEventMask != 0) { |
|
794 |
layerMaskList.remove(oldEventMask); |
|
3508 | 795 |
} |
3743 | 796 |
if (newEventMask != 0) { |
797 |
layerMaskList.add(newEventMask); |
|
3508 | 798 |
} |
799 |
long combinedMask = 0; |
|
3743 | 800 |
for (Long mask : layerMaskList) { |
801 |
combinedMask |= mask; |
|
3508 | 802 |
} |
5451
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
803 |
// filter out all unaccepted events |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
3975
diff
changeset
|
804 |
combinedMask &= ACCEPTED_EVENTS; |
3508 | 805 |
if (combinedMask == 0) { |
806 |
removeAWTEventListener(); |
|
807 |
} else if (getCurrentEventMask() != combinedMask) { |
|
808 |
removeAWTEventListener(); |
|
809 |
addAWTEventListener(combinedMask); |
|
810 |
} |
|
3743 | 811 |
currentEventMask = combinedMask; |
3508 | 812 |
} |
813 |
||
814 |
private long getCurrentEventMask() { |
|
815 |
return currentEventMask; |
|
816 |
} |
|
817 |
||
818 |
private void addAWTEventListener(final long eventMask) { |
|
819 |
AccessController.doPrivileged(new PrivilegedAction<Void>() { |
|
820 |
public Void run() { |
|
821 |
Toolkit.getDefaultToolkit(). |
|
822 |
addAWTEventListener(LayerEventController.this, eventMask); |
|
823 |
return null; |
|
824 |
} |
|
825 |
}); |
|
3743 | 826 |
|
3508 | 827 |
} |
828 |
||
829 |
private void removeAWTEventListener() { |
|
830 |
AccessController.doPrivileged(new PrivilegedAction<Void>() { |
|
831 |
public Void run() { |
|
832 |
Toolkit.getDefaultToolkit(). |
|
833 |
removeAWTEventListener(LayerEventController.this); |
|
834 |
return null; |
|
835 |
} |
|
836 |
}); |
|
837 |
} |
|
838 |
||
839 |
private boolean isEventEnabled(long eventMask, int id) { |
|
840 |
return (((eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 && |
|
841 |
id >= ComponentEvent.COMPONENT_FIRST && |
|
842 |
id <= ComponentEvent.COMPONENT_LAST) |
|
843 |
|| ((eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 && |
|
844 |
id >= ContainerEvent.CONTAINER_FIRST && |
|
845 |
id <= ContainerEvent.CONTAINER_LAST) |
|
846 |
|| ((eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0 && |
|
847 |
id >= FocusEvent.FOCUS_FIRST && |
|
848 |
id <= FocusEvent.FOCUS_LAST) |
|
849 |
|| ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 && |
|
850 |
id >= KeyEvent.KEY_FIRST && |
|
851 |
id <= KeyEvent.KEY_LAST) |
|
852 |
|| ((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0 && |
|
853 |
id == MouseEvent.MOUSE_WHEEL) |
|
854 |
|| ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 && |
|
855 |
(id == MouseEvent.MOUSE_MOVED || |
|
856 |
id == MouseEvent.MOUSE_DRAGGED)) |
|
857 |
|| ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 && |
|
858 |
id != MouseEvent.MOUSE_MOVED && |
|
859 |
id != MouseEvent.MOUSE_DRAGGED && |
|
860 |
id != MouseEvent.MOUSE_WHEEL && |
|
861 |
id >= MouseEvent.MOUSE_FIRST && |
|
862 |
id <= MouseEvent.MOUSE_LAST) |
|
863 |
|| ((eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 && |
|
864 |
id >= InputMethodEvent.INPUT_METHOD_FIRST && |
|
865 |
id <= InputMethodEvent.INPUT_METHOD_LAST) |
|
866 |
|| ((eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 && |
|
867 |
id == HierarchyEvent.HIERARCHY_CHANGED) |
|
868 |
|| ((eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 && |
|
869 |
(id == HierarchyEvent.ANCESTOR_MOVED || |
|
870 |
id == HierarchyEvent.ANCESTOR_RESIZED))); |
|
871 |
} |
|
872 |
} |
|
873 |
||
874 |
/** |
|
875 |
* The default glassPane for the {@link javax.swing.JLayer}. |
|
876 |
* It is a subclass of {@code JPanel} which is non opaque by default. |
|
877 |
*/ |
|
23697 | 878 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
3508 | 879 |
private static class DefaultLayerGlassPane extends JPanel { |
880 |
/** |
|
881 |
* Creates a new {@link DefaultLayerGlassPane} |
|
882 |
*/ |
|
883 |
public DefaultLayerGlassPane() { |
|
884 |
setOpaque(false); |
|
885 |
} |
|
886 |
||
887 |
/** |
|
8955 | 888 |
* First, implementation of this method iterates through |
3508 | 889 |
* glassPane's child components and returns {@code true} |
890 |
* if any of them is visible and contains passed x,y point. |
|
891 |
* After that it checks if no mouseListeners is attached to this component |
|
892 |
* and no mouse cursor is set, then it returns {@code false}, |
|
893 |
* otherwise calls the super implementation of this method. |
|
894 |
* |
|
895 |
* @param x the <i>x</i> coordinate of the point |
|
896 |
* @param y the <i>y</i> coordinate of the point |
|
897 |
* @return true if this component logically contains x,y |
|
898 |
*/ |
|
899 |
public boolean contains(int x, int y) { |
|
900 |
for (int i = 0; i < getComponentCount(); i++) { |
|
901 |
Component c = getComponent(i); |
|
902 |
Point point = SwingUtilities.convertPoint(this, new Point(x, y), c); |
|
903 |
if(c.isVisible() && c.contains(point)){ |
|
904 |
return true; |
|
905 |
} |
|
906 |
} |
|
907 |
if (getMouseListeners().length == 0 |
|
908 |
&& getMouseMotionListeners().length == 0 |
|
909 |
&& getMouseWheelListeners().length == 0 |
|
910 |
&& !isCursorSet()) { |
|
911 |
return false; |
|
912 |
} |
|
913 |
return super.contains(x, y); |
|
914 |
} |
|
915 |
} |
|
3733 | 916 |
} |