public void setValue(String value) { if (value != null) { value = MiSystem.getProperty(value, value); } if (Utility.isEqualTo(value, textField.getValue())) { return; } if (restrictingValuesToThoseInList) { if ((list.getIndexOfItem(value, restrictionIgnoresCase) == -1) && (list.getNumberOfItems() > 0)) { if (restrictionWarnsOnly) { textField.setValue(value); list.getSelectionManager().deSelectAll(); } else { throw new IllegalArgumentException( MiDebug.getMicaClassName(this) + ": Rejecting value: \"" + value + "\" because it is not present in list" + " (see MiComboBox.setRestrictingValuesToThoseInList()).\n" + "Values present in list are: " + getContents()); } } } textField.setValue(value); if (!list.getContents().contains(value)) list.getSelectionManager().deSelectAll(); else list.setValue(textField.getValue()); }
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); }
public String toString() { String str = new String(MiDebug.getMicaClassName(this)); if (constraints.size() > 0) { str += "<"; for (int i = 0; i < constraints.size(); ++i) { if (i > 0) str += " + "; str += constraints.elementAt(i).toString(); } str += ">"; } return (str); }
public MiComboBox(boolean textFieldSensitive) { boolean isThisClass = MiDebug.getMicaClassName(this).equals("MiComboBox"); if ((isThisClass) && (prototype != null)) { copy(prototype); // FIX add: setTextFieldSensitive(textFieldSensitive) ... refreshLookAndFeel(); applyCustomLookAndFeel(); return; } setBorderLook(Mi_INDENTED_BORDER_LOOK); setInsetMargins(1); MiPart decoration = makeDecoration(10, 6); decoration.setName("icon"); menuLauncherButton = new MiMenuLauncherButton(); menuLauncherButton.setLabel(decoration); menuLauncherButton.setPopupLocation(this, Mi_LOWER_LEFT_LOCATION); menuLauncherButton.addPopupLocation(this, Mi_UPPER_LEFT_LOCATION, Mi_LOWER_LEFT_LOCATION); menuLauncherButton.setAcceptingKeyboardFocus(false); menuLauncherButton.setAcceptingMouseFocus(false); menuLauncherButton.setBackgroundColor(getBackgroundColor()); menuLauncherButton.setBorderLook(Mi_OUTLINED_RAISED_BORDER_LOOK); menuLauncherButton.setInsetMargins(3); menuLauncherButton.setContextCursor(Mi_STANDARD_CURSOR); menuLauncherButton.setName("button"); MiList list = new MiList(false); list.getTableHeaderAndFooterManager().setResizableColumns(false); list.setName("list"); setList(list); MiComboBoxPopperKeyEventHandler popupKeyHandler; popupKeyHandler = new MiComboBoxPopperKeyEventHandler(); popupKeyHandler.setMenuLauncherButton(menuLauncherButton); textField = new MiTextField(true); textField.setName("field"); textField.appendActionHandler(this, Mi_LOST_KEYBOARD_FOCUS_ACTION | Mi_REQUEST_ACTION_PHASE); textField.appendActionHandler(this, Mi_LOST_KEYBOARD_FOCUS_ACTION); textField.appendActionHandler(this, Mi_ENTER_KEY_ACTION); textField.appendActionHandler(this, Mi_TEXT_CHANGE_ACTION); setBorderLook(Mi_INLINED_INDENTED_BORDER_LOOK); setNormalColor(getToolkit().getTextSensitiveColor()); setInSensitiveColor(getToolkit().getTextInSensitiveColor()); setNormalBackgroundColor(getToolkit().getTextFieldEditableBGColor()); setInSensitiveBackgroundColor(getToolkit().getTextFieldInEditableBGColor()); textField.setBackgroundColor(Mi_TRANSPARENT_COLOR); textField.setBorderLook(Mi_NONE); textField.setInsetMargins(0); textField.setAcceptingMouseFocus(false); MiRowLayout layout = new MiRowLayout(); layout.setAlleyHSpacing(0); layout.setElementHJustification(Mi_LEFT_JUSTIFIED); layout.setLastElementJustification(Mi_RIGHT_JUSTIFIED); layout.setElementVSizing(Mi_EXPAND_TO_FILL); layout.setUniqueElementSizing(Mi_EXPAND_TO_FILL); layout.setUniqueElementIndex(0); setLayout(layout); appendPart(textField); appendPart(menuLauncherButton); if (!textFieldSensitive) { popupKeyHandler.addEventToCommandTranslation( MiEventHandler.Mi_EXECUTE_COMMAND_NAME, MiEvent.Mi_LEFT_MOUSE_CLICK_EVENT, 0, 0); } textField.insertEventHandler(popupKeyHandler, 0); appendEventHandler(popupKeyHandler); refreshLookAndFeel(); applyCustomLookAndFeel(); }