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 aTableModeland 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.LayerListModelListenerwhich are mainly notified if the model requires views to make a specific list entry visible. It also listens toPropertyChangeEvents of everyLayerit manages, in particular to the propertiesLayer.VISIBLE_PROPandLayer.NAME_PROP.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private LayerListDialog.LayerListlayerListprivate MainLayerManagerlayerManagerprivate java.util.concurrent.CopyOnWriteArrayList<LayerListDialog.LayerListModelListener>listenersprivate javax.swing.DefaultListSelectionModelselectionModelmanages 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 voidactiveOrEditLayerChanged(MainLayerManager.ActiveLayerChangeEvent e)Called whenever the active or edit layer changed.voidaddLayerListModelListener(LayerListDialog.LayerListModelListener listener)Adds a listener to this modelbooleandoMove(int delta, int... selectedRows)Performs the move operation, without any check nor selection handling.private voidensureActiveSelected()Ensures that at least one layer is selected in the layer dialogprivate voidensureSelectedIsVisible()Make 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 voidfireRefresh()Fires a refresh event to listeners of this modelprivate LayergetActiveLayer()Replies the active layer.intgetColumnCount()LayergetFirstLayer()Replies the first layer.LayergetLayer(int index)Replies the layer at positionindexMainLayerManagergetLayerManager()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 forsourceintgetRowCount()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.DefaultListSelectionModelgetSelectionModel()Returns the selection model.LayergetValue(int index)Get object value at given index.java.lang.ObjectgetValueAt(int row, int col)booleanisCellEditable(int row, int col)voidlayerAdded(LayerManager.LayerAddEvent e)Notifies this listener that a layer has been added.voidlayerOrderChanged(LayerManager.LayerOrderChangeEvent e)Notifies this listener that the order of layers was changed.voidlayerRemoving(LayerManager.LayerRemoveEvent e)Notifies 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.voidpropertyChange(java.beans.PropertyChangeEvent evt)voidremoveLayerListModelListener(LayerListDialog.LayerListModelListener listener)removes a listener from this model(package private) voidsetLayerList(LayerListDialog.LayerList layerList)voidsetSelectedLayer(Layer layer)Markslayeras selected layer.LayersetValue(int index, Layer value)Set object value at given index.voidsetValueAt(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)
Markslayeras 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 byMapViewis removed- Parameters:
layer- the layer which is removed
-
onAddLayer
private void onAddLayer(Layer layer)
Invoked when a layer managed byMapViewis 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:ReorderableTableModelReturns the selection model.- Specified by:
getSelectionModelin interfaceReorderableTableModel<Layer>- Returns:
- the selection model (never null)
- See Also:
JList.getSelectionModel(),JTable.getSelectionModel()
-
getValue
public Layer getValue(int index)
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
public Layer setValue(int index, Layer value)
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
public boolean doMove(int delta, int... selectedRows)
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
public boolean move(int delta, int... selectedRows)
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:
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:ReorderableTableModelReturns the number of rows in the list/table.- Specified by:
getRowCountin interfaceReorderableTableModel<Layer>- Specified by:
getRowCountin 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:
getColumnCountin interfacejavax.swing.table.TableModel
-
getValueAt
public java.lang.Object getValueAt(int row, int col)
- Specified by:
getValueAtin interfacejavax.swing.table.TableModel
-
isCellEditable
public boolean isCellEditable(int row, int col)
- Specified by:
isCellEditablein interfacejavax.swing.table.TableModel- Overrides:
isCellEditablein classjavax.swing.table.AbstractTableModel
-
setValueAt
public void setValueAt(java.lang.Object value, int row, int col)
- Specified by:
setValueAtin interfacejavax.swing.table.TableModel- Overrides:
setValueAtin classjavax.swing.table.AbstractTableModel
-
activeOrEditLayerChanged
public void activeOrEditLayerChanged(MainLayerManager.ActiveLayerChangeEvent e)
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
public void layerAdded(LayerManager.LayerAddEvent e)
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
public void layerRemoving(LayerManager.LayerRemoveEvent e)
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
public void layerOrderChanged(LayerManager.LayerOrderChangeEvent e)
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
public void propertyChange(java.beans.PropertyChangeEvent evt)
- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener
-
-