Java Swing Key Action getPrettyStringFor(KeyStroke keyStroke)

Here you can find the source of getPrettyStringFor(KeyStroke keyStroke)

Description

Returns a pretty string value for a KeyStroke, suitable for display as the keystroke's value in a GUI.

License

BSD License

Parameter

Parameter Description
keyStroke The keystroke.

Return

The string value of the keystroke.

Declaration

public static String getPrettyStringFor(KeyStroke keyStroke) 

Method Source Code

//package com.java2s;
/*//ww w.  j a  v a 2 s.c om
 * 09/08/2005
 *
 * UIUtil.java - Utility methods for org.fife.ui classes.
 * Copyright (C) 2005 Robert Futrell
 * http://fifesoft.com/rtext
 * Licensed under a modified BSD license.
 * See the included license file for details.
 */

import java.awt.event.KeyEvent;

import javax.swing.KeyStroke;

public class Main {
    /**
     * Returns a pretty string value for a KeyStroke, suitable for display as
     * the keystroke's value in a GUI.
     *
     * @param keyStroke The keystroke.
     * @return The string value of the keystroke.
     */
    public static String getPrettyStringFor(KeyStroke keyStroke) {

        if (keyStroke == null)
            return "";

        String string = KeyEvent.getKeyModifiersText(keyStroke.getModifiers());
        if (string != null && string.length() > 0)
            string += "+";
        int keyCode = keyStroke.getKeyCode();
        if (keyCode != KeyEvent.VK_SHIFT && keyCode != KeyEvent.VK_CONTROL && keyCode != KeyEvent.VK_ALT
                && keyCode != KeyEvent.VK_META)
            string += KeyEvent.getKeyText(keyCode);
        return string;

    }
}

Related

  1. getKeyStroke(int i0, int i1)
  2. getKeystroke(int keyevent)
  3. getKeyStrokeCopy()
  4. getKeyStrokeRepresentation(KeyStroke ks)
  5. getKeyStrokeText(KeyStroke ks)
  6. getSystemHelpKey()
  7. getTypePanel(final ActionListener typeListener)
  8. handleSliderAdjustmentViaKey(KeyEvent e)
  9. initButton(String text, String actionKey, int shortcutKey, int modifiers, JComponent component, AbstractAction action)