コード例 #1
1
  public void unregisterKeyStroke(KeyStroke ks, JComponent c) {

    // component may have already been removed from the hierarchy, we
    // need to look up the container using the componentKeyStrokeMap.

    ComponentKeyStrokePair ckp = new ComponentKeyStrokePair(c, ks);

    Container topContainer = componentKeyStrokeMap.get(ckp);

    if (topContainer == null) { // never heard of this pairing, so bail
      return;
    }

    Hashtable keyMap = containerMap.get(topContainer);
    if (keyMap == null) { // this should never happen, but I'm being safe
      Thread.dumpStack();
      return;
    }

    Object tmp = keyMap.get(ks);
    if (tmp == null) { // this should never happen, but I'm being safe
      Thread.dumpStack();
      return;
    }

    if (tmp instanceof JComponent && tmp == c) {
      keyMap.remove(ks); // remove the KeyStroke from the Map
      // System.out.println("removed a stroke" + ks);
    } else if (tmp
        instanceof Vector) { // this means there is more than one component reg for this key
      Vector v = (Vector) tmp;
      v.removeElement(c);
      if (v.isEmpty()) {
        keyMap.remove(ks); // remove the KeyStroke from the Map
        // System.out.println("removed a ks vector");
      }
    }

    if (keyMap.isEmpty()) { // if no more bindings in this table
      containerMap.remove(topContainer); // remove table to enable GC
      // System.out.println("removed a container");
    }

    componentKeyStrokeMap.remove(ckp);

    // Check for EmbeddedFrame case, they know how to process accelerators even
    // when focus is not in Java
    if (topContainer instanceof EmbeddedFrame) {
      ((EmbeddedFrame) topContainer).unregisterAccelerator(ks);
    }
  }
コード例 #2
0
ファイル: AppletPanel.java プロジェクト: FauxFaux/jdk9-jdk
  /*
   * Fix for BugTraq ID 4041703.
   * Set the focus to a reasonable default for an Applet.
   */
  private void setDefaultFocus() {
    Component toFocus = null;
    Container parent = getParent();

    if (parent != null) {
      if (parent instanceof Window) {
        toFocus = getMostRecentFocusOwnerForWindow((Window) parent);
        if (toFocus == parent || toFocus == null) {
          toFocus = parent.getFocusTraversalPolicy().getInitialComponent((Window) parent);
        }
      } else if (parent.isFocusCycleRoot()) {
        toFocus = parent.getFocusTraversalPolicy().getDefaultComponent(parent);
      }
    }

    if (toFocus != null) {
      if (parent instanceof EmbeddedFrame) {
        ((EmbeddedFrame) parent).synthesizeWindowActivation(true);
      }
      // EmbeddedFrame might have focus before the applet was added.
      // Thus after its activation the most recent focus owner will be
      // restored. We need the applet's initial focusabled component to
      // be focused here.
      toFocus.requestFocusInWindow();
    }
  }
コード例 #3
0
 /*     */ public void addNotify() /*     */ {
   /*  65 */ if (getPeer() == null) {
     /*  66 */ XToolkit localXToolkit = (XToolkit) Toolkit.getDefaultToolkit();
     /*  67 */ setPeer(localXToolkit.createEmbeddedFrame(this));
     /*     */ }
   /*  69 */ super.addNotify();
   /*     */ }
コード例 #4
0
  /**
   * register keystrokes here which are for the WHEN_IN_FOCUSED_WINDOW case. Other types of
   * keystrokes will be handled by walking the hierarchy That simplifies some potentially hairy
   * stuff.
   */
  public void registerKeyStroke(KeyStroke k, JComponent c) {
    Container topContainer = getTopAncestor(c);
    if (topContainer == null) {
      return;
    }
    Hashtable keyMap = containerMap.get(topContainer);

    if (keyMap == null) { // lazy evaluate one
      keyMap = registerNewTopContainer(topContainer);
    }

    Object tmp = keyMap.get(k);
    if (tmp == null) {
      keyMap.put(k, c);
    } else if (tmp instanceof Vector) { // if there's a Vector there then add to it.
      Vector v = (Vector) tmp;
      if (!v.contains(c)) { // only add if this keystroke isn't registered for this component
        v.addElement(c);
      }
    } else if (tmp instanceof JComponent) {
      // if a JComponent is there then remove it and replace it with a vector
      // Then add the old compoennt and the new compoent to the vector
      // then insert the vector in the table
      if (tmp != c) { // this means this is already registered for this component, no need to dup
        Vector<JComponent> v = new Vector<JComponent>();
        v.addElement((JComponent) tmp);
        v.addElement(c);
        keyMap.put(k, v);
      }
    } else {
      System.out.println("Unexpected condition in registerKeyStroke");
      Thread.dumpStack();
    }

    componentKeyStrokeMap.put(new ComponentKeyStrokePair(c, k), topContainer);

    // Check for EmbeddedFrame case, they know how to process accelerators even
    // when focus is not in Java
    if (topContainer instanceof EmbeddedFrame) {
      ((EmbeddedFrame) topContainer).registerAccelerator(k);
    }
  }
コード例 #5
0
  // override XWindowPeer's method to let the embedded frame to block
  // the containing window
  public void setModalBlocked(Dialog blocker, boolean blocked) {
    super.setModalBlocked(blocker, blocked);

    EmbeddedFrame frame = (EmbeddedFrame) target;
    frame.notifyModalBlocked(blocker, blocked);
  }
コード例 #6
0
 @Override
 public void modalEnable(Dialog blocker) {
   super.modalEnable(blocker);
   ((EmbeddedFrame) target).notifyModalBlocked(blocker, false);
 }
コード例 #7
0
 @Override
 public void modalDisable(Dialog blocker, long blockerHWnd) {
   super.modalDisable(blocker, blockerHWnd);
   ((EmbeddedFrame) target).notifyModalBlocked(blocker, true);
 }