Class HistoryBrowserModel
- java.lang.Object
-
- org.openstreetmap.josm.gui.util.ChangeNotifier
-
- org.openstreetmap.josm.gui.history.HistoryBrowserModel
-
- All Implemented Interfaces:
DataSetListener,MainLayerManager.ActiveLayerChangeListener
public class HistoryBrowserModel extends ChangeNotifier implements MainLayerManager.ActiveLayerChangeListener, DataSetListener
This is the model used by the history browser. The model state consists of the following elements:- the
Historyof a specificOsmPrimitive - a dedicated version in this
Historycalled thePointInTimeType.REFERENCE_POINT_IN_TIME - another version in this
Historycalled thePointInTimeType.CURRENT_POINT_IN_TIME
HistoryBrowseralways compares thePointInTimeType.REFERENCE_POINT_IN_TIMEwith thePointInTimeType.CURRENT_POINT_IN_TIME. This model provides variousTableModels forJTables used inHistoryBrowser, for instance:getTagTableModel(PointInTimeType)replies aTableModelfor the tags of either of the two selected versionsgetNodeListTableModel(PointInTimeType)replies aTableModelfor the list of nodes of the two selected versions (if the current history provides information about aWay-
getRelationMemberTableModel(PointInTimeType)replies aTableModelfor the list of relation members of the two selected versions (if the current history provides information about aRelation
- See Also:
HistoryBrowser
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classHistoryBrowserModel.HistoryPrimitiveBuilderCreates aHistoryOsmPrimitivefrom aOsmPrimitive
-
Field Summary
Fields Modifier and Type Field Description private HistoryOsmPrimitivecurrentprivate DiffTableModelcurrentNodeListTableModelprivate DiffTableModelcurrentRelationMemberTableModelprivate TagTableModelcurrentTagTableModelprivate ColorScaledateScaleprivate Historyhistorythe history of an OsmPrimitiveprivate HistoryOsmPrimitivelatestlatest isn't a reference of history.private HistoryOsmPrimitivereferenceprivate DiffTableModelreferenceNodeListTableModelprivate DiffTableModelreferenceRelationMemberTableModelprivate TagTableModelreferenceTagTableModelprivate VersionTableModelversionTableModel
-
Constructor Summary
Constructors Constructor Description HistoryBrowserModel()constructorHistoryBrowserModel(History history)Creates a new history browser model for a given history.
-
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.private booleancanShowAsLatest(OsmPrimitive primitive)voiddataChanged(DataChangedEvent event)Called after big changes in dataset.private voidfireModelChange()HistoryOsmPrimitivegetCurrentPointInTime()Replies the history OSM primitive for thePointInTimeType.CURRENT_POINT_IN_TIMEHistorygetHistory()replies the history managed by this modeljava.util.Set<java.lang.String>getKeySet()Returns the key set (union of current and reference point in type key sets).HistoryOsmPrimitivegetLatest()Returns the latestHistoryOsmPrimitive.DiffTableModelgetNodeListTableModel(PointInTimeType pointInTimeType)Replies the node list table model for the respective point in time.HistoryOsmPrimitivegetPointInTime(PointInTimeType type)replies the history OSM primitive for a given point in timeHistoryOsmPrimitivegetPrimitive(int row)Returns theHistoryPrimitiveat the given row.HistoryOsmPrimitivegetReferencePointInTime()Replies the history OSM primitive for thePointInTimeType.REFERENCE_POINT_IN_TIMEDiffTableModelgetRelationMemberTableModel(PointInTimeType pointInTimeType)Replies the relation member table model for the respective point in time.TagTableModelgetTagTableModel(PointInTimeType pointInTimeType)Replies the tag table model for the respective point in time.java.awt.ColorgetVersionColor(int row)Returns the color for the primitive in the given rowjava.awt.ColorgetVersionColor(HistoryOsmPrimitive primitive)Returns the color for the given primitive timestampVersionTableModelgetVersionTableModel()Replies the table model to be used in aJTablewhich shows the list of versions in this history.private voidinitMemberListTableModels()private voidinitNodeListTableModels()Should be called every time either reference of current changes to update the diff.private voidinitTagTableModels()booleanisCurrentPointInTime(int row)Determines if the given row is the current point in time.booleanisLatest(int row)Determines if the given row is the latest.booleanisLatest(HistoryOsmPrimitive primitive)Returns true ifprimitiveis the latest primitive representing the version currently edited in the current data layer.booleanisReferencePointInTime(int row)Determines if the given row is the reference point in time.(package private) booleanisSamePrimitive(History history)voidnodeMoved(NodeMovedEvent event)A node's coordinates were modified.voidotherDatasetChange(AbstractDatasetChangedEvent event)Minor dataset change, currently only changeset id changed is supported, but can be extended in future.voidprimitivesAdded(PrimitivesAddedEvent event)A bunch of primitives were added into the DataSet, or existing deleted/invisible primitives were resurrected.voidprimitivesRemoved(PrimitivesRemovedEvent event)A bunch of primitives were removed from the DataSet, or preexisting primitives were marked as deleted.voidrelationMembersChanged(RelationMembersChangedEvent event)A relation's members have changed.voidsetCurrentPointInTime(int row)Sets the current point in time to the given row.voidsetCurrentPointInTime(HistoryOsmPrimitive current)Sets theHistoryOsmPrimitivewhich plays the role of the current point in time (seePointInTimeType).voidsetHistory(History history)sets the history to be managed by this modelprotected voidsetLatest(HistoryOsmPrimitive latest)Sets the latestHistoryOsmPrimitive.voidsetReferencePointInTime(int row)Sets the reference point in time to the given row.voidsetReferencePointInTime(HistoryOsmPrimitive reference)Sets theHistoryOsmPrimitivewhich plays the role of a reference point in time (seePointInTimeType).voidtagsChanged(TagsChangedEvent event)There was some change in the tag set of a primitive.voidunlinkAsListener()Removes this model as listener for data change and layer change events.voidwayNodesChanged(WayNodesChangedEvent event)A way's node list was changed.-
Methods inherited from class org.openstreetmap.josm.gui.util.ChangeNotifier
addChangeListener, fireStateChanged, removeChangeListener
-
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.osm.event.DataSetListener
dataChangedIndividualEvents
-
-
-
-
Field Detail
-
reference
private HistoryOsmPrimitive reference
-
current
private HistoryOsmPrimitive current
-
latest
private HistoryOsmPrimitive latest
latest isn't a reference of history. It's a clone of the currently editedOsmPrimitivein the current edit layer.
-
versionTableModel
private final VersionTableModel versionTableModel
-
currentTagTableModel
private final TagTableModel currentTagTableModel
-
referenceTagTableModel
private final TagTableModel referenceTagTableModel
-
currentRelationMemberTableModel
private final DiffTableModel currentRelationMemberTableModel
-
referenceRelationMemberTableModel
private final DiffTableModel referenceRelationMemberTableModel
-
referenceNodeListTableModel
private final DiffTableModel referenceNodeListTableModel
-
currentNodeListTableModel
private final DiffTableModel currentNodeListTableModel
-
dateScale
private final ColorScale dateScale
-
-
Constructor Detail
-
HistoryBrowserModel
public HistoryBrowserModel()
constructor
-
HistoryBrowserModel
public HistoryBrowserModel(History history)
Creates a new history browser model for a given history.- Parameters:
history- the history. Must not be null.- Throws:
java.lang.IllegalArgumentException- if history is null
-
-
Method Detail
-
getHistory
public History getHistory()
replies the history managed by this model- Returns:
- the history
-
isSamePrimitive
boolean isSamePrimitive(History history)
-
canShowAsLatest
private boolean canShowAsLatest(OsmPrimitive primitive)
-
setHistory
public void setHistory(History history)
sets the history to be managed by this model- Parameters:
history- the history
-
fireModelChange
private void fireModelChange()
-
getVersionTableModel
public VersionTableModel getVersionTableModel()
Replies the table model to be used in aJTablewhich shows the list of versions in this history.- Returns:
- the table model
-
initTagTableModels
private void initTagTableModels()
-
initNodeListTableModels
private void initNodeListTableModels()
Should be called every time either reference of current changes to update the diff. TODO: Maybe rename to reflect this? eg. updateNodeListTableModels
-
initMemberListTableModels
private void initMemberListTableModels()
-
getTagTableModel
public TagTableModel getTagTableModel(PointInTimeType pointInTimeType)
Replies the tag table model for the respective point in time.- Parameters:
pointInTimeType- the type of the point in time (must not be null)- Returns:
- the tag table model
- Throws:
java.lang.IllegalArgumentException- if pointInTimeType is null
-
getNodeListTableModel
public DiffTableModel getNodeListTableModel(PointInTimeType pointInTimeType)
Replies the node list table model for the respective point in time.- Parameters:
pointInTimeType- the type of the point in time (must not be null)- Returns:
- the node list table model
- Throws:
java.lang.IllegalArgumentException- if pointInTimeType is null
-
getRelationMemberTableModel
public DiffTableModel getRelationMemberTableModel(PointInTimeType pointInTimeType)
Replies the relation member table model for the respective point in time.- Parameters:
pointInTimeType- the type of the point in time (must not be null)- Returns:
- the relation member table model
- Throws:
java.lang.IllegalArgumentException- if pointInTimeType is null
-
setReferencePointInTime
public void setReferencePointInTime(HistoryOsmPrimitive reference)
Sets theHistoryOsmPrimitivewhich plays the role of a reference point in time (seePointInTimeType).- Parameters:
reference- the reference history primitive. Must not be null.- Throws:
java.lang.IllegalArgumentException- if reference is nulljava.lang.IllegalStateException- if this model isn't a assigned a history yetjava.lang.IllegalArgumentException- if reference isn't an history primitive for the history managed by this mode- See Also:
setHistory(History),PointInTimeType
-
setCurrentPointInTime
public void setCurrentPointInTime(HistoryOsmPrimitive current)
Sets theHistoryOsmPrimitivewhich plays the role of the current point in time (seePointInTimeType).- Parameters:
current- the reference history primitive. Must not benull.- Throws:
java.lang.IllegalArgumentException- if reference isnulljava.lang.IllegalStateException- if this model isn't a assigned a history yetjava.lang.IllegalArgumentException- if reference isn't an history primitive for the history managed by this mode- See Also:
setHistory(History),PointInTimeType
-
getCurrentPointInTime
public HistoryOsmPrimitive getCurrentPointInTime()
Replies the history OSM primitive for thePointInTimeType.CURRENT_POINT_IN_TIME- Returns:
- the history OSM primitive for the
PointInTimeType.CURRENT_POINT_IN_TIME(may be null)
-
getReferencePointInTime
public HistoryOsmPrimitive getReferencePointInTime()
Replies the history OSM primitive for thePointInTimeType.REFERENCE_POINT_IN_TIME- Returns:
- the history OSM primitive for the
PointInTimeType.REFERENCE_POINT_IN_TIME(may be null)
-
getPointInTime
public HistoryOsmPrimitive getPointInTime(PointInTimeType type)
replies the history OSM primitive for a given point in time- Parameters:
type- the type of the point in time (must not be null)- Returns:
- the respective primitive. Can be null.
- Throws:
java.lang.IllegalArgumentException- if type is null
-
isLatest
public boolean isLatest(HistoryOsmPrimitive primitive)
Returns true ifprimitiveis the latest primitive representing the version currently edited in the current data layer.- Parameters:
primitive- the primitive to check- Returns:
- true if
primitiveis the latest primitive
-
setReferencePointInTime
public void setReferencePointInTime(int row)
Sets the reference point in time to the given row.- Parameters:
row- row number
-
setCurrentPointInTime
public void setCurrentPointInTime(int row)
Sets the current point in time to the given row.- Parameters:
row- row number
-
isReferencePointInTime
public boolean isReferencePointInTime(int row)
Determines if the given row is the reference point in time.- Parameters:
row- row number- Returns:
trueif the given row is the reference point in time
-
isCurrentPointInTime
public boolean isCurrentPointInTime(int row)
Determines if the given row is the current point in time.- Parameters:
row- row number- Returns:
trueif the given row is the current point in time
-
getPrimitive
public HistoryOsmPrimitive getPrimitive(int row)
Returns theHistoryPrimitiveat the given row.- Parameters:
row- row number- Returns:
- the
HistoryPrimitiveat the given row
-
isLatest
public boolean isLatest(int row)
Determines if the given row is the latest.- Parameters:
row- row number- Returns:
trueif the given row is the latest
-
getLatest
public HistoryOsmPrimitive getLatest()
Returns the latestHistoryOsmPrimitive.- Returns:
- the latest
HistoryOsmPrimitive - Since:
- 11646
-
getKeySet
public java.util.Set<java.lang.String> getKeySet()
Returns the key set (union of current and reference point in type key sets).- Returns:
- the key set (union of current and reference point in type key sets)
- Since:
- 11647
-
setLatest
protected void setLatest(HistoryOsmPrimitive latest)
Sets the latestHistoryOsmPrimitive.- Parameters:
latest- the latestHistoryOsmPrimitive
-
unlinkAsListener
public void unlinkAsListener()
Removes this model as listener for data change and layer change events.
-
nodeMoved
public void nodeMoved(NodeMovedEvent event)
Description copied from interface:DataSetListenerA node's coordinates were modified.- Specified by:
nodeMovedin interfaceDataSetListener- Parameters:
event- The event for the node that was moved.
-
primitivesAdded
public void primitivesAdded(PrimitivesAddedEvent event)
Description copied from interface:DataSetListenerA bunch of primitives were added into the DataSet, or existing deleted/invisible primitives were resurrected.- Specified by:
primitivesAddedin interfaceDataSetListener- Parameters:
event- An event for an collection of newly-visible primitives
-
primitivesRemoved
public void primitivesRemoved(PrimitivesRemovedEvent event)
Description copied from interface:DataSetListenerA bunch of primitives were removed from the DataSet, or preexisting primitives were marked as deleted.- Specified by:
primitivesRemovedin interfaceDataSetListener- Parameters:
event- An event for an collection of newly-invisible primitives
-
relationMembersChanged
public void relationMembersChanged(RelationMembersChangedEvent event)
Description copied from interface:DataSetListenerA relation's members have changed.- Specified by:
relationMembersChangedin interfaceDataSetListener- Parameters:
event- The event for the relation that was modified.
-
tagsChanged
public void tagsChanged(TagsChangedEvent event)
Description copied from interface:DataSetListenerThere was some change in the tag set of a primitive. It can have been a tag addition, tag removal or change in tag value.- Specified by:
tagsChangedin interfaceDataSetListener- Parameters:
event- the event for the primitive, whose tags were affected.
-
wayNodesChanged
public void wayNodesChanged(WayNodesChangedEvent event)
Description copied from interface:DataSetListenerA way's node list was changed.- Specified by:
wayNodesChangedin interfaceDataSetListener- Parameters:
event- The event for the way that was modified.
-
dataChanged
public void dataChanged(DataChangedEvent event)
Description copied from interface:DataSetListenerCalled after big changes in dataset. Usually other events are stopped using Dataset.beginUpdate() and after operation is completed (Dataset.endUpdate()),DataSetListener.dataChanged(DataChangedEvent event)is called.- Specified by:
dataChangedin interfaceDataSetListener- Parameters:
event- data change event
-
otherDatasetChange
public void otherDatasetChange(AbstractDatasetChangedEvent event)
Description copied from interface:DataSetListenerMinor dataset change, currently only changeset id changed is supported, but can be extended in future.- Specified by:
otherDatasetChangein interfaceDataSetListener- Parameters:
event- the event for data modification
-
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.
-
getVersionColor
public java.awt.Color getVersionColor(int row)
Returns the color for the primitive in the given row- Parameters:
row- row number- Returns:
- the color for the primitive in the given row
-
getVersionColor
public java.awt.Color getVersionColor(HistoryOsmPrimitive primitive)
Returns the color for the given primitive timestamp- Parameters:
primitive- the history primitive- Returns:
- the color for the given primitive timestamp
-
-