예제 #1
2
  public MainPanel() {
    super(new BorderLayout());

    InputMap im = table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
    KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    KeyStroke stab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK);
    KeyStroke senter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK);
    im.put(tab, im.get(enter));
    im.put(stab, im.get(senter));

    final Color orgColor = table.getSelectionBackground();
    final Color tflColor = this.getBackground();
    table.addFocusListener(
        new FocusListener() {
          @Override
          public void focusGained(FocusEvent e) {
            table.setSelectionForeground(Color.WHITE);
            table.setSelectionBackground(orgColor);
          }

          @Override
          public void focusLost(FocusEvent e) {
            table.setSelectionForeground(Color.BLACK);
            table.setSelectionBackground(tflColor);
          }
        });

    table.setComponentPopupMenu(new TablePopupMenu());
    add(new JScrollPane(table));
    setPreferredSize(new Dimension(320, 240));
  }
예제 #2
0
  public void loadBindingMap(InputMap im, ActionMap am) {
    results.append("Bound Actions\n");
    String unboundActions = "";
    String unboundInputKeys = "";
    Hashtable mi = buildReverseMap(im);
    Object[] k = am.allKeys();
    if (k != null) {
      for (int i = 0; i < k.length; i++) {
        if (mi.containsKey(k[i])) {
          results.append("  " + getActionName(k[i]));
          results.append(";" + mi.get(k[i]) + "\n");
        } else {
          unboundActions += ("  " + getActionName(k[i]) + "\n");
        }
      }
      results.append("\nUnbound Actions\n\n");
      results.append(unboundActions);
    }

    results.append("\nUnbound InputMap Entries\n");
    k = im.allKeys();
    if (k != null) {
      for (int i = 0; i < k.length; i++) {
        KeyStroke key = (KeyStroke) k[i];
        Object actionKey = im.get(key);
        if (am.get(actionKey) == null) {
          results.append("  " + im.get((KeyStroke) k[i]) + ": " + k[i] + "\n");
        }
      }
    }
  }
예제 #3
0
 public void loadInputMap(InputMap im, String indent) {
   KeyStroke[] k = im.allKeys();
   if (k == null) {
     results.append(indent + "No InputMap defined\n");
   } else {
     results.append(indent + "\nInputMap (" + k.length + " local keys)\n");
   }
   if (k != null) {
     for (int i = 0; i < k.length; i++) {
       results.append(indent + "  Key:  " + k[i] + ", binding: " + im.get(k[i]) + "\n");
     }
   }
 }
예제 #4
0
 private Hashtable buildReverseMap(InputMap im) {
   KeyStroke k[] = im.allKeys();
   Hashtable h = new Hashtable();
   if (k != null) {
     for (int i = 0; i < k.length; i++) {
       Object nk = im.get(k[i]);
       Object cv = h.get(nk);
       if (h.containsKey(nk)) {
         ((Vector) cv).add(k[i]);
       } else {
         Vector v = new Vector();
         v.add(k[i]);
         h.put(nk, v);
       }
     }
   }
   return h;
 }