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:DragPictureDemo2.java

public void mouseDragged(MouseEvent e) {
    //Don't bother to drag if the component displays no image.
    if (image == null)
        return;/*from  w ww . j av  a  2  s . c  o m*/

    if (firstMouseEvent != null) {
        e.consume();

        //If they are holding down the control key, COPY rather than MOVE
        int ctrlMask = InputEvent.CTRL_DOWN_MASK;
        int action = ((e.getModifiersEx() & ctrlMask) == ctrlMask) ? TransferHandler.COPY
                : TransferHandler.MOVE;

        int dx = Math.abs(e.getX() - firstMouseEvent.getX());
        int dy = Math.abs(e.getY() - firstMouseEvent.getY());
        //Arbitrarily define a 5-pixel shift as the
        //official beginning of a drag.
        if (dx > 5 || dy > 5) {
            //This is a drag, not a click.
            JComponent c = (JComponent) e.getSource();
            TransferHandler handler = c.getTransferHandler();
            //Tell the transfer handler to initiate the drag.
            handler.exportAsDrag(c, firstMouseEvent, action);
            firstMouseEvent = null;
        }
    }
}

From source file:com.joey.software.regionSelectionToolkit.controlers.ImageProfileTool.java

@Override
public void mouseDragged(MouseEvent e) {

    int button = 0;

    if (e.getModifiersEx() == InputEvent.BUTTON1_DOWN_MASK) {
        button = 1;//from ww w  .j  a  v a  2s .c  o m
    } else if (e.getModifiersEx() == InputEvent.BUTTON2_DOWN_MASK) {
        button = 2;
    } else if (e.getModifiersEx() == InputEvent.BUTTON3_DOWN_MASK) {
        button = 3;
    }

    processMouse(e.getPoint(), button);

}

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

@Override
public void mousePressed(final MouseEvent e) {
    final boolean ctrlPressed = (e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) != 0;
    if (this.application == null) {
        if (!ctrlPressed && e.isPopupTrigger()) {
            final HexPosition hexNumber = this.hexMapPanel.getHexPosition(e.getPoint());
            onPopup(e.getPoint(), hexNumber);
        } else {/* w  ww  . j  a va2s  .c o m*/
            switch (e.getButton()) {
            case MouseEvent.BUTTON1: {
                if (selectedToolType != null && this.selectedLayer != null) {
                    addedUndoStep(new HexFieldLayer[] { this.selectedLayer });
                    final HexPosition hexNumber = this.hexMapPanel.getHexPosition(e.getPoint());
                    useCurrentToolAtPosition(hexNumber);
                }
            }
                break;
            case MouseEvent.BUTTON3: {
                if (ctrlPressed) {
                    this.dragging = true;
                    this.hexMapPanelDesktop.initDrag(e.getPoint());
                }
            }
                break;
            }
        }
    } else if (!ctrlPressed && e.isPopupTrigger() && this.application.allowPopupTrigger()) {
        this.application.processHexAction(this.hexMapPanel, e, HexAction.POPUP_TRIGGER,
                this.hexMapPanel.getHexPosition(e.getPoint()));
    } else if (e.getButton() == MouseEvent.BUTTON3) {
        this.dragging = true;
        this.hexMapPanelDesktop.initDrag(e.getPoint());
    }
}

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

@Override
public void mouseReleased(final MouseEvent e) {
    if (this.application == null) {
        if ((e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) == 0 && e.isPopupTrigger()) {
            final HexPosition hexNumber = this.hexMapPanel.getHexPosition(e.getPoint());
            onPopup(e.getPoint(), hexNumber);
        } else {// w w  w  . j  a  v a 2  s.c  o m
            switch (e.getButton()) {
            case MouseEvent.BUTTON3: {
                this.dragging = false;
                this.hexMapPanelDesktop.endDrag();
            }
                break;
            }
        }
    } else if (e.getButton() == MouseEvent.BUTTON3) {
        this.dragging = false;
        this.hexMapPanelDesktop.endDrag();
    }
}

From source file:com.projity.contrib.calendar.JXXMonthView.java

protected void selectFromEvent(MouseEvent e) {
    boolean shift = (e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK;
    boolean control = (e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK;
    int x = e.getX();
    int y = e.getY();

    long selected = getDayAt(x, y);
    if (selected == -1) {
        return;//from  ww w.  j a v a2  s  .c o m
    }
    if (!control && !shift)
        clearSelection();

    DateSpan selection;
    if (selected <= WEEKDAY_OFFSET) { //hk
        int weekDayNum = (int) (-selected + WEEKDAY_OFFSET);
        selectWeekDay(weekDayNum);
        _asKirkWouldSay_FIRE = true;
        return;
    } else {
        if (_pivotDate == -1 || (!shift))
            selection = new DateSpan(selected, selected);
        else
            selection = new DateSpan(Math.min(_pivotDate, selected), Math.max(_pivotDate, selected));
    }

    select(selection);

    _pivotDate = selected;

    // Arm so we fire action performed on mouse release.
    _asKirkWouldSay_FIRE = true;

}

From source file:de.codesourcery.jasm16.ide.ui.views.SourceCodeView.java

private final JPanel createPanel() {
    disableDocumentListener(); // necessary because setting colors on editor pane triggers document change listeners (is considered a style change...)

    try {//from   w  ww . ja  v  a2 s.  com
        editorPane.setEditable(editable);
        editorPane.getDocument().addUndoableEditListener(undoListener);
        editorPane.setCaretColor(Color.WHITE);
        setupKeyBindings(editorPane);
        setColors(editorPane);
        editorScrollPane = new JScrollPane(editorPane);
        setColors(editorScrollPane);
        editorPane.addCaretListener(listener);
        editorPane.addMouseListener(mouseListener);
        editorPane.addMouseMotionListener(new MouseMotionAdapter() {

            @Override
            public void mouseMoved(MouseEvent e) {
                if ((e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) != 0) // ctrl pressed
                {
                    final ASTNode node = getASTNodeForLocation(e.getPoint());
                    if (node instanceof SymbolReferenceNode) {
                        maybeUnderlineIdentifierAt(e.getPoint());
                    } else {
                        clearUnderlineHighlight();
                    }
                } else if (compilationUnit != null) {
                    String tooltipText = null;
                    if (compilationUnit != null) {
                        final ASTNode node = getASTNodeForLocation(e.getPoint());
                        if (node instanceof InvokeMacroNode) {
                            tooltipText = ExpandMacrosPhase.expandInvocation((InvokeMacroNode) node,
                                    compilationUnit);
                            if (tooltipText != null) {
                                tooltipText = "<html>" + tooltipText.replace("\n", "<br>") + "</html>";
                            }
                        }
                    }
                    if (!StringUtils.equals(editorPane.getToolTipText(), tooltipText)) {
                        editorPane.setToolTipText(tooltipText);
                    }
                }
            }
        });
        editorPane.addMouseListener(popupListener);
    } finally {
        enableDocumentListener();
    }

    EditorContainer.addEditorCloseKeyListener(editorPane, this);

    editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    editorScrollPane.setPreferredSize(new Dimension(400, 600));
    editorScrollPane.setMinimumSize(new Dimension(100, 100));

    final AdjustmentListener adjustmentListener = new AdjustmentListener() {

        @Override
        public void adjustmentValueChanged(AdjustmentEvent e) {
            if (!e.getValueIsAdjusting()) {
                if (compilationUnit != null) {
                    doHighlighting(compilationUnit, false);
                }
            }
        }
    };
    editorScrollPane.getVerticalScrollBar().addAdjustmentListener(adjustmentListener);
    editorScrollPane.getHorizontalScrollBar().addAdjustmentListener(adjustmentListener);

    // button panel
    final JPanel topPanel = new JPanel();

    final JToolBar toolbar = new JToolBar();

    setColors(toolbar);

    cursorPosition.setSize(new Dimension(400, 15));
    cursorPosition.setEditable(false);
    setColors(cursorPosition);

    /**
     * TOOLBAR
     * SOURCE
     * cursor position
     * status area 
     */
    topPanel.setLayout(new GridBagLayout());

    GridBagConstraints cnstrs = constraints(0, 0, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.weighty = 0;
    topPanel.add(toolbar, cnstrs);

    cnstrs = constraints(0, 1, GridBagConstraints.BOTH);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    topPanel.add(editorScrollPane, cnstrs);

    cnstrs = constraints(0, 2, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.weighty = 0;
    topPanel.add(cursorPosition, cnstrs);

    cnstrs = constraints(0, 3, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.weighty = 0;

    // setup result panel
    final JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    setColors(panel);
    cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH);
    panel.add(topPanel, cnstrs);
    return panel;
}

From source file:simMPLS.ui.simulator.JVentanaHija.java

/** Este mtodo se llama automticamente cuando se est arrastrando el ratn en la
 * pantalla de diseo. Se encarga de mover los elementos de un lugar a otro para
 * disear la topologa.//ww w  .j  a  v  a  2s. c o m
 * @since 1.0
 * @param evt El evento que hace que se dispare este mtodo.
 */
private void arrastrandoEnPanelDisenio(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_arrastrandoEnPanelDisenio
    if (evt.getModifiersEx() == java.awt.event.InputEvent.BUTTON1_DOWN_MASK) {
        if (nodoSeleccionado != null) {
            TTopology topo = escenario.getTopology();
            Point p2 = evt.getPoint();
            if (p2.x < 0)
                p2.x = 0;
            if (p2.x > panelDisenio.getSize().width)
                p2.x = panelDisenio.getSize().width;
            if (p2.y < 0)
                p2.y = 0;
            if (p2.y > panelDisenio.getSize().height)
                p2.y = panelDisenio.getSize().height;
            nodoSeleccionado.setPosition(new Point(p2.x, p2.y));
            panelDisenio.repaint();
            this.escenario.setModified(true);
        }
    }
}

From source file:simMPLS.ui.simulator.JVentanaHija.java

/**
 * Este mtodo se llama cuando se arrastra el ratn sobre el panel de diseo. Si se
 * hace sobre un elemento que estaba seleccionado, el resultado es que ese elemento
 * se mueve donde vaya el cursor del ratn.
 * Move an object of the simulation/*w  w  w.jav a2  s  .  c o m*/
 * @param evt El evento que provoca la llamada.
 * @since 1.0
 */
private void ratonArrastradoEnPanelSimulacion(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ratonArrastradoEnPanelSimulacion
    if (evt.getModifiersEx() == java.awt.event.InputEvent.BUTTON1_DOWN_MASK) {
        if (nodoSeleccionado != null) {
            TTopology topo = escenario.getTopology();
            Point p2 = evt.getPoint();
            if (p2.x < 0)
                p2.x = 0;
            if (p2.x > panelDisenio.getSize().width)
                p2.x = panelDisenio.getSize().width;
            if (p2.y < 0)
                p2.y = 0;
            if (p2.y > panelDisenio.getSize().height)
                p2.y = panelDisenio.getSize().height;
            nodoSeleccionado.setPosition(new Point(p2.x, p2.y));
            panelSimulacion.repaint();
            this.escenario.setModified(true);
        }
    }
}

From source file:org.jcurl.demo.editor.LocationController.java

public void mouseDragged(final MouseEvent e) {
    if (hotRockIdx < 0) {
        log.debug("no hot rock");
        return;/*from  w  w  w  .  j  a  v  a 2s . c o m*/
    }
    if (e.getModifiersEx() == InputEvent.BUTTON1_DOWN_MASK) {
        // move a rock
        final Point2D wc = getWc(e, tmpWc);
        int idx = PositionSet.findRockIndexTouchingRockAtPos(locations, wc, hotRockIdx);
        if (idx >= 0)
            log.debug("new position blocked");
        else {
            locations.getRock(hotRockIdx).setLocation(wc);
            locations.notifyChange();
            log.debug("relocated");
        }
    }
}

From source file:org.jcurl.demo.editor.SpeedController.java

public void mouseDragged(MouseEvent e) {
    if (e.getModifiersEx() == InputEvent.BUTTON1_DOWN_MASK) {
        if (RockEditDisplay.HotObject.ROCK.equals(hot.what)) {
            // move a rock
            final Point2D wc = getWc(e, tmp);
            int idx = PositionSet.findRockIndexTouchingRockAtPos(rocks, wc, hot.idx);
            if (idx >= 0)
                log.debug("new position blocked");
            else {
                rocks.getRock(hot.idx).setLocation(wc);
                rocks.notifyChange();/*from   w  w w .ja  v a  2s  .  c  o m*/
                log.debug("relocated");
            }
        }
        if (RockEditDisplay.HotObject.SPEED.equals(hot.what)) {
            // change the speed of a rock
            final Point2D wc = getWc(e, tmp);
            panel.setSpeedSpot(hot.idx, wc);
        }
    }
}