Пример #1
0
 /**
  * Assert that all shift keys are in the expected state.
  *
  * @param event the event that was triggered
  */
 private static void assertAllShiftKeys(
     Event event,
     boolean expectedCtrl,
     boolean expectedAlt,
     boolean expectedShift,
     boolean expectedMeta) {
   assertEquals("Expecting ctrl = " + expectedCtrl, expectedCtrl, event.getCtrlKey());
   assertEquals("Expecting alt = " + expectedAlt, expectedAlt, event.getAltKey());
   assertEquals("Expecting shift = " + expectedShift, expectedShift, event.getShiftKey());
   assertEquals("Expecting meta = " + expectedMeta, expectedMeta, event.getMetaKey());
 }
Пример #2
0
  private void resultSelect(Event e) {
    if (resultHighlight != null) {
      GQuery high = resultHighlight;
      String highId = high.attr("id");

      resultClearHighlight();

      if (isMultiple) {
        resultDeactivate(high);
      } else {
        searchResults.find("." + css.resultSelected()).removeClass(css.resultSelected());
        resultSingleSelected = high;
        selectedItem.removeClass(css.chznDefault());
      }

      high.addClass(css.resultSelected());

      int position = Integer.parseInt(highId.substring(highId.lastIndexOf("_") + 1));
      OptionItem item = (OptionItem) selectItems.get(position);
      item.setSelected(true);
      selectElement.getOptions().getItem(item.getOptionsIndex()).setSelected(true);

      if (isMultiple) {
        choiceBuild(item);
      } else {
        selectedItem.find("span").text(item.getText());
        if (allowSingleDeselect) {
          singleDeselectControlBuild();
        }
      }

      if (!e.getMetaKey() || !isMultiple) {
        resultsHide();
      }

      searchField.val("");

      if (isMultiple || currentValue == null || !currentValue.equals($selectElement.val())) {
        String value = selectElement.getOptions().getItem(item.getOptionsIndex()).getValue();
        fireEvent(new ChosenChangeEvent(value, this));
      }

      currentValue = $selectElement.val();

      searchFieldScale();
    }
  }
  private static KeyEvent toKeyEvent(Event e) {
    Key key = KeyCodeMapper.getKey(e.getKeyCode());

    Set<ModifierKey> modifiers = new HashSet<>();
    if (e.getCtrlKey()) {
      modifiers.add(ModifierKey.CONTROL);
    }
    if (e.getAltKey()) {
      modifiers.add(ModifierKey.ALT);
    }
    if (e.getShiftKey()) {
      modifiers.add(ModifierKey.SHIFT);
    }
    if (e.getMetaKey()) {
      modifiers.add(ModifierKey.META);
    }
    return new KeyEvent(key, (char) e.getCharCode(), modifiers);
  }