当前位置: 首页>>代码示例>>Java>>正文


Java SunToolkit.postEvent方法代码示例

本文整理汇总了Java中sun.awt.SunToolkit.postEvent方法的典型用法代码示例。如果您正苦于以下问题:Java SunToolkit.postEvent方法的具体用法?Java SunToolkit.postEvent怎么用?Java SunToolkit.postEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sun.awt.SunToolkit的用法示例。


在下文中一共展示了SunToolkit.postEvent方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: stopLWModal

import sun.awt.SunToolkit; //导入方法依赖的package包/类
private void stopLWModal() {
    synchronized (getTreeLock()) {
        if (modalAppContext != null) {
            Container nativeContainer = getHeavyweightContainer();
            if(nativeContainer != null) {
                if (this.modalComp !=  null) {
                    nativeContainer.modalComp = this.modalComp;
                    this.modalComp = null;
                    return;
                }
                else {
                    nativeContainer.modalComp = null;
                }
            }
            // Wake up event dispatch thread on which the dialog was
            // initially shown
            SunToolkit.postEvent(modalAppContext,
                    new PeerEvent(this,
                            new WakingRunnable(),
                            PeerEvent.PRIORITY_EVENT));
        }
        EventQueue.invokeLater(new WakingRunnable());
        getTreeLock().notifyAll();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:Container.java

示例2: checkChange

import sun.awt.SunToolkit; //导入方法依赖的package包/类
/**
 * Checks change of the {@code DataFlavor}s and, if necessary,
 * posts notifications on {@code FlavorEvent}s to the
 * AppContexts' EDTs.
 * The parameter {@code formats} is null iff we have just
 * failed to get formats available on the clipboard.
 *
 * @param formats data formats that have just been retrieved from
 *        this clipboard
 */
protected final void checkChange(final long[] formats) {
    if (Arrays.equals(formats, currentFormats)) {
        // we've been able to successfully get available on the clipboard
        // DataFlavors this and previous time and they are coincident;
        // don't notify
        return;
    }
    currentFormats = formats;

    for (final AppContext appContext : AppContext.getAppContexts()) {
        if (appContext == null || appContext.isDisposed()) {
            continue;
        }
        Set<FlavorListener> flavorListeners = getFlavorListeners(appContext);
        if (flavorListeners != null) {
            for (FlavorListener listener : flavorListeners) {
                if (listener != null) {
                    PeerEvent peerEvent = new PeerEvent(this,
                            () -> listener.flavorsChanged(new FlavorEvent(SunClipboard.this)),
                            PeerEvent.PRIORITY_EVENT);
                    SunToolkit.postEvent(appContext, peerEvent);
                }
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:SunClipboard.java

示例3: firePropertyChange

import sun.awt.SunToolkit; //导入方法依赖的package包/类
@Override
public void firePropertyChange(final PropertyChangeEvent evt) {
    Object oldValue = evt.getOldValue();
    Object newValue = evt.getNewValue();
    String propertyName = evt.getPropertyName();
    if (oldValue != null && newValue != null && oldValue.equals(newValue)) {
        return;
    }
    Runnable updater = new Runnable() {
        public void run() {
            PropertyChangeSupport pcs = (PropertyChangeSupport)
                    AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
            if (null != pcs) {
                pcs.firePropertyChange(evt);
            }
        }
    };
    final AppContext currentAppContext = AppContext.getAppContext();
    for (AppContext appContext : AppContext.getAppContexts()) {
        if (null == appContext || appContext.isDisposed()) {
            continue;
        }
        if (currentAppContext == appContext) {
            updater.run();
        } else {
            final PeerEvent e = new PeerEvent(source, updater, PeerEvent.ULTIMATE_PRIORITY_EVENT);
            SunToolkit.postEvent(appContext, e);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:Toolkit.java

示例4: sendMessage

import sun.awt.SunToolkit; //导入方法依赖的package包/类
/**
 * Sends a synthetic AWTEvent to a Component. If the Component is in
 * the current AppContext, then the event is immediately dispatched.
 * If the Component is in a different AppContext, then the event is
 * posted to the other AppContext's EventQueue, and this method blocks
 * until the event is handled or target AppContext is disposed.
 * Returns true if successfuly dispatched event, false if failed
 * to dispatch.
 */
static boolean sendMessage(Component target, AWTEvent e) {
    e.isPosted = true;
    AppContext myAppContext = AppContext.getAppContext();
    final AppContext targetAppContext = target.appContext;
    final SentEvent se =
        new DefaultKeyboardFocusManagerSentEvent(e, myAppContext);

    if (myAppContext == targetAppContext) {
        se.dispatch();
    } else {
        if (targetAppContext.isDisposed()) {
            return false;
        }
        SunToolkit.postEvent(targetAppContext, se);
        if (EventQueue.isDispatchThread()) {
            EventDispatchThread edt = (EventDispatchThread)
                Thread.currentThread();
            edt.pumpEvents(SentEvent.ID, new Conditional() {
                    public boolean evaluate() {
                        return !se.dispatched && !targetAppContext.isDisposed();
                    }
                });
        } else {
            synchronized (se) {
                while (!se.dispatched && !targetAppContext.isDisposed()) {
                    try {
                        se.wait(1000);
                    } catch (InterruptedException ie) {
                        break;
                    }
                }
            }
        }
    }
    return se.dispatched;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:46,代码来源:DefaultKeyboardFocusManager.java

示例5: repostIfFollowsKeyEvents

import sun.awt.SunToolkit; //导入方法依赖的package包/类
private boolean repostIfFollowsKeyEvents(WindowEvent e) {
    if (!(e instanceof TimedWindowEvent)) {
        return false;
    }
    TimedWindowEvent we = (TimedWindowEvent)e;
    long time = we.getWhen();
    synchronized (this) {
        KeyEvent ke = enqueuedKeyEvents.isEmpty() ? null : enqueuedKeyEvents.getFirst();
        if (ke != null && time >= ke.getWhen()) {
            TypeAheadMarker marker = typeAheadMarkers.isEmpty() ? null : typeAheadMarkers.getFirst();
            if (marker != null) {
                Window toplevel = marker.untilFocused.getContainingWindow();
                // Check that the component awaiting focus belongs to
                // the current focused window. See 8015454.
                if (toplevel != null && toplevel.isFocused()) {
                    SunToolkit.postEvent(AppContext.getAppContext(), new SequencedEvent(e));
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:DefaultKeyboardFocusManager.java

示例6: postDropTargetEvent

import sun.awt.SunToolkit; //导入方法依赖的package包/类
protected int postDropTargetEvent(final Component component,
                                  final int x, final int y,
                                  final int dropAction,
                                  final int actions,
                                  final long[] formats,
                                  final long nativeCtxt,
                                  final int eventID,
                                  final boolean dispatchType) {
    AppContext appContext = SunToolkit.targetToAppContext(component);

    EventDispatcher dispatcher =
        new EventDispatcher(this, dropAction, actions, formats, nativeCtxt,
                            dispatchType);

    SunDropTargetEvent event =
        new SunDropTargetEvent(component, eventID, x, y, dispatcher);

    if (dispatchType == SunDropTargetContextPeer.DISPATCH_SYNC) {
        DataTransferer.getInstance().getToolkitThreadBlockedHandler().lock();
    }

    // schedule callback
    SunToolkit.postEvent(appContext, event);

    eventPosted(event);

    if (dispatchType == SunDropTargetContextPeer.DISPATCH_SYNC) {
        while (!dispatcher.isDone()) {
            DataTransferer.getInstance().getToolkitThreadBlockedHandler().enter();
        }

        DataTransferer.getInstance().getToolkitThreadBlockedHandler().unlock();

        // return target's response
        return dispatcher.getReturnValue();
    } else {
        return 0;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:40,代码来源:SunDropTargetContextPeer.java

示例7: repaint

import sun.awt.SunToolkit; //导入方法依赖的package包/类
/**
 * Repaints the specified rectangle of this component within
 * <code>tm</code> milliseconds.
 * <p>
 * If this component is a lightweight component, this method causes
 * a call to this component's <code>paint</code> method.
 * Otherwise, this method causes a call to this component's
 * <code>update</code> method.
 * <p>
 * <b>Note</b>: For more information on the paint mechanisms utilitized
 * by AWT and Swing, including information on how to write the most
 * efficient painting code, see
 * <a href="http://www.oracle.com/technetwork/java/painting-140037.html">Painting in AWT and Swing</a>.
 *
 * @param     tm   maximum time in milliseconds before update
 * @param     x    the <i>x</i> coordinate
 * @param     y    the <i>y</i> coordinate
 * @param     width    the width
 * @param     height   the height
 * @see       #update(Graphics)
 * @since     JDK1.0
 */
public void repaint(long tm, int x, int y, int width, int height) {
    if (this.peer instanceof LightweightPeer) {
        // Needs to be translated to parent coordinates since
        // a parent native container provides the actual repaint
        // services.  Additionally, the request is restricted to
        // the bounds of the component.
        if (parent != null) {
            if (x < 0) {
                width += x;
                x = 0;
            }
            if (y < 0) {
                height += y;
                y = 0;
            }

            int pwidth = (width > this.width) ? this.width : width;
            int pheight = (height > this.height) ? this.height : height;

            if (pwidth <= 0 || pheight <= 0) {
                return;
            }

            int px = this.x + x;
            int py = this.y + y;
            parent.repaint(tm, px, py, pwidth, pheight);
        }
    } else {
        if (isVisible() && (this.peer != null) &&
            (width > 0) && (height > 0)) {
            PaintEvent e = new PaintEvent(this, PaintEvent.UPDATE,
                                          new Rectangle(x, y, width, height));
            SunToolkit.postEvent(SunToolkit.targetToAppContext(this), e);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:59,代码来源:Component.java

示例8: handleAction

import sun.awt.SunToolkit; //导入方法依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:CCheckboxMenuItem.java

示例9: showInputMethodMenuOnRequesterEDT

import sun.awt.SunToolkit; //导入方法依赖的package包/类
private void showInputMethodMenuOnRequesterEDT(Component requester)
    throws InterruptedException, InvocationTargetException {

    if (requester == null){
        return;
    }

    class AWTInvocationLock {}
    Object lock = new AWTInvocationLock();

    InvocationEvent event =
            new InvocationEvent(requester,
                                new Runnable() {
                                    public void run() {
                                        showInputMethodMenu();
                                    }
                                },
                                lock,
                                true);

    AppContext requesterAppContext = SunToolkit.targetToAppContext(requester);
    synchronized (lock) {
        SunToolkit.postEvent(requesterAppContext, event);
        while (!event.isDispatched()) {
            lock.wait();
        }
    }

    Throwable eventThrowable = event.getThrowable();
    if (eventThrowable != null) {
        throw new InvocationTargetException(eventThrowable);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:34,代码来源:ExecutableInputMethodManager.java

示例10: main

import sun.awt.SunToolkit; //导入方法依赖的package包/类
public static void main(String[] args) {
        frame = new Frame("");
        frame.pack();

        Runnable dummy = new Runnable() {
                public void run() {
                    System.err.println("Dummy is here.");
                    System.err.flush();
                }
            };
        EventQueue seq = Toolkit.getDefaultToolkit().getSystemEventQueue();
        MyEventQueue1 eq1 = new MyEventQueue1();
        MyEventQueue2 eq2 = new MyEventQueue2();
        EventQueue.invokeLater(dummy);

        seq.push(eq1);
        EventQueue.invokeLater(dummy);

        eq1.push(eq2);
        EventQueue.invokeLater(dummy);
        Runnable runnable = new Runnable() {
                public void run() {
                    System.err.println("Dummy from SunToolkit");
                    System.err.flush();
                }
            };
        InvocationEvent ie = new InvocationEvent(eq2, runnable, null, false);
//        System.err.println(ie);
        SunToolkit.postEvent(SunToolkit.targetToAppContext(frame), ie);
        eq1.pop();
        frame.dispose();
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:PushPopTest.java

示例11: main

import sun.awt.SunToolkit; //导入方法依赖的package包/类
public static void main(String[] args) throws Throwable {
    EventQueue q = Toolkit.getDefaultToolkit().getSystemEventQueue();
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            q.postEvent(new PostActionEvent());
            for (int k = 0; k < 10; k++) {
                SunToolkit.postEvent(AppContext.getAppContext(), new PostActionEvent());
            }
        }
        for (int k = 0; k < 100; k++) {
            SunToolkit.postEvent(AppContext.getAppContext(), new PostActionEvent());
        }
    }

    for (;;) {
        Thread.currentThread().sleep(100);
        if (q.peekEvent() == null) {
            Thread.currentThread().sleep(100);
            if (q.peekEvent() == null)
                break;
        }
    }

    if (!testPassed) {
        throw new Exception("PostEventOrderingTest FAILED -- events dispatched out of order.");
    } else {
        System.out.println("PostEventOrderingTest passed!");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:PostEventOrderingTest.java

示例12: dispose

import sun.awt.SunToolkit; //导入方法依赖的package包/类
/**
 * Disposes of this instance. This method is invoked once the nested event
 * has been dispatched and handled, or when the peer of the target of the
 * nested event has been disposed with a call to Component.removeNotify.
 *
 * NOTE: Locking protocol.  Since SunToolkit.postEvent can get EventQueue lock,
 * it shall never be called while holding the lock on the list,
 * as EventQueue lock is held during dispatching and dispatch() will get
 * lock on the list. The locks should be acquired in the same order.
 */
final void dispose() {
  synchronized (SequencedEvent.class) {
        if (disposed) {
            return;
        }
        if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
                getCurrentSequencedEvent() == this) {
            KeyboardFocusManager.getCurrentKeyboardFocusManager().
                setCurrentSequencedEvent(null);
        }
        disposed = true;
    }
    // Wake myself up
    if (appContext != null) {
        SunToolkit.postEvent(appContext, new SentEvent());
    }

    SequencedEvent next = null;

    synchronized (SequencedEvent.class) {
      SequencedEvent.class.notifyAll();

      if (list.getFirst() == this) {
          list.removeFirst();

          if (!list.isEmpty()) {
                next = list.getFirst();
          }
      } else {
          list.remove(this);
      }
  }
    // Wake up waiting threads
    if (next != null && next.appContext != null) {
        SunToolkit.postEvent(next.appContext, new SentEvent());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:48,代码来源:SequencedEvent.java

示例13: lostOwnershipLater

import sun.awt.SunToolkit; //导入方法依赖的package包/类
/**
 * Clears the clipboard state (contents, owner and contents context) and
 * notifies the current owner that ownership is lost. Does nothing if the
 * argument is not {@code null} and is not equal to the current
 * contents context.
 *
 * @param disposedContext the AppContext that is disposed or
 *        {@code null} if the ownership is lost because another
 *        application acquired ownership.
 */
protected void lostOwnershipLater(final AppContext disposedContext) {
    final AppContext context = this.contentsContext;
    if (context == null) {
        return;
    }

    SunToolkit.postEvent(context, new PeerEvent(this, () -> lostOwnershipNow(disposedContext),
                                                PeerEvent.PRIORITY_EVENT));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:SunClipboard.java

示例14: lostOwnershipLater

import sun.awt.SunToolkit; //导入方法依赖的package包/类
/**
 * Clears the clipboard state (contents, owner and contents context) and
 * notifies the current owner that ownership is lost. Does nothing if the
 * argument is not <code>null</code> and is not equal to the current
 * contents context.
 *
 * @param disposedContext the AppContext that is disposed or
 *        <code>null</code> if the ownership is lost because another
 *        application acquired ownership.
 */
protected void lostOwnershipLater(final AppContext disposedContext) {
    final AppContext context = this.contentsContext;
    if (context == null) {
        return;
    }

    SunToolkit.postEvent(context, new PeerEvent(this, () -> lostOwnershipNow(disposedContext),
                                                PeerEvent.PRIORITY_EVENT));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:SunClipboard.java


注:本文中的sun.awt.SunToolkit.postEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。