Java Swing Key Action translate(KeyStroke keyStroke, Locale locale)

Here you can find the source of translate(KeyStroke keyStroke, Locale locale)

Description

Returns the key stroke representation translated.

License

Open Source License

Parameter

Parameter Description
keyStroke The key stroke.
locale The locale.

Return

The key stroke representation translated.

Declaration

public static String translate(KeyStroke keyStroke, Locale locale) 

Method Source Code

//package com.java2s;
/*//from   ww w .java  2 s .c  o m
 * Copyright (C) 2015 Miquel Sas
 * 
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */

import java.awt.event.KeyEvent;

import java.util.Locale;

import javax.swing.KeyStroke;

public class Main {
    /**
     * Returns the key stroke representation translated.
     * 
     * @param keyStroke The key stroke.
     * @param locale The locale.
     * @return The key stroke representation translated.
     */
    public static String translate(KeyStroke keyStroke, Locale locale) {
        //      String[] tokens = StringUtils.parse(StringUtils.toString(keyStroke), " ");
        //      if (tokens.length > 1) {
        //         Arrays.sort(tokens, 0, tokens.length - 1);
        //      }
        //      StringBuilder b = new StringBuilder();
        //      for (int i = 0; i < tokens.length; i++) {
        //         String token = tokens[i];
        //         String key = "key_" + token;
        //         String translated = TextServer.getString(key, locale);
        //         if (translated.equals(TextServer.notFoundKey(key))) {
        //            translated = token;
        //         }
        //         if (i > 0) {
        //            b.append("+");
        //         }
        //         b.append(translated);
        //      }
        //      return b.toString();
        String acceleratorText = "";
        if (keyStroke != null) {
            int modifiers = keyStroke.getModifiers();
            if (modifiers > 0) {
                acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
                acceleratorText += "+";
            }
            acceleratorText += KeyEvent.getKeyText(keyStroke.getKeyCode());
        }
        return acceleratorText;
    }
}

Related

  1. simulateEnterKeyPressed(final Component component, final int delayInMilliseconds)
  2. simulateKeyStrokes(Component comp, String text)
  3. stringify(KeyStroke keyStroke)
  4. stringToKey(String s)
  5. stringToKeys(String s)
  6. validarNumeroInteiro(KeyEvent evt)