1 /*
2 * Copyright (c) 2011, 2019, 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
36 import java.awt.Font;
37 import java.awt.FontMetrics;
38 import java.awt.Graphics;
39 import java.awt.GraphicsConfiguration;
40 import java.awt.Image;
41 import java.awt.Point;
42 import java.awt.Rectangle;
43 import java.awt.Toolkit;
44 import java.awt.Window;
45 import java.awt.dnd.DropTarget;
46 import java.awt.dnd.peer.DropTargetPeer;
47 import java.awt.event.AWTEventListener;
48 import java.awt.event.ComponentEvent;
49 import java.awt.event.FocusEvent;
50 import java.awt.event.InputEvent;
51 import java.awt.event.KeyEvent;
52 import java.awt.event.MouseEvent;
53 import java.awt.event.MouseWheelEvent;
54 import java.awt.event.PaintEvent;
55 import java.awt.image.ColorModel;
56 import java.awt.image.ImageObserver;
57 import java.awt.image.ImageProducer;
58 import java.awt.image.VolatileImage;
59 import java.awt.peer.ComponentPeer;
60 import java.awt.peer.ContainerPeer;
61 import java.awt.peer.KeyboardFocusManagerPeer;
62 import java.lang.reflect.Field;
63 import java.security.AccessController;
64 import java.security.PrivilegedAction;
65 import java.util.concurrent.atomic.AtomicBoolean;
66
67 import javax.swing.JComponent;
68 import javax.swing.RepaintManager;
69 import javax.swing.SwingUtilities;
70
71 import com.sun.java.swing.SwingUtilities3;
72 import sun.awt.AWTAccessor;
73 import sun.awt.PaintEventDispatcher;
74 import sun.awt.RepaintArea;
75 import sun.awt.SunToolkit;
76 import sun.awt.event.IgnorePaintEvent;
77 import sun.awt.image.SunVolatileImage;
78 import sun.awt.image.ToolkitImage;
79 import sun.java2d.SunGraphics2D;
80 import sun.java2d.opengl.OGLRenderQueue;
81 import sun.java2d.pipe.Region;
82 import sun.util.logging.PlatformLogger;
83
84 public abstract class LWComponentPeer<T extends Component, D extends JComponent>
85 implements ComponentPeer, DropTargetPeer
86 {
87 private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWComponentPeer");
88
89 /**
90 * State lock is to be used for modifications to this peer's fields (e.g.
91 * bounds, background, font, etc.) It should be the last lock in the lock
92 * chain
93 */
94 private final Object stateLock = new Object();
95
96 /**
97 * The lock to operate with the peers hierarchy. AWT tree lock is not used
98 * as there are many peers related ops to be done on the toolkit thread, and
977 }
978 LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget());
979 return false;
980 }
981
982 KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
983 Component focusOwner = kfmPeer.getCurrentFocusOwner();
984 return LWKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
985 getTarget(), temporary,
986 focusedWindowChangeAllowed,
987 time, cause, focusOwner);
988
989 case LWKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
990 return true;
991 }
992
993 return false;
994 }
995
996 @Override
997 public final Image createImage(final ImageProducer producer) {
998 return new ToolkitImage(producer);
999 }
1000
1001 @Override
1002 public final Image createImage(final int width, final int height) {
1003 return getLWGC().createAcceleratedImage(getTarget(), width, height);
1004 }
1005
1006 @Override
1007 public final VolatileImage createVolatileImage(final int w, final int h) {
1008 return new SunVolatileImage(getTarget(), w, h);
1009 }
1010
1011 @Override
1012 public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
1013 // TODO: is it a right/complete implementation?
1014 return Toolkit.getDefaultToolkit().prepareImage(img, w, h, o);
1015 }
1016
1017 @Override
1018 public int checkImage(Image img, int w, int h, ImageObserver o) {
1019 // TODO: is it a right/complete implementation?
1020 return Toolkit.getDefaultToolkit().checkImage(img, w, h, o);
1021 }
1022
1023 @Override
1024 public boolean handlesWheelScrolling() {
1025 // TODO: not implemented
1026 return false;
1027 }
1028
1029 @Override
1030 public final void applyShape(final Region shape) {
1031 synchronized (getStateLock()) {
1032 if (region == shape || (region != null && region.equals(shape))) {
1033 return;
1034 }
1035 }
1036 applyShapeImpl(shape);
1037 }
1038
1039 void applyShapeImpl(final Region shape) {
1040 synchronized (getStateLock()) {
1041 if (shape != null) {
1042 region = Region.WHOLE_REGION.getIntersection(shape);
1043 } else {
|
1 /*
2 * Copyright (c) 2011, 2020, 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
36 import java.awt.Font;
37 import java.awt.FontMetrics;
38 import java.awt.Graphics;
39 import java.awt.GraphicsConfiguration;
40 import java.awt.Image;
41 import java.awt.Point;
42 import java.awt.Rectangle;
43 import java.awt.Toolkit;
44 import java.awt.Window;
45 import java.awt.dnd.DropTarget;
46 import java.awt.dnd.peer.DropTargetPeer;
47 import java.awt.event.AWTEventListener;
48 import java.awt.event.ComponentEvent;
49 import java.awt.event.FocusEvent;
50 import java.awt.event.InputEvent;
51 import java.awt.event.KeyEvent;
52 import java.awt.event.MouseEvent;
53 import java.awt.event.MouseWheelEvent;
54 import java.awt.event.PaintEvent;
55 import java.awt.image.ColorModel;
56 import java.awt.image.VolatileImage;
57 import java.awt.peer.ComponentPeer;
58 import java.awt.peer.ContainerPeer;
59 import java.awt.peer.KeyboardFocusManagerPeer;
60 import java.lang.reflect.Field;
61 import java.security.AccessController;
62 import java.security.PrivilegedAction;
63 import java.util.concurrent.atomic.AtomicBoolean;
64
65 import javax.swing.JComponent;
66 import javax.swing.RepaintManager;
67 import javax.swing.SwingUtilities;
68
69 import com.sun.java.swing.SwingUtilities3;
70 import sun.awt.AWTAccessor;
71 import sun.awt.PaintEventDispatcher;
72 import sun.awt.RepaintArea;
73 import sun.awt.SunToolkit;
74 import sun.awt.event.IgnorePaintEvent;
75 import sun.awt.image.SunVolatileImage;
76 import sun.java2d.SunGraphics2D;
77 import sun.java2d.opengl.OGLRenderQueue;
78 import sun.java2d.pipe.Region;
79 import sun.util.logging.PlatformLogger;
80
81 public abstract class LWComponentPeer<T extends Component, D extends JComponent>
82 implements ComponentPeer, DropTargetPeer
83 {
84 private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWComponentPeer");
85
86 /**
87 * State lock is to be used for modifications to this peer's fields (e.g.
88 * bounds, background, font, etc.) It should be the last lock in the lock
89 * chain
90 */
91 private final Object stateLock = new Object();
92
93 /**
94 * The lock to operate with the peers hierarchy. AWT tree lock is not used
95 * as there are many peers related ops to be done on the toolkit thread, and
974 }
975 LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget());
976 return false;
977 }
978
979 KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
980 Component focusOwner = kfmPeer.getCurrentFocusOwner();
981 return LWKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
982 getTarget(), temporary,
983 focusedWindowChangeAllowed,
984 time, cause, focusOwner);
985
986 case LWKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
987 return true;
988 }
989
990 return false;
991 }
992
993 @Override
994 public final Image createImage(final int width, final int height) {
995 return getLWGC().createAcceleratedImage(getTarget(), width, height);
996 }
997
998 @Override
999 public final VolatileImage createVolatileImage(final int w, final int h) {
1000 return new SunVolatileImage(getTarget(), w, h);
1001 }
1002
1003 @Override
1004 public boolean handlesWheelScrolling() {
1005 // TODO: not implemented
1006 return false;
1007 }
1008
1009 @Override
1010 public final void applyShape(final Region shape) {
1011 synchronized (getStateLock()) {
1012 if (region == shape || (region != null && region.equals(shape))) {
1013 return;
1014 }
1015 }
1016 applyShapeImpl(shape);
1017 }
1018
1019 void applyShapeImpl(final Region shape) {
1020 synchronized (getStateLock()) {
1021 if (shape != null) {
1022 region = Region.WHOLE_REGION.getIntersection(shape);
1023 } else {
|