Java Code Examples for sun.awt.SunToolkit#executeOnEventHandlerThread()

The following examples show how to use sun.awt.SunToolkit#executeOnEventHandlerThread() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XScrollbar.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
void notifyValue(int v, final boolean isAdjusting) {
    if (v < min) {
        v = min;
    } else if (v > max - vis) {
        v = max - vis;
    }
    final int value = v;
    final int mode = this.mode;
    if ((sb != null) && ((value != val)||(!pressed))) {
        SunToolkit.executeOnEventHandlerThread(sb.getEventSource(), new Runnable() {
                public void run() {
                    sb.notifyValue(XScrollbar.this, mode, value, isAdjusting);
                }
            });
    }
}
 
Example 2
Source File: XWarningWindow.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void handleExposeEvent(XEvent xev) {
    super.handleExposeEvent(xev);

    XExposeEvent xe = xev.get_xexpose();
    final int x = xe.get_x();
    final int y = xe.get_y();
    final int width = xe.get_width();
    final int height = xe.get_height();
    SunToolkit.executeOnEventHandlerThread(target,
            new Runnable() {
                public void run() {
                    final Graphics g = getGraphics();
                    if (g != null) {
                        try {
                            paint(g, x, y, width, height);
                        } finally {
                            g.dispose();
                        }
                    }
                }
            });
}
 
Example 3
Source File: XWarningWindow.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void handleExposeEvent(XEvent xev) {
    super.handleExposeEvent(xev);

    XExposeEvent xe = xev.get_xexpose();
    final int x = xe.get_x();
    final int y = xe.get_y();
    final int width = xe.get_width();
    final int height = xe.get_height();
    SunToolkit.executeOnEventHandlerThread(target,
            new Runnable() {
                public void run() {
                    final Graphics g = getGraphics();
                    if (g != null) {
                        try {
                            paint(g, x, y, width, height);
                        } finally {
                            g.dispose();
                        }
                    }
                }
            });
}
 
Example 4
Source File: WTrayIconPeer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
Example 5
Source File: GestureHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void handleGestureFromNative(final Window window, final int type, final double x, final double y, final double a, final double b) {
    if (window == null) return; // should never happen...

    SunToolkit.executeOnEventHandlerThread(window, new Runnable() {
        public void run() {
            final Component component = SwingUtilities.getDeepestComponentAt(window, (int)x, (int)y);

            final PerComponentNotifier firstNotifier;
            if (component instanceof RootPaneContainer) {
                firstNotifier = getNextNotifierForComponent(((RootPaneContainer)component).getRootPane());
            } else {
                firstNotifier = getNextNotifierForComponent(component);
            }
            if (firstNotifier == null) return;

            switch (type) {
                case PHASE:
                    firstNotifier.recursivelyHandlePhaseChange(a, new GesturePhaseEvent());
                    return;
                case ROTATE:
                    firstNotifier.recursivelyHandleRotate(new RotationEvent(a));
                    return;
                case MAGNIFY:
                    firstNotifier.recursivelyHandleMagnify(new MagnificationEvent(a));
                    return;
                case SWIPE:
                    firstNotifier.recursivelyHandleSwipe(a, b, new SwipeEvent());
                    return;
            }
        }
    });
}
 
Example 6
Source File: InfoWindow.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void doClose() {
    SunToolkit.executeOnEventHandlerThread(InfoWindow.this, new Runnable() {
        public void run() {
            InfoWindow.super.hide();
            invalidate();
            if (action != null) {
                action.run();
            }
        }
    });
}
 
Example 7
Source File: ScreenMenu.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Callback from JavaMenuUpdater.m -- called when mouse event happens on the menu.
 */
public void handleMouseEvent(final int kind, final int x, final int y, final int modifiers, final long when) {
    if (kind == 0) return;
    if (fItemBounds == null) return;

    SunToolkit.executeOnEventHandlerThread(fInvoker, new Runnable() {
        @Override
        public void run() {
            Component target = null;
            Rectangle targetRect = null;
            for (int i = 0; i < fItemBounds.length; i++) {
                final Rectangle testRect = fItemBounds[i];
                if (testRect != null) {
                    if (testRect.contains(x, y)) {
                        target = fInvoker.getMenuComponent(i);
                        targetRect = testRect;
                        break;
                    }
                }
            }
            if (target == null && fLastMouseEventTarget == null) return;

            // Send a mouseExited to the previously hilited item, if it wasn't 0.
            if (target != fLastMouseEventTarget) {
                if (fLastMouseEventTarget != null) {
                    LWToolkit.postEvent(new MouseEvent(fLastMouseEventTarget, MouseEvent.MOUSE_EXITED, when, modifiers, x - fLastTargetRect.x, y - fLastTargetRect.y, 0, false));
                }
                // Send a mouseEntered to the current hilited item, if it wasn't 0.
                if (target != null) {
                    LWToolkit.postEvent(new MouseEvent(target, MouseEvent.MOUSE_ENTERED, when, modifiers, x - targetRect.x, y - targetRect.y, 0, false));
                }
                fLastMouseEventTarget = target;
                fLastTargetRect = targetRect;
            }
            // Post a mouse event to the current item.
            if (target == null) return;
            LWToolkit.postEvent(new MouseEvent(target, kind, when, modifiers, x - targetRect.x, y - targetRect.y, 0, false));
        }
    });
}
 
Example 8
Source File: LWCursorManager.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Schedules updating the cursor on the corresponding event dispatch
 * thread for the given window.
 *
 * This method is called on the toolkit thread as a result of a
 * native update cursor request (e.g. WM_SETCURSOR on Windows).
 */
public final void updateCursorLater(final LWWindowPeer window) {
    if (updatePending.compareAndSet(false, true)) {
        Runnable r = new Runnable() {
            @Override
            public void run() {
                updateCursor();
            }
        };
        SunToolkit.executeOnEventHandlerThread(window.getTarget(), r);
    }
}
 
Example 9
Source File: CTrayIcon.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void postEvent(final AWTEvent event) {
    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
        public void run() {
            SunToolkit.postEvent(SunToolkit.targetToAppContext(target), event);
        }
    });
}
 
Example 10
Source File: XWindowPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method that executes the displayChanged(screen) method on
 * the event dispatch thread.  This method is used in the Xinerama case
 * and after display mode change events.
 */
private void executeDisplayChangedOnEDT(final GraphicsConfiguration gc) {
    Runnable dc = new Runnable() {
        public void run() {
            AWTAccessor.getComponentAccessor().
                setGraphicsConfiguration(target, gc);
        }
    };
    SunToolkit.executeOnEventHandlerThread(target, dc);
}
 
Example 11
Source File: FullScreenHandler.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void handleFullScreenEventFromNative(final Window window, final int type) {
    if (!(window instanceof RootPaneContainer)) return; // handles null

    SunToolkit.executeOnEventHandlerThread(window, new Runnable() {
        public void run() {
            final FullScreenHandler handler = getHandlerFor((RootPaneContainer)window);
            if (handler != null) handler.notifyListener(new FullScreenEvent(window), type);
        }
    });
}
 
Example 12
Source File: CTrayIcon.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void postEvent(final AWTEvent event) {
    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
        public void run() {
            SunToolkit.postEvent(SunToolkit.targetToAppContext(target), event);
        }
    });
}
 
Example 13
Source File: CCheckboxMenuItem.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void handleAction(final boolean state) {
    final CheckboxMenuItem target = (CheckboxMenuItem)getTarget();
    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
        public void run() {
            target.setState(state);
        }
    });
    ItemEvent event = new ItemEvent(target, ItemEvent.ITEM_STATE_CHANGED, target.getLabel(), state ? ItemEvent.SELECTED : ItemEvent.DESELECTED);
    SunToolkit.postEvent(SunToolkit.targetToAppContext(getTarget()), event);
}
 
Example 14
Source File: D3DSurfaceData.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void swapBuffers(D3DSurfaceData sd,
                        final int x1, final int y1,
                        final int x2, final int y2)
{
    long pData = sd.getNativeOps();
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    // swapBuffers can be called from the toolkit thread by swing, we
    // should detect this and prevent the deadlocks
    if (rq.isRenderQueueThread()) {
        if (!rq.tryLock()) {
            // if we could not obtain the lock, repaint the area
            // that was supposed to be swapped, and no-op this swap
            final Component target = (Component)sd.getPeer().getTarget();
            SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
                public void run() {
                    target.repaint(x1, y1, x2, y2);
                }
            });
            return;
        }
    } else {
        rq.lock();
    }
    try {
        RenderBuffer buf = rq.getBuffer();
        rq.ensureCapacityAndAlignment(28, 4);
        buf.putInt(SWAP_BUFFERS);
        buf.putLong(pData);
        buf.putInt(x1);
        buf.putInt(y1);
        buf.putInt(x2);
        buf.putInt(y2);
        rq.flushNow();
    } finally {
        rq.unlock();
    }
}
 
Example 15
Source File: CTrayIcon.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void postEvent(final AWTEvent event) {
    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
        public void run() {
            SunToolkit.postEvent(SunToolkit.targetToAppContext(target), event);
        }
    });
}
 
Example 16
Source File: CCheckboxMenuItem.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void handleAction(final boolean state) {
    final CheckboxMenuItem target = (CheckboxMenuItem)getTarget();
    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
        public void run() {
            target.setState(state);
        }
    });
    ItemEvent event = new ItemEvent(target, ItemEvent.ITEM_STATE_CHANGED, target.getLabel(), state ? ItemEvent.SELECTED : ItemEvent.DESELECTED);
    SunToolkit.postEvent(SunToolkit.targetToAppContext(getTarget()), event);
}
 
Example 17
Source File: D3DSurfaceData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static void swapBuffers(D3DSurfaceData sd,
                        final int x1, final int y1,
                        final int x2, final int y2)
{
    long pData = sd.getNativeOps();
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    // swapBuffers can be called from the toolkit thread by swing, we
    // should detect this and prevent the deadlocks
    if (rq.isRenderQueueThread()) {
        if (!rq.tryLock()) {
            // if we could not obtain the lock, repaint the area
            // that was supposed to be swapped, and no-op this swap
            final Component target = (Component)sd.getPeer().getTarget();
            SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
                public void run() {
                    target.repaint(x1, y1, x2, y2);
                }
            });
            return;
        }
    } else {
        rq.lock();
    }
    try {
        RenderBuffer buf = rq.getBuffer();
        rq.ensureCapacityAndAlignment(28, 4);
        buf.putInt(SWAP_BUFFERS);
        buf.putLong(pData);
        buf.putInt(x1);
        buf.putInt(y1);
        buf.putInt(x2);
        buf.putInt(y2);
        rq.flushNow();
    } finally {
        rq.unlock();
    }
}
 
Example 18
Source File: LWCursorManager.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Schedules updating the cursor on the corresponding event dispatch
 * thread for the given window.
 *
 * This method is called on the toolkit thread as a result of a
 * native update cursor request (e.g. WM_SETCURSOR on Windows).
 */
public final void updateCursorLater(final LWWindowPeer window) {
    if (updatePending.compareAndSet(false, true)) {
        Runnable r = new Runnable() {
            @Override
            public void run() {
                updateCursor();
            }
        };
        SunToolkit.executeOnEventHandlerThread(window.getTarget(), r);
    }
}
 
Example 19
Source File: GestureHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void handleGestureFromNative(final Window window, final int type, final double x, final double y, final double a, final double b) {
    if (window == null) return; // should never happen...

    SunToolkit.executeOnEventHandlerThread(window, new Runnable() {
        public void run() {
            final Component component = SwingUtilities.getDeepestComponentAt(window, (int)x, (int)y);

            final PerComponentNotifier firstNotifier;
            if (component instanceof RootPaneContainer) {
                firstNotifier = getNextNotifierForComponent(((RootPaneContainer)component).getRootPane());
            } else {
                firstNotifier = getNextNotifierForComponent(component);
            }
            if (firstNotifier == null) return;

            switch (type) {
                case PHASE:
                    firstNotifier.recursivelyHandlePhaseChange(a, new GesturePhaseEvent());
                    return;
                case ROTATE:
                    firstNotifier.recursivelyHandleRotate(new RotationEvent(a));
                    return;
                case MAGNIFY:
                    firstNotifier.recursivelyHandleMagnify(new MagnificationEvent(a));
                    return;
                case SWIPE:
                    firstNotifier.recursivelyHandleSwipe(a, b, new SwipeEvent());
                    return;
            }
        }
    });
}
 
Example 20
Source File: InfoWindow.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void _display(String caption, String text, String messageType) {
    captionLabel.setText(caption);

    BreakIterator iter = BreakIterator.getWordInstance();
    if (text != null) {
        iter.setText(text);
        int start = iter.first(), end;
        int nLines = 0;

        do {
            end = iter.next();

            if (end == BreakIterator.DONE ||
                text.substring(start, end).length() >= 50)
            {
                lineLabels[nLines].setText(text.substring(start, end == BreakIterator.DONE ?
                                                          iter.last() : end));
                textPanel.add(lineLabels[nLines++]);
                start = end;
            }
            if (nLines == BALLOON_WORD_LINE_MAX_COUNT) {
                if (end != BreakIterator.DONE) {
                    lineLabels[nLines - 1].setText(
                        new String(lineLabels[nLines - 1].getText() + " ..."));
                }
                break;
            }
        } while (end != BreakIterator.DONE);


        textPanel.setLayout(new GridLayout(nLines, 1));
    }

    if ("ERROR".equals(messageType)) {
        iconImage = errorImage;
    } else if ("WARNING".equals(messageType)) {
        iconImage = warnImage;
    } else if ("INFO".equals(messageType)) {
        iconImage = infoImage;
    } else {
        iconImage = null;
    }

    if (iconImage != null) {
        Dimension tpSize = textPanel.getSize();
        iconCanvas.setSize(BALLOON_ICON_WIDTH, (BALLOON_ICON_HEIGHT > tpSize.height ?
                                                BALLOON_ICON_HEIGHT : tpSize.height));
        iconCanvas.validate();
    }

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            public void run() {
                if (liveArguments.isDisposed()) {
                    return;
                }
                Point parLoc = getParent().getLocationOnScreen();
                Dimension parSize = getParent().getSize();
                show(new Point(parLoc.x + parSize.width/2, parLoc.y + parSize.height/2),
                     BALLOON_TRAY_ICON_INDENT);
                if (iconImage != null) {
                    iconCanvas.updateImage(iconImage); // call it after the show(..) above
                }
            }
        });
}