Пример #1
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();
     }
   }
 }
  /**
   * 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);
  }
Пример #4
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();
  }
Пример #5
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);
 }