/** * Sets the contents of this model. All previous contents are removed. * * @param contents The new contents of this model. */ public void setContents(Collection<Completion> contents) { clear(); int count = contents.size(); if (count>0) { delegate.addAll(contents); fireIntervalAdded(this, 0, count-1); // endpoints included (!) } }
/** * Removes all of the elements from this list. The list will * be empty after this call returns (unless it throws an exception). * * @see #setContents(Collection) */ public void clear() { int end = delegate.size()-1; delegate.clear(); if (end >= 0) { fireIntervalRemoved(this, 0, end); } }
/** * Sets the completions to display in the choices list. The first * completion is selected. * * @param completions The completions to display. */ public void setCompletions(List<Completion> completions) { model.setContents(completions); selectFirstItem(); }
/** * Selects the first item in the completion list. * * @see #selectLastItem() */ private void selectFirstItem() { if (model.getSize() > 0) { list.setSelectedIndex(0); list.ensureIndexIsVisible(0); } }
model = new CompletionListModel(); list = new PopupList(model);
/** * Selects the last item in the completion list. * * @see #selectFirstItem() */ private void selectLastItem() { int index = model.getSize() - 1; if (index > -1) { list.setSelectedIndex(index); list.ensureIndexIsVisible(index); } }
/** * Selects the next item in the completion list. * * @see #selectPreviousItem() */ private void selectNextItem() { int index = list.getSelectedIndex(); if (index > -1) { index = (index + 1) % model.getSize(); list.setSelectedIndex(index); list.ensureIndexIsVisible(index); } }