Search in sources :

Example 1 with AWTEventListener

use of java.awt.event.AWTEventListener in project jdk8u_jdk by JetBrains.

the class bug6872503 method layerEventControllerMaskEquals.

static boolean layerEventControllerMaskEquals(long mask) {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    AWTEventListener layerEventController = null;
    for (AWTEventListener listener : toolkit.getAWTEventListeners(mask)) {
        if (listener instanceof AWTEventListenerProxy) {
            listener = ((AWTEventListenerProxy) listener).getListener();
        }
        if ("LayerEventController".equals(listener.getClass().getSimpleName())) {
            if (layerEventController != null) {
                throw new RuntimeException("Duplicated LayerEventController");
            }
            layerEventController = listener;
        }
    }
    boolean ret = layerEventController != null;
    if (ret) {
        System.out.println("LayerEventController with the correct mask found");
    } else {
        System.out.println("No LayerEventController with the correct mask");
    }
    return ret;
}
Also used : AWTEventListener(java.awt.event.AWTEventListener) AWTEventListenerProxy(java.awt.event.AWTEventListenerProxy)

Example 2 with AWTEventListener

use of java.awt.event.AWTEventListener in project intellij-community by JetBrains.

the class MacScrollBarUI method installUI.

@Override
public void installUI(JComponent c) {
    super.installUI(c);
    updateStyle(Style.CURRENT.get());
    processReferences(this, null, null);
    // add only one movement listener
    AWTEventListener listener = MOVEMENT_LISTENER.getAndSet(null);
    if (listener != null)
        Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.MOUSE_MOTION_EVENT_MASK);
}
Also used : AWTEventListener(java.awt.event.AWTEventListener)

Example 3 with AWTEventListener

use of java.awt.event.AWTEventListener in project intellij-community by JetBrains.

the class DarculaTest method main.

public static void main(String[] args) {
    try {
        UIManager.setLookAndFeel(new DarculaLaf());
    } catch (UnsupportedLookAndFeelException ignored) {
    }
    final JFrame frame = new JFrame("Darcula Demo");
    frame.setSize(900, 500);
    final DarculaTest form = new DarculaTest();
    final JPanel root = form.myRoot;
    frame.setContentPane(root);
    frame.getRootPane().setDefaultButton(form.myDefaultButton);
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {

        @Override
        public void eventDispatched(AWTEvent event) {
            if (event instanceof KeyEvent && event.getID() == KeyEvent.KEY_PRESSED && ((KeyEvent) event).getKeyCode() == KeyEvent.VK_F1) {
                new ShowUIDefaultsAction().actionPerformed(null);
            }
        }
    }, AWTEvent.KEY_EVENT_MASK);
    SwingUtilities.invokeLater(() -> frame.setVisible(true));
}
Also used : DarculaLaf(com.intellij.ide.ui.laf.darcula.DarculaLaf) KeyEvent(java.awt.event.KeyEvent) ShowUIDefaultsAction(com.intellij.ui.ShowUIDefaultsAction) AWTEventListener(java.awt.event.AWTEventListener)

Example 4 with AWTEventListener

use of java.awt.event.AWTEventListener in project intellij-community by JetBrains.

the class WindowSystemPlaybackCall method waitForDialog.

public static AsyncResult<String> waitForDialog(final PlaybackContext context, final String title) {
    final AsyncResult<String> result = new AsyncResult<>();
    final Ref<AWTEventListener> listener = new Ref<>();
    listener.set(new AWTEventListener() {

        @Override
        public void eventDispatched(AWTEvent event) {
            if (event.getID() == WindowEvent.WINDOW_ACTIVATED) {
                final Window wnd = ((WindowEvent) event).getWindow();
                if (wnd instanceof JDialog) {
                    if (title.equals(((JDialog) wnd).getTitle())) {
                        Toolkit.getDefaultToolkit().removeAWTEventListener(listener.get());
                        SwingUtilities.invokeLater(() -> getUiReady(context).notify(result));
                    }
                }
            }
        }
    });
    Toolkit.getDefaultToolkit().addAWTEventListener(listener.get(), WindowEvent.WINDOW_EVENT_MASK);
    SimpleTimer.getInstance().setUp(() -> {
        Toolkit.getDefaultToolkit().removeAWTEventListener(listener.get());
        if (!result.isProcessed()) {
            result.setRejected("Timed out waiting for window: " + title);
        }
    }, Registry.intValue("actionSystem.commandProcessingTimeout"));
    return result;
}
Also used : ToolWindow(com.intellij.openapi.wm.ToolWindow) Ref(com.intellij.openapi.util.Ref) AWTEventListener(java.awt.event.AWTEventListener) AsyncResult(com.intellij.openapi.util.AsyncResult)

Example 5 with AWTEventListener

use of java.awt.event.AWTEventListener in project intellij-community by JetBrains.

the class IdeGlassPaneImpl method dispatch.

public boolean dispatch(@NotNull final AWTEvent e) {
    JRootPane eventRootPane = myRootPane;
    if (e instanceof MouseEvent) {
        MouseEvent me = (MouseEvent) e;
        Window eventWindow = UIUtil.getWindow(me.getComponent());
        if (isContextMenu(eventWindow))
            return false;
        final Window thisGlassWindow = SwingUtilities.getWindowAncestor(myRootPane);
        if (eventWindow instanceof JWindow) {
            eventRootPane = ((JWindow) eventWindow).getRootPane();
            if (eventRootPane != null) {
                if (!(eventRootPane.getGlassPane() instanceof IdeGlassPane)) {
                    final Container parentWindow = eventWindow.getParent();
                    if (parentWindow instanceof Window) {
                        eventWindow = (Window) parentWindow;
                    }
                }
            }
        }
        if (eventWindow != thisGlassWindow)
            return false;
    }
    if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
        if (ApplicationManager.getApplication() != null) {
            IdeTooltipManager.getInstance().hideCurrent((MouseEvent) e);
        }
    }
    boolean dispatched;
    if (e.getID() == MouseEvent.MOUSE_PRESSED || e.getID() == MouseEvent.MOUSE_RELEASED || e.getID() == MouseEvent.MOUSE_CLICKED) {
        dispatched = preprocess((MouseEvent) e, false, eventRootPane);
    } else if (e.getID() == MouseEvent.MOUSE_MOVED || e.getID() == MouseEvent.MOUSE_DRAGGED) {
        dispatched = preprocess((MouseEvent) e, true, eventRootPane);
    } else if (e.getID() == MouseEvent.MOUSE_EXITED || e.getID() == MouseEvent.MOUSE_ENTERED) {
        dispatched = preprocess((MouseEvent) e, false, eventRootPane);
    } else {
        return false;
    }
    MouseEvent me = (MouseEvent) e;
    final Component meComponent = me.getComponent();
    if (!dispatched && meComponent != null) {
        final Window eventWindow = UIUtil.getWindow(meComponent);
        if (eventWindow != SwingUtilities.getWindowAncestor(myRootPane)) {
            return false;
        }
        int button1 = MouseEvent.BUTTON1_MASK | MouseEvent.BUTTON1_DOWN_MASK;
        final boolean pureMouse1Event = (me.getModifiersEx() | button1) == button1;
        if (pureMouse1Event && me.getClickCount() <= 1 && !me.isPopupTrigger()) {
            final Point point = SwingUtilities.convertPoint(meComponent, me.getPoint(), myRootPane.getContentPane());
            JMenuBar menuBar = myRootPane.getJMenuBar();
            point.y += menuBar != null ? menuBar.getHeight() : 0;
            final Component target = SwingUtilities.getDeepestComponentAt(myRootPane.getContentPane().getParent(), point.x, point.y);
            if (target instanceof DnDAware) {
                final Point targetPoint = SwingUtilities.convertPoint(myRootPane.getContentPane().getParent(), point.x, point.y, target);
                final boolean overSelection = ((DnDAware) target).isOverSelection(targetPoint);
                if (overSelection) {
                    final MouseListener[] listeners = target.getListeners(MouseListener.class);
                    final MouseEvent mouseEvent = MouseEventAdapter.convert(me, target);
                    switch(me.getID()) {
                        case MouseEvent.MOUSE_PRESSED:
                            boolean consumed = false;
                            if (target.isFocusable()) {
                                IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                                    IdeFocusManager.getGlobalInstance().requestFocus(target, true);
                                });
                            }
                            for (final MouseListener listener : listeners) {
                                final String className = listener.getClass().getName();
                                if (className.indexOf("BasicTreeUI$") >= 0 || className.indexOf("MacTreeUI$") >= 0)
                                    continue;
                                fireMouseEvent(listener, mouseEvent);
                                if (mouseEvent.isConsumed()) {
                                    consumed = true;
                                    break;
                                }
                            }
                            if (!mouseEvent.isConsumed()) {
                                final AWTEventListener[] eventListeners = Toolkit.getDefaultToolkit().getAWTEventListeners(MouseEvent.MOUSE_EVENT_MASK);
                                if (eventListeners != null && eventListeners.length > 0) {
                                    for (final AWTEventListener eventListener : eventListeners) {
                                        eventListener.eventDispatched(me);
                                        if (me.isConsumed())
                                            break;
                                    }
                                    if (me.isConsumed()) {
                                        consumed = true;
                                        break;
                                    }
                                }
                            }
                            if (!consumed) {
                                myPrevPressEvent = mouseEvent;
                            } else {
                                me.consume();
                            }
                            dispatched = true;
                            break;
                        case MouseEvent.MOUSE_RELEASED:
                            if (myPrevPressEvent != null && myPrevPressEvent.getComponent() == target) {
                                for (final MouseListener listener : listeners) {
                                    final String className = listener.getClass().getName();
                                    if (className.indexOf("BasicTreeUI$") >= 0 || className.indexOf("MacTreeUI$") >= 0) {
                                        fireMouseEvent(listener, myPrevPressEvent);
                                        fireMouseEvent(listener, mouseEvent);
                                        if (mouseEvent.isConsumed()) {
                                            break;
                                        }
                                    }
                                    fireMouseEvent(listener, mouseEvent);
                                    if (mouseEvent.isConsumed()) {
                                        break;
                                    }
                                }
                                if (mouseEvent.isConsumed()) {
                                    me.consume();
                                }
                                myPrevPressEvent = null;
                                dispatched = true;
                            }
                            break;
                        default:
                            myPrevPressEvent = null;
                            break;
                    }
                }
            }
        }
    }
    if (isVisible() && getComponentCount() == 0) {
        boolean cursorSet = false;
        if (meComponent != null) {
            final Point point = SwingUtilities.convertPoint(meComponent, me.getPoint(), myRootPane.getContentPane());
            if (myRootPane.getMenuBar() != null && myRootPane.getMenuBar().isVisible()) {
                point.y += myRootPane.getMenuBar().getHeight();
            }
            final Component target = SwingUtilities.getDeepestComponentAt(myRootPane.getContentPane().getParent(), point.x, point.y);
            if (target != null) {
                setCursor(target.getCursor());
                cursorSet = true;
            }
        }
        if (!cursorSet) {
            setCursor(Cursor.getDefaultCursor());
        }
    }
    return dispatched;
}
Also used : MouseEvent(java.awt.event.MouseEvent) AWTEventListener(java.awt.event.AWTEventListener) MouseListener(java.awt.event.MouseListener) DnDAware(com.intellij.ide.dnd.DnDAware) IdeGlassPane(com.intellij.openapi.wm.IdeGlassPane)

Aggregations

AWTEventListener (java.awt.event.AWTEventListener)16 AWTEvent (java.awt.AWTEvent)7 KeyEvent (java.awt.event.KeyEvent)3 BioModelNode (cbit.vcell.desktop.BioModelNode)2 Component (java.awt.Component)2 AWTEventListenerProxy (java.awt.event.AWTEventListenerProxy)2 MouseEvent (java.awt.event.MouseEvent)2 JTree (javax.swing.JTree)2 TreePath (javax.swing.tree.TreePath)2 SplashWindow (apps.SplashWindow)1 DocumentWindowManager (cbit.vcell.client.DocumentWindowManager)1 VCellClientDataServiceImpl (cbit.vcell.client.data.VCellClientDataServiceImpl)1 DatabaseWindowPanel (cbit.vcell.client.desktop.DatabaseWindowPanel)1 DocumentWindow (cbit.vcell.client.desktop.DocumentWindow)1 NetworkProxyPreferences (cbit.vcell.client.desktop.NetworkProxyPreferences)1 BioModelsNetModelInfo (cbit.vcell.client.desktop.biomodel.BioModelsNetModelInfo)1 VCellClientDataService (cbit.vcell.client.pyvcellproxy.VCellClientDataService)1 ClientServerInfo (cbit.vcell.client.server.ClientServerInfo)1 BioModelMetaDataPanel (cbit.vcell.desktop.BioModelMetaDataPanel)1 GeometryMetaDataPanel (cbit.vcell.desktop.GeometryMetaDataPanel)1