Example #1
0
  public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();

    if (src == add) {
      // Selection has been made, or add button pressed:
      if ((sel != null) && (sel.getSelectedItem() != null)) {
        String s = sel.getSelectedItem().toString();
        addField(s);
      } else if ((input != null) && !input.getText().equals("")) {
        addField(input.getText());
      }
    } else if (src == input) {
      addField(input.getText());
    } else if (src == remove) {
      // Remove button pressed:
      removeSelected();
    } else if (src == sel) {
      if (e.getActionCommand().equals("comboBoxChanged") && (e.getModifiers() == 0))
        // These conditions signify arrow key navigation in the dropdown list, so we should
        // not react to it. I'm not sure if this is well defined enough to be guaranteed to work
        // everywhere.
        return;
      String s = sel.getSelectedItem().toString();
      addField(s);
      sel.getEditor().selectAll();
    } else if (src == up) {
      move(-1);
    } else if (src == down) {
      move(1);
    }
  }