Java Swing Key Action getKeyStrokeText(KeyStroke ks)

Here you can find the source of getKeyStrokeText(KeyStroke ks)

Description

get Key Stroke Text

License

Open Source License

Declaration

public static String getKeyStrokeText(KeyStroke ks) 

Method Source Code

//package com.java2s;
/**************************************************************************
 OmegaT - Computer Assisted Translation (CAT) tool 
  with fuzzy matching, translation memory, keyword search, 
  glossaries, and translation leveraging into updated projects.
    // w ww. j  a va  2 s.  c o m
 Copyright (C) 2006 Henry Pijffers
       2013 Yu Tang
       2014-2015 Aaron Madlon-Kay
       Home page: http://www.omegat.org/
       Support center: http://groups.yahoo.com/group/OmegaT/
    
 This file is part of OmegaT.
    
 OmegaT 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.
    
 OmegaT 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 javax.swing.KeyStroke;

public class Main {
    public static String getKeyStrokeText(KeyStroke ks) {
        StringBuilder sb = new StringBuilder();
        String modifierText = KeyEvent.getKeyModifiersText(ks.getModifiers());
        sb.append(modifierText);
        String keyText = KeyEvent.getKeyText(ks.getKeyCode());
        if (!keyText.isEmpty() && !modifierText.contains(keyText)) {
            if (sb.length() > 0) {
                sb.append('+');
            }
            sb.append(keyText);
        }
        return sb.toString();
    }
}

Related

  1. getEscapeKeystroke()
  2. getKeyStroke(int i0, int i1)
  3. getKeystroke(int keyevent)
  4. getKeyStrokeCopy()
  5. getKeyStrokeRepresentation(KeyStroke ks)
  6. getPrettyStringFor(KeyStroke keyStroke)
  7. getSystemHelpKey()
  8. getTypePanel(final ActionListener typeListener)
  9. handleSliderAdjustmentViaKey(KeyEvent e)