Example usage for java.awt.event KeyEvent VK_UP

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

Introduction

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

Prototype

int VK_UP

To view the source code for java.awt.event KeyEvent VK_UP.

Click Source Link

Document

Constant for the non-numpad up arrow key.

Usage

From source file:CopyAreaPerformance.java

/**
 * Arrow keys scroll the view around. The 'c' key toggles clip area
 * optimization. The 'a' key toggles copyArea optimization.
 *//*from   w w  w. ja va  2  s  .c  om*/
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
        scroll(SCROLL_SIZE, 0);
    } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
        scroll(-SCROLL_SIZE, 0);
    } else if (e.getKeyCode() == KeyEvent.VK_UP) {
        scroll(0, -SCROLL_SIZE);
    } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
        scroll(0, SCROLL_SIZE);
    } else if (e.getKeyCode() == KeyEvent.VK_C) {
        useClip = !useClip;
        System.out.println("useClip = " + useClip);
    } else if (e.getKeyCode() == KeyEvent.VK_A) {
        useCopyArea = !useCopyArea;
        prevVX = -10000;
        System.out.println("useCopyArea = " + useCopyArea);
    }
}

From source file:cz.babi.desktop.remoteme.common.Controller.java

/**
 * Make key stroke./*from  w ww .j  av  a 2 s. c o m*/
 * @param character Key(s) to stroke.
 */
private void makeStroke(Integer[] keyCodes) {
    /*
     * There is a bug with shift and arrows.
     * Workaround is turn num lock off.
     * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4908075
     */
    boolean needSetNumlockOn = false;
    /* If numlock is on. */
    if (Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_NUM_LOCK)) {
        boolean isShift = false;
        boolean isArrow = false;

        /* Check if there is a shift or an arrow. */
        for (Integer integer : keyCodes) {
            if (integer == KeyEvent.VK_SHIFT)
                isShift = true;
            if (integer == KeyEvent.VK_LEFT)
                isArrow = true;
            if (integer == KeyEvent.VK_RIGHT)
                isArrow = true;
            if (integer == KeyEvent.VK_UP)
                isArrow = true;
            if (integer == KeyEvent.VK_DOWN)
                isArrow = true;
        }

        /* Disable numlock. */
        if (isShift && isArrow) {
            robot.keyPress(KeyEvent.VK_NUM_LOCK);
            robot.keyRelease(KeyEvent.VK_NUM_LOCK);
            needSetNumlockOn = true;
        }
    }

    /* Do press. */
    for (int i = 0; i < keyCodes.length; i++) {
        if (Common.DEBUG)
            LOGGER.debug("[keyPress][" + keyCodes[i] + "]");

        robot.keyPress(keyCodes[i]);
    }

    /* Do release. */
    for (int i = keyCodes.length - 1; i >= 0; i--) {
        if (Common.DEBUG)
            LOGGER.debug("[keyRelease][" + keyCodes[i] + "]");

        robot.keyRelease(keyCodes[i]);
    }

    /* Set numlock back. */
    if (needSetNumlockOn) {
        robot.keyPress(KeyEvent.VK_NUM_LOCK);
        robot.keyRelease(KeyEvent.VK_NUM_LOCK);
    }
}

From source file:net.rptools.tokentool.ui.TokenCompositionPanel.java

public void keyReleased(KeyEvent e) {
    switch (e.getKeyCode()) {
    case java.awt.event.KeyEvent.VK_UP:
        tokenOffsetY += -1;/* w w  w. j av a  2  s.com*/
        repaint();
        fireCompositionChanged();
        break;
    case java.awt.event.KeyEvent.VK_DOWN:
        tokenOffsetY += 1;
        repaint();
        fireCompositionChanged();
        break;
    case java.awt.event.KeyEvent.VK_LEFT:
        tokenOffsetX += -1;
        repaint();
        fireCompositionChanged();
        break;
    case java.awt.event.KeyEvent.VK_RIGHT:
        tokenOffsetX += 1;
        repaint();
        fireCompositionChanged();
    }

}

From source file:bio.gcat.gui.BDATool.java

public BDATool() {
    super("BDA Tool - " + AnalysisTool.NAME);
    setIconImage(getImage("bda"));
    setMinimumSize(new Dimension(660, 400));
    setPreferredSize(new Dimension(1020, 400));
    setSize(getPreferredSize());/* ww w . jav  a 2  s . co  m*/
    setLocationByPlatform(true);
    setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

    menubar = new JMenuBar();
    menu = new JMenu[4];
    menubar.add(menu[0] = new JMenu("File"));
    menubar.add(menu[1] = new JMenu("Edit"));
    menubar.add(menu[2] = new JMenu("Window"));
    menubar.add(menu[3] = new JMenu("Help"));
    setJMenuBar(menubar);

    menu[0].add(createMenuItem("Open...", "folder-horizontal-open",
            KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK), ACTION_OPEN, this));
    menu[0].add(createMenuItem("Save As...", "disk--arrow",
            KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK), ACTION_SAVE_AS, this));
    menu[0].add(createSeparator());
    menu[0].add(createMenuItem("Close Window", "cross", ACTION_CLOSE, this));
    menu[1].add(createMenuText("Binary Dichotomic Algorithm:"));
    menu[1].add(createMenuItem("Add", KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_DOWN_MASK),
            ACTION_BDA_ADD, this));
    menu[1].add(createMenuItem("Edit...", KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_DOWN_MASK),
            ACTION_BDA_EDIT, this));
    menu[1].add(
            createMenuItem("Remove", KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), ACTION_BDA_REMOVE, this));
    menu[1].add(createMenuItem("Clear", ACTION_BDAS_CLEAR, this));
    menu[1].add(seperateMenuItem(createMenuItem("Move Up",
            KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.CTRL_DOWN_MASK), ACTION_BDA_MOVE_UP, this)));
    menu[1].add(createMenuItem("Move Down", KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.CTRL_DOWN_MASK),
            ACTION_BDA_MOVE_DOWN, this));
    menu[2].add(createMenuItem("Preferences", ACTION_PREFERENCES, this));
    menu[3].add(createMenuItem("About BDA Tool", "bda", ACTION_ABOUT, this));
    for (String action : new String[] { ACTION_BDA_EDIT, ACTION_BDA_REMOVE, ACTION_BDAS_CLEAR,
            ACTION_BDA_MOVE_UP, ACTION_BDA_MOVE_DOWN })
        getMenuItem(menubar, action).setEnabled(false);
    getMenuItem(menubar, ACTION_PREFERENCES).setEnabled(false);
    registerKeyStroke(getRootPane(), KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "remove",
            new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent event) {
                    if (bdaPanel.table.hasFocus())
                        removeBinaryDichotomicAlgorithm();
                }
            });

    toolbar = new JToolBar[1];
    toolbar[0] = new JToolBar("File");
    toolbar[0].add(createToolbarButton("Open File", "folder-horizontal-open", ACTION_OPEN, this));
    toolbar[0].add(createToolbarButton("Save As File", "disk--arrow", ACTION_SAVE_AS, this));

    toolbars = new JPanel(new FlowLayout(FlowLayout.LEADING));
    for (JToolBar toolbar : toolbar)
        toolbars.add(toolbar);
    add(toolbars, BorderLayout.NORTH);

    add(createSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, true, 360, 0.195,
            new JScrollPane(bdaPanel = new BinaryDichotomicAlgorithmPanel()),
            new JScrollPane(tablePanel = new JPanel(new BorderLayout()))), BorderLayout.CENTER);

    add(bottom = new JPanel(new FlowLayout(FlowLayout.RIGHT)), BorderLayout.SOUTH);

    status = new JLabel();
    status.setBorder(new EmptyBorder(0, 5, 0, 5));
    status.setHorizontalAlignment(JLabel.RIGHT);
    bottom.add(status);

    ((ListTableModel<?>) bdaPanel.table.getModel()).addListDataListener(this);
    bdaPanel.table.getSelectionModel().addListSelectionListener(this);

    revalidateGeneticCodeTable();
}

From source file:adams.gui.tools.TelnetPanel.java

/**
 * For initializing the GUI.//from  ww w . j  a  v a 2s  .c  o  m
 */
@Override
protected void initGUI() {
    JPanel topPanel;
    JPanel bottomPanel;
    JLabel label;

    super.initGUI();

    setLayout(new BorderLayout());

    // connection
    topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    add(topPanel, BorderLayout.NORTH);

    m_TextRemote = new BaseTextField(20);
    label = new JLabel("Remote");
    label.setDisplayedMnemonic('R');
    label.setLabelFor(m_TextRemote);
    topPanel.add(label);
    topPanel.add(m_TextRemote);

    m_PortModel = new SpinnerNumberModel();
    m_PortModel.setMinimum(1);
    m_PortModel.setMaximum(65536);
    m_PortModel.setStepSize(1);
    m_PortModel.setValue(23);
    m_SpinnerPort = new JSpinner(m_PortModel);
    label = new JLabel("Port");
    label.setDisplayedMnemonic('P');
    label.setLabelFor(m_SpinnerPort);
    topPanel.add(label);
    topPanel.add(m_SpinnerPort);

    m_ButtonConnection = new BaseButton();
    m_ButtonConnection.setMnemonic('n');
    m_ButtonConnection.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            handleConnectionEvent();
        }
    });
    topPanel.add(m_ButtonConnection);

    // output
    m_ButtonClear = new BaseButton("Clear", GUIHelper.getIcon("new.gif"));
    m_ButtonClear.setMnemonic('l');
    m_ButtonClear.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            m_TextOutput.setText("");
        }
    });
    m_ButtonCopy = new BaseButton("Copy", GUIHelper.getIcon("copy.gif"));
    m_ButtonCopy.setMnemonic('C');
    m_ButtonCopy.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (m_TextOutput.getSelectedText().length() > 0)
                ClipboardHelper.copyToClipboard(m_TextOutput.getSelectedText());
            else if (m_TextOutput.getText().length() > 0)
                ClipboardHelper.copyToClipboard(m_TextOutput.getText());
        }
    });
    m_TextOutput = new BaseTextAreaWithButtons(10, 40);
    m_TextOutput.setTextFont(Fonts.getMonospacedFont());
    m_TextOutput.addToButtonsPanel(m_ButtonClear);
    m_TextOutput.addToButtonsPanel(m_ButtonCopy);
    add(m_TextOutput, BorderLayout.CENTER);

    // commands
    bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    add(bottomPanel, BorderLayout.SOUTH);

    m_TextCommand = new BaseTextField(40);
    m_TextCommand.setFont(Fonts.getMonospacedFont());
    m_TextCommand.addKeyListener(new KeyListener() {
        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
            switch (e.getKeyCode()) {
            case KeyEvent.VK_ENTER:
                e.consume();
                execCommand();
                break;
            case KeyEvent.VK_UP:
                e.consume();
                previousCommand();
                break;
            case KeyEvent.VK_DOWN:
                e.consume();
                nextCommand();
                break;
            }
        }
    });
    label = new JLabel("Command");
    label.setDisplayedMnemonic('m');
    label.setLabelFor(m_TextCommand);
    bottomPanel.add(label);
    bottomPanel.add(m_TextCommand);

    m_ButtonCommand = new BaseButton(GUIHelper.getIcon("run.gif"));
    m_ButtonCommand.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            execCommand();
        }
    });
    bottomPanel.add(m_ButtonCommand);
}

From source file:org.tmpotter.ui.ActionHandler.java

public void onTablePressed(final KeyEvent event) {
    int index;//from w  ww.j  a v a  2  s  .c  o m
    if (modelMediator.getTmViewSelectedRow() != -1) {
        index = modelMediator.getTmViewSelectedRow();
        tmData.setPositionTextArea(0);
    } else {
        index = 1;
    }
    if (index < modelMediator.getTmViewRows() - 1) {
        if ((event.getKeyCode() == KeyEvent.VK_DOWN) || (event.getKeyCode() == KeyEvent.VK_NUMPAD2)) {
            if (tmData.getIndexPrevious() < tmData.getDocumentOriginalSize()) {
                tmData.setOriginalDocumentAnt(restoreText(modelMediator.getLeftEdit()));
                tmData.setTranslationDocumentAnt(restoreText(modelMediator.getRightEdit()));
            }
            modelMediator.setLeftEdit(formatText(modelMediator.getLeftSegment(index + 1)));
            modelMediator.setRightEdit(formatText(modelMediator.getRightSegment(index + 1)));
            tmData.setIndexCurrent(index + 1);
        } else if ((event.getKeyCode() == KeyEvent.VK_UP) || (event.getKeyCode() == KeyEvent.VK_NUMPAD8)) {
            tmData.setIndexCurrent(index - 1);
            if (index == 0) {
                index = 1;
                tmData.setIndexCurrent(0);
            }
            if (tmData.getIndexPrevious() < tmData.getDocumentOriginalSize()) {
                tmData.setOriginalDocumentAnt(restoreText(modelMediator.getLeftEdit()));
                tmData.setTranslationDocumentAnt(restoreText(modelMediator.getRightEdit()));
            }
            modelMediator.setLeftEdit(formatText(modelMediator.getLeftSegment(index - 1)));
            modelMediator.setRightEdit(formatText(modelMediator.getRightSegment(index - 1)));
        }
        if (tmData.isIdentTop()) {
            modelMediator.setJoinEnabled(false);
        } else {
            modelMediator.setJoinEnabled(true);
        }
        tmData.setIndexPrevious(tmData.getIndexCurrent());
    }
    modelMediator.updateTmView();
}

From source file:com.rapidminer.gui.plotter.charts.ChartPanelShiftController.java

/**
 * Pan / Shifts a plot if the arrow keys are pressed.
 *///from w w w.j  a  v  a 2s .  c  o  m
public void keyPressed(KeyEvent e) {
    if (!plotSupported) {
        return;
    }

    int keyCode = e.getKeyCode();

    // we're only interested in arrows (code 37,38,39,40)
    if ((keyCode < 37) || (keyCode > 40)) {
        return;
    }

    // The axes we're gonna shift
    ValueAxis[] axes = null;

    boolean domainShift = false; // used for PAN_FIXED
    // Calculations for the domain axis
    if ((keyCode == KeyEvent.VK_LEFT) || (keyCode == KeyEvent.VK_RIGHT)) {
        axes = getPlotAxis(chartPanel.getChart(), !axesSwaped);
        domainShift = true;
    }
    // Calculations for the range axis
    else {
        axes = getPlotAxis(chartPanel.getChart(), axesSwaped);
    }

    // Delta is the amount we'll shift in axes units.
    double[] delta = new double[axes.length];

    // Let's calculate 'delta', the amount by which we'll shift the plot
    for (int i = 0; i < axes.length; i++) {
        switch (shiftType) {
        case SHIFT_PERCENTUAL:
            delta[i] = (axes[i].getUpperBound() - axes[i].getLowerBound()) / 100.0;
            break;
        case SHIFT_FIXED:
            delta[i] = (domainShift ? fixedDomainShiftUnits : fixedRangeShiftUnits);
            break;
        case SHIFT_PIXEL: // also the default
        default:
            // Let's find out what's the range for 1 pixel.
            final Rectangle2D scaledDataArea = chartPanel.getScreenDataArea();
            delta[i] = axes[i].getRange().getLength() / (scaledDataArea.getWidth());
            break;
        }
    }

    // Shift modifier multiplies delta by 10
    if (e.isShiftDown()) {
        for (int i = 0; i < delta.length; i++) {
            delta[i] *= 10;
        }
    }

    for (int i = 0; i < axes.length; i++) {
        switch (keyCode) {
        case KeyEvent.VK_LEFT:
        case KeyEvent.VK_DOWN:
            axes[i].setRange(axes[i].getLowerBound() - delta[i], axes[i].getUpperBound() - delta[i]);
            break;
        case KeyEvent.VK_UP:
        case KeyEvent.VK_RIGHT:
            axes[i].setRange(axes[i].getLowerBound() + delta[i], axes[i].getUpperBound() + delta[i]);
            break;
        }
    }
}

From source file:com.nbt.TileCanvas.java

protected void keyPressed(KeyEvent e) {
    final int keyCode = e.getKeyCode();
    switch (keyCode) {
    case KeyEvent.VK_UP:
        int z = getTileZ();
        setTileZ(z - 1);//  ww  w .  java  2s  . c  o m
        break;
    case KeyEvent.VK_DOWN:
        z = getTileZ();
        setTileZ(z + 1);
        break;
    case KeyEvent.VK_LEFT:
        int x = getTileX();
        setTileX(x - 1);
        break;
    case KeyEvent.VK_RIGHT:
        x = getTileX();
        setTileX(x + 1);
        break;
    case KeyEvent.VK_PAGE_UP:
        int altitude = getAltitude();
        setAltitude(altitude + 1);
        break;
    case KeyEvent.VK_PAGE_DOWN:
        altitude = getAltitude();
        setAltitude(altitude - 1);
        break;
    }

    updateXYZ();
    doRepaint();
    save();
}

From source file:com.tradedesksoftware.ets.client.charting.ChartShiftController.java

/**
 * Pan/Shifts a plot if the arrow keys are pressed.
 * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
 *///from w w  w .  j  a  v  a  2s  . co  m
public void keyPressed(KeyEvent e) {
    if (!plotSupported)
        return;

    int keyCode = e.getKeyCode();

    // we're only interested in arrows (code 37,38,39,40)
    if ((keyCode < 37) || (keyCode > 40))
        return;

    // The axis we're gonna shift
    ValueAxis axis = null;

    // Delta is the amount we'll shift in axis units.
    double delta;

    boolean domainShift = false; // used for PAN_FIXED
    // Calculations for the domain axis
    if ((keyCode == KeyEvent.VK_LEFT) || (keyCode == KeyEvent.VK_RIGHT)) {
        axis = getPlotAxis(chartPanel.getChart(), !axesSwaped);
        domainShift = true;
    }
    // Calculations for the range axis
    else {
        axis = getPlotAxis(chartPanel.getChart(), axesSwaped);
    }

    // Let's calculate 'delta', the amount by which we'll shift the plot
    switch (shiftType) {
    case SHIFT_PERCENTUAL:
        delta = (axis.getUpperBound() - axis.getLowerBound()) / 100.0;
        break;
    case SHIFT_FIXED:
        delta = (domainShift ? fixedDomainShiftUnits : fixedRangeShiftUnits);
        break;
    case SHIFT_PIXEL: // also the default
    default:
        // Let's find out what's the range for 1 pixel.
        final Rectangle scaledDataArea = chartPanel.getScreenDataArea();
        delta = axis.getRange().getLength() / (scaledDataArea.width);
        break;
    }

    // Shift modifier multiplies delta by 10
    if (e.isShiftDown()) {
        delta *= 10;
    }

    switch (keyCode) {
    case KeyEvent.VK_LEFT:
    case KeyEvent.VK_DOWN:
        axis.setRange(axis.getLowerBound() - delta, axis.getUpperBound() - delta);
        break;
    case KeyEvent.VK_UP:
    case KeyEvent.VK_RIGHT:
        axis.setRange(axis.getLowerBound() + delta, axis.getUpperBound() + delta);
        break;
    }
}

From source file:Text2DTest.java

/**
 * Process a keyboard event to move or rotate the viewer.
 *//*from   w w  w  . j ava 2  s.c  o m*/
void processManualEvent(AWTEvent[] events) {

    for (int i = 0; i < events.length; ++i) {
        if (events[i] instanceof KeyEvent) {
            KeyEvent event = (KeyEvent) events[i];
            if (event.getKeyCode() == KeyEvent.VK_EQUALS) {
                continue;
            }
            Transform3D t = new Transform3D();
            viewTransformGroup.getTransform(t);
            Vector3f viewDir = new Vector3f(0f, 0f, -1f);
            Vector3f translation = new Vector3f();
            t.get(translation);
            t.transform(viewDir);
            if (event.getKeyCode() == KeyEvent.VK_UP) {
                translation.x += viewDir.x;
                translation.y += viewDir.y;
                translation.z += viewDir.z;
            } else if (event.getKeyCode() == KeyEvent.VK_DOWN) {
                translation.x -= viewDir.x;
                translation.y -= viewDir.y;
                translation.z -= viewDir.z;
            } else if (event.getKeyCode() == KeyEvent.VK_RIGHT) {
                rotation += -.1;
            } else if (event.getKeyCode() == KeyEvent.VK_LEFT) {
                rotation += .1;
            }
            t.rotY(rotation);
            t.setTranslation(translation);
            viewTransformGroup.setTransform(t);
        }
    }
}