20 package net.sf.gridarta.gui.dialog.plugin.parameter.archetype;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.Comparator;
26 import java.util.List;
27 import javax.swing.AbstractListModel;
28 import javax.swing.ComboBoxModel;
33 import org.jetbrains.annotations.NotNull;
34 import org.jetbrains.annotations.Nullable;
36 public class ArchComboBoxModel<G
extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>> extends AbstractListModel<Archetype<G, A, R>> implements ComboBoxModel<Archetype<G, A, R>> {
42 private final List<Archetype<G, A, R>>
archList;
52 final Collection<R> archetypes = archetypeSet.getArchetypes();
53 archList =
new ArrayList<>(archetypes);
76 return archList.size();
82 return archList.get(index);
85 public void setFilter(@NotNull
final String filter) {
86 if (filter.startsWith(CURRENT_FILTER)) {
88 }
else if (CURRENT_FILTER.startsWith(filter)) {
95 fireContentsChanged(
this, 0, archList.size());
98 private static int getCommonPrefix(@NotNull
final CharSequence s1, @NotNull
final CharSequence s2) {
100 while (s1.length() > i && s2.length() > i && s1.charAt(i) == s2.charAt(i)) {
119 int pos = Collections.binarySearch(archList, name,
new Comparator<Object>() {
122 public int compare(
final Object o1,
final Object o2) {
130 if (o2 instanceof Archetype) {
135 return s1.compareToIgnoreCase(s2);
141 if (pos >= archList.size()) {
142 pos = archList.size() - 1;
147 return archList.get(pos);
void setFilter(@NotNull final String filter)
void setSelectedItem(@Nullable final Object anItem)
void enlargeFilter(@NotNull final String filter)
Archetype< G, A, R > getElementAt(final int index)
String getArchetypeName()
Returns the name of this archetype.
void narrowFilter(@NotNull final String filter)
static int getCommonPrefix(@NotNull final CharSequence s1, @NotNull final CharSequence s2)
Archetype< G, A, R > getNearestMatch(@NotNull final String name)
TypeMayBeWeakened
Base package of all Gridarta classes.
Reflects a game object (object on a map).
final List< Archetype< G, A, R > > archList
GameObjects are the objects based on Archetypes found on maps.
static final String CURRENT_FILTER
static final long serialVersionUID
Interface that captures similarities between different ArchetypeSet implementations.
Interface for MapArchObjects.
ArchComboBoxModel(@NotNull final ArchetypeSet< G, A, R > archetypeSet)