org.openstreetmap.josm.gui.tagging.ac
Class AutoCompletionList

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel

public class AutoCompletionList
extends javax.swing.table.AbstractTableModel

AutoCompletionList manages a list of AutoCompletionListItems. The list is sorted, items with higher priority first, then according to lexicographic order on the value of the AutoCompletionListItem. AutoCompletionList maintains two views on the list of AutoCompletionListItems.

  1. the bare, unfiltered view which includes all items
  2. a filtered view, which includes only items which match a current filter expression
AutoCompletionList is an AbstractTableModel which serves the list of filtered items to a JTable.

See Also:
Serialized Form

Field Summary
private  java.lang.String filter
          the filter expression
private  java.util.ArrayList<AutoCompletionListItem> filtered
          the filtered list of AutoCompletionItems
private  java.util.ArrayList<AutoCompletionListItem> list
          the bare list of AutoCompletionItems
private  java.util.Map<java.lang.String,AutoCompletionListItem> valutToItemMap
          map from value to priority
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
AutoCompletionList()
          constructor
 
Method Summary
 void add(AutoCompletionList other)
          adds another AutoCompletionList to this list.
 void add(AutoCompletionListItem item)
          adds an AutoCompletionListItem to the list.
 void add(java.util.Collection<java.lang.String> values, AutoCompletionItemPritority priority)
          adds a list of strings to this list.
 void add(java.util.List<AutoCompletionListItem> other)
          adds a list of AutoCompletionListItem to this list.
protected  void appendOrUpdatePriority(AutoCompletionListItem toAdd)
           
 void applyFilter(java.lang.String filter)
          applies a filter expression to the list of AutoCompletionListItems.
 void clear()
          removes all elements from the auto completion list
 void clearFilter()
          clears the current filter
 boolean contains(AutoCompletionListItem item)
          checks whether a specific item is already in the list.
 boolean contains(java.lang.String value)
          checks whether an item with the given value is already in the list.
 void dump()
           
protected  void filter()
           
 int getColumnCount()
           
 java.lang.String getFilter()
           
 AutoCompletionListItem getFilteredItem(int idx)
          replies the idx-th item from the list of filtered items
 int getFilteredSize()
          replies the number of filtered items
(package private)  java.util.ArrayList<AutoCompletionListItem> getList()
           
 int getRowCount()
           
(package private)  java.util.List<AutoCompletionListItem> getUnmodifiableList()
           
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
           
 void remove(java.lang.String key)
          removes the auto completion item with key key
protected  void sort()
          sorts the list
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getColumnName, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

list

private java.util.ArrayList<AutoCompletionListItem> list
the bare list of AutoCompletionItems


filtered

private java.util.ArrayList<AutoCompletionListItem> filtered
the filtered list of AutoCompletionItems


filter

private java.lang.String filter
the filter expression


valutToItemMap

private java.util.Map<java.lang.String,AutoCompletionListItem> valutToItemMap
map from value to priority

Constructor Detail

AutoCompletionList

public AutoCompletionList()
constructor

Method Detail

applyFilter

public void applyFilter(java.lang.String filter)
applies a filter expression to the list of AutoCompletionListItems. The matching criterion is a case insensitive substring match.

Parameters:
filter - the filter expression; must not be null
Throws:
java.lang.IllegalArgumentException - thrown, if filter is null

clearFilter

public void clearFilter()
clears the current filter


getFilter

public java.lang.String getFilter()
Returns:
the current filter expression; null, if no filter expression is set

add

public void add(AutoCompletionListItem item)
adds an AutoCompletionListItem to the list. Only adds the item if it is not null and if not in the list yet.

Parameters:
item - the item

add

public void add(AutoCompletionList other)
adds another AutoCompletionList to this list. An item is only added it is not null and if it does not exist in the list yet.

Parameters:
other - another auto completion list; must not be null
Throws:
java.lang.IllegalArgumentException - thrown, if other is null

add

public void add(java.util.List<AutoCompletionListItem> other)
adds a list of AutoCompletionListItem to this list. Only items which are not null and which do not exist yet in the list are added.

Parameters:
other - a list of AutoCompletionListItem; must not be null
Throws:
java.lang.IllegalArgumentException - thrown, if other is null

add

public void add(java.util.Collection<java.lang.String> values,
                AutoCompletionItemPritority priority)
adds a list of strings to this list. Only strings which are not null and which do not exist yet in the list are added.

Parameters:
value - a list of strings to add
priority - the priority to use

appendOrUpdatePriority

protected void appendOrUpdatePriority(AutoCompletionListItem toAdd)

contains

public boolean contains(AutoCompletionListItem item)
checks whether a specific item is already in the list. Matches for the the value and the priority of the item

Parameters:
item - the item to check
Returns:
true, if item is in the list; false, otherwise

contains

public boolean contains(java.lang.String value)
checks whether an item with the given value is already in the list. Ignores priority of the items.

Parameters:
value - the value of an auto completion item
Returns:
true, if value is in the list; false, otherwise

remove

public void remove(java.lang.String key)
removes the auto completion item with key key

Parameters:
key - the key;

sort

protected void sort()
sorts the list


filter

protected void filter()

getFilteredSize

public int getFilteredSize()
replies the number of filtered items

Returns:
the number of filtered items

getFilteredItem

public AutoCompletionListItem getFilteredItem(int idx)
replies the idx-th item from the list of filtered items

Parameters:
idx - the index; must be in the range 0<= idx < getFilteredSize()
Returns:
the item
Throws:
java.lang.IndexOutOfBoundsException - thrown, if idx is out of bounds

getList

java.util.ArrayList<AutoCompletionListItem> getList()

getUnmodifiableList

java.util.List<AutoCompletionListItem> getUnmodifiableList()

clear

public void clear()
removes all elements from the auto completion list


getColumnCount

public int getColumnCount()

getRowCount

public int getRowCount()

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)

dump

public void dump()


JOSM