Class LayerListDialog.LayerListModel
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener
,java.io.Serializable
,java.util.EventListener
,javax.swing.table.TableModel
,ReorderableModel<Layer>
,LayerManager.LayerChangeListener
,MainLayerManager.ActiveLayerChangeListener
,ReorderableTableModel<Layer>
- Enclosing class:
- LayerListDialog
public static final class LayerListDialog.LayerListModel extends javax.swing.table.AbstractTableModel implements LayerManager.LayerChangeListener, MainLayerManager.ActiveLayerChangeListener, java.beans.PropertyChangeListener, ReorderableTableModel<Layer>
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 aTableModel
and it provides aListSelectionModel
. It expects to be configured with aDefaultListSelectionModel
. The selection model is used to update the selection state of views depending on messages sent to the model. The model manages a list ofLayerListDialog.LayerListModelListener
which are mainly notified if the model requires views to make a specific list entry visible. It also listens toPropertyChangeEvent
s of everyLayer
it manages, in particular to the propertiesLayer.VISIBLE_PROP
andLayer.NAME_PROP
.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private LayerListDialog.LayerList
layerList
private MainLayerManager
layerManager
private java.util.concurrent.CopyOnWriteArrayList<LayerListDialog.LayerListModelListener>
listeners
private javax.swing.DefaultListSelectionModel
selectionModel
manages list selection state
-
Constructor Summary
Constructors Constructor Description LayerListModel(MainLayerManager layerManager, javax.swing.DefaultListSelectionModel selectionModel)
constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activeOrEditLayerChanged(MainLayerManager.ActiveLayerChangeEvent e)
Called whenever the active or edit layer changed.void
addLayerListModelListener(LayerListDialog.LayerListModelListener listener)
Adds a listener to this modelboolean
doMove(int delta, int... selectedRows)
Performs the move operation, without any check nor selection handling.private void
ensureActiveSelected()
Ensures that at least one layer is selected in the layer dialogprivate void
ensureSelectedIsVisible()
Make sure the first of the selected layers is visible in the views of this model.private void
fireMakeVisible(int index, Layer layer)
Fires a make visible event to listenersprivate void
fireRefresh()
Fires a refresh event to listeners of this modelprivate Layer
getActiveLayer()
Replies the active layer.int
getColumnCount()
Layer
getFirstLayer()
Replies the first layer.Layer
getLayer(int index)
Replies the layer at positionindex
MainLayerManager
getLayerManager()
The layer manager this model is for.java.util.List<Layer>
getLayers()
Replies the list of layers currently managed byMapView
.java.util.List<Layer>
getPossibleMergeTargets(Layer source)
Replies a list of layers which are possible merge targets forsource
int
getRowCount()
Returns the number of rows in the list/table.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.javax.swing.DefaultListSelectionModel
getSelectionModel()
Returns the selection model.Layer
getValue(int index)
Get object value at given index.java.lang.Object
getValueAt(int row, int col)
boolean
isCellEditable(int row, int col)
void
layerAdded(LayerManager.LayerAddEvent e)
Notifies this listener that a layer has been added.void
layerOrderChanged(LayerManager.LayerOrderChangeEvent e)
Notifies this listener that the order of layers was changed.void
layerRemoving(LayerManager.LayerRemoveEvent e)
Notifies this listener that a layer was just removed.boolean
move(int delta, int... selectedRows)
Move selected rows by any number of positions, if possible.private void
onAddLayer(Layer layer)
Invoked when a layer managed byMapView
is addedprivate void
onRemoveLayer(Layer layer)
Invoked if a layer managed byMapView
is removedvoid
populate()
Populates the model with the current layers managed byMapView
.void
propertyChange(java.beans.PropertyChangeEvent evt)
void
removeLayerListModelListener(LayerListDialog.LayerListModelListener listener)
removes a listener from this model(package private) void
setLayerList(LayerListDialog.LayerList layerList)
void
setSelectedLayer(Layer layer)
Markslayer
as selected layer.Layer
setValue(int index, Layer value)
Set object value at given index.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
-
Methods inherited from interface org.openstreetmap.josm.data.ReorderableModel
canMove, canMoveDown, canMoveUp
-
Methods inherited from interface org.openstreetmap.josm.gui.util.ReorderableTableModel
canMove, canMoveDown, canMoveDown, canMoveUp, canMoveUp, getSelectedIndices, moveDown, moveDown, moveUp, moveUp, selectedIndices
-
-
-
-
Field Detail
-
selectionModel
private final javax.swing.DefaultListSelectionModel selectionModel
manages list selection state
-
listeners
private final java.util.concurrent.CopyOnWriteArrayList<LayerListDialog.LayerListModelListener> listeners
-
layerList
private LayerListDialog.LayerList layerList
-
layerManager
private final MainLayerManager layerManager
-
-
Constructor Detail
-
LayerListModel
LayerListModel(MainLayerManager layerManager, javax.swing.DefaultListSelectionModel selectionModel)
constructor- Parameters:
layerManager
- The layer manager to use for the list.selectionModel
- the list selection model
-
-
Method Detail
-
setLayerList
void setLayerList(LayerListDialog.LayerList layerList)
-
getLayerManager
public MainLayerManager getLayerManager()
The layer manager this model is for.- Returns:
- The layer manager.
-
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
private void fireMakeVisible(int index, Layer layer)
Fires a make visible event to listeners- Parameters:
index
- the index of the row to make visiblelayer
- the layer at this index- See Also:
LayerListDialog.LayerListModelListener.makeVisible(int, Layer)
-
fireRefresh
private void fireRefresh()
Fires a refresh event to listeners of this model
-
setSelectedLayer
public void setSelectedLayer(Layer layer)
Markslayer
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
private void onRemoveLayer(Layer layer)
Invoked if a layer managed byMapView
is removed- Parameters:
layer
- the layer which is removed
-
onAddLayer
private void onAddLayer(Layer layer)
Invoked when a layer managed byMapView
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 positionindex
- Parameters:
index
- the index- Returns:
- the layer at position
index
. Null, if index is out of range.
-
getSelectionModel
public javax.swing.DefaultListSelectionModel getSelectionModel()
Description copied from interface:ReorderableTableModel
Returns the selection model.- Specified by:
getSelectionModel
in interfaceReorderableTableModel<Layer>
- Returns:
- the selection model (never null)
- See Also:
JList.getSelectionModel()
,JTable.getSelectionModel()
-
getValue
public Layer getValue(int index)
Description copied from interface:ReorderableModel
Get object value at given index.- Specified by:
getValue
in interfaceReorderableModel<Layer>
- Parameters:
index
- index- Returns:
- object value at given index
-
setValue
public Layer setValue(int index, Layer value)
Description copied from interface:ReorderableModel
Set object value at given index.- Specified by:
setValue
in interfaceReorderableModel<Layer>
- Parameters:
index
- indexvalue
- new value- Returns:
- the value previously at the specified position
-
doMove
public boolean doMove(int delta, int... selectedRows)
Description copied from interface:ReorderableModel
Performs the move operation, without any check nor selection handling.- Specified by:
doMove
in interfaceReorderableModel<Layer>
- Parameters:
delta
- negative or positive deltaselectedRows
- rows to move- Returns:
true
if rows have been moved
-
move
public boolean move(int delta, int... selectedRows)
Description copied from interface:ReorderableTableModel
Move selected rows by any number of positions, if possible.- Specified by:
move
in interfaceReorderableTableModel<Layer>
- Parameters:
delta
- negative or positive deltaselectedRows
- rows to move- Returns:
true
if the move was performed- See Also:
ReorderableTableModel.canMove(int)
-
ensureSelectedIsVisible
private 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 forsource
- 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 byMapView
. Never null, but can be empty.- Returns:
- the list of layers currently managed by
MapView
. Never null, but can be empty.
-
ensureActiveSelected
private void ensureActiveSelected()
Ensures that at least one layer is selected in the layer dialog
-
getActiveLayer
private 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()
Description copied from interface:ReorderableTableModel
Returns the number of rows in the list/table.- Specified by:
getRowCount
in interfaceReorderableTableModel<Layer>
- Specified by:
getRowCount
in interfacejavax.swing.table.TableModel
- Returns:
- the number of rows in the list/table
- See Also:
ListModel.getSize()
,TableModel.getRowCount()
-
getColumnCount
public int getColumnCount()
- Specified by:
getColumnCount
in interfacejavax.swing.table.TableModel
-
getValueAt
public java.lang.Object getValueAt(int row, int col)
- Specified by:
getValueAt
in interfacejavax.swing.table.TableModel
-
isCellEditable
public boolean isCellEditable(int row, int col)
- Specified by:
isCellEditable
in interfacejavax.swing.table.TableModel
- Overrides:
isCellEditable
in classjavax.swing.table.AbstractTableModel
-
setValueAt
public void setValueAt(java.lang.Object value, int row, int col)
- Specified by:
setValueAt
in interfacejavax.swing.table.TableModel
- Overrides:
setValueAt
in classjavax.swing.table.AbstractTableModel
-
activeOrEditLayerChanged
public void activeOrEditLayerChanged(MainLayerManager.ActiveLayerChangeEvent e)
Description copied from interface:MainLayerManager.ActiveLayerChangeListener
Called whenever the active or edit layer changed.You can be sure that this layer is still contained in this set.
Listeners are called in the EDT thread and you can manipulate the layer manager in the current thread.
- Specified by:
activeOrEditLayerChanged
in interfaceMainLayerManager.ActiveLayerChangeListener
- Parameters:
e
- The change event.
-
layerAdded
public void layerAdded(LayerManager.LayerAddEvent e)
Description copied from interface:LayerManager.LayerChangeListener
Notifies this listener that a layer has been added.Listeners are called in the EDT thread. You should not do blocking or long-running tasks in this method.
- Specified by:
layerAdded
in interfaceLayerManager.LayerChangeListener
- Parameters:
e
- The new added layer event
-
layerRemoving
public void layerRemoving(LayerManager.LayerRemoveEvent e)
Description copied from interface:LayerManager.LayerChangeListener
Notifies this listener that a layer was just removed.Listeners are called in the EDT thread after the layer was removed. Use
LayerManager.LayerRemoveEvent.scheduleRemoval(Collection)
to remove more layers. You should not do blocking or long-running tasks in this method.- Specified by:
layerRemoving
in interfaceLayerManager.LayerChangeListener
- Parameters:
e
- The layer to be removed (as event)
-
layerOrderChanged
public void layerOrderChanged(LayerManager.LayerOrderChangeEvent e)
Description copied from interface:LayerManager.LayerChangeListener
Notifies this listener that the order of layers was changed.Listeners are called in the EDT thread. You should not do blocking or long-running tasks in this method.
- Specified by:
layerOrderChanged
in interfaceLayerManager.LayerChangeListener
- Parameters:
e
- The order change event.
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
- Specified by:
propertyChange
in interfacejava.beans.PropertyChangeListener
-
-