示例#1
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);
   }
 }
示例#2
0
 /**
  * handle event
  *
  * @param e event
  */
 public void keyReleased(KeyEvent e) {
   if (e.isControlDown() && (e.getKeyCode() == KeyEvent.VK_P)) {
     List selectionSet = getSelection();
     if (selectionSet.size() == 1) {
       showProperties((MetSymbol) selectionSet.get(0));
     }
     return;
   }
   super.keyReleased(e);
 }
示例#3
0
 public void keyReleased(KeyEvent e) {
   if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
     shiftPressed = false;
     repaint();
   }
   if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
     controlPressed = false;
     repaint();
   }
 }
示例#4
0
    public void processKeyEvent(KeyEvent evt) {
      evt = KeyEventWorkaround.processKeyEvent(evt);
      if (evt == null) return;

      switch (evt.getID()) {
        case KeyEvent.KEY_TYPED:
          char ch = evt.getKeyChar();
          if (!nonDigit && Character.isDigit(ch)) {
            super.processKeyEvent(evt);
            repeat = true;
            repeatCount = Integer.parseInt(action.getText());
          } else {
            nonDigit = true;
            if (repeat) {
              passToView(evt);
            } else super.processKeyEvent(evt);
          }
          break;
        case KeyEvent.KEY_PRESSED:
          int keyCode = evt.getKeyCode();
          if (evt.isActionKey()
              || evt.isControlDown()
              || evt.isAltDown()
              || evt.isMetaDown()
              || keyCode == KeyEvent.VK_BACK_SPACE
              || keyCode == KeyEvent.VK_DELETE
              || keyCode == KeyEvent.VK_ENTER
              || keyCode == KeyEvent.VK_TAB
              || keyCode == KeyEvent.VK_ESCAPE) {
            nonDigit = true;
            if (repeat) {
              passToView(evt);
              break;
            } else if (keyCode == KeyEvent.VK_TAB) {
              complete(true);
              evt.consume();
            } else if (keyCode == KeyEvent.VK_ESCAPE) {
              evt.consume();
              if (popup != null) {
                popup.dispose();
                popup = null;
                action.requestFocus();
              } else {
                if (temp) view.removeToolBar(ActionBar.this);
                view.getEditPane().focusOnTextArea();
              }
              break;
            } else if ((keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN)
                && popup != null) {
              popup.list.processKeyEvent(evt);
              break;
            }
          }
          super.processKeyEvent(evt);
          break;
      }
    }
    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]);
        }
      }
    }
示例#6
0
 /**
  * Processes key stroke events such as mnemonics and accelerators.
  *
  * @param evt the key event to be processed
  */
 protected void processKeyEvent(KeyEvent evt) {
   MenuSelectionManager.defaultManager().processKeyEvent(evt);
   if (evt.isConsumed()) {
     return;
   }
   super.processKeyEvent(evt);
 }
示例#7
0
 public void keyPressed(KeyEvent evt) {
   int keyCode = evt.getKeyCode();
   if (keyCode == KeyEvent.VK_ESCAPE) action.processKeyEvent(evt);
   else if (keyCode == KeyEvent.VK_ENTER) invoke();
   else if (keyCode == KeyEvent.VK_UP) {
     int selected = list.getSelectedIndex();
     if (selected == 0) {
       list.setSelectedIndex(list.getModel().getSize() - 1);
       evt.consume();
     }
   } else if (keyCode == KeyEvent.VK_DOWN) {
     int selected = list.getSelectedIndex();
     if (selected == list.getModel().getSize() - 1) {
       list.setSelectedIndex(0);
       evt.consume();
     }
   }
 }
示例#8
0
  public void keyTyped(KeyEvent e) {
    char key = e.getKeyChar();

    if (state.equals("regular") && key == 'a') {
      stringToAdd = "";
      state = "add";
    } else if (state.equals("add") && (' ' <= key && key <= '~')) {
      stringToAdd += key;
    }
  }
  /**
   * When a MenuElement receives an event from a KeyListener, it should never process the event
   * directly. Instead all MenuElements should call this method with the event.
   *
   * @param e a KeyEvent object
   */
  public void processKeyEvent(KeyEvent e) {
    MenuElement[] sel2 = new MenuElement[0];
    sel2 = selection.toArray(sel2);
    int selSize = sel2.length;
    MenuElement[] path;

    if (selSize < 1) {
      return;
    }

    for (int i = selSize - 1; i >= 0; i--) {
      MenuElement elem = sel2[i];
      MenuElement[] subs = elem.getSubElements();
      path = null;

      for (int j = 0; j < subs.length; j++) {
        if (subs[j] == null
            || !subs[j].getComponent().isShowing()
            || !subs[j].getComponent().isEnabled()) {
          continue;
        }

        if (path == null) {
          path = new MenuElement[i + 2];
          System.arraycopy(sel2, 0, path, 0, i + 1);
        }
        path[i + 1] = subs[j];
        subs[j].processKeyEvent(e, path, this);
        if (e.isConsumed()) {
          return;
        }
      }
    }

    // finally dispatch event to the first component in path
    path = new MenuElement[1];
    path[0] = sel2[0];
    path[0].processKeyEvent(e, path, this);
    if (e.isConsumed()) {
      return;
    }
  }
示例#10
0
 // KeyListener interface ---------------
 public void keyPressed(KeyEvent e) {
   int code = e.getKeyCode();
   switch (code) {
     case KeyEvent.VK_DOWN:
       fireActionPerformed("down");
       e.consume();
       break;
     case KeyEvent.VK_UP:
       fireActionPerformed("up");
       e.consume();
       break;
     case KeyEvent.VK_PAGE_DOWN:
       fireActionPerformed("next");
       e.consume();
       break;
     case KeyEvent.VK_PAGE_UP:
       fireActionPerformed("prev");
       e.consume();
       break;
   }
 }
示例#11
0
 /**
  * Forwards key events directly to the input handler. This is slightly faster than using a
  * KeyListener because some Swing overhead is avoided.
  */
 public void processKeyEvent(KeyEvent evt) {
   if (inputHandler == null) return;
   switch (evt.getID()) {
     case KeyEvent.KEY_TYPED:
       inputHandler.keyTyped(evt);
       break;
     case KeyEvent.KEY_PRESSED:
       inputHandler.keyPressed(evt);
       break;
     case KeyEvent.KEY_RELEASED:
       inputHandler.keyReleased(evt);
       break;
   }
 }
 // Implementation of keyPressed
 public void keyPressed(KeyEvent e) {
   if (e.getSource() == searchbutton && e.getKeyCode() == KeyEvent.VK_ENTER) {
     update();
   } else if (e.getSource() == addfeesbutton && e.getKeyCode() == KeyEvent.VK_ENTER) {
     addFees();
   } else if (e.getSource() == addcoursebutton && e.getKeyCode() == KeyEvent.VK_ENTER) {
     addCourse();
   }
 }
示例#13
0
  public void keyTyped(KeyEvent e) {
    char code = e.getKeyChar();
    if (code == e.VK_ENTER) {
      //      if (dataField != null)
      {
        e.setKeyChar(e.CHAR_UNDEFINED);
        e.setKeyCode(-1);

        // only fire this event, if the data has been changed
        if (textField.isDataChanged()) {
          fireActionPerformed("enter");
        }

        // not shift + enter => focus to next
        if ((e.getModifiers() & e.SHIFT_MASK) != e.SHIFT_MASK) {
          this.changeFocusToNext();
        }
      }
    } else {
      if (!TKeyLock.keys.isLocked()) {
        textField.setDataChanged(true);
      }
    }
  }
示例#14
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) {
     }
   }
 }
示例#15
0
  /**
   * Processes a key event forwarded from the <code>MenuSelectionManager</code> and changes the menu
   * selection, if necessary, by using <code>MenuSelectionManager</code>'s API.
   *
   * <p>Note: you do not have to forward the event to sub-components. This is done automatically by
   * the <code>MenuSelectionManager</code>.
   *
   * @param e a <code>KeyEvent</code>
   * @param path the <code>MenuElement</code> path array
   * @param manager the <code>MenuSelectionManager</code>
   */
  public void processKeyEvent(KeyEvent e, MenuElement path[], MenuSelectionManager manager) {
    MenuKeyEvent mke =
        new MenuKeyEvent(
            e.getComponent(),
            e.getID(),
            e.getWhen(),
            e.getModifiers(),
            e.getKeyCode(),
            e.getKeyChar(),
            path,
            manager);
    processMenuKeyEvent(mke);

    if (mke.isConsumed()) {
      e.consume();
    }
  }
示例#16
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));
          }
        }
示例#17
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;
      }
    }
示例#18
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
  }
示例#19
0
 void fireBinding(JComponent c, KeyStroke ks, KeyEvent e, boolean pressed) {
   if (c.processKeyBinding(ks, e, JComponent.WHEN_IN_FOCUSED_WINDOW, pressed)) {
     e.consume();
   }
 }
示例#20
0
  /**
   * This method is called when the focused component (and none of its ancestors) want the key
   * event. This will look up the keystroke to see if any chidren (or subchildren) of the specified
   * container want a crack at the event. If one of them wants it, then it will "DO-THE-RIGHT-THING"
   */
  public boolean fireKeyboardAction(KeyEvent e, boolean pressed, Container topAncestor) {

    if (e.isConsumed()) {
      System.out.println("Acquired pre-used event!");
      Thread.dumpStack();
    }

    // There may be two keystrokes associated with a low-level key event;
    // in this case a keystroke made of an extended key code has a priority.
    KeyStroke ks;
    KeyStroke ksE = null;

    if (e.getID() == KeyEvent.KEY_TYPED) {
      ks = KeyStroke.getKeyStroke(e.getKeyChar());
    } else {
      if (e.getKeyCode() != e.getExtendedKeyCode()) {
        ksE = KeyStroke.getKeyStroke(e.getExtendedKeyCode(), e.getModifiers(), !pressed);
      }
      ks = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers(), !pressed);
    }

    Hashtable keyMap = containerMap.get(topAncestor);
    if (keyMap != null) { // this container isn't registered, so bail

      Object tmp = null;
      // extended code has priority
      if (ksE != null) {
        tmp = keyMap.get(ksE);
        if (tmp != null) {
          ks = ksE;
        }
      }
      if (tmp == null) {
        tmp = keyMap.get(ks);
      }

      if (tmp == null) {
        // don't do anything
      } else if (tmp instanceof JComponent) {
        JComponent c = (JComponent) tmp;
        if (c.isShowing() && c.isEnabled()) { // only give it out if enabled and visible
          fireBinding(c, ks, e, pressed);
        }
      } else if (tmp instanceof Vector) { // more than one comp registered for this
        Vector v = (Vector) tmp;
        // There is no well defined order for WHEN_IN_FOCUSED_WINDOW
        // bindings, but we give precedence to those bindings just
        // added. This is done so that JMenus WHEN_IN_FOCUSED_WINDOW
        // bindings are accessed before those of the JRootPane (they
        // both have a WHEN_IN_FOCUSED_WINDOW binding for enter).
        for (int counter = v.size() - 1; counter >= 0; counter--) {
          JComponent c = (JComponent) v.elementAt(counter);
          // System.out.println("Trying collision: " + c + " vector = "+ v.size());
          if (c.isShowing() && c.isEnabled()) { // don't want to give these out
            fireBinding(c, ks, e, pressed);
            if (e.isConsumed()) return true;
          }
        }
      } else {
        System.out.println("Unexpected condition in fireKeyboardAction " + tmp);
        // This means that tmp wasn't null, a JComponent, or a Vector.  What is it?
        Thread.dumpStack();
      }
    }

    if (e.isConsumed()) {
      return true;
    }
    // if no one else handled it, then give the menus a crack
    // The're handled differently.  The key is to let any JMenuBars
    // process the event
    if (keyMap != null) {
      Vector v = (Vector) keyMap.get(JMenuBar.class);
      if (v != null) {
        Enumeration iter = v.elements();
        while (iter.hasMoreElements()) {
          JMenuBar mb = (JMenuBar) iter.nextElement();
          if (mb.isShowing() && mb.isEnabled()) { // don't want to give these out
            boolean extended = (ksE != null) && !ksE.equals(ks);
            if (extended) {
              fireBinding(mb, ksE, e, pressed);
            }
            if (!extended || !e.isConsumed()) {
              fireBinding(mb, ks, e, pressed);
            }
            if (e.isConsumed()) {
              return true;
            }
          }
        }
      }
    }

    return e.isConsumed();
  }
示例#21
0
 public void keyTyped(KeyEvent ke) {
   if (ke.getKeyChar() == KeyEvent.VK_ENTER) {
     sendMessage();
   }
 }
示例#22
0
 @Override
 protected void processKeyEvent(KeyEvent evt) {
   if (evt.getID() == KeyEvent.KEY_PRESSED) {
     ActionContext ac = VFSBrowser.getActionContext();
     int row = parentDirectories.getSelectedIndex();
     switch (evt.getKeyCode()) {
       case KeyEvent.VK_DOWN:
         evt.consume();
         if (row < parentDirectories.getSize().height - 1)
           parentDirectories.setSelectedIndex(++row);
         break;
       case KeyEvent.VK_LEFT:
         if ((evt.getModifiers() & InputEvent.ALT_MASK) > 0) {
           evt.consume();
           browser.previousDirectory();
         } else super.processEvent(evt);
         break;
       case KeyEvent.VK_RIGHT:
         if ((evt.getModifiers() & InputEvent.ALT_MASK) > 0) {
           evt.consume();
           browser.nextDirectory();
         } else super.processEvent(evt);
         break;
       case KeyEvent.VK_TAB:
         evt.consume();
         if ((evt.getModifiers() & InputEvent.SHIFT_MASK) > 0) browser.focusOnDefaultComponent();
         else table.requestFocus();
         break;
       case KeyEvent.VK_UP:
         evt.consume();
         if (row > 0) {
           parentDirectories.setSelectedIndex(--row);
         }
         break;
       case KeyEvent.VK_BACK_SPACE:
         evt.consume();
         EditAction up = ac.getAction("vfs.browser.up");
         ac.invokeAction(evt, up);
         break;
       case KeyEvent.VK_F5:
         evt.consume();
         EditAction reload = ac.getAction("vfs.browser.reload");
         ac.invokeAction(evt, reload);
         break;
       case KeyEvent.VK_ENTER:
         evt.consume();
         if (row != -1) {
           // basically the same handling as in ParentMouseHandler#mouseReleased
           Object obj = parentDirectories.getModel().getElementAt(row);
           if (obj instanceof VFSFile) {
             VFSFile dirEntry = (VFSFile) obj;
             browser.setDirectory(dirEntry.getPath());
             if (browser.getMode() == VFSBrowser.BROWSER) focusOnFileView();
           }
         }
         break;
         /* These actions don't work because they look at the EntryTable for the current selected
         * 	item. We need actions that look at the parentDirectoryList item instead.
         *
         			case KeyEvent.VK_DELETE:
         				evt.consume();
         				ea = ac.getAction("vfs.browser.delete");
         				ac.invokeAction(evt, ea);
         				break;
         			case KeyEvent.CTRL_MASK | KeyEvent.VK_N:
         				evt.consume();
         				ea = ac.getAction("vfs.browser.new-file");
         				ac.invokeAction(evt, ea);
         				break;
         			case KeyEvent.VK_INSERT:
         				evt.consume();
         				ea = ac.getAction("vfs.browser.new-directory");
         				ac.invokeAction(evt, ea);
         				break; */
     }
   } else if (evt.getID() == KeyEvent.KEY_TYPED) {
     if (evt.isControlDown() || evt.isAltDown() || evt.isMetaDown()) {
       evt.consume();
       return;
     }
     switch (evt.getKeyChar()) {
       case '~':
         evt.consume();
         if (browser.getMode() == VFSBrowser.BROWSER)
           browser.setDirectory(System.getProperty("user.home"));
         break;
       case '/':
         evt.consume();
         if (browser.getMode() == VFSBrowser.BROWSER) browser.rootDirectory();
         break;
       case '-':
         evt.consume();
         if (browser.getMode() == VFSBrowser.BROWSER) {
           browser.setDirectory(browser.getView().getBuffer().getDirectory());
         }
         break;
     }
   }
   if (!evt.isConsumed()) super.processKeyEvent(evt);
 }
示例#23
0
 // {{{ processKeyEvent() method
 public void processKeyEvents(KeyEvent ke) {
   if ((ke.getID() == KeyEvent.KEY_PRESSED) && (ke.getKeyCode() == KeyEvent.VK_ESCAPE)) {
     cancel();
     ke.consume();
   }
 } // }}}