Example usage for java.awt.event MouseEvent getModifiersEx

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

Introduction

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

Prototype

public int getModifiersEx() 

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {
    String[] items = { "Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat" };
    JList<String> myJList = new JList(items) {
        @Override// w w w .  ja va  2 s . c o m
        protected void processMouseEvent(MouseEvent e) {
            int modifiers = e.getModifiers() | InputEvent.CTRL_MASK;
            int modifiersEx = e.getModifiersEx() | InputEvent.CTRL_MASK;
            MouseEvent myME = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), modifiers,
                    e.getX(), e.getY(), e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(),
                    e.isPopupTrigger(), e.getButton());
            super.processMouseEvent(myME);
        }
    };
    JFrame f = new JFrame();
    f.add(new JScrollPane(myJList));
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

static boolean isLeftButtonOnly(final MouseEvent event) {
    final int modifiers = event.getModifiersEx();
    if ((modifiers & InputEvent.BUTTON1_DOWN_MASK) == InputEvent.BUTTON1_DOWN_MASK) {
        for (int button = 11; button <= 30; button++) {
            final int mask = 1 << button;
            if ((modifiers & mask) == mask) {
                return false;
            }/*from  www  .  j a  v  a  2s .  c o m*/
        }
        return true;
    }
    return false;
}

From source file:Main.java

public static MouseEvent newMouseEvent(Component comp, int id, MouseEvent e) {
    return new MouseEvent(comp, id, e.getWhen(), e.getModifiers() | e.getModifiersEx(), e.getX(), e.getY(),
            e.getClickCount(), e.isPopupTrigger());
}

From source file:Main.java

public static MouseEvent convertMouseEvent(MouseEvent e, Component newSource, Point newPoint) {
    return new MouseEvent(newSource, e.getID(), e.getWhen(), e.getModifiersEx(), newPoint.x, newPoint.y,
            e.getClickCount(), e.isPopupTrigger(), e.getButton());
}

From source file:Main.java

public static MouseEvent convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination) {
    Point p = SwingUtilities.convertPoint(source, new Point(sourceEvent.getX(), sourceEvent.getY()),
            destination);//from   ww  w  . j  av a  2 s. c  o  m
    Component newSource;

    if (destination != null)
        newSource = destination;
    else
        newSource = source;

    MouseEvent newEvent;
    if (sourceEvent instanceof MouseWheelEvent) {
        MouseWheelEvent sourceWheelEvent = (MouseWheelEvent) sourceEvent;
        newEvent = new MouseWheelEvent(newSource, sourceWheelEvent.getID(), sourceWheelEvent.getWhen(),
                sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y,
                sourceWheelEvent.getClickCount(), sourceWheelEvent.isPopupTrigger(),
                sourceWheelEvent.getScrollType(), sourceWheelEvent.getScrollAmount(),
                sourceWheelEvent.getWheelRotation());
    } else if (sourceEvent instanceof MenuDragMouseEvent) {
        MenuDragMouseEvent sourceMenuDragEvent = (MenuDragMouseEvent) sourceEvent;
        newEvent = new MenuDragMouseEvent(newSource, sourceMenuDragEvent.getID(), sourceMenuDragEvent.getWhen(),
                sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y,
                sourceMenuDragEvent.getClickCount(), sourceMenuDragEvent.isPopupTrigger(),
                sourceMenuDragEvent.getPath(), sourceMenuDragEvent.getMenuSelectionManager());
    } else {
        newEvent = new MouseEvent(newSource, sourceEvent.getID(), sourceEvent.getWhen(),
                sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y,
                sourceEvent.getClickCount(), sourceEvent.isPopupTrigger(), sourceEvent.getButton());
    }
    return newEvent;
}

From source file:Main.java

public Main() {
    setLayout(null);/*from  ww  w.  j  ava2  s .  c om*/
    add(button);
    button.setSize(button.getPreferredSize());
    button.setLocation(20, 20);
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            int onmask = MouseEvent.SHIFT_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
            int offmask = MouseEvent.CTRL_DOWN_MASK;
            if ((event.getModifiersEx() & (onmask | offmask)) == onmask) {
                System.out.println(event.getLocationOnScreen());
            }
        }
    });
}

From source file:com.cburch.draw.tools.LineTool.java

@Override
public void mouseDragged(Canvas canvas, MouseEvent e) {
    updateMouse(canvas, e.getX(), e.getY(), e.getModifiersEx());
}

From source file:com.cburch.draw.tools.LineTool.java

@Override
public void mousePressed(Canvas canvas, MouseEvent e) {
    int x = e.getX();
    int y = e.getY();
    int mods = e.getModifiersEx();
    if ((mods & InputEvent.CTRL_DOWN_MASK) != 0) {
        x = canvas.snapX(x);/*from w  ww.  j  ava  2s  .co m*/
        y = canvas.snapY(y);
    }
    Location loc = Location.create(x, y);
    mouseStart = loc;
    mouseEnd = loc;
    lastMouseX = loc.getX();
    lastMouseY = loc.getY();
    active = canvas.getModel() != null;
    repaintArea(canvas);
}

From source file:com.cburch.draw.tools.LineTool.java

@Override
public void mouseReleased(Canvas canvas, MouseEvent e) {
    if (active) {
        updateMouse(canvas, e.getX(), e.getY(), e.getModifiersEx());
        Location start = mouseStart;
        Location end = mouseEnd;// w w w .jav a  2  s  .  c  om
        CanvasObject add = null;
        if (!start.equals(end)) {
            active = false;
            CanvasModel model = canvas.getModel();
            Location[] ends = { start, end };
            List<Location> locs = UnmodifiableList.decorate(Arrays.asList(ends));
            add = attrs.applyTo(new Poly(false, locs));
            add.setValue(DrawAttr.PAINT_TYPE, DrawAttr.PAINT_STROKE);
            canvas.doAction(new ModelAddAction(model, add));
            repaintArea(canvas);
        }
        canvas.toolGestureComplete(this, add);
    }
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.tooloptions.LayerValueIconList.java

protected void processMouseClick(final HexButton source, final MouseEvent evt) {
    if ((evt.getModifiersEx() & (MouseEvent.CTRL_DOWN_MASK | MouseEvent.SHIFT_DOWN_MASK)) != 0) {
        if ((evt.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) != 0) {
            this.selectionModel.addSelectionInterval(source.value.getIndex(), source.value.getIndex());
        } else {//from   w  w  w  .ja  v a 2  s .co  m
            final int selIndex = source.value.getIndex();
            final int minindex = Math.min(selIndex, this.selectionModel.getMinSelectionIndex());
            final int maxindex = Math.max(selIndex, this.selectionModel.getMaxSelectionIndex());
            this.selectionModel.setSelectionInterval(Math.max(0, minindex), Math.max(0, maxindex));
        }
    } else {
        this.selectionModel.setSelectionInterval(source.value.getIndex(), source.value.getIndex());
    }

    switch (evt.getButton()) {
    case MouseEvent.BUTTON1: {
        for (final LayerIconListListener l : this.listeners) {
            l.onLeftClick(source.getHexValue(), source.getHexIcon());
        }
    }
        break;
    case MouseEvent.BUTTON3: {
        for (final LayerIconListListener l : this.listeners) {
            l.onRightClick(source.getHexValue(), source.getHexIcon());
        }
    }
        break;
    }
}