Example usage for java.awt.event KeyEvent isShiftDown

List of usage examples for java.awt.event KeyEvent isShiftDown

Introduction

In this page you can find the example usage for java.awt.event KeyEvent isShiftDown.

Prototype

public boolean isShiftDown() 

Source Link

Document

Returns whether or not the Shift modifier is down on this event.

Usage

From source file:Main.java

public void keyPressed(KeyEvent evt) {
    int keyCode = evt.getKeyCode();
    int d;/* w  w w.  ja va 2s. c  om*/
    if (evt.isShiftDown()) {
        System.out.println("shift down");
    }
    if (keyCode == KeyEvent.VK_LEFT)
        System.out.println("KeyEvent.VK_LEFT");
    else if (keyCode == KeyEvent.VK_RIGHT)
        System.out.println("KeyEvent.VK_RIGHT");
    else if (keyCode == KeyEvent.VK_UP)
        System.out.println("KeyEvent.VK_UP");
    else if (keyCode == KeyEvent.VK_DOWN)
        System.out.println("KeyEvent.VK_DOWN");
}

From source file:Main.java

public void keyPressed(KeyEvent evt) {
    int keyCode = evt.getKeyCode();
    int d;// www.j  ava2  s.c  o  m
    if (evt.isShiftDown())
        d = 5;
    else
        d = 1;
    if (keyCode == KeyEvent.VK_LEFT)
        add(-d, 0);
    else if (keyCode == KeyEvent.VK_RIGHT)
        add(d, 0);
    else if (keyCode == KeyEvent.VK_UP)
        add(0, -d);
    else if (keyCode == KeyEvent.VK_DOWN)
        add(0, d);
}

From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.panel.Chromatogram1DViewPanel.java

@Override
public void keyPressed(KeyEvent e) {
    if (e.isShiftDown()) {
        selectionHandler.setMode(InstanceContentSelectionHandler.Mode.ON_HOVER);
    }/*from ww  w . j  ava2  s.c o m*/
}

From source file:edu.ku.brc.af.ui.forms.validation.ValTextArea.java

public void init() {
    bgColor = getBackground();//  ww  w. ja  v  a  2 s. c  om
    if (valTextColor == null || requiredFieldColor == null) {
        valTextColor = AppPrefsCache.getColorWrapper("ui", "formatting", "valtextcolor");
        requiredFieldColor = AppPrefsCache.getColorWrapper("ui", "formatting", "requiredfieldcolor");
    }
    AppPrefsCache.addChangeListener("ui.formatting.requiredfieldcolor", this);

    initDocument();

    addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            isNew = false;
            repaint();
        }
    });

    // Enable being able to TAB out of TextArea
    getInputMap().put(KeyStroke.getKeyStroke("TAB"), "none");
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent event) {
            if (event.getKeyCode() == KeyEvent.VK_TAB) {
                if (event.isShiftDown()) {
                    transferFocusBackward();
                } else {
                    transferFocus();
                }
            }
        }
    });

}

From source file:Main.java

private void displayInfo(KeyEvent e, String keyStatus) {

    // You should only rely on the key char if the event
    // is a key typed event.
    int id = e.getID();
    String keyString;/*  ww w.  j  a v a2s .  c  om*/
    if (id == KeyEvent.KEY_TYPED) {
        char c = e.getKeyChar();
        keyString = "key character = '" + c + "'";
    } else {
        int keyCode = e.getKeyCode();
        keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")";
    }

    int modifiersEx = e.getModifiersEx();
    String modString = "extended modifiers = " + modifiersEx;
    String tmpString = KeyEvent.getModifiersExText(modifiersEx);
    System.out.println(e.isShiftDown());

    if (tmpString.length() > 0) {
        modString += " (" + tmpString + ")";
    } else {
        modString += " (no extended modifiers)";
    }

    String actionString = "action key? ";
    if (e.isActionKey()) {
        actionString += "YES";
    } else {
        actionString += "NO";
    }

    String locationString = "key location: ";
    int location = e.getKeyLocation();
    if (location == KeyEvent.KEY_LOCATION_STANDARD) {
        locationString += "standard";
    } else if (location == KeyEvent.KEY_LOCATION_LEFT) {
        locationString += "left";
    } else if (location == KeyEvent.KEY_LOCATION_RIGHT) {
        locationString += "right";
    } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) {
        locationString += "numpad";
    } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN)
        locationString += "unknown";
    }

    displayArea.append(keyStatus + newline + "    " + keyString + newline + "    " + modString + newline
            + "    " + actionString + newline + "    " + locationString + newline);
    displayArea.setCaretPosition(displayArea.getDocument().getLength());
}

From source file:Console.java

public void keyPressed(KeyEvent e) {
    int code = e.getKeyCode();
    if (code == KeyEvent.VK_BACK_SPACE || code == KeyEvent.VK_LEFT) {
        if (outputMark == getCaretPosition()) {
            e.consume();/*w  w  w  .  j a v  a2  s .com*/
        }
    } else if (code == KeyEvent.VK_HOME) {
        int caretPos = getCaretPosition();
        if (caretPos == outputMark) {
            e.consume();
        } else if (caretPos > outputMark) {
            if (!e.isControlDown()) {
                if (e.isShiftDown()) {
                    moveCaretPosition(outputMark);
                } else {
                    setCaretPosition(outputMark);
                }
                e.consume();
            }
        }
    } else if (code == KeyEvent.VK_ENTER) {
        returnPressed();
        e.consume();
    } else if (code == KeyEvent.VK_UP) {
        historyIndex--;
        if (historyIndex >= 0) {
            if (historyIndex >= history.size()) {
                historyIndex = history.size() - 1;
            }
            if (historyIndex >= 0) {
                String str = history.elementAt(historyIndex);
                int len = getDocument().getLength();
                replaceRange(str, outputMark, len);
                int caretPos = outputMark + str.length();
                select(caretPos, caretPos);
            } else {
                historyIndex++;
            }
        } else {
            historyIndex++;
        }
        e.consume();
    } else if (code == KeyEvent.VK_DOWN) {
        int caretPos = outputMark;
        if (history.size() > 0) {
            historyIndex++;
            if (historyIndex < 0) {
                historyIndex = 0;
            }
            int len = getDocument().getLength();
            if (historyIndex < history.size()) {
                String str = history.elementAt(historyIndex);
                replaceRange(str, outputMark, len);
                caretPos = outputMark + str.length();
            } else {
                historyIndex = history.size();
                replaceRange("", outputMark, len);
            }
        }
        select(caretPos, caretPos);
        e.consume();
    }
}

From source file:ch.zhaw.iamp.rct.ui.GrammarWindow.java

private void grammarTextPaneKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_grammarTextPaneKeyTyped
    if (evt.getKeyChar() == KeyEvent.VK_TAB) {
        if (evt.isShiftDown()) {
            removeTabIfPossilbe(evt, grammarTextPane);
        } else {/*from   w w  w  .ja v  a  2s . c  om*/
            insertTabAsSpace(evt, grammarTextPane);
        }
    }
}

From source file:ch.zhaw.iamp.rct.ui.GrammarWindow.java

private void initialisationTextPaneKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_initialisationTextPaneKeyTyped
    if (evt.getKeyChar() == KeyEvent.VK_TAB) {
        if (evt.isShiftDown()) {
            removeTabIfPossilbe(evt, initialisationTextPane);
        } else {//from  w ww . j  a  v  a 2 s  . co  m
            insertTabAsSpace(evt, initialisationTextPane);
        }
    }
}

From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.panel.Chromatogram1DHeatmapViewerPanel.java

@Override
public void keyPressed(KeyEvent ke) {
    Logger.getLogger(getClass().getName()).log(Level.INFO, "Received key event: {0}", ke.toString());
    if (ke.isControlDown()) {
        modeSpinner.setValue(InstanceContentSelectionHandler.Mode.ON_HOVER.toString());
    }/*  w w  w .j a  v a  2 s  .co  m*/
    if (getDataPoint() != null) {
        Logger.getLogger(getClass().getName()).info("Data point is not null!");
        Point p = null;
        if (ke.getKeyCode() == KeyEvent.VK_RIGHT) {
            p = new Point(getDataPoint());
            p.translate(1, 0);
        } else if (ke.getKeyCode() == KeyEvent.VK_LEFT) {
            p = new Point(getDataPoint());
            p.translate(-1, 0);
        } else if (ke.getKeyCode() == KeyEvent.VK_UP) {
            p = new Point(getDataPoint());
            p.translate(0, 1);
        } else if (ke.getKeyCode() == KeyEvent.VK_DOWN) {
            p = new Point(getDataPoint());
            p.translate(0, -1);
        }
        setDataPoint(p);
        if (!ke.isShiftDown()) {
            //                triggerMSUpdate();
        }
    }
}

From source file:KeyNavigateTest.java

protected void processKeyEvent(KeyEvent event) {
    int keycode = event.getKeyCode();

    if (event.isShiftDown())
        speed = FAST_SPEED;//from w w w.j  a va2  s  .c o  m
    else
        speed = NORMAL_SPEED;

    if (event.isAltDown())
        altMove(keycode);
    else if (event.isControlDown())
        controlMove(keycode);
    else
        standardMove(keycode);
}