Example usage for java.awt.event MouseEvent getModifiers

List of usage examples for java.awt.event MouseEvent getModifiers

Introduction

In this page you can find the example usage for java.awt.event MouseEvent getModifiers.

Prototype

@Deprecated(since = "9")
public int getModifiers() 

Source Link

Document

Returns the modifier mask for this event.

Usage

From source file:GlassPaneDemo.java

private void redispatchMouseEvent(MouseEvent e, boolean repaint) {
    Point glassPanePoint = e.getPoint();
    Container container = contentPane;
    Point containerPoint = SwingUtilities.convertPoint(glassPane, glassPanePoint, contentPane);
    if (containerPoint.y < 0) { // we're not in the content pane
        if (containerPoint.y + menuBar.getHeight() >= 0) {
            // The mouse event is over the menu bar.
            // Could handle specially.
        } else {//from   w ww  .j ava2  s .co  m
            // The mouse event is over non-system window
            // decorations, such as the ones provided by
            // the Java look and feel.
            // Could handle specially.
        }
    } else {
        // The mouse event is probably over the content pane.
        // Find out exactly which component it's over.
        Component component = SwingUtilities.getDeepestComponentAt(container, containerPoint.x,
                containerPoint.y);

        if ((component != null) && (component.equals(liveButton))) {
            // Forward events over the check box.
            Point componentPoint = SwingUtilities.convertPoint(glassPane, glassPanePoint, component);
            component.dispatchEvent(new MouseEvent(component, e.getID(), e.getWhen(), e.getModifiers(),
                    componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger()));
        }
    }

    // Update the glass pane if requested.
    if (repaint) {
        glassPane.setPoint(glassPanePoint);
        glassPane.repaint();
    }
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java

/**
 * Opens the <tt>WritePanelRightButtonMenu</tt> when user clicks with the
 * right mouse button on the editor area.
 *
 * @param e the <tt>MouseEvent</tt> that notified us
 *//*from   w w  w .j  a v  a2 s  . c  o  m*/
public void mouseClicked(MouseEvent e) {
    if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 || (e.isControlDown() && !e.isMetaDown())) {
        Point p = e.getPoint();
        SwingUtilities.convertPointToScreen(p, e.getComponent());

        //SPELLCHECK
        ArrayList<JMenuItem> contributedMenuEntries = new ArrayList<JMenuItem>();

        for (ChatMenuListener listener : this.menuListeners) {
            contributedMenuEntries.addAll(listener.getMenuElements(this.chatPanel, e));
        }

        for (JMenuItem item : contributedMenuEntries) {
            rightButtonMenu.add(item);
        }

        JPopupMenu rightMenu = rightButtonMenu.makeMenu(contributedMenuEntries);
        rightMenu.setInvoker(editorPane);
        rightMenu.setLocation(p.x, p.y);
        rightMenu.setVisible(true);
    }
}

From source file:com.jcraft.weirdx.DDXWindowImpSwing.java

private void procPressed(MouseEvent e) {
    int x = e.getX() + window.x;
    int y = e.getY() + window.y;
    XWindow.sprite.hot.x = x;//from  w  w w .j  a  v  a2 s.c  o m
    XWindow.sprite.hot.y = y;
    int mod = e.getModifiers();
    if (mod == 0) {
        mod |= InputEvent.BUTTON1_MASK;
    } // ?????

    int state = 0;
    int detail = 1;
    if ((mod & InputEvent.BUTTON1_MASK) != 0)
        detail = 1;
    if ((mod & InputEvent.BUTTON2_MASK) != 0)
        detail = 2;
    if ((mod & InputEvent.BUTTON3_MASK) != 0)
        detail = 3;
    if ((mod & InputEvent.SHIFT_MASK) != 0)
        state |= 1;
    if ((mod & InputEvent.CTRL_MASK) != 0)
        state |= 4;
    // alt -> state|=8;

    Event.filters[Event.MotionNotify] = Event.PointerMotionMask | Event.ButtonMotionMask
            | ((Event.Button1Mask >> 1) << detail);

    event.mkButtonPress(detail, window.screen.rootId, window.id, 0, x, y, e.getX(), e.getY(), state, 1);

    try {
        if (XWindow.grab == null) {
            if (XWindow.checkDeviceGrabs(event, 0, 1)) {
                return;
            }
        }
        if (XWindow.grab != null)
            XWindow.sendGrabbedEvent(event, false, 1);
        else
            XWindow.sendDeviceEvent(window, event, XWindow.grab, null, 1);
    } catch (Exception ee) {
    }

    if ((mod & InputEvent.BUTTON1_MASK) != 0) {
        state |= (1 << 8);
    }
    if ((mod & InputEvent.BUTTON2_MASK) != 0) {
        state |= (1 << 9);
    }
    if ((mod & InputEvent.BUTTON3_MASK) != 0) {
        state |= (1 << 10);
    }
    //    if((mod & InputEvent.SHIFT_MASK)!=0) state|=1;
    //    if((mod & InputEvent.CTRL_MASK)!=0) state|=4;
    // alt -> state|=8;

    XWindow.sprite.hot.state = state;
}

From source file:SwingGlassExample.java

private void redispatchMouseEvent(MouseEvent e) {
    boolean inButton = false;
    boolean inMenuBar = false;
    Point glassPanePoint = e.getPoint();
    Component component = null;/*from   www. ja  v  a2s  .  c o m*/
    Container container = contentPane;
    Point containerPoint = SwingUtilities.convertPoint(this, glassPanePoint, contentPane);
    int eventID = e.getID();

    if (containerPoint.y < 0) {
        inMenuBar = true;
        container = menuBar;
        containerPoint = SwingUtilities.convertPoint(this, glassPanePoint, menuBar);
        testForDrag(eventID);
    }

    //XXX: If the event is from a component in a popped-up menu,
    //XXX: then the container should probably be the menu's
    //XXX: JPopupMenu, and containerPoint should be adjusted
    //XXX: accordingly.
    component = SwingUtilities.getDeepestComponentAt(container, containerPoint.x, containerPoint.y);

    if (component == null) {
        return;
    } else {
        inButton = true;
        testForDrag(eventID);
    }

    if (inMenuBar || inButton || inDrag) {
        Point componentPoint = SwingUtilities.convertPoint(this, glassPanePoint, component);
        component.dispatchEvent(new MouseEvent(component, eventID, e.getWhen(), e.getModifiers(),
                componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger()));
    }
}

From source file:com.jcraft.weirdx.DDXWindowImp.java

public void mouseMoved(MouseEvent e) {
    int x = e.getX() + window.x;
    int y = e.getY() + window.y;

    XWindow.sprite.hot.x = x;//from  w  w  w  . jav a  2s  .  c o  m
    XWindow.sprite.hot.y = y;

    int mod = e.getModifiers();
    int state = 0;

    px = x;
    py = y;

    if ((mod & InputEvent.BUTTON1_MASK) != 0)
        state |= (1 << 8);
    if ((mod & InputEvent.BUTTON2_MASK) != 0)
        state |= (1 << 9);
    if ((mod & InputEvent.BUTTON3_MASK) != 0)
        state |= (1 << 10);
    if ((mod & InputEvent.SHIFT_MASK) != 0)
        state |= 1;
    if ((mod & InputEvent.CTRL_MASK) != 0)
        state |= 4;
    // alt -> state|=8;
    XWindow.sprite.hot.state = state;

    event.mkMotionNotify(0, window.screen.rootId, window.id, 0, x, y, x - window.x, y - window.y, state, 1);

    try {
        if (!XWindow.checkMotion(event, window)) {
            return;
        }
        if (XWindow.grab != null)
            XWindow.sendGrabbedEvent(event, false, 1);
        else
            XWindow.sendDeviceEvent(window, event, XWindow.grab, null, 1);
    } catch (Exception ee) {
    }
}

From source file:com.jcraft.weirdx.DDXWindowImp.java

private void procReleased(MouseEvent e) {
    int x = e.getX() + window.x;
    int y = e.getY() + window.y;

    XWindow.sprite.hot.x = x;/* w  w  w.  ja v  a  2 s.  c om*/
    XWindow.sprite.hot.y = y;

    int mod = e.getModifiers();
    int state = 0;
    int detail = 0;

    if ((mod & InputEvent.BUTTON1_MASK) != 0) {
        state |= (1 << 8);
        detail = 1;
    }
    if ((mod & InputEvent.BUTTON2_MASK) != 0) {
        state |= (1 << 9);
        detail = 2;
    }
    if ((mod & InputEvent.BUTTON3_MASK) != 0) {
        state |= (1 << 10);
        detail = 3;
    }
    if ((mod & InputEvent.SHIFT_MASK) != 0)
        state |= 1;
    if ((mod & InputEvent.CTRL_MASK) != 0)
        state |= 4;
    // alt -> state|=8;
    XWindow.sprite.hot.state = 0; // ?????
    Event.filters[Event.MotionNotify] = Event.PointerMotionMask/*|
                                                               ((Event.Button1Mask>>1)<<detail)*/;
    event.mkButtonRelease(detail, window.screen.rootId, window.id, 0, x, y, e.getX(), e.getY(), state, 1);

    try {
        if (XWindow.grab != null)
            XWindow.sendGrabbedEvent(event, true, 1);
        else
            XWindow.sendDeviceEvent(window, event, XWindow.grab, null, 1);
    } catch (Exception ee) {
    }
    XWindow.grab = null;
}

From source file:com.jcraft.weirdx.DDXWindowImp.java

private void procPressed(MouseEvent e) {
    int x = e.getX() + window.x;
    int y = e.getY() + window.y;
    oldWindowx = window.x;//w ww. ja  va  2  s.c  o m
    oldWindowy = window.y;
    XWindow.sprite.hot.x = x;
    XWindow.sprite.hot.y = y;
    int mod = e.getModifiers();
    if (mod == 0) {
        mod |= InputEvent.BUTTON1_MASK;
    } // ?????

    int state = 0;
    int detail = 1;
    if ((mod & InputEvent.BUTTON1_MASK) != 0)
        detail = 1;
    if ((mod & InputEvent.BUTTON2_MASK) != 0)
        detail = 2;
    if ((mod & InputEvent.BUTTON3_MASK) != 0)
        detail = 3;
    if ((mod & InputEvent.SHIFT_MASK) != 0)
        state |= 1;
    if ((mod & InputEvent.CTRL_MASK) != 0)
        state |= 4;
    // alt -> state|=8;

    Event.filters[Event.MotionNotify] = Event.PointerMotionMask | Event.ButtonMotionMask
            | ((Event.Button1Mask >> 1) << detail);

    event.mkButtonPress(detail, window.screen.rootId, window.id, 0, x, y, e.getX(), e.getY(), state, 1);

    try {
        if (XWindow.grab == null) {
            if (XWindow.checkDeviceGrabs(event, 0, 1)) {
                return;
            }
        }
        if (XWindow.grab != null)
            XWindow.sendGrabbedEvent(event, false, 1);
        else
            XWindow.sendDeviceEvent(window, event, XWindow.grab, null, 1);
    } catch (Exception ee) {
    }

    if ((mod & InputEvent.BUTTON1_MASK) != 0) {
        state |= (1 << 8);
    }
    if ((mod & InputEvent.BUTTON2_MASK) != 0) {
        state |= (1 << 9);
    }
    if ((mod & InputEvent.BUTTON3_MASK) != 0) {
        state |= (1 << 10);
    }
    //    if((mod & InputEvent.SHIFT_MASK)!=0) state|=1;
    //    if((mod & InputEvent.CTRL_MASK)!=0) state|=4;
    // alt -> state|=8;

    XWindow.sprite.hot.state = state;
}

From source file:com.jcraft.weirdx.DDXWindowImp.java

public void mouseExited(MouseEvent e) {
    if (window == null)
        return;//from w  w  w . j av a2s.  co m

    if (window.id == window.screen.rootId) {
        return;
    }

    int x = e.getX() + window.x;
    int y = e.getY() + window.y;

    XWindow.sprite.hot.x = x;
    XWindow.sprite.hot.y = y;

    int mod = e.getModifiers();
    int state = 0;
    if ((mod & InputEvent.BUTTON1_MASK) != 0)
        state |= (1 << 8);
    if ((mod & InputEvent.BUTTON2_MASK) != 0)
        state |= (1 << 9);
    if ((mod & InputEvent.BUTTON3_MASK) != 0)
        state |= (1 << 10);
    if ((mod & InputEvent.SHIFT_MASK) != 0)
        state |= 1;
    if ((mod & InputEvent.CTRL_MASK) != 0)
        state |= 4;
    // alt -> state|=8;
    Client client = window.client;
    if (client == null || client == serverClient)
        return;

    event.mkLeaveNotify(0, // Ancestor
            window.screen.rootId, window.id, 0, x, y, e.getX(), e.getY(), state, 0, // Normal
            0x1 | 0x02 // focus|same-screen
    );
    try {
        XWindow.sendDeviceEvent(window, event, XWindow.grab, null, 1);
    } catch (Exception ee) {
    }
}

From source file:base.BasePlayer.ClusterTable.java

public void mousePressed(MouseEvent event) {

    switch (event.getModifiers()) {

    case InputEvent.BUTTON1_MASK: {
        if (!this.isEnabled()) {
            break;
        }/*from  w  ww .  j a  v a  2  s  .co  m*/
        this.dragX = event.getX();
        if (headerHover > -1) {
            if (resizeColumn == -1) {
                if (sorter.ascending) {
                    sorter.ascending = false;
                } else {
                    sorter.ascending = true;
                }

                sorter.index = headerHover;
                Collections.sort(Main.drawCanvas.clusterNodes, sorter);
                createPolygon();

                repaint();
            }
        }

    }

        if (hoverNode != null || hoverVar != null) {
            Main.chromDraw.repaint();
        }
    }

}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

@Override
public void mousePressed(MouseEvent e) {
    int mods = e.getModifiers();
    //        if (isMaskingEnabled() && (mods & maskingKeyMask) != 0) {
    if (isInternalLegendEnabled && isInternalLegendSelected) {
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        if (cursorType == Cursor.DEFAULT_CURSOR) {
            Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
            if (screenDataArea != null) {
                legendPoint = e.getPoint();
            } else {
                legendPoint = null;/* w  w w  . j  a v  a2  s .com*/
            }
        } else {
            if (cursorType == Cursor.MOVE_CURSOR) {
                legendPoint = e.getPoint();
            }
        }
    }
    if (isMaskingEnabled()) {
        // Prepare masking service.
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        if (cursorType == Cursor.DEFAULT_CURSOR && (mods & maskingKeyMask) != 0) {
            Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
            if (screenDataArea != null) {
                this.maskPoint = getPointInRectangle(e.getX(), e.getY(), screenDataArea).getX();
            } else {
                this.maskPoint = Double.NaN;
            }
        } else {
            if (cursorType == Cursor.MOVE_CURSOR) {
                //                 this.maskMovePoint = translateScreenToChart(
                //                       translateScreenToJava2D(e.getPoint())).getX();
                Insets insets = getInsets();
                this.maskMovePoint = ChartMaskingUtilities.translateScreenX(
                        (e.getX() - insets.left) / getScaleX(), getScreenDataArea(), getChart());
            }
            setMaskDragIndicator(cursorType);
        }
    }
    if (getMaskDragIndicator() == Cursor.DEFAULT_CURSOR) {
        super.mousePressed(e);
    }
}