Example #1
0
  public void keyReleased(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE || e.getKeyCode() == KeyEvent.VK_ENTER) {

      String text = textEditor.getText();
      if (comboBox.isShowing()) {
        suggestionList.hide();
        suggestionList.filter(text);
        suggestionList.show();
      }
    }
  }
Example #2
0
 private void processEnterPressed() {
   Object value = suggestionList.getSelectedValue();
   if (!allowsUserValues && value == null && suggestionList.getItemCount() > 0) {
     value = suggestionList.getItemAt(0);
   }
   // reset the item (value == null) only if user values are not supported
   if (value != null || !allowsUserValues) {
     comboBox.setSelectedItem(value);
   }
   suggestionList.hide();
 }
Example #3
0
  public void run() {
    String text = textEditor.getText();

    // need to hide first because Swing incorrectly updates popups (getSize() returns
    // dimension not the same as seen on the screen)
    suggestionList.hide();

    if (comboBox.isShowing()) {
      suggestionList.filter(text);

      if (suggestionList.getItemCount() > 0) {
        suggestionList.show();
      }
    }
  }
Example #4
0
  private void handleNavigationKeys(boolean suggest, int next, int sel, int max) {
    if (!suggest && !comboBox.isPopupVisible()) {
      comboBox.setPopupVisible(true);
      return;
    }

    if (comboBox.getItemCount() > 0) {
      if (next < 0) {
        next = 0;
      }

      if (next > max) {
        next = max;
      }

      if (next != sel) {
        if (suggest) {
          suggestionList.setSelectedIndex(next);
        } else {
          comboBox.setPopupVisible(true);
          comboBox.setSelectedIndex(next);
        }
      }
      textEditor.requestFocus();
    }
  }
Example #5
0
  /**
   * Calculates next selection row, according to a pressed key and selects it. This might affect
   * either suggestion list or original popup
   */
  private void handleKeyPressed(KeyEvent e) {
    boolean suggest = suggestionList.isVisible();

    if (suggest) {
      processKeyPressedWhenSuggestionListIsVisible(e);
    } else {
      processKeyPressedWhenSuggestionListIsInvisible(e);
    }

    // scroll doesn't work in suggestionList..so we will scroll manually
    suggestionListScrolling();
  }
Example #6
0
 private void processKeyPressedWhenSuggestionListIsVisible(KeyEvent e) {
   int sel = suggestionList.getSelectedIndex();
   int max = suggestionList.getItemCount() - 1;
   int next;
   switch (e.getKeyCode()) {
     case KeyEvent.VK_UP:
     case KeyEvent.VK_NUMPAD8:
       next = sel - 1;
       break;
     case KeyEvent.VK_DOWN:
     case KeyEvent.VK_NUMPAD2:
       next = sel + 1;
       break;
     case KeyEvent.VK_PAGE_UP:
       next = sel - comboBox.getMaximumRowCount();
       break;
     case KeyEvent.VK_PAGE_DOWN:
       next = sel + comboBox.getMaximumRowCount();
       break;
     case KeyEvent.VK_HOME:
       next = 0;
       break;
     case KeyEvent.VK_END:
       next = max;
       break;
     case KeyEvent.VK_ENTER:
       processEnterPressed();
       return;
     case KeyEvent.VK_ESCAPE:
       suggestionList.hide();
       return;
     default:
       // invoke in end of AWT thread so that information in textEditor would update
       SwingUtilities.invokeLater(this);
       return;
   }
   e.consume();
   handleNavigationKeys(true, next, sel, max);
 }
Example #7
0
 public void focusLost(FocusEvent e) {
   suggestionList.hide();
 }
Example #8
0
 private void suggestionListScrolling() {
   JList list = suggestionList.getList();
   int selectedIndex = suggestionList.getSelectedIndex();
   list.ensureIndexIsVisible(selectedIndex);
 }