org.openstreetmap.josm.gui.tagging
Class TagEditorModel

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

public class TagEditorModel
extends javax.swing.table.AbstractTableModel

TagEditorModel is a table model.

See Also:
Serialized Form

Nested Class Summary
(package private)  class TagEditorModel.SelectionStateMemento
           
 
Field Summary
private  javax.swing.DefaultListSelectionModel colSelectionModel
           
private  boolean dirty
          indicates whether the model is dirty
static java.lang.String PROP_DIRTY
           
private  java.beans.PropertyChangeSupport propChangeSupport
           
private  javax.swing.DefaultListSelectionModel rowSelectionModel
           
protected  java.util.ArrayList<TagModel> tags
          the list holding the tags
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
TagEditorModel()
          Creates a new tag editor model.
TagEditorModel(javax.swing.DefaultListSelectionModel rowSelectionModel, javax.swing.DefaultListSelectionModel colSelectionModel)
          Creates a new tag editor model.
 
Method Summary
 void add(java.lang.String name, java.lang.String value)
          adds a tag given by a name/value pair to the tag editor model.
 void add(TagModel tag)
          adds a tag to the model
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
           
 void appendNewTag()
          creates a new tag and appends it to the model
 void applyToPrimitive(Tagged primitive)
          applies the current state of the tag editor model to a primitive
 void applyToTags(java.util.Map<java.lang.String,java.lang.String> tags)
          applies the current state of the tag editor model to a map of tags
 void clear()
          removes all tags in the model
protected  Command createDeleteTagsCommand(java.util.Collection<OsmPrimitive> primitives)
           
protected  Command createUpdateTagCommand(java.util.Collection<OsmPrimitive> primitives, TagModel tag)
           
 void delete(java.lang.String name)
          Deletes all tags with name name
 void deleteTagNames(int[] tagIndices)
          deletes the names of the tags given by tagIndices
 void deleteTags(int[] tagIndices)
          deletes the tags given by tagIndices
 void deleteTagValues(int[] tagIndices)
          deletes the values of the tags given by tagIndices
 void ensureOneTag()
          makes sure the model includes at least one (empty) tag
protected  void fireDirtyStateChanged(boolean oldValue, boolean newValue)
           
 TagModel get(int idx)
           
 TagModel get(java.lang.String name)
          replies the tag with name name; null, if no such tag exists
 int getColumnCount()
           
 javax.swing.DefaultListSelectionModel getColumnSelectionModel()
          Replies the column selection model used by this tag editor model
 java.util.List<java.lang.String> getKeys()
          replies the list of keys of the tags managed by this model
 int getRowCount()
           
 javax.swing.DefaultListSelectionModel getRowSelectionModel()
          Replies the row selection model used by this tag editor model
 TagCollection getTagCollection()
          Replies the tags in this tag editor model as TagCollection.
 java.util.Map<java.lang.String,java.lang.String> getTags()
           
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
           
 boolean includesTag(java.lang.String key)
          checks whether the tag model includes a tag with a given key
 void initFromPrimitive(Tagged primitive)
          initializes the model with the tags of an OSM primitive
 void initFromTags(java.util.Map<java.lang.String,java.lang.String> tags)
          initializes the model with the tags of an OSM primitive
 void initFromTags(TagCollection tags)
          Initializes the model with the tags in a tag collection.
 boolean isCellEditable(int row, int col)
           
 boolean isDirty()
          replies true, if this model has been updated
 void prepend(TagModel tag)
           
 void removeProperyChangeListener(java.beans.PropertyChangeListener listener)
           
protected  void setDirty(boolean newValue)
           
 void setValueAt(java.lang.Object value, int row, int col)
           
protected  void sort()
          sorts the current tags according alphabetical order of names
 void updateTagName(TagModel tag, java.lang.String newName)
          updates the name of a tag and sets the dirty state to true if the new name is different from the old name.
 void updateTagValue(TagModel tag, java.lang.String newValue)
          updates the value value of a tag and sets the dirty state to true if the new name is different from the old name
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getColumnName, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_DIRTY

public static final java.lang.String PROP_DIRTY

tags

protected final java.util.ArrayList<TagModel> tags
the list holding the tags


dirty

private boolean dirty
indicates whether the model is dirty


propChangeSupport

private final java.beans.PropertyChangeSupport propChangeSupport

rowSelectionModel

private javax.swing.DefaultListSelectionModel rowSelectionModel

colSelectionModel

private javax.swing.DefaultListSelectionModel colSelectionModel
Constructor Detail

TagEditorModel

public TagEditorModel()
Creates a new tag editor model. Internally allocates two selection models for row selection and column selection. To create a JTable with this model:
    TagEditorModel model = new TagEditorModel();
    TagTable tbl  = new TagTabel(model);
 

See Also:
getRowSelectionModel(), getColumnSelectionModel()

TagEditorModel

public TagEditorModel(javax.swing.DefaultListSelectionModel rowSelectionModel,
                      javax.swing.DefaultListSelectionModel colSelectionModel)
               throws java.lang.IllegalArgumentException
Creates a new tag editor model.

Parameters:
rowSelectionModel - the row selection model. Must not be null.
colSelectionModel - the column selection model. Must not be null.
Throws:
java.lang.IllegalArgumentException - thrown if rowSelectionModel is null
java.lang.IllegalArgumentException - thrown if colSelectionModel is null
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)

getRowSelectionModel

public javax.swing.DefaultListSelectionModel getRowSelectionModel()
Replies the row selection model used by this tag editor model

Returns:
the row selection model used by this tag editor model

getColumnSelectionModel

public javax.swing.DefaultListSelectionModel getColumnSelectionModel()
Replies the column selection model used by this tag editor model

Returns:
the column selection model used by this tag editor model

removeProperyChangeListener

public void removeProperyChangeListener(java.beans.PropertyChangeListener listener)

fireDirtyStateChanged

protected void fireDirtyStateChanged(boolean oldValue,
                                     boolean newValue)

setDirty

protected void setDirty(boolean newValue)

getColumnCount

public int getColumnCount()

getRowCount

public int getRowCount()

getValueAt

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

setValueAt

public void setValueAt(java.lang.Object value,
                       int row,
                       int col)
Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class javax.swing.table.AbstractTableModel

clear

public void clear()
removes all tags in the model


add

public void add(TagModel tag)
adds a tag to the model

Parameters:
tag - the tag. Must not be null.
Throws:
java.lang.IllegalArgumentException - thrown, if tag is null

prepend

public void prepend(TagModel tag)

add

public void add(java.lang.String name,
                java.lang.String value)
adds a tag given by a name/value pair to the tag editor model. If there is no tag with name name yet, a new TagModel is created and append to this model. If there is a tag with name name, value is merged to the list of values for this tag.

Parameters:
name - the name; converted to "" if null
value - the value; converted to "" if null

get

public TagModel get(java.lang.String name)
replies the tag with name name; null, if no such tag exists

Parameters:
name - the tag name
Returns:
the tag with name name; null, if no such tag exists

get

public TagModel get(int idx)

isCellEditable

public boolean isCellEditable(int row,
                              int col)
Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel

deleteTagNames

public void deleteTagNames(int[] tagIndices)
deletes the names of the tags given by tagIndices

Parameters:
tagIndices - a list of tag indices

deleteTagValues

public void deleteTagValues(int[] tagIndices)
deletes the values of the tags given by tagIndices

Parameters:
tagIndices - the lit of tag indices

delete

public void delete(java.lang.String name)
Deletes all tags with name name

Parameters:
name - the name. Ignored if null.

deleteTags

public void deleteTags(int[] tagIndices)
deletes the tags given by tagIndices

Parameters:
tagIndices - the list of tag indices

appendNewTag

public void appendNewTag()
creates a new tag and appends it to the model


ensureOneTag

public void ensureOneTag()
makes sure the model includes at least one (empty) tag


initFromPrimitive

public void initFromPrimitive(Tagged primitive)
initializes the model with the tags of an OSM primitive

Parameters:
primitive - the OSM primitive

initFromTags

public void initFromTags(java.util.Map<java.lang.String,java.lang.String> tags)
initializes the model with the tags of an OSM primitive

Parameters:
primitive - the OSM primitive

initFromTags

public void initFromTags(TagCollection tags)
Initializes the model with the tags in a tag collection. Removes all tags if tags is null.

Parameters:
tags - the tags

applyToPrimitive

public void applyToPrimitive(Tagged primitive)
applies the current state of the tag editor model to a primitive

Parameters:
primitive - the primitive

applyToTags

public void applyToTags(java.util.Map<java.lang.String,java.lang.String> tags)
applies the current state of the tag editor model to a map of tags

Parameters:
tags - the map of key/value pairs

getTags

public java.util.Map<java.lang.String,java.lang.String> getTags()

getTagCollection

public TagCollection getTagCollection()
Replies the tags in this tag editor model as TagCollection.

Returns:
the tags in this tag editor model as TagCollection

includesTag

public boolean includesTag(java.lang.String key)
checks whether the tag model includes a tag with a given key

Parameters:
key - the key
Returns:
true, if the tag model includes the tag; false, otherwise

createUpdateTagCommand

protected Command createUpdateTagCommand(java.util.Collection<OsmPrimitive> primitives,
                                         TagModel tag)

createDeleteTagsCommand

protected Command createDeleteTagsCommand(java.util.Collection<OsmPrimitive> primitives)

getKeys

public java.util.List<java.lang.String> getKeys()
replies the list of keys of the tags managed by this model

Returns:
the list of keys managed by this model

sort

protected void sort()
sorts the current tags according alphabetical order of names


updateTagName

public void updateTagName(TagModel tag,
                          java.lang.String newName)
updates the name of a tag and sets the dirty state to true if the new name is different from the old name.

Parameters:
tag - the tag
newName - the new name

updateTagValue

public void updateTagValue(TagModel tag,
                           java.lang.String newValue)
updates the value value of a tag and sets the dirty state to true if the new name is different from the old name

Parameters:
tag - the tag
newValue - the new value

isDirty

public boolean isDirty()
replies true, if this model has been updated

Returns:
true, if this model has been updated


JOSM