Ejemplo n.º 1
0
  private void translateSelected() {
    if (getSelectedIndex() < 0) {
      return;
    }

    IArticle article = engine.getFinder().get(getSelectedIndex());

    model.bookmark(article);
    model.translate(article);

    selectAll();
  }
Ejemplo n.º 2
0
  public void onKeyPressed(KeyEvent e) {
    int selectedIndex = list.getSelectedIndex();
    int newIndex = selectedIndex;

    int rowsOnScreen = scroll.getHeight() / list.getFixedCellHeight();

    switch (e.getKeyCode()) {
      case KeyEvent.VK_UP:
      case KeyEvent.VK_KP_UP:
        if (!e.isAltDown()) {
          newIndex--;
        }
        break;
      case KeyEvent.VK_DOWN:
      case KeyEvent.VK_KP_DOWN:
        if (!e.isAltDown()) {
          newIndex++;
        }
        break;
      case KeyEvent.VK_PAGE_UP:
        newIndex -= rowsOnScreen;
        break;
      case KeyEvent.VK_PAGE_DOWN:
        newIndex += rowsOnScreen;
        break;
      case KeyEvent.VK_ENTER:
        if ((e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) > 0) {
          model.suggest(field.getText().trim());
        } else if ((e.getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) > 0) {
          model.popOut(field.getText().trim());
        } else {
          translateSelected();
        }
        break;
    }

    // check, whether index was changed
    if (newIndex == selectedIndex) {
      return;
    }

    int size = list.getModel().getSize();

    if (newIndex < 0) {
      newIndex = 0;
    }
    if (newIndex >= size) {
      newIndex = size - 1;
    }

    setSelectedIndex(newIndex);
    setSearchTextWithoutNavigating(getSelectedIndexText());
  }
Ejemplo n.º 3
0
  private void navigateAndTranslate(String title) {
    navigate(title);

    if (engine.getTitleComparator().compare(title, getSelectedIndexText()) == 0) {
      translateSelected();
    } else {
      lastNavigated = null;
      model.translateNotFound(title);
    }
  }