Example #1
0
  protected boolean processKeyBinding(
      javax.swing.KeyStroke ks, java.awt.event.KeyEvent e, int condition, boolean pressed) {
    // live search in current parent node
    if ((Character.isLetterOrDigit(e.getKeyChar())) && ks.isOnKeyRelease()) {
      char keyChar = e.getKeyChar();

      // search term
      String search = ("" + keyChar).toLowerCase();

      // try to find node with matching searchterm plus the search before
      int nextIndexMatching = getNextIndexMatching(cachedSearchKey + search);

      // if we did not find anything, try to find search term only: restart!
      if (nextIndexMatching < 0) {
        nextIndexMatching = getNextIndexMatching(search);
        cachedSearchKey = "";
      }
      // if we found a node, select it, make it visible and return true
      if (nextIndexMatching >= 0) {

        // store found treepath
        cachedSearchKey = cachedSearchKey + search;
        setSelectedIndex(nextIndexMatching);
        return true;
      }
      cachedSearchKey = "";
      return true;
    }
    return super.processKeyBinding(ks, e, condition, pressed);
  }
 void objectTable_keyTyped(KeyEvent e) {
   if (e.getKeyCode() == KeyEvent.VK_DELETE) {
     removeCurrent();
   } else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
     editCurrent();
   }
 }
    /**
     * I made this method public in order to be able to call it from the outside. This is needed for
     * delegating calls.
     */
    public void processKeyEvent(KeyEvent e) {
      int i = e.getKeyCode();
      if (i == KeyEvent.VK_BACK_SPACE && getDocument().getLength() == 0) {
        e.consume();
        return;
      }
      if (i == KeyEvent.VK_ENTER
          || i == KeyEvent.VK_ESCAPE
          || i == KeyEvent.VK_PAGE_UP
          || i == KeyEvent.VK_PAGE_DOWN
          || i == KeyEvent.VK_LEFT
          || i == KeyEvent.VK_RIGHT) {
        manageSearchPopup(null);
        if (i == KeyEvent.VK_ESCAPE) {
          e.consume();
        }
        return;
      }

      if (isUpDownHomeEnd(i)) {
        e.consume();
        return;
      }

      super.processKeyEvent(e);
      if (i == KeyEvent.VK_BACK_SPACE) {
        e.consume();
      }
    }
Example #4
0
 void dispatch() {
   synchronized (events) {
     if (mousemv != null) {
       mousepos = new Coord(mousemv.getX(), mousemv.getY());
       ui.mousemove(mousemv, mousepos);
       mousemv = null;
     }
     InputEvent e = null;
     while ((e = events.poll()) != null) {
       if (e instanceof MouseEvent) {
         MouseEvent me = (MouseEvent) e;
         if (me.getID() == MouseEvent.MOUSE_PRESSED) {
           ui.mousedown(me, new Coord(me.getX(), me.getY()), me.getButton());
         } else if (me.getID() == MouseEvent.MOUSE_RELEASED) {
           ui.mouseup(me, new Coord(me.getX(), me.getY()), me.getButton());
         } else if (me instanceof MouseWheelEvent) {
           ui.mousewheel(
               me, new Coord(me.getX(), me.getY()), ((MouseWheelEvent) me).getWheelRotation());
         }
       } else if (e instanceof KeyEvent) {
         KeyEvent ke = (KeyEvent) e;
         if (ke.getID() == KeyEvent.KEY_PRESSED) {
           ui.keydown(ke);
         } else if (ke.getID() == KeyEvent.KEY_RELEASED) {
           ui.keyup(ke);
         } else if (ke.getID() == KeyEvent.KEY_TYPED) {
           ui.type(ke);
         }
       }
       ui.lastevent = System.currentTimeMillis();
     }
   }
 }
Example #5
0
 private void jtfRacionAsignadaKeyTyped(
     java.awt.event.KeyEvent evt) { // GEN-FIRST:event_jtfRacionAsignadaKeyTyped
   // TODO add your handling code here:
   if (!Character.isDigit(evt.getKeyChar()) || evt.getKeyChar() != '.') {
     evt.consume();
   }
 } // GEN-LAST:event_jtfRacionAsignadaKeyTyped
Example #6
0
 public void keyReleased(KeyEvent e) {
   if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
     keyStates.put(KeyStates.CONTROL, false);
   } else if (e.getKeyCode() == KeyEvent.VK_ALT) {
     keyStates.put(KeyStates.ALT, false);
   }
 }
  public void keyPressed(final KeyEvent e) {

    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
      // on enter add new unit to workflow
      final JTree tree = (JTree) e.getSource();

      if (tree.getSelectionRows() != null && tree.getSelectionRows().length > 0) {
        // with 'Enter' all selected Units were inserted, therefore used an array
        final int[] selRows = tree.getSelectionRows();

        final TreePath[] selPaths = new TreePath[selRows.length];
        for (int i = 0; i < selRows.length; i++) {
          selPaths[i] = tree.getPathForRow(selRows[i]);
        }

        final Point insertPoint = UnitDelegate.POINT;
        // counts only Units, not Folders
        int realUnitCount = 0;

        for (int i = 0; i < selRows.length; i++) {
          if (selRows[i] != -1 && selPaths[i].getLastPathComponent() instanceof UnitDelegate) {
            final UnitDelegate delegate = ((UnitDelegate) selPaths[i].getLastPathComponent());
            Point point =
                new Point(
                    insertPoint.x + realUnitCount * GraphPanel.GRIDSIZE,
                    insertPoint.y + realUnitCount * GraphPanel.GRIDSIZE);
            GraphControllerManager.getInstance().getController().addNode(delegate, point);

            realUnitCount++;
          }
        }
      }
    }
  }
Example #8
0
  @Override
  public void keyPressed(KeyEvent evt) {
    Figure f = getOwner();
    if (f.isTransformable()) {
      AffineTransform tx = new AffineTransform();

      switch (evt.getKeyCode()) {
        case KeyEvent.VK_UP:
          tx.translate(0, -1);
          evt.consume();
          break;
        case KeyEvent.VK_DOWN:
          tx.translate(0, +1);
          evt.consume();
          break;
        case KeyEvent.VK_LEFT:
          tx.translate(-1, 0);
          evt.consume();
          break;
        case KeyEvent.VK_RIGHT:
          tx.translate(+1, 0);
          evt.consume();
          break;
      }
      f.willChange();
      f.transform(tx);
      f.changed();
      fireUndoableEditHappened(new TransformEdit(f, tx));
    }
  }
  @Override
  public void keyPressed(final KeyEvent e) {
    //		System.out.println( "MouseAndKeyHandler.keyPressed()" );
    update();

    if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
      shiftPressed = true;
    } else if (e.getKeyCode() == KeyEvent.VK_META) {
      metaPressed = true;
    } else if (e.getKeyCode() != KeyEvent.VK_ALT
        && e.getKeyCode() != KeyEvent.VK_CONTROL
        && e.getKeyCode() != KeyEvent.VK_ALT_GRAPH) {
      pressedKeys.add(e.getKeyCode());

      final int mask = getMask(e);

      for (final BehaviourEntry<DragBehaviour> drag : keyDrags) {
        if (!activeKeyDrags.contains(drag) && drag.buttons.matches(mask, pressedKeys)) {
          drag.behaviour.init(mouseX, mouseY);
          activeKeyDrags.add(drag);
        }
      }

      for (final BehaviourEntry<ClickBehaviour> click : keyClicks) {
        if (click.buttons.matches(mask, pressedKeys)) {
          click.behaviour.click(mouseX, mouseY);
        }
      }
    }
  }
        /**
         * The keyReleased event ensures that the caret-position is updated for both peers, when the
         * user moves the caret with the arrow-keys.
         */
        public void keyReleased(KeyEvent e) {
          int left = e.VK_LEFT;
          int right = e.VK_RIGHT;
          int up = e.VK_UP;
          int down = e.VK_DOWN;
          int home = e.VK_HOME;
          int end = e.VK_END;
          int A = e.VK_A;
          int kc = e.getKeyCode();

          if (kc == left
              || kc == right
              || kc == up
              || kc == down
              || kc == home
              || kc == end
              || (kc == A && e.isControlDown())) {
            if (dec == null) return;
            lc.increment();
            TextEvent cu = new CaretUpdate(area1.getCaretPosition(), lc.getTimeStamp());
            dec.sendObjectToAllPeers(cu);
            er.getEventHistoryLock().lock();
            er.getEventHistory().add(cu);
            er.getEventHistoryLock().unlock();
          }
        }
 public void keyTyped(java.awt.event.KeyEvent evt) {
   if (evt.getSource() == tf_cantidad) {
     MovimientoArticuloModificarEliminar.this.tf_cantidadKeyTyped(evt);
   } else if (evt.getSource() == tf_valor) {
     MovimientoArticuloModificarEliminar.this.tf_valorKeyTyped(evt);
   }
 }
Example #12
0
 @Override
 public void keyTyped(KeyEvent e) {
   char caracter = e.getKeyChar();
   if (((caracter < '0') || (caracter > '9')) && (caracter != '.')) {
     e.consume();
   }
 }
    public void keyPressed(KeyEvent keyEvent) {
      keyEvent.getKeyCode();

      if (keyEvent.getKeyCode() == KeyEvent.VK_ESCAPE) {
        System.exit(0);
      }
    }
Example #14
0
 private void PrecioKeyTyped(java.awt.event.KeyEvent evt) { // GEN-FIRST:event_PrecioKeyTyped
   // TODO add your handling code here:
   int cont = 0;
   char caracter = evt.getKeyChar();
   if (cont == 0) {
     if (((caracter < '0') || (caracter > '9'))
         && (caracter != KeyEvent.VK_BACK_SPACE)
         && (caracter != '.')) {
       evt.consume();
     } else if (caracter == '.') {
       String s = Precio.getText();
       if (s.length() == 0) {
         Precio.setText(0 + s);
       }
       cont++;
     }
   } else {
     if ((caracter < '0' || caracter > '9')) evt.consume();
   }
   if ((int) caracter == 8) {
     if (Precio.getText().equals("")) {
       cont = 0;
     }
   }
 } // GEN-LAST:event_PrecioKeyTyped
Example #15
0
 @Action
 private void keyTyped(java.awt.event.KeyEvent evt) { // {{{
   switch (evt.getKeyCode()) {
     case KeyEvent.VK_ENTER:
       // sendAsyncTweet();
       btnTweet.doClick();
       // sendTweetClicked().execute();
       break;
     case KeyEvent.VK_M:
       if (evt.isControlDown()) view.showMiniMode();
       break;
     case KeyEvent.VK_ESCAPE:
       view.getMainApp().toggleWindowView("down");
       break;
       //	default:
       //		int c = txtTweet.getDocument().getLength();
       //		lblChars.setText((140 - c)+"");
       //		if((c > 0) && (c < 141)) {
       //			btnTweet.setEnabled(true);
       //			lblChars.setForeground(getResourceMap().getColor("lblChars.foreground"));
       //		}
       //		else if(c > 140) {
       //			lblChars.setForeground(Color.RED);
       //			btnTweet.setEnabled(false);
       //		}
       //		else
       //		{
       //			btnTweet.setEnabled(false);
       //		}
   }
 } // }}}
Example #16
0
  @Override
  /** met a jour les commandes en fonctions des touches appuyees */
  public void keyPressed(KeyEvent e) {

    switch (e.getKeyChar()) {
        // si on appuie sur 'q',commande joueur est gauche
      case 'q':
        this.commandeEnCours.gauche = true;
        break;
        // si on appuie sur 'd',commande joueur est droite
      case 'd':
        this.commandeEnCours.droite = true;
        break;
        // si on appuie sur 'z',commande joueur est haut
      case 'z':
        this.commandeEnCours.haut = true;
        break;
        // si on appuie sur 's',commande joueur est bas
      case 's':
        this.commandeEnCours.bas = true;
        break;
    }

    switch (e.getKeyCode()) {
      case KeyEvent.VK_SPACE:
        this.commandeEnCours.attaque = true;
    }
  }
Example #17
0
 public void keyPressed(KeyEvent e) {
   if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
     keyStates.put(KeyStates.CONTROL, true);
   } else if (e.getKeyCode() == KeyEvent.VK_ALT) {
     keyStates.put(KeyStates.ALT, true);
   }
 }
  @Override
  public void keyPressed(final KeyEvent e) {
    if (!(e.isAltDown() || e.isMetaDown() || e.isControlDown() || myPanel.isNodePopupActive())) {
      if (!Character.isLetter(e.getKeyChar())) {
        return;
      }

      final IdeFocusManager focusManager = IdeFocusManager.getInstance(myPanel.getProject());
      final ActionCallback firstCharTyped = new ActionCallback();
      focusManager.typeAheadUntil(firstCharTyped);
      myPanel.moveDown();
      //noinspection SSBasedInspection
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              try {
                final Robot robot = new Robot();
                final boolean shiftOn = e.isShiftDown();
                final int code = e.getKeyCode();
                if (shiftOn) {
                  robot.keyPress(KeyEvent.VK_SHIFT);
                }
                robot.keyPress(code);
                robot.keyRelease(code);

                // don't release Shift
                firstCharTyped.setDone();
              } catch (AWTException ignored) {
              }
            }
          });
    }
  }
  /*
   * if an action key is released the coressponding boolean becomes false end
   * the action is not executed any more
   **/
  public void keyReleased(KeyEvent e) {
    if (e.getKeyCode() == fire) {
      dropBombKeyPressed = false;
      interrupt();
    }

    if (e.getKeyCode() == left) {
      leftKeyPressed = false;
      enable = true;
      interrupt();
    }
    if (e.getKeyCode() == up) {
      upKeyPressed = false;
      enable = true;
      interrupt();
    }

    if (e.getKeyCode() == right) {
      rightKeyPressed = false;
      enable = true;
      interrupt();
    }
    if (e.getKeyCode() == down) {
      downKeyPressed = false;
      enable = true;
      interrupt();
    }
  }
  /** KeyListener method. */
  @Override
  public void keyPressed(KeyEvent ke) {
    animator.start();
    int DELTA_SIZE = 1;

    switch (ke.getKeyCode()) {
      case KeyEvent.VK_UP:
        gcodeRenderer.pan(0, DELTA_SIZE);
        // this.eye.y+=DELTA_SIZE;
        break;
      case KeyEvent.VK_DOWN:
        gcodeRenderer.pan(0, -DELTA_SIZE);
        break;
      case KeyEvent.VK_LEFT:
        gcodeRenderer.pan(-DELTA_SIZE, 0);
        break;
      case KeyEvent.VK_RIGHT:
        gcodeRenderer.pan(DELTA_SIZE, 0);
        break;
      case KeyEvent.VK_MINUS:
        if (ke.isControlDown()) gcodeRenderer.zoom(-1);
        break;
      case KeyEvent.VK_0:
      case KeyEvent.VK_ESCAPE:
        gcodeRenderer.resetView();
        break;
    }

    switch (ke.getKeyChar()) {
      case '+':
        if (ke.isControlDown()) gcodeRenderer.zoom(1);
        break;
    }
  }
  /**
   * Method declaration
   *
   * @param k
   */
  public void keyTyped(KeyEvent k) {

    if (k.getKeyChar() == '\n' && k.isControlDown()) {
      k.consume();
      execute();
    }
  }
 private void txtEstablecimientoKeyTyped(
     java.awt.event.KeyEvent evt) { // GEN-FIRST:event_txtEstablecimientoKeyTyped
   // TODO add your handling code here:
   if (!Character.isDigit(evt.getKeyChar()) && evt.getKeyChar() != '\t') {
     evt.consume();
   }
 } // GEN-LAST:event_txtEstablecimientoKeyTyped
 @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();
     }
   }
 }
Example #24
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());
    }
  }
Example #25
0
 /**
  * Used only on Mac OS, to remove key modifiers that are used to simulate mouse buttons 2 and 3.
  * Returns whether the event should be ignored.
  */
 private boolean pruneClickModifiers(AWTEvent event) {
   lastButton = 0;
   boolean ignoreEvent = false;
   if (event.getID() == MouseEvent.MOUSE_PRESSED) {
     MouseEvent me = (MouseEvent) event;
     int buttons = me.getModifiers() & (MouseEvent.BUTTON2_MASK | MouseEvent.BUTTON3_MASK);
     pruneButtonModifier = buttons != 0;
     lastButton = buttons;
   } else if (event.getID() == KeyEvent.KEY_RELEASED && pruneButtonModifier) {
     pruneButtonModifier = false;
     KeyEvent ke = (KeyEvent) event;
     int code = ke.getKeyCode();
     if ((code == KeyEvent.VK_CONTROL
             || code == KeyEvent.VK_ALT && (lastButton & MouseEvent.BUTTON2_MASK) != 0)
         || (code == KeyEvent.VK_META && (lastButton & MouseEvent.BUTTON3_MASK) != 0)) {
       if (steps.size() > 1) {
         Step step = (Step) steps.get(steps.size() - 2);
         if ((code == KeyEvent.VK_CONTROL && isKey(step, "VK_CONTROL", PRESS)
                 || (code == KeyEvent.VK_ALT && isKey(step, "VK_ALT", PRESS)))
             || (code == KeyEvent.VK_META && isKey(step, "VK_META", PRESS))) {
           // might be another one
           steps.remove(steps.size() - 2);
           pruneButtonModifier = true;
           ignoreEvent = true;
         }
       }
     }
   }
   return ignoreEvent;
 }
  public static boolean isTooltipRequest(KeyEvent keyEvent) {
    if (ourTooltipKeysProperty == null) {
      ourTooltipKeysProperty = Registry.get("ide.forcedShowTooltip");
      ourTooltipKeysProperty.addListener(
          new RegistryValueListener.Adapter() {
            @Override
            public void afterValueChanged(RegistryValue value) {
              updateTooltipRequestKey(value);
            }
          },
          Disposer.get("ui"));

      updateTooltipRequestKey(ourTooltipKeysProperty);
    }

    if (keyEvent.getID() != KeyEvent.KEY_PRESSED) return false;

    for (Integer each : ourTooltipKeys) {
      if ((keyEvent.getModifiers() & each.intValue()) == 0) return false;
    }

    for (Integer each : ourOtherTooltipKeys) {
      if ((keyEvent.getModifiers() & each.intValue()) > 0) return false;
    }

    final int code = keyEvent.getKeyCode();

    return code == KeyEvent.VK_META
        || code == KeyEvent.VK_CONTROL
        || code == KeyEvent.VK_SHIFT
        || code == KeyEvent.VK_ALT;
  }
Example #27
0
  @Override
  public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
      System.exit(0);
    }

    // TODO Auto-generated method stub
    if (state == 1) // we are in a story
    {
      if (fadeCounter < FADETIMELIMIT) {
        fadeCounter = FADETIMELIMIT;
        oldbg = bg;
      }

      fadeUpdate = true;
      fadeCounter = 0;
      progress(); // keep going
    } else if (state == 2) {
      if (e.getKeyCode() == KeyEvent.VK_1) {
        index = next(tag, index, 1);
        progress();
      } else if (e.getKeyCode() == KeyEvent.VK_2) {
        index = next(tag, index, 2);
        progress();
      } else if (e.getKeyCode() == KeyEvent.VK_3) {
        index = next(tag, index, 3);
        progress();
      }
    }
  }
Example #28
0
 private void reOrderKeyTyped(java.awt.event.KeyEvent evt) { // GEN-FIRST:event_reOrderKeyTyped
   char c = evt.getKeyChar();
   if (!(Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))) {
     getToolkit().beep();
     evt.consume();
   }
 } // GEN-LAST:event_reOrderKeyTyped
Example #29
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();
  }
Example #30
0
 /** @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent) */
 public void keyPressed(KeyEvent ke) {
   int key = ke.getKeyCode();
   if (key == KeyEvent.VK_UP || key == KeyEvent.VK_DOWN) {
     CompartmentFigText ft = unhighlight();
     if (ft != null) {
       int i = new Vector(getAttributesFig().getFigs()).indexOf(ft);
       FigGroup fg = getAttributesFig();
       if (i == -1) {
         i = new Vector(getOperationsFig().getFigs()).indexOf(ft);
         fg = getOperationsFig();
       }
       if (i != -1) {
         if (key == KeyEvent.VK_UP) {
           ft = (CompartmentFigText) getPreviousVisibleFeature(fg, ft, i);
         } else {
           ft = (CompartmentFigText) getNextVisibleFeature(fg, ft, i);
         }
         if (ft != null) {
           ft.setHighlighted(true);
           highlightedFigText = ft;
           return;
         }
       }
     }
   } else if (key == KeyEvent.VK_ENTER && highlightedFigText != null) {
     highlightedFigText.startTextEditor(ke);
     ke.consume();
     return;
   }
   super.keyPressed(ke);
 }