author | lana |
Tue, 04 Feb 2014 16:24:39 -0800 | |
changeset 23281 | 93c0a5484bb5 |
parent 23280 | df31f522531f |
parent 22618 | 927e4fe6cb24 |
child 25195 | 9de77f5b0df2 |
permissions | -rw-r--r-- |
15983 | 1 |
/* |
22618 | 2 |
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
15983 | 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; |
|
20127 | 36 |
import java.awt.MouseInfo; |
37 |
import java.awt.Point; |
|
15983 | 38 |
import java.awt.Rectangle; |
23280
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
39 |
import java.awt.Window; |
19026
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
40 |
import java.awt.event.ContainerEvent; |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
41 |
import java.awt.event.ContainerListener; |
15983 | 42 |
import java.awt.image.BufferedImage; |
43 |
import java.awt.image.DataBufferInt; |
|
19026
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
44 |
import java.beans.PropertyChangeEvent; |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
45 |
import java.beans.PropertyChangeListener; |
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
46 |
import java.security.AccessController; |
23280
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
47 |
import javax.swing.JComponent; |
15983 | 48 |
|
49 |
import javax.swing.JLayeredPane; |
|
50 |
import javax.swing.JPanel; |
|
51 |
import javax.swing.JRootPane; |
|
52 |
import javax.swing.LayoutFocusTraversalPolicy; |
|
23280
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
53 |
import javax.swing.RepaintManager; |
15983 | 54 |
import javax.swing.RootPaneContainer; |
20127 | 55 |
import javax.swing.SwingUtilities; |
15983 | 56 |
|
57 |
import sun.awt.LightweightFrame; |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
58 |
import sun.security.action.GetPropertyAction; |
23280
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
59 |
import sun.swing.SwingUtilities2.RepaintListener; |
15983 | 60 |
|
61 |
/** |
|
62 |
* The frame serves as a lightweight container which paints its content |
|
63 |
* to an offscreen image and provides access to the image's data via the |
|
64 |
* {@link LightweightContent} interface. Note, that it may not be shown |
|
65 |
* as a standalone toplevel frame. Its purpose is to provide functionality |
|
66 |
* for lightweight embedding. |
|
67 |
* |
|
68 |
* @author Artem Ananiev |
|
69 |
* @author Anton Tarasov |
|
70 |
*/ |
|
22618 | 71 |
@SuppressWarnings("serial") // JDK-implementation class |
15983 | 72 |
public final class JLightweightFrame extends LightweightFrame implements RootPaneContainer { |
73 |
||
74 |
private final JRootPane rootPane = new JRootPane(); |
|
75 |
||
76 |
private LightweightContent content; |
|
77 |
||
78 |
private Component component; |
|
79 |
private JPanel contentPane; |
|
80 |
||
81 |
private BufferedImage bbImage; |
|
82 |
||
83 |
/** |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
84 |
* {@code copyBufferEnabled}, true by default, defines the following strategy. |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
85 |
* A duplicating (copy) buffer is created for the original pixel buffer. |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
86 |
* The copy buffer is synchronized with the original buffer every time the |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
87 |
* latter changes. {@code JLightweightFrame} passes the copy buffer array |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
88 |
* to the {@link LightweightContent#imageBufferReset} method. The code spot |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
89 |
* which synchronizes two buffers becomes the only critical section guarded |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
90 |
* by the lock (managed with the {@link LightweightContent#paintLock()}, |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
91 |
* {@link LightweightContent#paintUnlock()} methods). |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
92 |
*/ |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
93 |
private boolean copyBufferEnabled; |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
94 |
private int[] copyBuffer; |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
95 |
|
19026
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
96 |
private PropertyChangeListener layoutSizeListener; |
23280
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
97 |
private RepaintListener repaintListener; |
19026
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
98 |
|
20127 | 99 |
static { |
100 |
SwingAccessor.setJLightweightFrameAccessor(new SwingAccessor.JLightweightFrameAccessor() { |
|
101 |
@Override |
|
102 |
public void updateCursor(JLightweightFrame frame) { |
|
103 |
frame.updateClientCursor(); |
|
104 |
} |
|
105 |
}); |
|
106 |
} |
|
107 |
||
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
108 |
/** |
15983 | 109 |
* Constructs a new, initially invisible {@code JLightweightFrame} |
110 |
* instance. |
|
111 |
*/ |
|
112 |
public JLightweightFrame() { |
|
113 |
super(); |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
114 |
copyBufferEnabled = "true".equals(AccessController. |
20136
594c0830f18c
8022512: JLightweightFrame: the content pane should be transparent
ant
parents:
20127
diff
changeset
|
115 |
doPrivileged(new GetPropertyAction("swing.jlf.copyBufferEnabled", "true"))); |
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
116 |
|
15983 | 117 |
add(rootPane, BorderLayout.CENTER); |
118 |
setFocusTraversalPolicy(new LayoutFocusTraversalPolicy()); |
|
16706
4b243017cd27
8010375: sun.swing.JLightweightFrame should be implemented for XToolkit
ant
parents:
15983
diff
changeset
|
119 |
if (getGraphicsConfiguration().isTranslucencyCapable()) { |
4b243017cd27
8010375: sun.swing.JLightweightFrame should be implemented for XToolkit
ant
parents:
15983
diff
changeset
|
120 |
setBackground(new Color(0, 0, 0, 0)); |
4b243017cd27
8010375: sun.swing.JLightweightFrame should be implemented for XToolkit
ant
parents:
15983
diff
changeset
|
121 |
} |
19026
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
122 |
|
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
123 |
layoutSizeListener = new PropertyChangeListener() { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
124 |
@Override |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
125 |
public void propertyChange(PropertyChangeEvent e) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
126 |
Dimension d = (Dimension)e.getNewValue(); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
127 |
|
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
128 |
if ("preferredSize".equals(e.getPropertyName())) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
129 |
content.preferredSizeChanged(d.width, d.height); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
130 |
|
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
131 |
} else if ("maximumSize".equals(e.getPropertyName())) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
132 |
content.maximumSizeChanged(d.width, d.height); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
133 |
|
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
134 |
} else if ("minimumSize".equals(e.getPropertyName())) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
135 |
content.minimumSizeChanged(d.width, d.height); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
136 |
} |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
137 |
} |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
138 |
}; |
23280
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
139 |
|
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
140 |
repaintListener = (JComponent c, int x, int y, int w, int h) -> { |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
141 |
Window jlf = SwingUtilities.getWindowAncestor(c); |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
142 |
if (jlf != JLightweightFrame.this) { |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
143 |
return; |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
144 |
} |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
145 |
Point p = SwingUtilities.convertPoint(c, x, y, jlf); |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
146 |
Rectangle r = new Rectangle(p.x, p.y, w, h).intersection( |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
147 |
new Rectangle(0, 0, bbImage.getWidth(), bbImage.getHeight())); |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
148 |
|
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
149 |
if (!r.isEmpty()) { |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
150 |
notifyImageUpdated(r.x, r.y, r.width, r.height); |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
151 |
} |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
152 |
}; |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
153 |
|
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
154 |
SwingAccessor.getRepaintManagerAccessor().addRepaintListener( |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
155 |
RepaintManager.currentManager(this), repaintListener); |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
156 |
} |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
157 |
|
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
158 |
@Override |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
159 |
public void dispose() { |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
160 |
SwingAccessor.getRepaintManagerAccessor().removeRepaintListener( |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
161 |
RepaintManager.currentManager(this), repaintListener); |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
162 |
super.dispose(); |
15983 | 163 |
} |
164 |
||
165 |
/** |
|
166 |
* Sets the {@link LightweightContent} instance for this frame. |
|
167 |
* The {@code JComponent} object returned by the |
|
168 |
* {@link LightweightContent#getComponent()} method is immediately |
|
169 |
* added to the frame's content pane. |
|
170 |
* |
|
171 |
* @param content the {@link LightweightContent} instance |
|
172 |
*/ |
|
19026
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
173 |
public void setContent(final LightweightContent content) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
174 |
if (content == null) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
175 |
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
|
176 |
return; |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
177 |
} |
15983 | 178 |
this.content = content; |
179 |
this.component = content.getComponent(); |
|
180 |
||
19026
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
181 |
Dimension d = this.component.getPreferredSize(); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
182 |
content.preferredSizeChanged(d.width, d.height); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
183 |
|
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
184 |
d = this.component.getMaximumSize(); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
185 |
content.maximumSizeChanged(d.width, d.height); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
186 |
|
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
187 |
d = this.component.getMinimumSize(); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
188 |
content.minimumSizeChanged(d.width, d.height); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
189 |
|
15983 | 190 |
initInterior(); |
191 |
} |
|
192 |
||
193 |
@Override |
|
194 |
public Graphics getGraphics() { |
|
195 |
if (bbImage == null) return null; |
|
196 |
||
197 |
Graphics2D g = bbImage.createGraphics(); |
|
198 |
g.setBackground(getBackground()); |
|
199 |
g.setColor(getForeground()); |
|
200 |
g.setFont(getFont()); |
|
201 |
return g; |
|
202 |
} |
|
203 |
||
204 |
/** |
|
205 |
* {@inheritDoc} |
|
206 |
* |
|
207 |
* @see LightweightContent#focusGrabbed() |
|
208 |
*/ |
|
209 |
@Override |
|
210 |
public void grabFocus() { |
|
211 |
if (content != null) content.focusGrabbed(); |
|
212 |
} |
|
213 |
||
214 |
/** |
|
215 |
* {@inheritDoc} |
|
216 |
* |
|
217 |
* @see LightweightContent#focusUngrabbed() |
|
218 |
*/ |
|
219 |
@Override |
|
220 |
public void ungrabFocus() { |
|
221 |
if (content != null) content.focusUngrabbed(); |
|
222 |
} |
|
223 |
||
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
224 |
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
|
225 |
content.paintLock(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
226 |
try { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
227 |
int[] srcBuffer = ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
228 |
if (reset) { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
229 |
copyBuffer = new int[srcBuffer.length]; |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
230 |
} |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
231 |
int linestride = bbImage.getWidth(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
232 |
|
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
233 |
for (int i=0; i<h; i++) { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
234 |
int from = (y + i) * linestride + x; |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
235 |
System.arraycopy(srcBuffer, from, copyBuffer, from, w); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
236 |
} |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
237 |
} finally { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
238 |
content.paintUnlock(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
239 |
} |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
240 |
} |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
241 |
|
23280
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
242 |
private void notifyImageUpdated(int x, int y, int width, int height) { |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
243 |
if (copyBufferEnabled) { |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
244 |
syncCopyBuffer(false, x, y, width, height); |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
245 |
} |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
246 |
content.imageUpdated(x, y, width, height); |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
247 |
} |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
248 |
|
22618 | 249 |
@SuppressWarnings("serial") // anonymous class inside |
15983 | 250 |
private void initInterior() { |
251 |
contentPane = new JPanel() { |
|
252 |
@Override |
|
253 |
public void paint(Graphics g) { |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
254 |
if (!copyBufferEnabled) { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
255 |
content.paintLock(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
256 |
} |
15983 | 257 |
try { |
258 |
super.paint(g); |
|
259 |
||
260 |
final Rectangle clip = g.getClipBounds() != null ? |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
261 |
g.getClipBounds() : |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
262 |
new Rectangle(0, 0, contentPane.getWidth(), contentPane.getHeight()); |
15983 | 263 |
|
264 |
clip.x = Math.max(0, clip.x); |
|
265 |
clip.y = Math.max(0, clip.y); |
|
266 |
clip.width = Math.min(contentPane.getWidth(), clip.width); |
|
267 |
clip.height = Math.min(contentPane.getHeight(), clip.height); |
|
268 |
||
269 |
EventQueue.invokeLater(new Runnable() { |
|
270 |
@Override |
|
271 |
public void run() { |
|
23280
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
20136
diff
changeset
|
272 |
notifyImageUpdated(clip.x, clip.y, clip.width, clip.height); |
15983 | 273 |
} |
274 |
}); |
|
275 |
} finally { |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
276 |
if (!copyBufferEnabled) { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
277 |
content.paintUnlock(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
278 |
} |
15983 | 279 |
} |
280 |
} |
|
281 |
@Override |
|
282 |
protected boolean isPaintingOrigin() { |
|
283 |
return true; |
|
284 |
} |
|
285 |
}; |
|
286 |
contentPane.setLayout(new BorderLayout()); |
|
287 |
contentPane.add(component); |
|
20136
594c0830f18c
8022512: JLightweightFrame: the content pane should be transparent
ant
parents:
20127
diff
changeset
|
288 |
if ("true".equals(AccessController. |
594c0830f18c
8022512: JLightweightFrame: the content pane should be transparent
ant
parents:
20127
diff
changeset
|
289 |
doPrivileged(new GetPropertyAction("swing.jlf.contentPaneTransparent", "false")))) |
594c0830f18c
8022512: JLightweightFrame: the content pane should be transparent
ant
parents:
20127
diff
changeset
|
290 |
{ |
594c0830f18c
8022512: JLightweightFrame: the content pane should be transparent
ant
parents:
20127
diff
changeset
|
291 |
contentPane.setOpaque(false); |
594c0830f18c
8022512: JLightweightFrame: the content pane should be transparent
ant
parents:
20127
diff
changeset
|
292 |
} |
15983 | 293 |
setContentPane(contentPane); |
19026
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
294 |
|
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
295 |
contentPane.addContainerListener(new ContainerListener() { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
296 |
@Override |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
297 |
public void componentAdded(ContainerEvent e) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
298 |
Component c = JLightweightFrame.this.component; |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
299 |
if (e.getChild() == c) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
300 |
c.addPropertyChangeListener("preferredSize", layoutSizeListener); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
301 |
c.addPropertyChangeListener("maximumSize", layoutSizeListener); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
302 |
c.addPropertyChangeListener("minimumSize", layoutSizeListener); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
303 |
} |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
304 |
} |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
305 |
@Override |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
306 |
public void componentRemoved(ContainerEvent e) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
307 |
Component c = JLightweightFrame.this.component; |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
308 |
if (e.getChild() == c) { |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
309 |
c.removePropertyChangeListener(layoutSizeListener); |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
310 |
} |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
311 |
} |
96141cb8d7eb
8020927: JLightweightFrame API should export layout properties change notifications
ant
parents:
17415
diff
changeset
|
312 |
}); |
15983 | 313 |
} |
314 |
||
315 |
@SuppressWarnings("deprecation") |
|
316 |
@Override public void reshape(int x, int y, int width, int height) { |
|
317 |
super.reshape(x, y, width, height); |
|
318 |
||
319 |
if (width == 0 || height == 0) { |
|
320 |
return; |
|
321 |
} |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
322 |
if (!copyBufferEnabled) { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
323 |
content.paintLock(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
324 |
} |
15983 | 325 |
try { |
326 |
if ((bbImage == null) || (width != bbImage.getWidth()) || (height != bbImage.getHeight())) { |
|
327 |
boolean createBB = true; |
|
328 |
int newW = width; |
|
329 |
int newH = height; |
|
330 |
if (bbImage != null) { |
|
331 |
int oldW = bbImage.getWidth(); |
|
332 |
int oldH = bbImage.getHeight(); |
|
333 |
if ((oldW >= newW) && (oldH >= newH)) { |
|
334 |
createBB = false; |
|
335 |
} else { |
|
336 |
if (oldW >= newW) { |
|
337 |
newW = oldW; |
|
338 |
} else { |
|
339 |
newW = Math.max((int)(oldW * 1.2), width); |
|
340 |
} |
|
341 |
if (oldH >= newH) { |
|
342 |
newH = oldH; |
|
343 |
} else { |
|
344 |
newH = Math.max((int)(oldH * 1.2), height); |
|
345 |
} |
|
346 |
} |
|
347 |
} |
|
348 |
if (createBB) { |
|
349 |
BufferedImage oldBB = bbImage; |
|
350 |
bbImage = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_ARGB_PRE); |
|
351 |
if (oldBB != null) { |
|
352 |
Graphics g = bbImage.getGraphics(); |
|
353 |
try { |
|
354 |
g.drawImage(oldBB, 0, 0, newW, newH, null); |
|
355 |
} finally { |
|
356 |
g.dispose(); |
|
357 |
oldBB.flush(); |
|
358 |
} |
|
359 |
} |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
360 |
int[] pixels = ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
361 |
if (copyBufferEnabled) { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
362 |
syncCopyBuffer(true, 0, 0, width, height); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
363 |
pixels = copyBuffer; |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
364 |
} |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
365 |
content.imageBufferReset(pixels, 0, 0, width, height, bbImage.getWidth()); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
366 |
return; |
15983 | 367 |
} |
368 |
} |
|
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
369 |
content.imageReshaped(0, 0, width, height); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
370 |
|
15983 | 371 |
} finally { |
17415
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
372 |
if (!copyBufferEnabled) { |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
373 |
content.paintUnlock(); |
62b97a10da72
8014227: JLightweightFrame needs another synchronization policy
ant
parents:
16706
diff
changeset
|
374 |
} |
15983 | 375 |
} |
376 |
} |
|
377 |
||
378 |
@Override |
|
379 |
public JRootPane getRootPane() { |
|
380 |
return rootPane; |
|
381 |
} |
|
382 |
||
383 |
@Override |
|
384 |
public void setContentPane(Container contentPane) { |
|
385 |
getRootPane().setContentPane(contentPane); |
|
386 |
} |
|
387 |
||
388 |
@Override |
|
389 |
public Container getContentPane() { |
|
390 |
return getRootPane().getContentPane(); |
|
391 |
} |
|
392 |
||
393 |
@Override |
|
394 |
public void setLayeredPane(JLayeredPane layeredPane) { |
|
395 |
getRootPane().setLayeredPane(layeredPane); |
|
396 |
} |
|
397 |
||
398 |
@Override |
|
399 |
public JLayeredPane getLayeredPane() { |
|
400 |
return getRootPane().getLayeredPane(); |
|
401 |
} |
|
402 |
||
403 |
@Override |
|
404 |
public void setGlassPane(Component glassPane) { |
|
405 |
getRootPane().setGlassPane(glassPane); |
|
406 |
} |
|
407 |
||
408 |
@Override |
|
409 |
public Component getGlassPane() { |
|
410 |
return getRootPane().getGlassPane(); |
|
411 |
} |
|
20127 | 412 |
|
413 |
||
414 |
/* |
|
415 |
* Notifies client toolkit that it should change a cursor. |
|
416 |
* |
|
417 |
* Called from the peer via SwingAccessor, because the |
|
418 |
* Component.updateCursorImmediately method is final |
|
419 |
* and could not be overridden. |
|
420 |
*/ |
|
421 |
private void updateClientCursor() { |
|
422 |
Point p = MouseInfo.getPointerInfo().getLocation(); |
|
423 |
SwingUtilities.convertPointFromScreen(p, this); |
|
424 |
Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y); |
|
425 |
if (target != null) { |
|
426 |
content.setCursor(target.getCursor()); |
|
427 |
} |
|
428 |
} |
|
15983 | 429 |
} |