org.openstreetmap.josm.gui.dialogs
Class LayerListDialog.LayerListModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener, javax.swing.table.TableModel, MapView.LayerChangeListener
Enclosing class:
LayerListDialog

public class LayerListDialog.LayerListModel
extends javax.swing.table.AbstractTableModel
implements MapView.LayerChangeListener, java.beans.PropertyChangeListener

The layer list model. The model manages a list of layers and provides methods for moving layers up and down, for toggling their visibility, and for activating a layer. The model is a TableModel and it provides a ListSelectionModel. It expects to be configured with a DefaultListSelectionModel. The selection model is used to update the selection state of views depending on messages sent to the model. The model manages a list of LayerListDialog.LayerListModelListener which are mainly notified if the model requires views to make a specific list entry visible. It also listens to PropertyChangeEvents of every Layer it manages, in particular to the properties Layer.VISIBLE_PROP and Layer.NAME_PROP.

See Also:
Serialized Form

Field Summary
private  java.util.concurrent.CopyOnWriteArrayList<LayerListDialog.LayerListModelListener> listeners
           
private  javax.swing.DefaultListSelectionModel selectionModel
          manages list selection state
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
private LayerListDialog.LayerListModel(javax.swing.DefaultListSelectionModel selectionModel)
          constructor
 
Method Summary
 void activeLayerChange(Layer oldLayer, Layer newLayer)
          Notifies this listener that the active layer has changed.
 void addLayerListModelListener(LayerListDialog.LayerListModelListener listener)
          Adds a listener to this model
 boolean canMoveDown()
          Replies true if the currently selected layers can move down by one position
 boolean canMoveUp()
          Replies true if the currently selected layers can move up by one position
protected  void ensureActiveSelected()
          Ensures that at least one layer is selected in the layer dialog
protected  void ensureSelectedIsVisible()
          Make sure the first of the selected layers is visible in the views of this model.
protected  void fireMakeVisible(int index, Layer layer)
          Fires a make visible event to listeners
protected  void fireRefresh()
          Fires a refresh event to listeners of this model
protected  Layer getActiveLayer()
          Replies the active layer.
 int getColumnCount()
           
 Layer getFirstLayer()
          Replies the first layer.
 Layer getLayer(int index)
          Replies the layer at position index
 java.util.List<Layer> getLayers()
          Replies the list of layers currently managed by MapView.
 java.util.List<Layer> getPossibleMergeTargets(Layer source)
          Replies a list of layers which are possible merge targets for source
 int getRowCount()
           
 java.util.List<Layer> getSelectedLayers()
          Replies the list of currently selected layers.
 java.util.List<java.lang.Integer> getSelectedRows()
          Replies a the list of indices of the selected rows.
 java.lang.Object getValueAt(int row, int col)
           
 boolean isCellEditable(int row, int col)
           
 void layerAdded(Layer newLayer)
          Notifies this listener that a layer has been added.
 void layerRemoved(Layer oldLayer)
          Notifies this listener that a layer has been removed.
 void moveDown()
          Move down the currently selected layers by one position
 void moveUp()
          Move up the currently selected layers by one position
protected  void onAddLayer(Layer layer)
          Invoked when a layer managed by MapView is added
protected  void onRemoveLayer(Layer layer)
          Invoked if a layer managed by MapView is removed
 void populate()
          Populates the model with the current layers managed by MapView.
 void propertyChange(java.beans.PropertyChangeEvent evt)
           
 void removeLayerListModelListener(LayerListDialog.LayerListModelListener listener)
          removes a listener from this model
 void setSelectedLayer(Layer layer)
          Marks layer as selected layer.
 void setValueAt(java.lang.Object value, int row, int col)
           
 
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

selectionModel

private javax.swing.DefaultListSelectionModel selectionModel
manages list selection state


listeners

private java.util.concurrent.CopyOnWriteArrayList<LayerListDialog.LayerListModelListener> listeners
Constructor Detail

LayerListDialog.LayerListModel

private LayerListDialog.LayerListModel(javax.swing.DefaultListSelectionModel selectionModel)
constructor

Parameters:
selectionModel - the list selection model
Method Detail

addLayerListModelListener

public void addLayerListModelListener(LayerListDialog.LayerListModelListener listener)
Adds a listener to this model

Parameters:
listener - the listener

removeLayerListModelListener

public void removeLayerListModelListener(LayerListDialog.LayerListModelListener listener)
removes a listener from this model

Parameters:
listener - the listener

fireMakeVisible

protected void fireMakeVisible(int index,
                               Layer layer)
Fires a make visible event to listeners

Parameters:
index - the index of the row to make visible
layer - the layer at this index
See Also:
LayerListDialog.LayerListModelListener.makeVisible(int, Layer)

fireRefresh

protected void fireRefresh()
Fires a refresh event to listeners of this model

See Also:
LayerListDialog.LayerListModelListener.refresh()

populate

public void populate()
Populates the model with the current layers managed by MapView.


setSelectedLayer

public void setSelectedLayer(Layer layer)
Marks layer as selected layer. Ignored, if layer is null.

Parameters:
layer - the layer.

getSelectedLayers

public java.util.List<Layer> getSelectedLayers()
Replies the list of currently selected layers. Never null, but may be empty.

Returns:
the list of currently selected layers. Never null, but may be empty.

getSelectedRows

public java.util.List<java.lang.Integer> getSelectedRows()
Replies a the list of indices of the selected rows. Never null, but may be empty.

Returns:
the list of indices of the selected rows. Never null, but may be empty.

onRemoveLayer

protected void onRemoveLayer(Layer layer)
Invoked if a layer managed by MapView is removed

Parameters:
layer - the layer which is removed

onAddLayer

protected void onAddLayer(Layer layer)
Invoked when a layer managed by MapView is added

Parameters:
layer - the layer

getFirstLayer

public Layer getFirstLayer()
Replies the first layer. Null if no layers are present

Returns:
the first layer. Null if no layers are present

getLayer

public Layer getLayer(int index)
Replies the layer at position index

Parameters:
index - the index
Returns:
the layer at position index. Null, if index is out of range.

canMoveUp

public boolean canMoveUp()
Replies true if the currently selected layers can move up by one position

Returns:
true if the currently selected layers can move up by one position

moveUp

public void moveUp()
Move up the currently selected layers by one position


canMoveDown

public boolean canMoveDown()
Replies true if the currently selected layers can move down by one position

Returns:
true if the currently selected layers can move down by one position

moveDown

public void moveDown()
Move down the currently selected layers by one position


ensureSelectedIsVisible

protected void ensureSelectedIsVisible()
Make sure the first of the selected layers is visible in the views of this model.


getPossibleMergeTargets

public java.util.List<Layer> getPossibleMergeTargets(Layer source)
Replies a list of layers which are possible merge targets for source

Parameters:
source - the source layer
Returns:
a list of layers which are possible merge targets for source. Never null, but can be empty.

getLayers

public java.util.List<Layer> getLayers()
Replies the list of layers currently managed by MapView. Never null, but can be empty.

Returns:
the list of layers currently managed by MapView. Never null, but can be empty.

ensureActiveSelected

protected void ensureActiveSelected()
Ensures that at least one layer is selected in the layer dialog


getActiveLayer

protected Layer getActiveLayer()
Replies the active layer. null, if no active layer is available

Returns:
the active layer. null, if no active layer is available

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface javax.swing.table.TableModel

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface javax.swing.table.TableModel

getValueAt

public java.lang.Object getValueAt(int row,
                                   int col)
Specified by:
getValueAt in interface javax.swing.table.TableModel

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

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

activeLayerChange

public void activeLayerChange(Layer oldLayer,
                              Layer newLayer)
Description copied from interface: MapView.LayerChangeListener
Notifies this listener that the active layer has changed.

Specified by:
activeLayerChange in interface MapView.LayerChangeListener
Parameters:
oldLayer - The previous active layer
newLayer - The new activer layer

layerAdded

public void layerAdded(Layer newLayer)
Description copied from interface: MapView.LayerChangeListener
Notifies this listener that a layer has been added.

Specified by:
layerAdded in interface MapView.LayerChangeListener
Parameters:
newLayer - The new added layer

layerRemoved

public void layerRemoved(Layer oldLayer)
Description copied from interface: MapView.LayerChangeListener
Notifies this listener that a layer has been removed.

Specified by:
layerRemoved in interface MapView.LayerChangeListener
Parameters:
oldLayer - The old removed layer

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener


JOSM