Exemple #1
0
  public void setList(MiTable list) {
    if (this.list != null) this.list.removeActionHandlers(this);

    this.list = list;
    list.appendActionHandler(this, Mi_ITEM_SELECTED_ACTION);
    list.setMinimumNumberOfVisibleRows(3);
    list.setPreferredNumberOfVisibleRows(7);
    list.setInsetMargins(0);
    MiToolkit.setBackgroundAttributes(
        list.getContentsBackground(), MiToolkit.Mi_TOOLKIT_UNEDITABLE_BG_ATTRIBUTES);
    list.getSelectionManager().setMinimumNumberSelected(1);
    // Do not allow interactive resizing of scrolled list cause not usefull and
    // when menu pops down the TableHeaderAndFooterManager is left grabbing the window
    list.getTableHeaderAndFooterManager().setEnabled(false);

    scrolledBox = new MiScrolledBox(list);
    scrolledBox.setInsetMargins(0);

    if (menu != null) menu.removeActionHandlers(this);

    menu = new MiMenu(scrolledBox);
    menu.setInsetMargins(2);
    menu.insertActionHandler(this, Mi_VISIBLE_ACTION, 0);

    menuLauncherButton.setMenu(menu);
  }
Exemple #2
0
  public boolean processAction(MiiAction action) {
    // MiDebug.println(this + " proecssAction: " + action);
    if (action.hasActionType(Mi_ITEM_SELECTED_ACTION)) {
      textField.setValue(list.getSelectedItem());
      dispatchAction(Mi_VALUE_CHANGED_ACTION);
      menu.popdown();
    } else if (action.hasActionType(Mi_LOST_KEYBOARD_FOCUS_ACTION | Mi_REQUEST_ACTION_PHASE)) {
      if (restrictingValuesToThoseInList) {
        String value = textField.getValue();
        if ((list.getIndexOfItem(value) == -1) && (list.getNumberOfItems() > 0)) {
          if (restrictionWarnsOnly) {
            dispatchAction(Mi_INVALID_VALUE_ACTION);
          } else {
            action.veto();
            dispatchAction(Mi_INVALID_VALUE_ACTION);
            if (MiDebug.debug
                && MiDebug.isTracing(null, MiDebug.TRACE_KEYBOARD_FOCUS_DISPATCHING)) {
              MiDebug.println(
                  MiDebug.getMicaClassName(this)
                      + ": Rejecting loss of keyboard focus because "
                      + "isRestrictingValuesToThoseInList() == true.");
            }
            return (true);
          }
        }
      }
      dispatchAction(Mi_VALUE_CHANGED_ACTION);
    } else if ((action.hasActionType(Mi_LOST_KEYBOARD_FOCUS_ACTION))
        || (action.hasActionType(Mi_ENTER_KEY_ACTION))) {
      dispatchAction(Mi_VALUE_CHANGED_ACTION);

      if (!list.getContents().contains(textField.getValue()))
        list.getSelectionManager().deSelectAll();
      else list.setValue(textField.getValue());
    } else if (action.hasActionType(Mi_TEXT_CHANGE_ACTION)) {
      dispatchAction(Mi_TEXT_CHANGE_ACTION);
    } else if (action.hasActionType(Mi_VISIBLE_ACTION)) {
      MiSize prefSize = menu.getPreferredSize(new MiSize());
      if (prefSize.getWidth() < getWidth() - getMargins(new MiMargins()).getWidth()) {
        prefSize.setWidth(getWidth() - getMargins(new MiMargins()).getWidth());
        menu.setPreferredSize(prefSize);
        menu.setSize(prefSize);
        menu.validateLayout();
      }
    }
    return (true);
  }