Exemple #1
0
 /** Sets the mnemonic key on a text component. */
 public void setFocusAccelerator(JTextComponent component) {
   if (assignedModifier == getGroupModifier(MNEMONIC)
       && getKeyStroke() != null
       && KeyEvent.getKeyText(assignedKey).length() == 1) {
     component.setFocusAccelerator(KeyEvent.getKeyText(assignedKey).charAt(0));
   }
 }
Exemple #2
0
 /**
  * Returns a human readable text for the shortcut.
  *
  * @return a human readable text for the shortcut
  */
 public String getKeyText() {
   KeyStroke keyStroke = getKeyStroke();
   if (keyStroke == null) return "";
   String modifText = KeyEvent.getKeyModifiersText(keyStroke.getModifiers());
   if ("".equals(modifText)) return KeyEvent.getKeyText(keyStroke.getKeyCode());
   return modifText + '+' + KeyEvent.getKeyText(keyStroke.getKeyCode());
 }
Exemple #3
0
 /** use this to set a buttons's mnemonic */
 public void setMnemonic(AbstractButton button) {
   if (assignedModifier == getGroupModifier(MNEMONIC)
       && getKeyStroke() != null
       && KeyEvent.getKeyText(assignedKey).length() == 1) {
     button.setMnemonic(
         KeyEvent.getKeyText(assignedKey)
             .charAt(0)); // getKeyStroke().getKeyChar() seems not to work here
   }
 }
 public static void initKeys(JComponent component) {
   int mapName = JComponent.WHEN_IN_FOCUSED_WINDOW;
   im = component.getInputMap(mapName);
   am = component.getActionMap();
   for (int i = 3; i < 124; i++) {
     if (KeyEvent.getKeyText(i).contains("Des")) continue;
     addKeyBind(i, KeyEvent.getKeyText(i));
   }
 }
 /** process the text field key event */
 protected void processKeyEvent(KeyEvent e) {
   int keyCode = e.getKeyCode();
   if (KeyEvent.getKeyText(keyCode).equals("Backspace")
       || KeyEvent.getKeyText(keyCode).equals("Enter")) {
     super.processKeyEvent(e);
   }
   if (49 <= keyCode && keyCode <= 58) {
     super.processKeyEvent(e);
     String mValue = KeyEvent.getKeyText(keyCode);
     this.setText(mValue);
   }
 }
 @Override
 public void mouseClicked(MouseEvent mouseEvent) {
   Board b = bgui.getGridView();
   if (b.getAction() == Board.Action.KEY_DISCONNECT) {
     Point mouseP = MouseInfo.getPointerInfo().getLocation();
     Point gridP = b.getLocationOnScreen();
     int x = mouseP.x - gridP.x;
     int y = mouseP.y - gridP.y;
     x -= x % 20;
     y -= y % 20;
     f = m.findFlipper(x, y);
     String keys = "";
     if (f != null) {
       for (KeyConnectionFlipper kcf : m.getKeyConnectionsFlipper()) {
         if (kcf.getFlipper().equals(f)) {
           keys += ("'" + KeyEvent.getKeyText(kcf.getKeyID()) + "', ");
         }
       }
       if (keys.length() > 2) {
         keys = keys.substring(0, keys.length() - 2);
       }
       abs = null;
       b.requestFocus();
       bgui.setMessageColor(Color.BLACK);
       bgui.setMessage(
           "This flipper is connected to keys "
               + keys
               + ". Press key to remove connection to it.");
     } else if (m.getAbsorber() != null
         && x <= m.getAbsorber().getXBottomRight()
         && x >= m.getAbsorber().getXTopLeft()
         && y <= m.getAbsorber().getYBottomRight()
         && y >= m.getAbsorber().getYTopLeft()) {
       for (KeyConnectionAbs kca : m.getKeyConnectionsAbs()) {
         keys += ("'" + KeyEvent.getKeyText(kca.getKeyID()) + "', ");
       }
       if (keys.length() > 2) {
         keys = keys.substring(0, keys.length() - 2);
       }
       abs = m.getAbsorber();
       b.requestFocus();
       bgui.setMessageColor(Color.BLACK);
       bgui.setMessage(
           "This absorber is connected to keys "
               + keys
               + ". Press key to remove connection to it.");
     }
   }
 }
 @Override
 public void keyPressed(KeyEvent keyEvent) {
   Board b = bgui.getGridView();
   if (b.getAction() == Board.Action.KEY_DISCONNECT) {
     if (f != null) {
       boolean removed = false;
       for (KeyConnectionFlipper kcf : m.getKeyConnectionsFlipper()) {
         if (kcf.getFlipper().equals(f) && (kcf.getKeyID() == keyEvent.getKeyCode())) {
           m.getKeyConnectionsFlipper().remove(kcf);
           bgui.setMessageColor(Color.GREEN);
           bgui.setMessage("Key '" + KeyEvent.getKeyText(kcf.getKeyID()) + "' is removed!");
           removed = true;
           break;
         }
       }
       if (!removed) {
         bgui.setMessageColor(Color.RED);
         bgui.setMessage(
             "Key '"
                 + KeyEvent.getKeyText(keyEvent.getKeyCode())
                 + "' is not connected "
                 + " to that flipper! ");
       }
     } else if (abs != null) {
       boolean removed = false;
       for (KeyConnectionAbs kca : m.getKeyConnectionsAbs()) {
         if ((kca.getKeyID() == keyEvent.getKeyCode())) {
           m.getKeyConnectionsAbs().remove(kca);
           bgui.setMessageColor(Color.GREEN);
           bgui.setMessage("Key '" + KeyEvent.getKeyText(kca.getKeyID()) + "' is removed!");
           removed = true;
           break;
         }
       }
       if (!removed) {
         bgui.setMessageColor(Color.RED);
         bgui.setMessage(
             "Key '"
                 + KeyEvent.getKeyText(keyEvent.getKeyCode())
                 + "' is not connected "
                 + " to that absorber! ");
       }
     } else {
       bgui.setMessageColor(Color.YELLOW);
       bgui.setMessage("No Component chosen yet");
     }
   }
 }
 @Override
 public void typeKey(int key) {
   Debug.log(3, "Robot: doType: %s ( %d )", KeyEvent.getKeyText(key), key);
   if (Settings.isMac()) {
     if (key == Key.toJavaKeyCodeFromText("#N.")) {
       doType(KeyMode.PRESS_ONLY, Key.toJavaKeyCodeFromText("#C."));
       doType(KeyMode.PRESS_RELEASE, key);
       doType(KeyMode.RELEASE_ONLY, Key.toJavaKeyCodeFromText("#C."));
       return;
     } else if (key == Key.toJavaKeyCodeFromText("#T.")) {
       doType(KeyMode.PRESS_ONLY, Key.toJavaKeyCodeFromText("#C."));
       doType(KeyMode.PRESS_ONLY, Key.toJavaKeyCodeFromText("#A."));
       doType(KeyMode.PRESS_RELEASE, key);
       doType(KeyMode.RELEASE_ONLY, Key.toJavaKeyCodeFromText("#A."));
       doType(KeyMode.RELEASE_ONLY, Key.toJavaKeyCodeFromText("#C."));
       return;
     } else if (key == Key.toJavaKeyCodeFromText("#X.")) {
       key = Key.toJavaKeyCodeFromText("#T.");
       doType(KeyMode.PRESS_ONLY, Key.toJavaKeyCodeFromText("#A."));
       doType(KeyMode.PRESS_RELEASE, key);
       doType(KeyMode.RELEASE_ONLY, Key.toJavaKeyCodeFromText("#A."));
       return;
     }
   }
   doType(KeyMode.PRESS_RELEASE, key);
   waitForIdle();
 }
Exemple #9
0
 /** Controls the movements and actions of character and tetris pieces */
 public void keyPressed(KeyEvent key) {
   String keyText = KeyEvent.getKeyText(key.getKeyCode());
   if (!pause) {
     if (!shapeAI.getAI()) {
       if (keyText.equalsIgnoreCase("a")) {
         shapes.get(0).moveLeft(map);
         shapeTrack.add(1);
       }
       if (keyText.equalsIgnoreCase("d")) {
         shapes.get(0).moveRight(map);
         shapeTrack.add(2);
       }
       if (keyText.equalsIgnoreCase("w")) {
         shapes.get(0).turn(map, shapeTrack);
       }
     }
     if (keyText.equalsIgnoreCase("left")) {
       character.moveLeft();
     }
     if (keyText.equalsIgnoreCase("right")) {
       character.moveRight();
     }
     if (keyText.equalsIgnoreCase("up")) {
       character.jump();
     }
     if (keyText.equalsIgnoreCase("Slash")) {
       guntrack += 1;
       if (guntrack > weapons.length - 1) {
         guntrack = 0;
       }
     }
   }
   repaint();
 }
 @Override
 protected int calcButtonNum(Object value) {
   for (int keyCode : keys) {
     if (value.equals(KeyEvent.getKeyText(keyCode))) {
       return keyCode;
     }
   }
   return 0;
 }
 @Override
 protected Component createMainComponent() {
   _keyList = new ArrayList<String>();
   for (int keyCode : keys) {
     _keyList.add(KeyEvent.getKeyText(keyCode));
   }
   Component component = super.createMainComponent();
   return component;
 }
 public OpenAddIpRangeAction(String actionId) {
   super(actionId);
   String text = ClientCoreContext.getString("Button.add");
   int vk = XGuiUtils.getMnemonicKey('a');
   text =
       new StringBuilder(text).append("(").append(KeyEvent.getKeyText(vk)).append(")").toString();
   putValue(NAME, text);
   putValue(MNEMONIC_KEY, vk);
 }
Exemple #13
0
  public void keyTyped(KeyEvent e) {

    if (e.isActionKey()) {
      E.info("action key " + KeyEvent.getKeyText(keyCode));

    } else {
      char c = e.getKeyChar();
      insertCharacter(c);
    }
  }
Exemple #14
0
 // Special case for OS X, where Ctrl-Space is not detected as KEY_TYPED
 // https://github.com/processing/processing/issues/2699
 private void processControlSpace(final KeyEvent event) {
   if (event.getKeyCode() == KeyEvent.VK_SPACE && event.isControlDown()) {
     // Provide completions only if it's enabled
     if (JavaMode.codeCompletionsEnabled) {
       Messages.log(
           "[KeyEvent]" + KeyEvent.getKeyText(event.getKeyCode()) + "  |Prediction started");
       fetchPhrase();
     }
   }
 }
 @Override
 public void typeChar(char character, KeyMode mode) {
   Debug.log(
       3,
       "Robot: doType: %s ( %d )",
       KeyEvent.getKeyText(Key.toJavaKeyCode(character)[0]).toString(),
       Key.toJavaKeyCode(character)[0]);
   doType(mode, Key.toJavaKeyCode(character));
   waitForIdle();
 }
 /** Translate KeyStrokes into String representation. */
 private String[] getKeyStrings(KeyStroke[] keys) {
   String[] keyStrings = new String[keys.length];
   for (int i = 0; i < keys.length; i++) {
     int modifiers = keys[i].getModifiers();
     keyStrings[i] = KeyEvent.getKeyModifiersText(modifiers);
     if (keyStrings[i].length() > 0) keyStrings[i] += "+";
     keyStrings[i] += KeyEvent.getKeyText(keys[i].getKeyCode());
   }
   return keyStrings;
 }
Exemple #17
0
  // keypressed
  public void keyPressed(KeyEvent e) {

    int KeyCode = e.getKeyCode();

    if (KeyCode == KeyEvent.VK_ESCAPE) { // VK_ what ever
      stop();
    } else {
      mess = "You pressed: " + KeyEvent.getKeyText(KeyCode);
      e.consume(); // not allowing key combinations
    }
  }
Exemple #18
0
 public void keyReleased(KeyEvent key) {
   String keyText = KeyEvent.getKeyText(key.getKeyCode());
   if (!pause) {
     if (keyText.equalsIgnoreCase("left")) {
       character.stop();
     }
     if (keyText.equalsIgnoreCase("right")) {
       character.stop();
     }
   }
   repaint();
 }
Exemple #19
0
  @Override
  public void paint(Graphics g) {
    super.paint(g);
    StringBuffer sb = new StringBuffer();
    sb.append("X=");
    sb.append(mouseX);
    sb.append("  Y=");
    sb.append(mouseY);

    sb.append("  code=");
    sb.append(KeyEvent.getKeyText(keyCode));
    g.drawString(sb.toString(), 20, 90);
  }
  /* (non-Javadoc)
   * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
   */
  public void keyPressed(KeyEvent evt) {
    // System.out.println(evt);
    StringBuffer str = new StringBuffer();

    str.append(getModifiers(evt));
    str.append("|");

    if (evt.isActionKey()) {
      str.append(KeyEvent.getKeyText(evt.getKeyCode()));
    } else {
      char c = evt.getKeyChar();

      if (!Character.isISOControl(c)) {
        str.append(Character.toString(c));
      } else {
        int code = evt.getKeyCode();
        str.append(KeyEvent.getKeyText(code));
      }
    }

    evt.consume();
    setText(str.toString());
  }
Exemple #21
0
    public void keyPressed(KeyEvent keyEvent) {

      int code = keyEvent.getKeyCode();
      String text = KeyEvent.getKeyText(code);

      if (sendStrings) {
        // keyBuffer.append(b)
        if (code == KeyEvent.VK_ENTER) {
          myService.send(boundServiceName, "keyCommand", keyBuffer.toString());
          addLogEntry(sdf.format(cal.getTime()) + " " + keyBuffer.toString());
          keyBuffer.setLength(0);
        } else {
          keyBuffer.append(text);
        }
      } else {
        myService.send(boundServiceName, "keyCommand", text);
        addLogEntry(
            sdf.format(cal.getTime())
                + " "
                + keyEvent.getKeyCode()
                + " "
                + KeyEvent.getKeyText(keyEvent.getKeyCode()));
      }
    }
  private int toKey(char c, boolean filterExisting) {
    // We convert candidate characters to key by converting to uppercase...
    final char upper = Character.toUpperCase(c);

    // .. filtering out existing mnemonics...
    if (!filterExisting || !m_existingMnemonics.contains(upper)) {

      // .. and throwing away anything that doesn't map to a key.
      if (KeyEvent.getKeyText(upper).equals(String.valueOf(upper))) {
        return upper;
      }
    }

    return 0;
  }
Exemple #23
0
  /**
   * Return a good string representation of the given keystroke, since the toString method returns
   * more garbage than we want to see in a user interface.
   */
  public static String keyStrokeToString(KeyStroke key) {
    int modifiers = key.getModifiers();
    StringBuffer buffer = new StringBuffer();

    if ((modifiers & Event.SHIFT_MASK) == Event.SHIFT_MASK) {
      buffer.append("(Shift-");
      buffer.append(KeyEvent.getKeyText(key.getKeyCode()));
      buffer.append(")");
    }

    if ((modifiers & Event.CTRL_MASK) == Event.CTRL_MASK) {
      buffer.append("(Ctrl-");
      buffer.append(KeyEvent.getKeyText(key.getKeyCode()));
      buffer.append(")");
    }

    if ((modifiers & Event.META_MASK) == Event.META_MASK) {
      buffer.append("(Meta-");
      buffer.append(KeyEvent.getKeyText(key.getKeyCode()));
      buffer.append(")");
    }

    if ((modifiers & Event.ALT_MASK) == Event.ALT_MASK) {
      buffer.append("(Alt-");
      buffer.append(KeyEvent.getKeyText(key.getKeyCode()));
      buffer.append(")");
    }

    if (modifiers == 0) {
      buffer.append("(");
      buffer.append(KeyEvent.getKeyText(key.getKeyCode()));
      buffer.append(")");
    }

    return buffer.toString();
  }
  private void displayInfo(KeyEvent e, String keyStatus) {
    // Method copied from http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html

    // You should only rely on the key char if the event
    // is a key typed event.
    int id = e.getID();
    String keyString;
    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);
    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";
    }

    // Added:
    System.out.println("Keypress: " + keyString);
  }
 @Override
 public void readButtonSetting(Map<Integer, Integer> setting) {
   pushDefaultButton();
   for (int b : getButtons()) {
     Integer i = setting.get(b);
     if (i != null) {
       int k = i.intValue();
       for (int keyCode : keys) {
         if (k == keyCode) {
           getSpinner(b).setValue(KeyEvent.getKeyText(keyCode));
           break;
         }
       }
     }
   }
 }
    /** Initializes all the components of the panel. */
    private void init() {
      final int[] ctrls = my_controls.getControls();
      final String[] ctrl_labels = my_controls.getControlLabels();

      final GridLayout grid = new GridLayout(ctrl_labels.length, NUM_COLUMNS_PER_PLAYER);
      grid.setVgap(VERTICAL_GAP);
      grid.setHgap(HORIZONTAL_GAP);
      setLayout(grid);

      for (int i = 0; i < ctrl_labels.length; i++) {
        final JLabel label = new JLabel(ctrl_labels[i]);
        add(label);
        final JTextField tf = new JTextField(KeyEvent.getKeyText(ctrls[i]));
        setUpTextField(tf, i);
        add(tf);
      }
    }
    /**
     * Sets the code string.
     *
     * @param str0 &emsp; The new code string (space delimited)
     */
    public final void setCodeString(final String str0) {
      if ("null".equals(str0)) {
        return;
      }

      this.codeString = str0.trim();

      final List<String> codes = new ArrayList<>(Arrays.asList(this.codeString.split(" ")));
      final List<String> displayText = new ArrayList<>();

      for (final String s : codes) {
        if (!s.isEmpty()) {
          displayText.add(KeyEvent.getKeyText(Integer.valueOf(s)));
        }
      }

      this.setText(StringUtils.join(displayText, ' '));
    }
Exemple #28
0
  private void processCompletionKeys(final KeyEvent event) {
    char keyChar = event.getKeyChar();
    int keyCode = event.getKeyCode();
    if (keyChar == KeyEvent.VK_ENTER
        || keyChar == KeyEvent.VK_ESCAPE
        || keyChar == KeyEvent.VK_TAB
        || (event.getID() == KeyEvent.KEY_RELEASED
            && keyCode != KeyEvent.VK_LEFT
            && keyCode != KeyEvent.VK_RIGHT)) {
      // ignore
    } else if (keyChar == ')') {
      // https://github.com/processing/processing/issues/2741
      hideSuggestion();

    } else if (keyChar == '.') {
      if (JavaMode.codeCompletionsEnabled) {
        Messages.log(
            "[KeyEvent]" + KeyEvent.getKeyText(event.getKeyCode()) + "  |Prediction started");
        fetchPhrase();
      }
    } else if (keyChar == ' ') { // Trigger on Ctrl-Space
      if (!Platform.isMacOS()
          && JavaMode.codeCompletionsEnabled
          && (event.isControlDown() || event.isMetaDown())) {
        // Provide completions only if it's enabled
        if (JavaMode.codeCompletionsEnabled) {
          // Removed for https://github.com/processing/processing/issues/3847
          // try {
          //  getDocument().remove(getCaretPosition() - 1, 1); // Remove the typed space
          Messages.log("[KeyEvent]" + event.getKeyChar() + "  |Prediction started");
          fetchPhrase();
          // } catch (BadLocationException e) {
          //  e.printStackTrace();
          // }
        }
      } else {
        hideSuggestion(); // hide on spacebar
      }
    } else {
      if (JavaMode.codeCompletionsEnabled) {
        prepareSuggestions(event);
      }
    }
  }
Exemple #29
0
 private static Map<Integer, String> setKeyList() {
   Map<Integer, String> list = new LinkedHashMap<Integer, String>();
   String unknown = Toolkit.getProperty("AWT.unknown", "Unknown");
   // Assume all known keys are declared in KeyEvent as "public static int VK_*"
   for (Field field : KeyEvent.class.getFields()) {
     if (field.getName().startsWith("VK_")) {
       try {
         int i = field.getInt(null);
         String s = KeyEvent.getKeyText(i);
         if (s != null && s.length() > 0 && !s.contains(unknown)) {
           list.put(Integer.valueOf(i), s);
         }
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   }
   list.put(Integer.valueOf(-1), "");
   return list;
 }
Exemple #30
0
 public static String getPressedKey() {
   String allowed = "0123456789 QWERTZUIOPÜASDFGHJKLÖÄYXCVBNM.,:-?!";
   String raw = "";
   boolean shiftMask = false;
   for (int id : keysPressed.keySet()) {
     if (id > 0 && keysPressed.get(id) == KeyState.DOWN) {
       raw = KeyEvent.getKeyText(id);
       if (!allowed.contains(raw.toUpperCase())) {
         raw = "";
       }
       switch (id) {
         case KeyEvent.VK_SPACE:
           raw = " ";
           break;
         case KeyEvent.VK_MINUS:
           raw = "-";
           break;
         case KeyEvent.VK_PERIOD:
           raw = ".";
           break;
         case KeyEvent.VK_COMMA:
           raw = ",";
           break;
         case KeyEvent.VK_SHIFT:
           shiftMask = true;
       }
     }
   }
   if (shiftMask) {
     if (getKeyDown(KeyEvent.VK_9)) {
       raw = ")";
     } else if (getKeyDown(KeyEvent.VK_8)) {
       raw = "(";
     } else if (getKeyDown(KeyEvent.VK_PERIOD)) {
       raw = ":";
     } else if (getKeyDown(KeyEvent.VK_MINUS)) {
       raw = "_";
     }
   }
   return raw;
 }