author | ant |
Tue, 30 Jul 2013 16:15:31 +0400 | |
changeset 19026 | 96141cb8d7eb |
parent 17415 | 62b97a10da72 |
child 20127 | a3a34675d847 |
permissions | -rw-r--r-- |
15983 | 1 |
/* |
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
|
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 |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
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 |
* |
|
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 |
||
26 |
package sun.swing; |
|
27 |
||
28 |
import java.awt.BorderLayout; |
|
29 |
import java.awt.Color; |
|
30 |
import java.awt.Component; |
|
31 |
import java.awt.Container; |
|
19026
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
32 |
import java.awt.Dimension; |
15983 | 33 |
import java.awt.EventQueue; |
34 |
import java.awt.Graphics; |
|
35 |
import java.awt.Graphics2D; |
|
36 |
import java.awt.Rectangle; |
|
19026
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
37 |
import java.awt.event.ComponentListener; |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
38 |
import java.awt.event.ContainerEvent; |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
39 |
import java.awt.event.ContainerListener; |
15983 | 40 |
import java.awt.image.BufferedImage; |
41 |
import java.awt.image.DataBufferInt; |
|
19026
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
42 |
import java.beans.PropertyChangeEvent; |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
43 |
import java.beans.PropertyChangeListener; |
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
44 |
import java.security.AccessController; |
15983 | 45 |
|
46 |
import javax.swing.JLayeredPane; |
|
47 |
import javax.swing.JPanel; |
|
48 |
import javax.swing.JRootPane; |
|
49 |
import javax.swing.LayoutFocusTraversalPolicy; |
|
50 |
import javax.swing.RootPaneContainer; |
|
51 |
||
52 |
import sun.awt.LightweightFrame; |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
53 |
import sun.security.action.GetPropertyAction; |
15983 | 54 |
|
55 |
/** |
|
56 |
* The frame serves as a lightweight container which paints its content |
|
57 |
* to an offscreen image and provides access to the image's data via the |
|
58 |
* {@link LightweightContent} interface. Note, that it may not be shown |
|
59 |
* as a standalone toplevel frame. Its purpose is to provide functionality |
|
60 |
* for lightweight embedding. |
|
61 |
* |
|
62 |
* @author Artem Ananiev |
|
63 |
* @author Anton Tarasov |
|
64 |
*/ |
|
65 |
public final class JLightweightFrame extends LightweightFrame implements RootPaneContainer { |
|
66 |
||
67 |
private final JRootPane rootPane = new JRootPane(); |
|
68 |
||
69 |
private LightweightContent content; |
|
70 |
||
71 |
private Component component; |
|
72 |
private JPanel contentPane; |
|
73 |
||
74 |
private BufferedImage bbImage; |
|
75 |
||
76 |
/** |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
77 |
* {@code copyBufferEnabled}, true by default, defines the following strategy. |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
78 |
* A duplicating (copy) buffer is created for the original pixel buffer. |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
79 |
* The copy buffer is synchronized with the original buffer every time the |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
80 |
* latter changes. {@code JLightweightFrame} passes the copy buffer array |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
81 |
* to the {@link LightweightContent#imageBufferReset} method. The code spot |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
82 |
* which synchronizes two buffers becomes the only critical section guarded |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
83 |
* by the lock (managed with the {@link LightweightContent#paintLock()}, |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
84 |
* {@link LightweightContent#paintUnlock()} methods). |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
85 |
*/ |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
86 |
private boolean copyBufferEnabled; |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
87 |
private int[] copyBuffer; |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
88 |
|
19026
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
89 |
private PropertyChangeListener layoutSizeListener; |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
90 |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
91 |
/** |
15983 | 92 |
* Constructs a new, initially invisible {@code JLightweightFrame} |
93 |
* instance. |
|
94 |
*/ |
|
95 |
public JLightweightFrame() { |
|
96 |
super(); |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
97 |
copyBufferEnabled = "true".equals(AccessController. |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
98 |
doPrivileged(new GetPropertyAction("jlf.copyBufferEnabled", "true"))); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
99 |
|
15983 | 100 |
add(rootPane, BorderLayout.CENTER); |
101 |
setFocusTraversalPolicy(new LayoutFocusTraversalPolicy()); |
|
16706
4b243017cd27
8010375: sun.swing.JLightweightFrame should be implemented for XToolkit
ant
parents:
15983
diff
changeset
|
102 |
if (getGraphicsConfiguration().isTranslucencyCapable()) { |
4b243017cd27
8010375: sun.swing.JLightweightFrame should be implemented for XToolkit
ant
parents:
15983
diff
changeset
|
103 |
setBackground(new Color(0, 0, 0, 0)); |
4b243017cd27
8010375: sun.swing.JLightweightFrame should be implemented for XToolkit
ant
parents:
15983
diff
changeset
|
104 |
} |
19026
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
105 |
|
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
106 |
layoutSizeListener = new PropertyChangeListener() { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
107 |
@Override |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
108 |
public void propertyChange(PropertyChangeEvent e) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
109 |
Dimension d = (Dimension)e.getNewValue(); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
110 |
|
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
111 |
if ("preferredSize".equals(e.getPropertyName())) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
112 |
content.preferredSizeChanged(d.width, d.height); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
113 |
|
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
114 |
} else if ("maximumSize".equals(e.getPropertyName())) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
115 |
content.maximumSizeChanged(d.width, d.height); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
116 |
|
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
117 |
} else if ("minimumSize".equals(e.getPropertyName())) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
118 |
content.minimumSizeChanged(d.width, d.height); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
119 |
} |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
120 |
} |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
121 |
}; |
15983 | 122 |
} |
123 |
||
124 |
/** |
|
125 |
* Sets the {@link LightweightContent} instance for this frame. |
|
126 |
* The {@code JComponent} object returned by the |
|
127 |
* {@link LightweightContent#getComponent()} method is immediately |
|
128 |
* added to the frame's content pane. |
|
129 |
* |
|
130 |
* @param content the {@link LightweightContent} instance |
|
131 |
*/ |
|
19026
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
132 |
public void setContent(final LightweightContent content) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
133 |
if (content == null) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
134 |
System.err.println("JLightweightFrame.setContent: content may not be null!"); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
135 |
return; |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
136 |
} |
15983 | 137 |
this.content = content; |
138 |
this.component = content.getComponent(); |
|
139 |
||
19026
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
140 |
Dimension d = this.component.getPreferredSize(); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
141 |
content.preferredSizeChanged(d.width, d.height); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
142 |
|
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
143 |
d = this.component.getMaximumSize(); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
144 |
content.maximumSizeChanged(d.width, d.height); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
145 |
|
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
146 |
d = this.component.getMinimumSize(); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
147 |
content.minimumSizeChanged(d.width, d.height); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
148 |
|
15983 | 149 |
initInterior(); |
150 |
} |
|
151 |
||
152 |
@Override |
|
153 |
public Graphics getGraphics() { |
|
154 |
if (bbImage == null) return null; |
|
155 |
||
156 |
Graphics2D g = bbImage.createGraphics(); |
|
157 |
g.setBackground(getBackground()); |
|
158 |
g.setColor(getForeground()); |
|
159 |
g.setFont(getFont()); |
|
160 |
return g; |
|
161 |
} |
|
162 |
||
163 |
/** |
|
164 |
* {@inheritDoc} |
|
165 |
* |
|
166 |
* @see LightweightContent#focusGrabbed() |
|
167 |
*/ |
|
168 |
@Override |
|
169 |
public void grabFocus() { |
|
170 |
if (content != null) content.focusGrabbed(); |
|
171 |
} |
|
172 |
||
173 |
/** |
|
174 |
* {@inheritDoc} |
|
175 |
* |
|
176 |
* @see LightweightContent#focusUngrabbed() |
|
177 |
*/ |
|
178 |
@Override |
|
179 |
public void ungrabFocus() { |
|
180 |
if (content != null) content.focusUngrabbed(); |
|
181 |
} |
|
182 |
||
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
183 |
private void syncCopyBuffer(boolean reset, int x, int y, int w, int h) { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
184 |
content.paintLock(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
185 |
try { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
186 |
int[] srcBuffer = ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
187 |
if (reset) { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
188 |
copyBuffer = new int[srcBuffer.length]; |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
189 |
} |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
190 |
int linestride = bbImage.getWidth(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
191 |
|
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
192 |
for (int i=0; i<h; i++) { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
193 |
int from = (y + i) * linestride + x; |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
194 |
System.arraycopy(srcBuffer, from, copyBuffer, from, w); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
195 |
} |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
196 |
} finally { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
197 |
content.paintUnlock(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
198 |
} |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
199 |
} |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
200 |
|
15983 | 201 |
private void initInterior() { |
202 |
contentPane = new JPanel() { |
|
203 |
@Override |
|
204 |
public void paint(Graphics g) { |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
205 |
if (!copyBufferEnabled) { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
206 |
content.paintLock(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
207 |
} |
15983 | 208 |
try { |
209 |
super.paint(g); |
|
210 |
||
211 |
final Rectangle clip = g.getClipBounds() != null ? |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
212 |
g.getClipBounds() : |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
213 |
new Rectangle(0, 0, contentPane.getWidth(), contentPane.getHeight()); |
15983 | 214 |
|
215 |
clip.x = Math.max(0, clip.x); |
|
216 |
clip.y = Math.max(0, clip.y); |
|
217 |
clip.width = Math.min(contentPane.getWidth(), clip.width); |
|
218 |
clip.height = Math.min(contentPane.getHeight(), clip.height); |
|
219 |
||
220 |
EventQueue.invokeLater(new Runnable() { |
|
221 |
@Override |
|
222 |
public void run() { |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
223 |
if (copyBufferEnabled) { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
224 |
syncCopyBuffer(false, clip.x, clip.y, clip.width, clip.height); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
225 |
} |
15983 | 226 |
content.imageUpdated(clip.x, clip.y, clip.width, clip.height); |
227 |
} |
|
228 |
}); |
|
229 |
} finally { |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
230 |
if (!copyBufferEnabled) { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
231 |
content.paintUnlock(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
232 |
} |
15983 | 233 |
} |
234 |
} |
|
235 |
@Override |
|
236 |
protected boolean isPaintingOrigin() { |
|
237 |
return true; |
|
238 |
} |
|
239 |
}; |
|
240 |
contentPane.setLayout(new BorderLayout()); |
|
241 |
contentPane.add(component); |
|
242 |
setContentPane(contentPane); |
|
19026
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
243 |
|
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
244 |
contentPane.addContainerListener(new ContainerListener() { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
245 |
@Override |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
246 |
public void componentAdded(ContainerEvent e) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
247 |
Component c = JLightweightFrame.this.component; |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
248 |
if (e.getChild() == c) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
249 |
c.addPropertyChangeListener("preferredSize", layoutSizeListener); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
250 |
c.addPropertyChangeListener("maximumSize", layoutSizeListener); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
251 |
c.addPropertyChangeListener("minimumSize", layoutSizeListener); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
252 |
} |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
253 |
} |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
254 |
@Override |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
255 |
public void componentRemoved(ContainerEvent e) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
256 |
Component c = JLightweightFrame.this.component; |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
257 |
if (e.getChild() == c) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
258 |
c.removePropertyChangeListener(layoutSizeListener); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
259 |
} |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
260 |
} |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
261 |
}); |
15983 | 262 |
} |
263 |
||
264 |
@SuppressWarnings("deprecation") |
|
265 |
@Override public void reshape(int x, int y, int width, int height) { |
|
266 |
super.reshape(x, y, width, height); |
|
267 |
||
268 |
if (width == 0 || height == 0) { |
|
269 |
return; |
|
270 |
} |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
271 |
if (!copyBufferEnabled) { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
272 |
content.paintLock(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
273 |
} |
15983 | 274 |
try { |
275 |
if ((bbImage == null) || (width != bbImage.getWidth()) || (height != bbImage.getHeight())) { |
|
276 |
boolean createBB = true; |
|
277 |
int newW = width; |
|
278 |
int newH = height; |
|
279 |
if (bbImage != null) { |
|
280 |
int oldW = bbImage.getWidth(); |
|
281 |
int oldH = bbImage.getHeight(); |
|
282 |
if ((oldW >= newW) && (oldH >= newH)) { |
|
283 |
createBB = false; |
|
284 |
} else { |
|
285 |
if (oldW >= newW) { |
|
286 |
newW = oldW; |
|
287 |
} else { |
|
288 |
newW = Math.max((int)(oldW * 1.2), width); |
|
289 |
} |
|
290 |
if (oldH >= newH) { |
|
291 |
newH = oldH; |
|
292 |
} else { |
|
293 |
newH = Math.max((int)(oldH * 1.2), height); |
|
294 |
} |
|
295 |
} |
|
296 |
} |
|
297 |
if (createBB) { |
|
298 |
BufferedImage oldBB = bbImage; |
|
299 |
bbImage = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_ARGB_PRE); |
|
300 |
if (oldBB != null) { |
|
301 |
Graphics g = bbImage.getGraphics(); |
|
302 |
try { |
|
303 |
g.drawImage(oldBB, 0, 0, newW, newH, null); |
|
304 |
} finally { |
|
305 |
g.dispose(); |
|
306 |
oldBB.flush(); |
|
307 |
} |
|
308 |
} |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
309 |
int[] pixels = ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
310 |
if (copyBufferEnabled) { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
311 |
syncCopyBuffer(true, 0, 0, width, height); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
312 |
pixels = copyBuffer; |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
313 |
} |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
314 |
content.imageBufferReset(pixels, 0, 0, width, height, bbImage.getWidth()); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
315 |
return; |
15983 | 316 |
} |
317 |
} |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
318 |
content.imageReshaped(0, 0, width, height); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
319 |
|
15983 | 320 |
} finally { |
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
321 |
if (!copyBufferEnabled) { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
322 |
content.paintUnlock(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
323 |
} |
15983 | 324 |
} |
325 |
} |
|
326 |
||
327 |
@Override |
|
328 |
public JRootPane getRootPane() { |
|
329 |
return rootPane; |
|
330 |
} |
|
331 |
||
332 |
@Override |
|
333 |
public void setContentPane(Container contentPane) { |
|
334 |
getRootPane().setContentPane(contentPane); |
|
335 |
} |
|
336 |
||
337 |
@Override |
|
338 |
public Container getContentPane() { |
|
339 |
return getRootPane().getContentPane(); |
|
340 |
} |
|
341 |
||
342 |
@Override |
|
343 |
public void setLayeredPane(JLayeredPane layeredPane) { |
|
344 |
getRootPane().setLayeredPane(layeredPane); |
|
345 |
} |
|
346 |
||
347 |
@Override |
|
348 |
public JLayeredPane getLayeredPane() { |
|
349 |
return getRootPane().getLayeredPane(); |
|
350 |
} |
|
351 |
||
352 |
@Override |
|
353 |
public void setGlassPane(Component glassPane) { |
|
354 |
getRootPane().setGlassPane(glassPane); |
|
355 |
} |
|
356 |
||
357 |
@Override |
|
358 |
public Component getGlassPane() { |
|
359 |
return getRootPane().getGlassPane(); |
|
360 |
} |
|
361 |
} |