Exemplo n.º 1
0
  public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ESCAPE && gamerunner.running) {

      Graphics gr = this.getGraphics();
      gr.setFont(new Font("TimesRoman", Font.PLAIN, 40));
      gr.drawString("PAUSE", (int) this.getWidth() / 2, this.getHeight() / 2);
      if (!online) {
        gamerunner.running = false;
      }
      if (soundan) {} // end of if
      Menu menu = new Menu(this);
      // volume.setValue(vol);
    } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
      gamerunner.running = true;
      if (soundan) {} // end of if
    } // end of if-else
    else if (e.getKeyCode() == KeyEvent.VK_R && !online) {
      restartGame();
    } else if (e.getKeyCode() == KeyEvent.VK_F11) {
      dispose();
      setUndecorated(true);
      String[] arguments = {"fullscreen"};
      new JavaGame(arguments);
    } else if (e.getKeyCode() == KeyEvent.VK_ENTER && online) {
      String message =
          JOptionPane.showInputDialog(null, "Chat", "Nachricht", JOptionPane.PLAIN_MESSAGE);
      try {
        if (!message.isEmpty()) {
          client.sendNewChatMessage(player[client.id].name, message);
        }
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    }
  }
Exemplo n.º 2
0
  /** This method cannot be called directly. */
  public void keyTyped(KeyEvent e) {
    int keyCode = e.getKeyCode();
    System.out.println(keyCode);
    switch (keyCode) {
      case KeyEvent.VK_W:
        // handle up
        System.out.println("up?");
        break;
      case KeyEvent.VK_DOWN:
        // handle down
        break;
      case KeyEvent.VK_LEFT:
        // handle left
        break;
      case KeyEvent.VK_RIGHT:
        // handle right
        break;
    }
    System.out.println(e.getKeyChar());
    if (e.getKeyChar() == KeyEvent.VK_UP) {
      System.out.println("up arrow pressed");
    }

    synchronized (keyLock) {
      keysTyped.addFirst(e.getKeyChar());
    }
  }
Exemplo n.º 3
0
 public void keyReleased(KeyEvent E) {
   if (E.getKeyCode() == E.VK_ENTER) {
     if (E.getSource() == yes) {
       dispose();
       server.shutdown();
       return;
     } else if (E.getSource() == cancel) {
       dispose();
       return;
     }
   }
 }
Exemplo n.º 4
0
 public void keyTyped(KeyEvent e) {
   char keyChar = e.getKeyChar();
   int flags = e.getModifiers();
   if (IJ.debugMode)
     IJ.log(
         "keyTyped: char=\""
             + keyChar
             + "\" ("
             + (int) keyChar
             + "), flags= "
             + Integer.toHexString(flags)
             + " ("
             + KeyEvent.getKeyModifiersText(flags)
             + ")");
   if (keyChar == '\\' || keyChar == 171 || keyChar == 223) {
     if (((flags & Event.ALT_MASK) != 0)) doCommand("Animation Options...");
     else doCommand("Start Animation [\\]");
   }
 }
Exemplo n.º 5
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;
   }
 }
Exemplo n.º 6
0
  /** This method cannot be called directly. */
  public void keyPressed(KeyEvent e) {
    int keyCode = e.getKeyCode();
    System.out.println("pressed: " + keyCode);
    synchronized (keyLock) {
      keysDown.add(e.getKeyCode());
    }

    if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
      // Right arrow key code
      move(MOVE_RIGHT);
      drawGame();
      //	rx += 0.1;
    } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
      // Left arrow key code
      move(MOVE_LEFT);
      drawGame();
      // rx -= 0.1;
    } else if (e.getKeyCode() == KeyEvent.VK_UP) {
      // Up arrow key code
      move(MOVE_UP);
      drawGame();
      // ry += 0.1;
    } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
      // Down arrow key code
      move(MOVE_DOWN);
      drawGame();
      // ry -= 0.1;
    }
  }
Exemplo n.º 7
0
  public void keyReleased(KeyEvent e) {
    char ch = e.getKeyChar();
    if (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch)) return;
    int pos = m_editor.getCaretPosition();
    String str = m_editor.getText();
    if (str.length() == 0) return;

    for (int k = 0; k < m_comboBox.getItemCount(); k++) {
      String item = m_comboBox.getItemAt(k).toString();
      if (item.startsWith(str)) {
        m_editor.setText(item);
        m_editor.setCaretPosition(item.length());
        m_editor.moveCaretPosition(pos);
        m_comboBox.setSelectedItem(item);
        break;
      }
    }
  }
Exemplo n.º 8
0
 /** This method cannot be called directly. */
 public void keyReleased(KeyEvent e) {
   keysDown.remove(e.getKeyCode());
 }
Exemplo n.º 9
0
 /** This method cannot be called directly. */
 public void keyPressed(KeyEvent e) {
   keysDown.add(e.getKeyCode());
 }
Exemplo n.º 10
0
 /** This method cannot be called directly. */
 public void keyTyped(KeyEvent e) {
   synchronized (keyLock) {
     keysTyped.addFirst(e.getKeyChar());
   }
 }
Exemplo n.º 11
0
 /** This method cannot be called directly. */
 public void keyReleased(KeyEvent e) {
   synchronized (keyLock) {
     keysDown.remove(e.getKeyCode());
   }
 }
Exemplo n.º 12
0
 public void keyReleased(KeyEvent e) {
   IJ.setKeyUp(e.getKeyCode());
 }
Exemplo n.º 13
0
  public void keyPressed(KeyEvent e) {
    // if (e.isConsumed()) return;
    int keyCode = e.getKeyCode();
    IJ.setKeyDown(keyCode);
    hotkey = false;
    if (keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_SHIFT) return;
    char keyChar = e.getKeyChar();
    int flags = e.getModifiers();
    if (IJ.debugMode)
      IJ.log(
          "keyPressed: code="
              + keyCode
              + " ("
              + KeyEvent.getKeyText(keyCode)
              + "), char=\""
              + keyChar
              + "\" ("
              + (int) keyChar
              + "), flags="
              + KeyEvent.getKeyModifiersText(flags));
    boolean shift = (flags & KeyEvent.SHIFT_MASK) != 0;
    boolean control = (flags & KeyEvent.CTRL_MASK) != 0;
    boolean alt = (flags & KeyEvent.ALT_MASK) != 0;
    boolean meta = (flags & KeyEvent.META_MASK) != 0;
    String cmd = null;
    ImagePlus imp = WindowManager.getCurrentImage();
    boolean isStack = (imp != null) && (imp.getStackSize() > 1);

    if (imp != null
        && !control
        && ((keyChar >= 32 && keyChar <= 255) || keyChar == '\b' || keyChar == '\n')) {
      Roi roi = imp.getRoi();
      if (roi instanceof TextRoi) {
        if ((flags & KeyEvent.META_MASK) != 0 && IJ.isMacOSX()) return;
        if (alt) {
          switch (keyChar) {
            case 'u':
            case 'm':
              keyChar = IJ.micronSymbol;
              break;
            case 'A':
              keyChar = IJ.angstromSymbol;
              break;
            default:
          }
        }
        ((TextRoi) roi).addChar(keyChar);
        return;
      }
    }

    // Handle one character macro shortcuts
    if (!control && !meta) {
      Hashtable macroShortcuts = Menus.getMacroShortcuts();
      if (macroShortcuts.size() > 0) {
        if (shift) cmd = (String) macroShortcuts.get(new Integer(keyCode + 200));
        else cmd = (String) macroShortcuts.get(new Integer(keyCode));
        if (cmd != null) {
          // MacroInstaller.runMacroCommand(cmd);
          commandName = cmd;
          MacroInstaller.runMacroShortcut(cmd);
          return;
        }
      }
    }

    if ((!Prefs.requireControlKey || control || meta) && keyChar != '+') {
      Hashtable shortcuts = Menus.getShortcuts();
      if (shift) cmd = (String) shortcuts.get(new Integer(keyCode + 200));
      else cmd = (String) shortcuts.get(new Integer(keyCode));
    }

    if (cmd == null) {
      switch (keyChar) {
        case '<':
        case ',':
          if (isStack) cmd = "Previous Slice [<]";
          break;
        case '>':
        case '.':
        case ';':
          if (isStack) cmd = "Next Slice [>]";
          break;
        case '+':
        case '=':
          cmd = "In [+]";
          break;
        case '-':
          cmd = "Out [-]";
          break;
        case '/':
          cmd = "Reslice [/]...";
          break;
        default:
      }
    }

    if (cmd == null) {
      switch (keyCode) {
        case KeyEvent.VK_TAB:
          WindowManager.putBehind();
          return;
        case KeyEvent.VK_BACK_SPACE: // delete
          if (deleteOverlayRoi(imp)) return;
          cmd = "Clear";
          hotkey = true;
          break;
          // case KeyEvent.VK_BACK_SLASH: cmd=IJ.altKeyDown()?"Animation Options...":"Start
          // Animation"; break;
        case KeyEvent.VK_EQUALS:
          cmd = "In [+]";
          break;
        case KeyEvent.VK_MINUS:
          cmd = "Out [-]";
          break;
        case KeyEvent.VK_SLASH:
        case 0xbf:
          cmd = "Reslice [/]...";
          break;
        case KeyEvent.VK_COMMA:
        case 0xbc:
          if (isStack) cmd = "Previous Slice [<]";
          break;
        case KeyEvent.VK_PERIOD:
        case 0xbe:
          if (isStack) cmd = "Next Slice [>]";
          break;
        case KeyEvent.VK_LEFT:
        case KeyEvent.VK_RIGHT:
        case KeyEvent.VK_UP:
        case KeyEvent.VK_DOWN: // arrow keys
          if (imp == null) return;
          Roi roi = imp.getRoi();
          if (IJ.shiftKeyDown() && imp == Orthogonal_Views.getImage()) return;
          boolean stackKey = imp.getStackSize() > 1 && (roi == null || IJ.shiftKeyDown());
          boolean zoomKey = roi == null || IJ.shiftKeyDown() || IJ.controlKeyDown();
          if (stackKey && keyCode == KeyEvent.VK_RIGHT) cmd = "Next Slice [>]";
          else if (stackKey && keyCode == KeyEvent.VK_LEFT) cmd = "Previous Slice [<]";
          else if (zoomKey
              && keyCode == KeyEvent.VK_DOWN
              && !ignoreArrowKeys(imp)
              && Toolbar.getToolId() < Toolbar.SPARE6) cmd = "Out [-]";
          else if (zoomKey
              && keyCode == KeyEvent.VK_UP
              && !ignoreArrowKeys(imp)
              && Toolbar.getToolId() < Toolbar.SPARE6) cmd = "In [+]";
          else if (roi != null) {
            if ((flags & KeyEvent.ALT_MASK) != 0) roi.nudgeCorner(keyCode);
            else roi.nudge(keyCode);
            return;
          }
          break;
        case KeyEvent.VK_ESCAPE:
          abortPluginOrMacro(imp);
          return;
        case KeyEvent.VK_ENTER:
          WindowManager.toFront(this);
          return;
        default:
          break;
      }
    }

    if (cmd != null && !cmd.equals("")) {
      commandName = cmd;
      if (cmd.equals("Fill") || cmd.equals("Draw")) hotkey = true;
      if (cmd.charAt(0) == MacroInstaller.commandPrefix) MacroInstaller.runMacroShortcut(cmd);
      else {
        doCommand(cmd);
        keyPressedTime = System.currentTimeMillis();
        lastKeyCommand = cmd;
      }
    }
  }
Exemplo n.º 14
0
 /** This method cannot be called directly. */
 public void keyPressed(KeyEvent e) {
   synchronized (keyLock) {
     keysDown.add(e.getKeyCode());
   }
 }