Class LayerListDialog.LayerListModel
java.lang.Object
javax.swing.table.AbstractTableModel
org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel
- All Implemented Interfaces:
PropertyChangeListener,Serializable,EventListener,TableModel,ReorderableModel<Layer>,LayerManager.LayerChangeListener,MainLayerManager.ActiveLayerChangeListener,ReorderableTableModel<Layer>
- Enclosing class:
- LayerListDialog
public static final class LayerListDialog.LayerListModel
extends AbstractTableModel
implements LayerManager.LayerChangeListener, MainLayerManager.ActiveLayerChangeListener, 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 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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate LayerListDialog.LayerListprivate final MainLayerManagerprivate final CopyOnWriteArrayList<LayerListDialog.LayerListModelListener>private final DefaultListSelectionModelmanages list selection stateFields inherited from class javax.swing.table.AbstractTableModel
listenerList -
Constructor Summary
ConstructorsConstructorDescriptionLayerListModel(MainLayerManager layerManager, DefaultListSelectionModel selectionModel) constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled whenever the active or edit layer changed.voidAdds a listener to this modelbooleandoMove(int delta, int... selectedRows) Performs the move operation, without any check nor selection handling.private voidEnsures that at least one layer is selected in the layer dialogprivate voidMake sure the first of the selected layers is visible in the views of this model.private voidfireMakeVisible(int index, Layer layer) Fires a make visible event to listenersprivate voidFires a refresh event to listeners of this modelprivate LayerReplies the active layer.intReplies the first layer.getLayer(int index) Replies the layer at positionindexThe layer manager this model is for.Replies the list of layers currently managed byMapView.getPossibleMergeTargets(Layer source) Replies a list of layers which are possible merge targets forsourceintReturns the number of rows in the list/table.Replies the list of currently selected layers.Replies a the list of indices of the selected rows.Returns the selection model.getValue(int index) Get object value at given index.getValueAt(int row, int col) booleanisCellEditable(int row, int col) voidNotifies this listener that a layer has been added.voidNotifies this listener that the order of layers was changed.voidNotifies this listener that a layer was just removed.booleanmove(int delta, int... selectedRows) Move selected rows by any number of positions, if possible.private voidonAddLayer(Layer layer) Invoked when a layer managed byMapViewis addedprivate voidonRemoveLayer(Layer layer) Invoked if a layer managed byMapViewis removedvoidpopulate()Populates the model with the current layers managed byMapView.voidvoidremoves a listener from this model(package private) voidsetLayerList(LayerListDialog.LayerList layerList) voidsetSelectedLayer(Layer layer) Markslayeras selected layer.Set object value at given index.voidsetValueAt(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, removeTableModelListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.openstreetmap.josm.data.ReorderableModel
canMove, canMoveDown, canMoveUpMethods inherited from interface org.openstreetmap.josm.gui.util.ReorderableTableModel
canMove, canMoveDown, canMoveDown, canMoveUp, canMoveUp, getSelectedIndices, moveDown, moveDown, moveUp, moveUp, selectedIndices
-
Field Details
-
selectionModel
manages list selection state -
listeners
-
layerList
-
layerManager
-
-
Constructor Details
-
LayerListModel
LayerListModel(MainLayerManager layerManager, DefaultListSelectionModel selectionModel) constructor- Parameters:
layerManager- The layer manager to use for the list.selectionModel- the list selection model
-
-
Method Details
-
setLayerList
-
getLayerManager
The layer manager this model is for.- Returns:
- The layer manager.
-
addLayerListModelListener
Adds a listener to this model- Parameters:
listener- the listener
-
removeLayerListModelListener
removes a listener from this model- Parameters:
listener- the listener
-
fireMakeVisible
Fires a make visible event to listeners- Parameters:
index- the index of the row to make visiblelayer- the layer at this index- See Also:
-
fireRefresh
Fires a refresh event to listeners of this model -
populate
Populates the model with the current layers managed byMapView. -
setSelectedLayer
Markslayeras selected layer. Ignored, if layer is null.- Parameters:
layer- the 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
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
Invoked if a layer managed byMapViewis removed- Parameters:
layer- the layer which is removed
-
onAddLayer
Invoked when a layer managed byMapViewis added- Parameters:
layer- the layer
-
getFirstLayer
Replies the first layer. Null if no layers are present- Returns:
- the first layer. Null if no layers are present
-
getLayer
Replies the layer at positionindex- Parameters:
index- the index- Returns:
- the layer at position
index. Null, if index is out of range.
-
getSelectionModel
Description copied from interface:ReorderableTableModelReturns the selection model.- Specified by:
getSelectionModelin interfaceReorderableTableModel<Layer>- Returns:
- the selection model (never null)
- See Also:
-
getValue
Description copied from interface:ReorderableModelGet object value at given index.- Specified by:
getValuein interfaceReorderableModel<Layer>- Parameters:
index- index- Returns:
- object value at given index
-
setValue
Description copied from interface:ReorderableModelSet object value at given index.- Specified by:
setValuein interfaceReorderableModel<Layer>- Parameters:
index- indexvalue- new value- Returns:
- the value previously at the specified position
-
doMove
Description copied from interface:ReorderableModelPerforms the move operation, without any check nor selection handling.- Specified by:
doMovein interfaceReorderableModel<Layer>- Parameters:
delta- negative or positive deltaselectedRows- rows to move- Returns:
trueif rows have been moved
-
move
Description copied from interface:ReorderableTableModelMove selected rows by any number of positions, if possible.- Specified by:
movein interfaceReorderableTableModel<Layer>- Parameters:
delta- negative or positive deltaselectedRows- rows to move- Returns:
trueif the move was performed- See Also:
-
ensureSelectedIsVisible
Make sure the first of the selected layers is visible in the views of this model. -
getPossibleMergeTargets
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
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
Ensures that at least one layer is selected in the layer dialog -
getActiveLayer
Replies the active layer. null, if no active layer is available- Returns:
- the active layer. null, if no active layer is available
-
getRowCount
Description copied from interface:ReorderableTableModelReturns the number of rows in the list/table.- Specified by:
getRowCountin interfaceReorderableTableModel<Layer>- Specified by:
getRowCountin interfaceTableModel- Returns:
- the number of rows in the list/table
- See Also:
-
getColumnCount
- Specified by:
getColumnCountin interfaceTableModel
-
getValueAt
- Specified by:
getValueAtin interfaceTableModel
-
isCellEditable
- Specified by:
isCellEditablein interfaceTableModel- Overrides:
isCellEditablein classAbstractTableModel
-
setValueAt
- Specified by:
setValueAtin interfaceTableModel- Overrides:
setValueAtin classAbstractTableModel
-
activeOrEditLayerChanged
Description copied from interface:MainLayerManager.ActiveLayerChangeListenerCalled 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:
activeOrEditLayerChangedin interfaceMainLayerManager.ActiveLayerChangeListener- Parameters:
e- The change event.
-
layerAdded
Description copied from interface:LayerManager.LayerChangeListenerNotifies 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:
layerAddedin interfaceLayerManager.LayerChangeListener- Parameters:
e- The new added layer event
-
layerRemoving
Description copied from interface:LayerManager.LayerChangeListenerNotifies 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:
layerRemovingin interfaceLayerManager.LayerChangeListener- Parameters:
e- The layer to be removed (as event)
-
layerOrderChanged
Description copied from interface:LayerManager.LayerChangeListenerNotifies 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:
layerOrderChangedin interfaceLayerManager.LayerChangeListener- Parameters:
e- The order change event.
-
propertyChange
- Specified by:
propertyChangein interfacePropertyChangeListener
-