1 /*
2 * Copyright (c) 2013, 2014, 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
44 import java.awt.dnd.DropTarget;
45 import java.awt.dnd.InvalidDnDOperationException;
46 import java.awt.dnd.peer.DragSourceContextPeer;
47 import java.awt.event.ContainerEvent;
48 import java.awt.event.ContainerListener;
49 import java.awt.image.BufferedImage;
50 import java.awt.image.DataBufferInt;
51 import java.beans.PropertyChangeEvent;
52 import java.beans.PropertyChangeListener;
53 import java.security.AccessController;
54 import javax.swing.JComponent;
55
56 import javax.swing.JLayeredPane;
57 import javax.swing.JPanel;
58 import javax.swing.JRootPane;
59 import javax.swing.LayoutFocusTraversalPolicy;
60 import javax.swing.RepaintManager;
61 import javax.swing.RootPaneContainer;
62 import javax.swing.SwingUtilities;
63
64 import sun.awt.DisplayChangedListener;
65 import sun.awt.LightweightFrame;
66 import sun.security.action.GetPropertyAction;
67 import sun.swing.SwingUtilities2.RepaintListener;
68
69 /**
70 * The frame serves as a lightweight container which paints its content
71 * to an offscreen image and provides access to the image's data via the
72 * {@link LightweightContent} interface. Note, that it may not be shown
73 * as a standalone toplevel frame. Its purpose is to provide functionality
74 * for lightweight embedding.
75 *
76 * @author Artem Ananiev
77 * @author Anton Tarasov
78 */
79 @SuppressWarnings("serial") // JDK-implementation class
80 public final class JLightweightFrame extends LightweightFrame implements RootPaneContainer {
81
82 private final JRootPane rootPane = new JRootPane();
83
224 public void grabFocus() {
225 if (content != null) content.focusGrabbed();
226 }
227
228 /**
229 * {@inheritDoc}
230 *
231 * @see LightweightContent#focusUngrabbed()
232 */
233 @Override
234 public void ungrabFocus() {
235 if (content != null) content.focusUngrabbed();
236 }
237
238 @Override
239 public int getScaleFactor() {
240 return scaleFactor;
241 }
242
243 @Override
244 @SuppressWarnings("deprecation")
245 public void notifyDisplayChanged(final int scaleFactor) {
246 if (scaleFactor != this.scaleFactor) {
247 if (!copyBufferEnabled) content.paintLock();
248 try {
249 if (bbImage != null) {
250 resizeBuffer(getWidth(), getHeight(), scaleFactor);
251 }
252 } finally {
253 if (!copyBufferEnabled) content.paintUnlock();
254 }
255 this.scaleFactor = scaleFactor;
256 }
257 if (getPeer() instanceof DisplayChangedListener) {
258 ((DisplayChangedListener)getPeer()).displayChanged();
259 }
260 repaint();
261 }
262
263 @Override
264 @SuppressWarnings("deprecation")
265 public void addNotify() {
266 super.addNotify();
267 if (getPeer() instanceof DisplayChangedListener) {
268 ((DisplayChangedListener)getPeer()).displayChanged();
269 }
270 }
271
272 private void syncCopyBuffer(boolean reset, int x, int y, int w, int h, int scale) {
273 content.paintLock();
274 try {
275 int[] srcBuffer = ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData();
276 if (reset) {
277 copyBuffer = new int[srcBuffer.length];
278 }
279 int linestride = bbImage.getWidth();
280
281 x *= scale;
282 y *= scale;
283 w *= scale;
284 h *= scale;
285
286 for (int i=0; i<h; i++) {
287 int from = (y + i) * linestride + x;
288 System.arraycopy(srcBuffer, from, copyBuffer, from, w);
|
1 /*
2 * Copyright (c) 2013, 2015, 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
44 import java.awt.dnd.DropTarget;
45 import java.awt.dnd.InvalidDnDOperationException;
46 import java.awt.dnd.peer.DragSourceContextPeer;
47 import java.awt.event.ContainerEvent;
48 import java.awt.event.ContainerListener;
49 import java.awt.image.BufferedImage;
50 import java.awt.image.DataBufferInt;
51 import java.beans.PropertyChangeEvent;
52 import java.beans.PropertyChangeListener;
53 import java.security.AccessController;
54 import javax.swing.JComponent;
55
56 import javax.swing.JLayeredPane;
57 import javax.swing.JPanel;
58 import javax.swing.JRootPane;
59 import javax.swing.LayoutFocusTraversalPolicy;
60 import javax.swing.RepaintManager;
61 import javax.swing.RootPaneContainer;
62 import javax.swing.SwingUtilities;
63
64 import sun.awt.AWTAccessor;
65 import sun.awt.DisplayChangedListener;
66 import sun.awt.LightweightFrame;
67 import sun.security.action.GetPropertyAction;
68 import sun.swing.SwingUtilities2.RepaintListener;
69
70 /**
71 * The frame serves as a lightweight container which paints its content
72 * to an offscreen image and provides access to the image's data via the
73 * {@link LightweightContent} interface. Note, that it may not be shown
74 * as a standalone toplevel frame. Its purpose is to provide functionality
75 * for lightweight embedding.
76 *
77 * @author Artem Ananiev
78 * @author Anton Tarasov
79 */
80 @SuppressWarnings("serial") // JDK-implementation class
81 public final class JLightweightFrame extends LightweightFrame implements RootPaneContainer {
82
83 private final JRootPane rootPane = new JRootPane();
84
225 public void grabFocus() {
226 if (content != null) content.focusGrabbed();
227 }
228
229 /**
230 * {@inheritDoc}
231 *
232 * @see LightweightContent#focusUngrabbed()
233 */
234 @Override
235 public void ungrabFocus() {
236 if (content != null) content.focusUngrabbed();
237 }
238
239 @Override
240 public int getScaleFactor() {
241 return scaleFactor;
242 }
243
244 @Override
245 public void notifyDisplayChanged(final int scaleFactor) {
246 if (scaleFactor != this.scaleFactor) {
247 if (!copyBufferEnabled) content.paintLock();
248 try {
249 if (bbImage != null) {
250 resizeBuffer(getWidth(), getHeight(), scaleFactor);
251 }
252 } finally {
253 if (!copyBufferEnabled) content.paintUnlock();
254 }
255 this.scaleFactor = scaleFactor;
256 }
257 final Object peer = AWTAccessor.getComponentAccessor().getPeer(this);
258 if (peer instanceof DisplayChangedListener) {
259 ((DisplayChangedListener) peer).displayChanged();
260 }
261 repaint();
262 }
263
264 @Override
265 public void addNotify() {
266 super.addNotify();
267 final Object peer = AWTAccessor.getComponentAccessor().getPeer(this);
268 if (peer instanceof DisplayChangedListener) {
269 ((DisplayChangedListener) peer).displayChanged();
270 }
271 }
272
273 private void syncCopyBuffer(boolean reset, int x, int y, int w, int h, int scale) {
274 content.paintLock();
275 try {
276 int[] srcBuffer = ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData();
277 if (reset) {
278 copyBuffer = new int[srcBuffer.length];
279 }
280 int linestride = bbImage.getWidth();
281
282 x *= scale;
283 y *= scale;
284 w *= scale;
285 h *= scale;
286
287 for (int i=0; i<h; i++) {
288 int from = (y + i) * linestride + x;
289 System.arraycopy(srcBuffer, from, copyBuffer, from, w);
|