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
History
of a specificOsmPrimitive
- a dedicated version in this
History
called thePointInTimeType.REFERENCE_POINT_IN_TIME
- another version in this
History
called thePointInTimeType.CURRENT_POINT_IN_TIME
HistoryBrowser
always compares thePointInTimeType.REFERENCE_POINT_IN_TIME
with thePointInTimeType.CURRENT_POINT_IN_TIME
. This model provides variousTableModel
s forJTable
s used inHistoryBrowser
, for instance:getTagTableModel(PointInTimeType)
replies aTableModel
for the tags of either of the two selected versionsgetNodeListTableModel(PointInTimeType)
replies aTableModel
for the list of nodes of the two selected versions (if the current history provides information about aWay
-
getRelationMemberTableModel(PointInTimeType)
replies aTableModel
for 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 class
HistoryBrowserModel.HistoryPrimitiveBuilder
Creates aHistoryOsmPrimitive
from aOsmPrimitive
-
Field Summary
Fields Modifier and Type Field Description private HistoryOsmPrimitive
current
private DiffTableModel
currentNodeListTableModel
private DiffTableModel
currentRelationMemberTableModel
private TagTableModel
currentTagTableModel
private ColorScale
dateScale
private History
history
the history of an OsmPrimitiveprivate HistoryOsmPrimitive
latest
latest isn't a reference of history.private HistoryOsmPrimitive
reference
private DiffTableModel
referenceNodeListTableModel
private DiffTableModel
referenceRelationMemberTableModel
private TagTableModel
referenceTagTableModel
private VersionTableModel
versionTableModel
-
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 void
activeOrEditLayerChanged(MainLayerManager.ActiveLayerChangeEvent e)
Called whenever the active or edit layer changed.private boolean
canShowAsLatest(OsmPrimitive primitive)
void
dataChanged(DataChangedEvent event)
Called after big changes in dataset.private void
fireModelChange()
HistoryOsmPrimitive
getCurrentPointInTime()
Replies the history OSM primitive for thePointInTimeType.CURRENT_POINT_IN_TIME
History
getHistory()
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).HistoryOsmPrimitive
getLatest()
Returns the latestHistoryOsmPrimitive
.DiffTableModel
getNodeListTableModel(PointInTimeType pointInTimeType)
Replies the node list table model for the respective point in time.HistoryOsmPrimitive
getPointInTime(PointInTimeType type)
replies the history OSM primitive for a given point in timeHistoryOsmPrimitive
getPrimitive(int row)
Returns theHistoryPrimitive
at the given row.HistoryOsmPrimitive
getReferencePointInTime()
Replies the history OSM primitive for thePointInTimeType.REFERENCE_POINT_IN_TIME
DiffTableModel
getRelationMemberTableModel(PointInTimeType pointInTimeType)
Replies the relation member table model for the respective point in time.TagTableModel
getTagTableModel(PointInTimeType pointInTimeType)
Replies the tag table model for the respective point in time.java.awt.Color
getVersionColor(int row)
Returns the color for the primitive in the given rowjava.awt.Color
getVersionColor(HistoryOsmPrimitive primitive)
Returns the color for the given primitive timestampVersionTableModel
getVersionTableModel()
Replies the table model to be used in aJTable
which shows the list of versions in this history.private void
initMemberListTableModels()
private void
initNodeListTableModels()
Should be called every time either reference of current changes to update the diff.private void
initTagTableModels()
boolean
isCurrentPointInTime(int row)
Determines if the given row is the current point in time.boolean
isLatest(int row)
Determines if the given row is the latest.boolean
isLatest(HistoryOsmPrimitive primitive)
Returns true ifprimitive
is the latest primitive representing the version currently edited in the current data layer.boolean
isReferencePointInTime(int row)
Determines if the given row is the reference point in time.(package private) boolean
isSamePrimitive(History history)
void
nodeMoved(NodeMovedEvent event)
A node's coordinates were modified.void
otherDatasetChange(AbstractDatasetChangedEvent event)
Minor dataset change, currently only changeset id changed is supported, but can be extended in future.void
primitivesAdded(PrimitivesAddedEvent event)
A bunch of primitives were added into the DataSet, or existing deleted/invisible primitives were resurrected.void
primitivesRemoved(PrimitivesRemovedEvent event)
A bunch of primitives were removed from the DataSet, or preexisting primitives were marked as deleted.void
relationMembersChanged(RelationMembersChangedEvent event)
A relation's members have changed.void
setCurrentPointInTime(int row)
Sets the current point in time to the given row.void
setCurrentPointInTime(HistoryOsmPrimitive current)
Sets theHistoryOsmPrimitive
which plays the role of the current point in time (seePointInTimeType
).void
setHistory(History history)
sets the history to be managed by this modelprotected void
setLatest(HistoryOsmPrimitive latest)
Sets the latestHistoryOsmPrimitive
.void
setReferencePointInTime(int row)
Sets the reference point in time to the given row.void
setReferencePointInTime(HistoryOsmPrimitive reference)
Sets theHistoryOsmPrimitive
which plays the role of a reference point in time (seePointInTimeType
).void
tagsChanged(TagsChangedEvent event)
There was some change in the tag set of a primitive.void
unlinkAsListener()
Removes this model as listener for data change and layer change events.void
wayNodesChanged(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 editedOsmPrimitive
in 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 aJTable
which 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 theHistoryOsmPrimitive
which 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 theHistoryOsmPrimitive
which 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 isnull
java.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 ifprimitive
is the latest primitive representing the version currently edited in the current data layer.- Parameters:
primitive
- the primitive to check- Returns:
- true if
primitive
is 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:
true
if 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:
true
if the given row is the current point in time
-
getPrimitive
public HistoryOsmPrimitive getPrimitive(int row)
Returns theHistoryPrimitive
at the given row.- Parameters:
row
- row number- Returns:
- the
HistoryPrimitive
at the given row
-
isLatest
public boolean isLatest(int row)
Determines if the given row is the latest.- Parameters:
row
- row number- Returns:
true
if 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:DataSetListener
A node's coordinates were modified.- Specified by:
nodeMoved
in interfaceDataSetListener
- Parameters:
event
- The event for the node that was moved.
-
primitivesAdded
public void primitivesAdded(PrimitivesAddedEvent event)
Description copied from interface:DataSetListener
A bunch of primitives were added into the DataSet, or existing deleted/invisible primitives were resurrected.- Specified by:
primitivesAdded
in interfaceDataSetListener
- Parameters:
event
- An event for an collection of newly-visible primitives
-
primitivesRemoved
public void primitivesRemoved(PrimitivesRemovedEvent event)
Description copied from interface:DataSetListener
A bunch of primitives were removed from the DataSet, or preexisting primitives were marked as deleted.- Specified by:
primitivesRemoved
in interfaceDataSetListener
- Parameters:
event
- An event for an collection of newly-invisible primitives
-
relationMembersChanged
public void relationMembersChanged(RelationMembersChangedEvent event)
Description copied from interface:DataSetListener
A relation's members have changed.- Specified by:
relationMembersChanged
in interfaceDataSetListener
- Parameters:
event
- The event for the relation that was modified.
-
tagsChanged
public void tagsChanged(TagsChangedEvent event)
Description copied from interface:DataSetListener
There 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:
tagsChanged
in interfaceDataSetListener
- Parameters:
event
- the event for the primitive, whose tags were affected.
-
wayNodesChanged
public void wayNodesChanged(WayNodesChangedEvent event)
Description copied from interface:DataSetListener
A way's node list was changed.- Specified by:
wayNodesChanged
in interfaceDataSetListener
- Parameters:
event
- The event for the way that was modified.
-
dataChanged
public void dataChanged(DataChangedEvent event)
Description copied from interface:DataSetListener
Called 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:
dataChanged
in interfaceDataSetListener
- Parameters:
event
- data change event
-
otherDatasetChange
public void otherDatasetChange(AbstractDatasetChangedEvent event)
Description copied from interface:DataSetListener
Minor dataset change, currently only changeset id changed is supported, but can be extended in future.- Specified by:
otherDatasetChange
in interfaceDataSetListener
- Parameters:
event
- the event for data modification
-
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.
-
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
-
-