@Override
 public void keyPressed(KeyEvent e) {
   TreePath path = myTree.getLeadSelectionPath();
   if (path == null) return;
   final Object lastComponent = path.getLastPathComponent();
   if (e.getKeyCode() == KeyEvent.VK_ENTER) {
     if (lastComponent instanceof ParentNode) return;
     doOKAction();
     e.consume();
   } else if (e.getKeyCode() == KeyEvent.VK_INSERT) {
     if (lastComponent instanceof ElementNode) {
       final DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent;
       if (!mySelectedNodes.contains(node)) {
         if (node.getNextNode() != null) {
           myTree.setSelectionPath(new TreePath(node.getNextNode().getPath()));
         }
       } else {
         if (node.getNextNode() != null) {
           myTree.removeSelectionPath(new TreePath(node.getPath()));
           myTree.setSelectionPath(new TreePath(node.getNextNode().getPath()));
           myTree.repaint();
         }
       }
       e.consume();
     }
   }
 }
示例#2
0
  @Override
  public void keyPressed(KeyEvent e) {
    // TODO Auto-generated method stub
    if (e.getKeyCode() == KeyEvent.VK_W) {
      this.hero.setDirection(0);
      hero.moveUp();
    } else if (e.getKeyCode() == KeyEvent.VK_D) {
      this.hero.setDirection(1);
      hero.moveRight();
    } else if (e.getKeyCode() == KeyEvent.VK_S) {
      this.hero.setDirection(2);
      hero.moveDown();
    } else if (e.getKeyCode() == KeyEvent.VK_A) {
      this.hero.setDirection(3);
      hero.moveLeft();
    }
    // 判断玩家是否按下J键 则开火
    if (e.getKeyCode() == KeyEvent.VK_J) {
      if (this.hero.bombs.size() <= 40) {

        hero.fire();
      }
    }
    this.repaint();
  }
示例#3
0
 /**
  * Event handler helper-method. Actionable F2-key check
  *
  * @param evt User Keyboard Press
  */
 private void checkF2Key(KeyEvent evt) {
   if (evt.getKeyCode() == 113) {
     System.out.println(evt.getKeyCode());
     EasyButtonMouseReleased(null);
     // HardButtonMouseReleased(null);
     // FileMenuMouseClicked(null);
   }
 }
 public void keyPressed(KeyEvent e) {
   if (e.getKeyCode() == KeyEvent.VK_UP) {
     y1Rise++;
     if (y1Rise >= 20) y1Rise = 20;
   } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
     y1Rise--;
     if (y1Rise >= 20) y1Rise = 20;
   }
 }
示例#5
0
 public void keyReleased(KeyEvent ke) {
   if (ke.getKeyCode() == KeyEvent.VK_UP) {
     String up = history.getUp();
     if (up != null) messageText.setText(up);
   } else if (ke.getKeyCode() == KeyEvent.VK_DOWN) {
     String down = history.getDown();
     if (down != null) messageText.setText(down);
   }
 }
示例#6
0
 /**
  * ************************************************
  *
  * <pre>
  * Summary: Catch any key pressed.
  *
  * </pre>
  *
  * *************************************************
  */
 public void keyPressed(KeyEvent e) {
   // Have an escape do the same as clicking cancel.
   if (e.getKeyCode() == KeyEvent.VK_ESCAPE) abandonButton.doClick();
   // Return
   else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
     if (closeButton.isEnabled()) {
       closeButton.doClick();
     }
   }
 }
示例#7
0
 public void keyPressed(KeyEvent e) {
   if (this.pan.getGameState() != null && this.pan.getGameState()) {
     if (e.getKeyCode() == KeyEvent.VK_UP) {
       // this.pan.moveUp();
     }
     if (e.getKeyCode() == KeyEvent.VK_DOWN) {
       // this.pan.moveDown();
     }
     if (e.getKeyCode() == KeyEvent.VK_LEFT) {
       this.pan.moveLeft();
     }
     if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
       this.pan.moveRight();
     }
     if (e.getKeyCode() == KeyEvent.VK_A) {
       this.pan.rCCW();
     }
     if (e.getKeyCode() == KeyEvent.VK_D) {
       this.pan.rCW();
     }
     if (e.getKeyCode() == KeyEvent.VK_SPACE) { // set piece in place
       this.pan.placeElectromino();
     }
     if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
       this.pan.setMenuState(new Boolean(true));
       this.pan.setGameState(new Boolean(false));
     }
   }
 }
示例#8
0
  // For KeyEvents that invole keys being pressed
  public void keyPressed(KeyEvent event) {
    // Assigns the keyPressed array at event.getKeyCode() to true as the key has been pressed
    keyPressed[event.getKeyCode()] = true;

    // Calls the update positions method to update the positions of the sprites.
    updatePositions();
  }
  @SuppressWarnings("HardCodedStringLiteral")
  private boolean togglePopup(KeyEvent e) {
    final KeyStroke stroke = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers());
    final Object action = ((InputMap) UIManager.get("ComboBox.ancestorInputMap")).get(stroke);
    if ("selectNext".equals(action)) {
      if (!isPopupShowing()) {
        return true;
      } else {
        return false;
      }
    } else if ("togglePopup".equals(action)) {
      if (isPopupShowing()) {
        closePopup();
      } else {
        suggestCompletion(true, true);
      }
      return true;
    } else {
      final Keymap active = KeymapManager.getInstance().getActiveKeymap();
      final String[] ids = active.getActionIds(stroke);
      if (ids.length > 0 && IdeActions.ACTION_CODE_COMPLETION.equals(ids[0])) {
        suggestCompletion(true, true);
      }
    }

    return false;
  }
示例#10
0
    public void keyPressed(KeyEvent e) {
      int keyCode = e.getKeyCode();

      System.out.println(keyCode + ", " + e.getKeyChar()); // testing

      // When shift is held, the user has entered editing mode
      if (e.isShiftDown()) {
        editingMode = true;
      } else {
        editingMode = false;
      }

      if (keyCode == KeyEvent.VK_SPACE)
        // Stop all stoppable sounds
        soundManager.stopSounds();
      else {
        SoundInfo sound = soundManager.getSound(keyCode);
        if (sound != null) {
          // Play, stop, or edit the sound
          dialogManager.handleSoundEvent(sound);
        } else if (getEditingMode()
            && keyCode != KeyEvent.VK_SHIFT
            && keyCode != KeyEvent.VK_CAPS_LOCK) {
          // Create a new sound
          dialogManager.displayNewSoundDialog();
        }
      }
    }
示例#11
0
    @Override
    public void keyPressed(KeyEvent evt) {
      switch (evt.getKeyCode()) {
        case KeyEvent.VK_SPACE:
          goToSelectedNode(M_OPEN);

          // f**k me dead
          EventQueue.invokeLater(
              new Runnable() {
                @Override
                public void run() {
                  resultTree.requestFocus();
                }
              });

          evt.consume();
          break;
        case KeyEvent.VK_ENTER:
          goToSelectedNode(M_OPEN);
          evt.consume();
          break;
        case KeyEvent.VK_DELETE:
          removeSelectedNode();
          evt.consume();
          break;
        default:
          break;
      }
    }
示例#12
0
 public void keyReleased(KeyEvent evt) {
   keys[evt.getKeyCode()] = false;
   // reset the counters for for the sprite s
   player1.resetCounter();
   if (!player1.getPower().equals("Balloon")) {
     player1.resetPicCounter();
   }
 }
示例#13
0
 public void keyReleased(KeyEvent e) {
   int keyCode = e.getKeyCode();
   IJ.setKeyUp(keyCode);
   int flags = e.getModifiers();
   boolean control = (flags & KeyEvent.CTRL_MASK) != 0;
   boolean meta = (flags & KeyEvent.META_MASK) != 0;
   boolean shift = (flags & e.SHIFT_MASK) != 0;
   if (keyCode == KeyEvent.VK_G && shift && (control || meta)) new ScreenGrabber().run("");
 }
示例#14
0
 @Override
 public void keyPressed(KeyEvent e) {
   // Accept "copy" key strokes
   KeyStroke ks = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers());
   JComponent comp = (JComponent) e.getSource();
   for (int i = 0; i < 3; i++) {
     InputMap im = comp.getInputMap(i);
     Object key = im.get(ks);
     if (defaultEditorKitCopyActionName.equals(key)
         || transferHandlerCopyActionName.equals(key)) {
       return;
     }
   }
   // Accept JTable navigation key strokes
   if (!tableNavigationKeys.contains(e.getKeyCode())) {
     e.consume();
   }
 }
 public void keyPressed(KeyEvent evt) {
   if (evt.getKeyCode() == evt.VK_RIGHT) {
     charcounter++;
     if (charcounter >= charnames.size()) {
       charcounter = 0;
     }
     showing = readGlyph((String) charnames.get(charcounter));
   } else if (evt.getKeyCode() == evt.VK_LEFT) {
     charcounter--;
     if (charcounter < 0) {
       charcounter = charnames.size() - 1;
     }
     showing = readGlyph((String) charnames.get(charcounter));
   } else {
     char c = evt.getKeyChar();
     //	System.out.println("Got char: "+name);
     showing = readGlyph(FontSupport.stdNames[FontSupport.standardEncoding[(int) c & 0xff]]);
   }
   repaint();
 }
示例#16
0
 public void keyPressed(KeyEvent k) {
   switch (k.getKeyCode()) {
     case KeyEvent.VK_UP:
       scale -= 0.1;
       repaint();
       break;
     case KeyEvent.VK_DOWN:
       scale += 0.1;
       repaint();
       break;
   }
 }
示例#17
0
 /**
  * Event handler method. Frame checks for user keyboard presses
  *
  * @param evt User Keyboard Press
  */
 private void formKeyPressed(KeyEvent evt) {
   // TODO add your handling code here:
   checkF2Key(evt);
   // checkTestCMD(evt);
   System.out.println(
       "Form detected a key press: "
           + evt.getKeyLocation()
           + ": "
           + evt.getKeyCode()
           + " - "
           + evt.getKeyChar());
 }
示例#18
0
        public void keyPressed(KeyEvent e) {
          int dx = 0;
          int dy = 0;
          if (e.getKeyCode() == KeyEvent.VK_LEFT) {
            dx = -1;
          } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
            dx = 1;
          } else if (e.getKeyCode() == KeyEvent.VK_UP) {
            dy = -1;
          } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
            dy = 1;
          }
          int multiplier = 1;
          if (e.isShiftDown() && e.isAltDown()) {
            multiplier = 10;
          } else if (e.isShiftDown() || e.isAltDown()) {
            multiplier = 5;
          }
          if (dx != 0 || dy != 0) {
            int size =
                Math.min(
                    MAX_SIZE,
                    Math.min(
                        getWidth() - imagePadding.left - imagePadding.right,
                        getHeight() - imagePadding.top - imagePadding.bottom));

            int offsetX = getWidth() / 2 - size / 2;
            int offsetY = getHeight() / 2 - size / 2;
            mouseListener.mousePressed(
                new MouseEvent(
                    ColorPickerPanel.this,
                    MouseEvent.MOUSE_PRESSED,
                    System.currentTimeMillis(),
                    0,
                    point.x + multiplier * dx + offsetX,
                    point.y + multiplier * dy + offsetY,
                    1,
                    false));
          }
        }
 public void keyPressed(KeyEvent evt) {
   requestFocus();
   if (evt.getKeyCode() == KeyEvent.VK_UP) {
     scalefactor = (float) (scalefactor * 1.1);
     scale = findScale();
     redrawneeded = true;
     repaint();
   } else if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
     scalefactor = (float) (scalefactor * 0.9);
     scale = findScale();
     redrawneeded = true;
     repaint();
   } else if (evt.getKeyChar() == 's') {
     System.out.println("Rectangle selection");
     if (rectx2 != -1 && recty2 != -1) {
       rectSelect(rectx1, recty1, rectx2, recty2);
       redrawneeded = true;
       repaint();
     }
   }
   return;
 }
  @SuppressWarnings("HardCodedStringLiteral")
  private void processListSelection(final KeyEvent e) {
    if (togglePopup(e)) return;

    if (!isPopupShowing()) return;

    final InputMap map = myPathTextField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    if (map != null) {
      final Object object = map.get(KeyStroke.getKeyStrokeForEvent(e));
      if (object instanceof Action) {
        final Action action = (Action) object;
        if (action.isEnabled()) {
          action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "action"));
          e.consume();
          return;
        }
      }
    }

    final Object action = getAction(e, myList);

    if ("selectNextRow".equals(action)) {
      if (ensureSelectionExists()) {
        ListScrollingUtil.moveDown(myList, e.getModifiersEx());
      }
    } else if ("selectPreviousRow".equals(action)) {
      ListScrollingUtil.moveUp(myList, e.getModifiersEx());
    } else if ("scrollDown".equals(action)) {
      ListScrollingUtil.movePageDown(myList);
    } else if ("scrollUp".equals(action)) {
      ListScrollingUtil.movePageUp(myList);
    } else if (getSelectedFileFromCompletionPopup() != null
        && (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_TAB)
        && e.getModifiers() == 0) {
      hideCurrentPopup();
      e.consume();
      processChosenFromCompletion(e.getKeyCode() == KeyEvent.VK_TAB);
    }
  }
示例#21
0
    public void keyPressed(KeyEvent ke) {

      if (ke.getKeyCode() == ke.VK_TAB) {
        int x = ((JTable) ke.getSource()).getSelectedColumn();
        int y = ((JTable) ke.getSource()).getSelectedRow();
        int maxX = ((JTable) ke.getSource()).getColumnCount();
        int maxY = ((JTable) ke.getSource()).getRowCount();
        TableModel tm = ((JTable) ke.getSource()).getModel();
        if (x == maxX - 1 && y == maxY - 1) {
          ((DefaultTableModel) tm).addRow(new Object[maxX]);
        }
      }
    }
  /**
   * Treat escape key events. Stop drawing the rectangle and revert to the previous state, without
   * doing anything. The event can be consumed (return true) or be delegated to other listeners
   * (return false).
   *
   * @param keyEvent The new key event.
   * @return True if the key event has been consumed, false otherwise.
   */
  public boolean keyEvent(KeyEvent keyEvent) {
    final boolean keyReleased = keyEvent.getID() == KeyEvent.KEY_RELEASED;
    final boolean isEscapeKey = keyEvent.getKeyCode() == KeyEvent.VK_ESCAPE;

    if (keyReleased && isEscapeKey) {
      dragStartPos = null;
      dragCurrentPos = null;
      releaseBackground();
      mapComponent.repaint();
      setDefaultCursor();
      reportClearDistance();
    }

    return false;
  }
  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 boolean dispatchKeyEvent(KeyEvent e) {
   int code = e.getKeyCode();
   int modifiers = e.getModifiers();
   if (code == KeyEvent.VK_ESCAPE) {
     if (isShowingSheet()) {
       discardTopSheet();
       return true;
     }
   }
   if (code == KeyEvent.VK_Q && modifiers == Platform.getPlatform().getCommandModifierMask()) {
     shutdown();
     return true;
   }
   return false;
 }
 /**
  * Handles key down events. Cursor keys are handled by the view the other key events are
  * delegated to the currently active tool.
  */
 public void keyPressed(KeyEvent e) {
   int code = e.getKeyCode();
   if ((code == KeyEvent.VK_BACK_SPACE) || (code == KeyEvent.VK_DELETE)) {
     if (deleteCmd.isExecutable()) {
       deleteCmd.execute();
       //					deleteCmd.viewSelectionChanged(this);
     }
   } else if ((code == KeyEvent.VK_DOWN)
       || (code == KeyEvent.VK_UP)
       || (code == KeyEvent.VK_RIGHT)
       || (code == KeyEvent.VK_LEFT)) {
     handleCursorKey(code);
   } else {
     tool().keyDown(e, code);
   }
   checkDamage();
 }
示例#26
0
 public void keyPressed(KeyEvent e) {
   int keyCode = e.getKeyCode();
   IJ.setKeyDown(keyCode);
   if (keyCode == KeyEvent.VK_ENTER && textArea1 == null && okay != null && okay.isEnabled()) {
     wasOKed = true;
     if (IJ.isMacOSX()) accessTextFields();
     dispose();
   } else if (keyCode == KeyEvent.VK_ESCAPE) {
     wasCanceled = true;
     dispose();
     IJ.resetEscape();
   } else if (keyCode == KeyEvent.VK_W
       && (e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0) {
     wasCanceled = true;
     dispose();
   }
 }
示例#27
0
 void editorPane_keyPressed(KeyEvent e) {
   StyledDocument doc = editorPane.getStyledDocument();
   int pos = editorPane.getCaretPosition();
   int code = e.getKeyCode();
   Element el;
   switch (code) {
     case KeyEvent.VK_BACK_SPACE:
     case KeyEvent.VK_DELETE:
     case KeyEvent.VK_LEFT:
     case KeyEvent.VK_KP_LEFT:
       if (pos == 0) return;
       // we want to get the element to the left of position.
       el = doc.getCharacterElement(pos - 1);
       break;
     case KeyEvent.VK_RIGHT:
     case KeyEvent.VK_KP_RIGHT:
       // we want to get the element to the right of position.
       el = doc.getCharacterElement(pos + 1);
       break;
     default:
       return; // bail we don't handle it.
   }
   AttributeSet attr = el.getAttributes();
   String el_name = (String) attr.getAttribute(StyleConstants.NameAttribute);
   int el_range = el.getEndOffset() - el.getStartOffset() - 1;
   if (el_name.startsWith("Parameter") && StyleConstants.getComponent(attr) != null) {
     try {
       switch (code) {
         case KeyEvent.VK_BACK_SPACE:
         case KeyEvent.VK_DELETE:
           doc.remove(el.getStartOffset(), el_range);
           break;
         case KeyEvent.VK_LEFT:
         case KeyEvent.VK_KP_LEFT:
           editorPane.setCaretPosition(pos - el_range);
           break;
         case KeyEvent.VK_RIGHT:
         case KeyEvent.VK_KP_RIGHT:
           editorPane.setCaretPosition(pos + (el_range));
           break;
       }
     } catch (BadLocationException ex) {
     }
   }
 }
示例#28
0
    @Override
    public void keyPressed(KeyEvent e) {
      switch (e.getKeyCode()) {
        case KeyEvent.VK_CONTEXT_MENU:
          if (popup != null && popup.isVisible()) {
            popup.setVisible(false);
            popup = null;
            return;
          }

          int row = table.getSelectedRow();
          Point pos = new Point(0, row * table.getRowHeight());
          if (row == -1) showFilePopup(null, table, pos);
          else {
            if (!table.getSelectionModel().isSelectedIndex(row))
              table.getSelectionModel().setSelectionInterval(row, row);
            showFilePopup(getSelectedFiles(), table, pos);
          }
          break;
      }
    }
示例#29
0
  public void keyPressed(KeyEvent e) {
    int code = e.getKeyCode();

    Camera cam = cameras.get(0);

    if (state.equals("regular")) {
      if (code == KeyEvent.VK_L) {
        cam.shiftRegion(0.25, 0);
      } else if (code == KeyEvent.VK_R) {
        cam.shiftRegion(-0.25, 0);
      } else if (code == KeyEvent.VK_U) {
        cam.shiftRegion(0, -0.25);
      } else if (code == KeyEvent.VK_D) {
        cam.shiftRegion(0, 0.25);
      } else if (code == KeyEvent.VK_S) {
        cam.scaleRegion(1.1, 1.1);
      } else if (code == KeyEvent.VK_B) {
        cam.scaleRegion(1 / 1.1, 1 / 1.1);
      } else if (code == KeyEvent.VK_W) {
        spread *= 1.1;
      } else if (code == KeyEvent.VK_N) {
        spread /= 1.1;
      } else if (code == KeyEvent.VK_H) {
        cam.setRegion(0, 100, 0, 100);
      }

    } // regular state
    else if (state.equals("add")) {
      if (code == KeyEvent.VK_ENTER) {
        state = "regular";
        if (!stringToAdd.equals("")) tree.add(stringToAdd);
      } else if (code == KeyEvent.VK_DELETE || code == KeyEvent.VK_BACK_SPACE) {
        if (stringToAdd.length() > 0)
          stringToAdd = stringToAdd.substring(0, stringToAdd.length() - 1);
      }
    } // add state
  }
示例#30
0
    private void init(KeyEvent e) {
      byte[] bdata = getBData(e);
      long data = Native.toData(bdata);
      if (data == 0) {
        return;
      }
      try {
        XToolkit.awtLock();
        try {
          keysym = XWindow.getKeySymForAWTKeyCode(e.getKeyCode());
        } finally {
          XToolkit.awtUnlock();
        }
        XKeyEvent ke = new XKeyEvent(data);

        // We recognize only these masks
        modifiers =
            ke.get_state() & (XConstants.ShiftMask | XConstants.ControlMask | XConstants.LockMask);
        if (xembedLog.isLoggable(PlatformLogger.FINEST))
          xembedLog.finest("Mapped " + e + " to " + this);
      } finally {
        XlibWrapper.unsafe.freeMemory(data);
      }
    }