/** * Installs support for autocompletion into the <code>comboBox</code> and * returns the support object that is actually providing those facilities. * The support object is returned so that the caller may invoke * {@link #uninstall} at some later time to remove the autocompletion * features. * * <p>This method assumes that the <code>items</code> can be converted into * reasonable String representations via {@link Object#toString()}. * * <p>The following must be true in order to successfully install support * for autocompletion on a {@link JComboBox}: * * <ul> * <li> The JComboBox must use a {@link JTextField} as its editor component * <li> The JTextField must use an {@link AbstractDocument} as its model * </ul> * * @param comboBox the {@link JComboBox} to decorate with autocompletion * @param items the objects to display in the <code>comboBox</code> * @return an instance of the support class providing autocomplete features * @throws IllegalStateException if this method is called from any Thread * other than the Swing Event Dispatch Thread */ public static <E> AutoCompleteSupport<E> install(JComboBox comboBox, EventList<E> items) { return install(comboBox, items, null); }
/** * This method is used to report environmental invariants which are * violated when the user adjusts the combo box in a way that is * incompatible with the requirements for autocompletion. A message can be * specified which will be included in the {@link IllegalStateException} * that is throw out of this method after the autocompletion support is * uninstalled. * * @param message a message to the programmer explaining the environmental * invariant that was violated */ private void throwIllegalStateException(String message) { final String exceptionMsg = message + "\n" + "In order for AutoCompleteSupport to continue to " + "work, the following invariants must be maintained after " + "AutoCompleteSupport.install() has been called:\n" + "* the ComboBoxModel may not be removed\n" + "* the AbstractDocument behind the JTextField can be changed but must be changed to some subclass of AbstractDocument\n" + "* the DocumentFilter on the AbstractDocument behind the JTextField may not be removed\n"; uninstall(); throw new IllegalStateException(exceptionMsg); }
/** * Returns <tt>true</tt> if this autocomplete support instance is currently * installed and altering the behaviour of the combo box; <tt>false</tt> if * it has been {@link #uninstall}ed. * * @throws IllegalStateException if this method is called from any Thread * other than the Swing Event Dispatch Thread */ public boolean isInstalled() { checkAccessThread(); return comboBox != null; }
public void run() { SortedList<Object> sorted = new SortedList<Object>(GlazedLists.eventListOf(elements)); // auto completion support for selection list support = AutoCompleteSupport.install(contextBox, sorted); support.setStrict(true); support.setFilterMode(TextMatcherEditor.CONTAINS); } };
public void run() { SortedList<Object> sorted = new SortedList<Object>(GlazedLists.eventListOf(elements)); // auto completion support for selection list if (box == tags) { if (supportTag == null || !supportTag.isInstalled()) supportTag = AutoCompleteSupport.install(box, sorted); supportTag.setStrict(true); supportTag.setFilterMode(TextMatcherEditor.STARTS_WITH); } else if (box == dataSources) { if (supportDataSource == null || !supportDataSource.isInstalled()) supportDataSource = AutoCompleteSupport.install(box, sorted); supportDataSource.setStrict(true); supportDataSource.setFilterMode(TextMatcherEditor.STARTS_WITH); } else if (box == conceptClasses) { if (supportConceptClass == null || !supportConceptClass.isInstalled()) supportConceptClass = AutoCompleteSupport.install(box, sorted); supportConceptClass.setStrict(true); supportConceptClass.setFilterMode(TextMatcherEditor.STARTS_WITH); } // OVTK-328 box.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_ENTER) { goButton.doClick(); } } }); box.revalidate(); } };
checkAccessThread(); Object currentItem = findAutoCompleteTerm(currentText); String currentItemText = convertToString(currentItem); boolean itemMatches = currentItem == comboBox.getSelectedItem(); boolean textMatches = GlazedListsImpl.equal(currentItemText, currentText); currentItemText = convertToString(currentItem); itemMatches = currentItem == comboBox.getSelectedItem(); textMatches = GlazedListsImpl.equal(currentItemText, currentText); applyFilter("");
autoComplete.uninstall(); autoComplete = null; autoComplete = AutoCompleteSupport.install(jLocation, EventModels.createSwingThreadProxyList(filterList), new LocationsFilterator()); autoComplete.setStrict(true); autoComplete.setCorrectsCase(true);
/** * This factory method creates and returns a {@link AutoCompleteCellEditor} * which adapts an autocompleting {@link JComboBox} for use as a Table * Cell Editor. The values within the <code>source</code> are used as * autocompletion terms within the {@link ComboBoxModel}. * * <p>If the appearance or function of the autocompleting {@link JComboBox} * is to be customized, it can be retrieved using * {@link AutoCompleteCellEditor#getComponent()}. * * @param source the source of data for the JComboBox within the table cell editor * @return a {@link AutoCompleteCellEditor} which contains an autocompleting * combobox whose model contents are determined by the given <code>source</code> */ public static <E> AutoCompleteCellEditor<E> createTableCellEditor(EventList<E> source) { // build a special JComboBox used only in Table Cell Editors final JComboBox comboBox = new TableCellComboBox(); comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); // install autocompletion support on the special JComboBox final AutoCompleteSupport<E> autoCompleteSupport = AutoCompleteSupport.install(comboBox, source); autoCompleteSupport.setSelectsTextOnFocusGain(false); // create an AutoCompleteCellEditor using the AutoCompleteSupport object final AutoCompleteCellEditor<E> cellEditor = new AutoCompleteCellEditor<E>(autoCompleteSupport); cellEditor.setClickCountToStart(2); return cellEditor; }
AutoCompleteSupport<Item> itemAutoComplete = AutoCompleteSupport.install(jItems, EventModels.createSwingThreadProxyList(items), new ItemFilterator()); itemAutoComplete.setStrict(true); itemAutoComplete.setCorrectsCase(true);
public void run() { if (supportConceptClass != null && supportConceptClass.isInstalled()) supportConceptClass.uninstall(); conceptClasses.removeAllItems(); list.add(Config.language.getProperty("ToolBar.Search.ConceptClass")); conceptClasses.addItem(Config.language.getProperty("ToolBar.Search.ConceptClass")); boolean hasCCs = false; for (ConceptClass conceptClass : graph.getMetaData().getConceptClasses()) { Set<ONDEXConcept> view = graph.getConceptsOfConceptClass(conceptClass); if (view.size() > 0) { hasCCs = true; MetaDataWrapper wrapper = new MetaDataWrapper(conceptClass); conceptClasses.addItem(wrapper); list.add(wrapper); } } conceptClasses.setEnabled(hasCCs); if (hasCCs) addAutoCompleteSupport(list, conceptClasses); } };
jIncludeContainer = new JCheckBox(TabsStockpile.get().includeContainer()); JCopyPopup.install((JTextComponent) jContainer.getEditor().getEditorComponent()); AutoCompleteSupport<String> install = AutoCompleteSupport.install(jContainer, EventModels.createSwingThreadProxyList(containerEventList), new Filterator()); install.setFilterMode(TextMatcherEditor.CONTAINS); ((JTextComponent) jContainer.getEditor().getEditorComponent()).getDocument().addDocumentListener(listener); jContainer.setActionCommand(StockpileDialogAction.VALIDATE.name());
jRegions = new JComboBox<>(); jRegions.getEditor().getEditorComponent().addFocusListener(listener); regionsAutoComplete = AutoCompleteSupport.install(jRegions, EventModels.createSwingThreadProxyList(regions), new RegionTypeFilterator()); regionsAutoComplete.setStrict(true); jSystems.setPrototypeDisplayValue(system); jSystems.getEditor().getEditorComponent().addFocusListener(listener); systemsAutoComplete = AutoCompleteSupport.install(jSystems, EventModels.createSwingThreadProxyList(systemsSortedList), new LocationsFilterator()); systemsEventList.getReadWriteLock().readLock().lock(); systemsAutoComplete.setStrict(true); systemsEventList.getReadWriteLock().readLock().unlock(); jStations.setPrototypeDisplayValue(station); jStations.getEditor().getEditorComponent().addFocusListener(listener); stationsAutoComplete = AutoCompleteSupport.install(jStations, EventModels.createSwingThreadProxyList(stationsSortedList), new LocationsFilterator()); stationsEventList.getReadWriteLock().readLock().lock(); stationsAutoComplete.setStrict(true); stationsEventList.getReadWriteLock().readLock().unlock();
final Matcher<String> valueMatcher = new TextMatcher<String>(new SearchTerm[] {new SearchTerm(value)}, GlazedLists.toStringTextFilterator(), TextMatcherEditor.STARTS_WITH, getTextMatchingStrategy()); final String itemString = convertToString(item);
checkAccessThread(); this.undecorateOriginalUI();
checkAccessThread(); throw new IllegalArgumentException("comboBox is already configured for autocompletion"); return new AutoCompleteSupport<E>(comboBox, items, filterator, format);
return createTableCellEditor(GlazedLists.comparableComparator(), tableFormat, tableData, columnIndex);
this.popupMenu = (JPopupMenu) comboBox.getUI().getAccessibleChild(comboBox, 0); this.popup = (ComboPopup) popupMenu; this.arrowButton = findArrowButton(comboBox);
checkAccessThread(); Object currentItem = findAutoCompleteTerm(currentText); String currentItemText = convertToString(currentItem); boolean itemMatches = currentItem == comboBox.getSelectedItem(); boolean textMatches = GlazedListsImpl.equal(currentItemText, currentText); currentItemText = convertToString(currentItem); itemMatches = currentItem == comboBox.getSelectedItem(); textMatches = GlazedListsImpl.equal(currentItemText, currentText); applyFilter("");
.install(cbo, sourceList, textFilterator, this.completionSupport.getFormat()); autoCompleteSupport.setStrict(this.completionSupport.isStrict()); int mode = (Integer) Utils.getConstant(TextMatcherEditor.class, filterMode); autoCompleteSupport.setFilterMode(mode);