package sun.awt.windows;
import java.awt.peer.TaskbarPeer;
import java.awt.*;
import java.awt.im.InputMethodHighlight;
import java.awt.im.spi.InputMethodDescriptor;
import java.awt.image.*;
import java.awt.peer.*;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.datatransfer.Clipboard;
import java.awt.TextComponent;
import java.awt.TrayIcon;
import java.beans.PropertyChangeListener;
import java.lang.ref.WeakReference;
import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.swing.text.JTextComponent;
import sun.awt.AWTAccessor;
import sun.awt.AppContext;
import sun.awt.AWTAutoShutdown;
import sun.awt.AWTPermissions;
import sun.awt.AppContext;
import sun.awt.DisplayChangedListener;
import sun.awt.LightweightFrame;
import sun.awt.SunToolkit;
import sun.awt.util.ThreadGroupUtils;
import sun.awt.Win32GraphicsDevice;
import sun.awt.Win32GraphicsEnvironment;
import sun.awt.datatransfer.DataTransferer;
import sun.java2d.d3d.D3DRenderQueue;
import sun.java2d.opengl.OGLRenderQueue;
import sun.print.PrintJob2D;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureRecognizer;
import java.awt.dnd.MouseDragGestureRecognizer;
import java.awt.dnd.InvalidDnDOperationException;
import java.awt.dnd.peer.DragSourceContextPeer;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import sun.awt.util.PerformanceLogger;
import sun.font.FontManager;
import sun.font.FontManagerFactory;
import sun.font.SunFontManager;
import sun.util.logging.PlatformLogger;
public final class WToolkit extends SunToolkit implements Runnable {
private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WToolkit");
public static final String XPSTYLE_THEME_ACTIVE = "win.xpstyle.themeActive";
WClipboard clipboard;
private Hashtable<String,FontPeer> cacheFontPeer;
private WDesktopProperties wprops;
protected boolean dynamicLayoutSetting = false;
private static boolean = true;
private static native void initIDs();
private static boolean loaded = false;
public static void loadLibraries() {
if (!loaded) {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
@Override
public Void run() {
System.loadLibrary("awt");
return null;
}
});
loaded = true;
}
}
private static native String getWindowsVersion();
static {
loadLibraries();
initIDs();
if (log.isLoggable(PlatformLogger.Level.FINE)) {
log.fine("Win version: " + getWindowsVersion());
}
AccessController.doPrivileged(
new PrivilegedAction <Void> ()
{
@Override
public Void run() {
String browserProp = System.getProperty("browser");
if (browserProp != null && browserProp.equals("sun.plugin")) {
disableCustomPalette();
}
return null;
}
});
}
private static native void disableCustomPalette();
public static native boolean embeddedInit();
public static native boolean embeddedDispose();
public native void embeddedEventLoopIdleProcessing();
static class ToolkitDisposer implements sun.java2d.DisposerRecord {
@Override
public void dispose() {
WToolkit.postDispose();
}
}
private final Object anchor = new Object();
private static native void postDispose();
private static native boolean startToolkitThread(Runnable thread, ThreadGroup rootThreadGroup);
public WToolkit() {
if (PerformanceLogger.loggingEnabled()) {
PerformanceLogger.setTime("WToolkit construction");
}
sun.java2d.Disposer.addRecord(anchor, new ToolkitDisposer());
AWTAutoShutdown.notifyToolkitThreadBusy();
ThreadGroup rootTG = AccessController.doPrivileged(
(PrivilegedAction<ThreadGroup>) ThreadGroupUtils::getRootThreadGroup);
if (!startToolkitThread(this, rootTG)) {
String name = "AWT-Windows";
Thread toolkitThread = new Thread(rootTG, this, name, 0, false);
toolkitThread.setDaemon(true);
toolkitThread.start();
}
try {
synchronized(this) {
while(!inited) {
wait();
}
}
} catch (InterruptedException x) {
}
setDynamicLayout(true);
areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);
setExtraMouseButtonsEnabledNative(areExtraMouseButtonsEnabled);
}
private void registerShutdownHook() {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
Thread shutdown = new Thread(
ThreadGroupUtils.getRootThreadGroup(), this::shutdown,
"ToolkitShutdown", 0, false);
shutdown.setContextClassLoader(null);
Runtime.getRuntime().addShutdownHook(shutdown);
return null;
});
}
@Override
public void run() {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
Thread.currentThread().setContextClassLoader(null);
Thread.currentThread().setPriority(Thread.NORM_PRIORITY + 1);
return null;
});
boolean startPump = init();
if (startPump) {
registerShutdownHook();
}
synchronized(this) {
inited = true;
notifyAll();
}
if (startPump) {
eventLoop();
}
}
private native boolean init();
private boolean inited = false;
private native void eventLoop();
private native void shutdown();
static native void startSecondaryEventLoop();
static native void quitSecondaryEventLoop();
@Override
public ButtonPeer createButton(Button target) {
ButtonPeer peer = new WButtonPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public TextFieldPeer createTextField(TextField target) {
TextFieldPeer peer = new WTextFieldPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public LabelPeer createLabel(Label target) {
LabelPeer peer = new WLabelPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public ListPeer createList(List target) {
ListPeer peer = new WListPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public CheckboxPeer createCheckbox(Checkbox target) {
CheckboxPeer peer = new WCheckboxPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public ScrollbarPeer createScrollbar(Scrollbar target) {
ScrollbarPeer peer = new WScrollbarPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public ScrollPanePeer createScrollPane(ScrollPane target) {
ScrollPanePeer peer = new WScrollPanePeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public TextAreaPeer createTextArea(TextArea target) {
TextAreaPeer peer = new WTextAreaPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public ChoicePeer createChoice(Choice target) {
ChoicePeer peer = new WChoicePeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public FramePeer createFrame(Frame target) {
FramePeer peer = new WFramePeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public FramePeer createLightweightFrame(LightweightFrame target) {
FramePeer peer = new WLightweightFramePeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public CanvasPeer createCanvas(Canvas target) {
CanvasPeer peer = new WCanvasPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public void disableBackgroundErase(Canvas canvas) {
WCanvasPeer peer = AWTAccessor.getComponentAccessor().getPeer(canvas);
if (peer == null) {
throw new IllegalStateException("Canvas must have a valid peer");
}
peer.disableBackgroundErase();
}
@Override
public PanelPeer createPanel(Panel target) {
PanelPeer peer = new WPanelPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public WindowPeer createWindow(Window target) {
WindowPeer peer = new WWindowPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public DialogPeer createDialog(Dialog target) {
DialogPeer peer = new WDialogPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public FileDialogPeer createFileDialog(FileDialog target) {
FileDialogPeer peer = new WFileDialogPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public MenuBarPeer (MenuBar target) {
MenuBarPeer peer = new WMenuBarPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public MenuPeer (Menu target) {
MenuPeer peer = new WMenuPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public PopupMenuPeer (PopupMenu target) {
PopupMenuPeer peer = new WPopupMenuPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public MenuItemPeer (MenuItem target) {
MenuItemPeer peer = new WMenuItemPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public CheckboxMenuItemPeer (CheckboxMenuItem target) {
CheckboxMenuItemPeer peer = new WCheckboxMenuItemPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public RobotPeer createRobot(Robot target, GraphicsDevice screen) {
return new WRobotPeer(screen);
}
public WEmbeddedFramePeer createEmbeddedFrame(WEmbeddedFrame target) {
WEmbeddedFramePeer peer = new WEmbeddedFramePeer(target);
targetCreatedPeer(target, peer);
return peer;
}
WPrintDialogPeer createWPrintDialog(WPrintDialog target) {
WPrintDialogPeer peer = new WPrintDialogPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
WPageDialogPeer createWPageDialog(WPageDialog target) {
WPageDialogPeer peer = new WPageDialogPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public TrayIconPeer createTrayIcon(TrayIcon target) {
WTrayIconPeer peer = new WTrayIconPeer(target);
targetCreatedPeer(target, peer);
return peer;
}
@Override
public SystemTrayPeer createSystemTray(SystemTray target) {
return new WSystemTrayPeer(target);
}
@Override
public boolean isTraySupported() {
return true;
}
@Override
public DataTransferer getDataTransferer() {
return WDataTransferer.getInstanceImpl();
}
@Override
public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer()
throws HeadlessException
{
return WKeyboardFocusManagerPeer.getInstance();
}
private static WMouseInfoPeer wPeer = null;
@Override
public synchronized MouseInfoPeer getMouseInfoPeer() {
if (wPeer == null) {
wPeer = new WMouseInfoPeer();
}
return wPeer;
}
private native void setDynamicLayoutNative(boolean b);
@Override
public void setDynamicLayout(boolean b) {
if (b == dynamicLayoutSetting) {
return;
}
dynamicLayoutSetting = b;
setDynamicLayoutNative(b);
}
@Override
protected boolean isDynamicLayoutSet() {
return dynamicLayoutSetting;
}
private native boolean isDynamicLayoutSupportedNative();
@Override
public boolean isDynamicLayoutActive() {
return (isDynamicLayoutSet() && isDynamicLayoutSupported());
}
@Override
public boolean isFrameStateSupported(int state) {
switch (state) {
case Frame.NORMAL:
case Frame.ICONIFIED:
case Frame.MAXIMIZED_BOTH:
return true;
default:
return false;
}
}
static native ColorModel makeColorModel();
static ColorModel screenmodel;
@Override
public Insets getScreenInsets(final GraphicsConfiguration gc) {
GraphicsDevice gd = gc.getDevice();
if (!(gd instanceof Win32GraphicsDevice)) {
return super.getScreenInsets(gc);
}
return getScreenInsets(((Win32GraphicsDevice) gd).getScreen());
}
@Override
public int getScreenResolution() {
Win32GraphicsEnvironment ge = (Win32GraphicsEnvironment)
GraphicsEnvironment.getLocalGraphicsEnvironment();
return ge.getXResolution();
}
private native Insets getScreenInsets(int screen);
@Override
public FontMetrics getFontMetrics(Font font) {
FontManager fm = FontManagerFactory.getInstance();
if (fm instanceof SunFontManager
&& ((SunFontManager) fm).usePlatformFontMetrics()) {
return WFontMetrics.getFontMetrics(font);
}
return super.getFontMetrics(font);
}
@Override
public FontPeer getFontPeer(String name, int style) {
FontPeer retval = null;
String lcName = name.toLowerCase();
if (null != cacheFontPeer) {
retval = cacheFontPeer.get(lcName + style);
if (null != retval) {
return retval;
}
}
retval = new WFontPeer(name, style);
if (retval != null) {
if (null == cacheFontPeer) {
cacheFontPeer = new Hashtable<>(5, 0.9f);
}
if (null != cacheFontPeer) {
cacheFontPeer.put(lcName + style, retval);
}
}
return retval;
}
private native void nativeSync();
@Override
public void sync() {
nativeSync();
OGLRenderQueue.sync();
D3DRenderQueue.sync();
}
@Override
public PrintJob getPrintJob(Frame frame, String doctitle,
Properties props) {
return getPrintJob(frame, doctitle, null, null);
}
@Override
public PrintJob getPrintJob(Frame frame, String doctitle,
JobAttributes jobAttributes,
PageAttributes pageAttributes)
{
if (frame == null) {
throw new NullPointerException("frame must not be null");
}
PrintJob2D printJob = new PrintJob2D(frame, doctitle,
jobAttributes, pageAttributes);
if (printJob.printDialog() == false) {
printJob = null;
}
return printJob;
}
@Override
public native void beep();
@Override
public boolean getLockingKeyState(int key) {
if (! (key == KeyEvent.VK_CAPS_LOCK || key == KeyEvent.VK_NUM_LOCK ||
key == KeyEvent.VK_SCROLL_LOCK || key == KeyEvent.VK_KANA_LOCK)) {
throw new IllegalArgumentException("invalid key for Toolkit.getLockingKeyState");
}
return getLockingKeyStateNative(key);
}
private native boolean getLockingKeyStateNative(int key);
@Override
public void setLockingKeyState(int key, boolean on) {
if (! (key == KeyEvent.VK_CAPS_LOCK || key == KeyEvent.VK_NUM_LOCK ||
key == KeyEvent.VK_SCROLL_LOCK || key == KeyEvent.VK_KANA_LOCK)) {
throw new IllegalArgumentException("invalid key for Toolkit.setLockingKeyState");
}
setLockingKeyStateNative(key, on);
}
private native void setLockingKeyStateNative(int key, boolean on);
@Override
public Clipboard getSystemClipboard() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
}
synchronized (this) {
if (clipboard == null) {
clipboard = new WClipboard();
}
}
return clipboard;
}
@Override
protected native void loadSystemColors(int[] systemColors);
public static Object targetToPeer(Object target) {
return SunToolkit.targetToPeer(target);
}
public static void targetDisposedPeer(Object target, Object peer) {
SunToolkit.targetDisposedPeer(target, peer);
}
@Override
public InputMethodDescriptor getInputMethodAdapterDescriptor() {
return new WInputMethodDescriptor();
}
@Override
public Map<java.awt.font.TextAttribute,?> mapInputMethodHighlight(
InputMethodHighlight highlight)
{
return WInputMethod.mapInputMethodHighlight(highlight);
}
@Override
public boolean enableInputMethodsForTextComponent() {
return true;
}
@Override
public Locale getDefaultKeyboardLocale() {
Locale locale = WInputMethod.getNativeLocale();
if (locale == null) {
return super.getDefaultKeyboardLocale();
} else {
return locale;
}
}
@Override
public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)
throws IndexOutOfBoundsException {
return new WCustomCursor(cursor, hotSpot, name);
}
@Override
public Dimension getBestCursorSize(int preferredWidth, int preferredHeight) {
return new Dimension(WCustomCursor.getCursorWidth(),
WCustomCursor.getCursorHeight());
}
@Override
public native int getMaximumCursorColors();
static void paletteChanged() {
Object lge = GraphicsEnvironment.getLocalGraphicsEnvironment();
if (lge instanceof DisplayChangedListener) {
((DisplayChangedListener) lge).paletteChanged();
}
}
private static ExecutorService displayChangeExecutor;
public static void displayChanged() {
final Runnable runnable = () -> {
Object lge = GraphicsEnvironment.getLocalGraphicsEnvironment();
if (lge instanceof DisplayChangedListener) {
((DisplayChangedListener) lge).displayChanged();
}
};
if (AppContext.getAppContext() != null) {
EventQueue.invokeLater(runnable);
} else {
if (displayChangeExecutor == null) {
displayChangeExecutor = Executors.newFixedThreadPool(1, r -> {
Thread t = Executors.defaultThreadFactory().newThread(r);
t.setDaemon(true);
return t;
});
}
displayChangeExecutor.submit(runnable);
}
}
@Override
public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
final LightweightFrame f = SunToolkit.getLightweightFrame(dge.getComponent());
if (f != null) {
return f.createDragSourceContextPeer(dge);
}
return WDragSourceContextPeer.createDragSourceContextPeer(dge);
}
@Override
@SuppressWarnings("unchecked")
public <T extends DragGestureRecognizer> T
createDragGestureRecognizer(Class<T> abstractRecognizerClass,
DragSource ds, Component c, int srcActions,
DragGestureListener dgl)
{
final LightweightFrame f = SunToolkit.getLightweightFrame(c);
if (f != null) {
return f.createDragGestureRecognizer(abstractRecognizerClass, ds, c, srcActions, dgl);
}
if (MouseDragGestureRecognizer.class.equals(abstractRecognizerClass))
return (T)new WMouseDragGestureRecognizer(ds, c, srcActions, dgl);
else
return null;
}
private static final String prefix = "DnD.Cursor.";
private static final String postfix = ".32x32";
private static final String awtPrefix = "awt.";
private static final String dndPrefix = "DnD.";
@Override
protected Object lazilyLoadDesktopProperty(String name) {
if (name.startsWith(prefix)) {
String cursorName = name.substring(prefix.length(), name.length()) + postfix;
try {
return Cursor.getSystemCustomCursor(cursorName);
} catch (AWTException awte) {
throw new RuntimeException("cannot load system cursor: " + cursorName, awte);
}
}
if (name.equals("awt.dynamicLayoutSupported")) {
return Boolean.valueOf(isDynamicLayoutSupported());
}
if (WDesktopProperties.isWindowsProperty(name) ||
name.startsWith(awtPrefix) || name.startsWith(dndPrefix))
{
synchronized(this) {
lazilyInitWProps();
return desktopProperties.get(name);
}
}
return super.lazilyLoadDesktopProperty(name);
}
private synchronized void lazilyInitWProps() {
if (wprops == null) {
wprops = new WDesktopProperties(this);
updateProperties(wprops.getProperties());
}
}
private synchronized boolean isDynamicLayoutSupported() {
boolean nativeDynamic = isDynamicLayoutSupportedNative();
lazilyInitWProps();
Boolean prop = (Boolean) desktopProperties.get("awt.dynamicLayoutSupported");
if (log.isLoggable(PlatformLogger.Level.FINER)) {
log.finer("In WTK.isDynamicLayoutSupported()" +
" nativeDynamic == " + nativeDynamic +
" wprops.dynamic == " + prop);
}
if ((prop == null) || (nativeDynamic != prop.booleanValue())) {
windowsSettingChange();
return nativeDynamic;
}
return prop.booleanValue();
}
private void windowsSettingChange() {
final Map<String, Object> props = getWProps();
if (props == null) {
return;
}
updateXPStyleEnabled(props.get(XPSTYLE_THEME_ACTIVE));
if (AppContext.getAppContext() == null) {
updateProperties(props);
} else {
EventQueue.invokeLater(() -> updateProperties(props));
}
}
private synchronized void updateProperties(final Map<String, Object> props) {
if (null == props) {
return;
}
updateXPStyleEnabled(props.get(XPSTYLE_THEME_ACTIVE));
for (String propName : props.keySet()) {
Object val = props.get(propName);
if (log.isLoggable(PlatformLogger.Level.FINER)) {
log.finer("changed " + propName + " to " + val);
}
setDesktopProperty(propName, val);
}
}
private synchronized Map<String, Object> getWProps() {
return (wprops != null) ? wprops.getProperties() : null;
}
private void updateXPStyleEnabled(final Object dskProp) {
ThemeReader.xpStyleEnabled = Boolean.TRUE.equals(dskProp);
}
@Override
public synchronized void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
if (name == null) {
return;
}
if ( WDesktopProperties.isWindowsProperty(name)
|| name.startsWith(awtPrefix)
|| name.startsWith(dndPrefix))
{
lazilyInitWProps();
}
super.addPropertyChangeListener(name, pcl);
}
@Override
protected synchronized void initializeDesktopProperties() {
desktopProperties.put("DnD.Autoscroll.initialDelay",
Integer.valueOf(50));
desktopProperties.put("DnD.Autoscroll.interval",
Integer.valueOf(50));
desktopProperties.put("DnD.isDragImageSupported",
Boolean.TRUE);
desktopProperties.put("Shell.shellFolderManager",
"sun.awt.shell.Win32ShellFolderManager2");
}
@Override
protected synchronized RenderingHints getDesktopAAHints() {
if (wprops == null) {
return null;
} else {
return wprops.getDesktopAAHints();
}
}
@Override
public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) {
return (modalityType == null) ||
(modalityType == Dialog.ModalityType.MODELESS) ||
(modalityType == Dialog.ModalityType.DOCUMENT_MODAL) ||
(modalityType == Dialog.ModalityType.APPLICATION_MODAL) ||
(modalityType == Dialog.ModalityType.TOOLKIT_MODAL);
}
@Override
public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) {
return (exclusionType == null) ||
(exclusionType == Dialog.ModalExclusionType.NO_EXCLUDE) ||
(exclusionType == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) ||
(exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);
}
public static WToolkit getWToolkit() {
WToolkit toolkit = (WToolkit)Toolkit.getDefaultToolkit();
return toolkit;
}
@Override
public boolean useBufferPerWindow() {
return !Win32GraphicsEnvironment.isDWMCompositionEnabled();
}
@Override
public void grab(Window w) {
final Object peer = AWTAccessor.getComponentAccessor().getPeer(w);
if (peer != null) {
((WWindowPeer) peer).grab();
}
}
@Override
public void ungrab(Window w) {
final Object peer = AWTAccessor.getComponentAccessor().getPeer(w);
if (peer != null) {
((WWindowPeer) peer).ungrab();
}
}
private static final WeakReference<Component> NULL_COMPONENT_WR =
new WeakReference<>(null);
private volatile WeakReference<Component> compOnTouchDownEvent =
NULL_COMPONENT_WR;
private volatile WeakReference<Component> compOnMousePressedEvent =
NULL_COMPONENT_WR;
private boolean isComponentValidForTouchKeyboard(Component comp) {
if ((comp != null) && comp.isEnabled() && comp.isFocusable() &&
(((comp instanceof TextComponent) &&
((TextComponent) comp).isEditable()) ||
((comp instanceof JTextComponent) &&
((JTextComponent) comp).isEditable()))) {
return true;
}
return false;
}
@Override
public void showOrHideTouchKeyboard(Component comp, AWTEvent e) {
if (!(comp instanceof TextComponent) &&
!(comp instanceof JTextComponent)) {
return;
}
if ((e instanceof MouseEvent) && isComponentValidForTouchKeyboard(comp)) {
MouseEvent me = (MouseEvent) e;
if (me.getID() == MouseEvent.MOUSE_PRESSED) {
if (AWTAccessor.getMouseEventAccessor().isCausedByTouchEvent(me)) {
compOnTouchDownEvent = new WeakReference<>(comp);
} else {
compOnMousePressedEvent = new WeakReference<>(comp);
}
} else if (me.getID() == MouseEvent.MOUSE_RELEASED) {
if (AWTAccessor.getMouseEventAccessor().isCausedByTouchEvent(me)) {
if (compOnTouchDownEvent.get() == comp) {
showTouchKeyboard(true);
}
compOnTouchDownEvent = NULL_COMPONENT_WR;
} else {
if (compOnMousePressedEvent.get() == comp) {
showTouchKeyboard(false);
}
compOnMousePressedEvent = NULL_COMPONENT_WR;
}
}
} else if (e instanceof FocusEvent) {
FocusEvent fe = (FocusEvent) e;
if (fe.getID() == FocusEvent.FOCUS_LOST) {
if (!isComponentValidForTouchKeyboard(fe.getOppositeComponent())) {
hideTouchKeyboard();
}
}
}
}
private native void showTouchKeyboard(boolean causedByTouchEvent);
private native void hideTouchKeyboard();
@Override
public native boolean syncNativeQueue(final long timeout);
@Override
public boolean isDesktopSupported() {
return true;
}
@Override
public DesktopPeer createDesktopPeer(Desktop target) {
return new WDesktopPeer();
}
@Override
public boolean isTaskbarSupported() {
return WTaskbarPeer.isTaskbarSupported();
}
@Override
public TaskbarPeer createTaskbarPeer(Taskbar target) {
return new WTaskbarPeer();
}
private static native void (boolean enable);
@Override
public boolean () throws HeadlessException {
return areExtraMouseButtonsEnabled;
}
private synchronized native int getNumberOfButtonsImpl();
@Override
public int getNumberOfButtons(){
if (numberOfButtons == 0) {
numberOfButtons = getNumberOfButtonsImpl();
}
return (numberOfButtons > MAX_BUTTONS_SUPPORTED)? MAX_BUTTONS_SUPPORTED : numberOfButtons;
}
@Override
public boolean isWindowOpacitySupported() {
return true;
}
@Override
public boolean isWindowShapingSupported() {
return true;
}
@Override
public boolean isWindowTranslucencySupported() {
return true;
}
@Override
public boolean isTranslucencyCapable(GraphicsConfiguration gc) {
return true;
}
@Override
public boolean needUpdateWindow() {
return true;
}
}