Package org.openstreetmap.josm.gui.layer
Class NoteLayer
- java.lang.Object
-
- org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable
-
- org.openstreetmap.josm.gui.layer.Layer
-
- org.openstreetmap.josm.gui.layer.AbstractModifiableLayer
-
- org.openstreetmap.josm.gui.layer.NoteLayer
-
- All Implemented Interfaces:
java.awt.event.MouseListener
,java.util.EventListener
,Lockable
,NoteData.NoteDataUpdateListener
,ProjectionChangeListener
,DownloadFromServer
,MapViewPaintable
,SaveToFile
,UploadToServer
,Destroyable
public class NoteLayer extends AbstractModifiableLayer implements java.awt.event.MouseListener, NoteData.NoteDataUpdateListener
A layer to hold Note objects.- Since:
- 7522
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.openstreetmap.josm.gui.layer.Layer
Layer.LayerAction, Layer.LayerGpxExportAction, Layer.LayerSaveAction, Layer.LayerSaveAsAction, Layer.MultiLayerAction, Layer.SeparatorLayerAction
-
Nested classes/interfaces inherited from class org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable
AbstractMapViewPaintable.CompatibilityModeLayerPainter
-
Nested classes/interfaces inherited from interface org.openstreetmap.josm.gui.layer.MapViewPaintable
MapViewPaintable.LayerPainter, MapViewPaintable.MapViewEvent, MapViewPaintable.PaintableInvalidationEvent, MapViewPaintable.PaintableInvalidationListener
-
-
Field Summary
Fields Modifier and Type Field Description private Note
displayedNote
private HtmlPanel
displayedPanel
private javax.swing.JWindow
displayedWindow
private static java.util.regex.Pattern
HTML_LINK
private static java.util.regex.Pattern
HTML_LINK_MARK
private static java.util.regex.Pattern
HTTP_LINK
private NoteData
noteData
private static java.util.regex.Pattern
SENTENCE_MARKS_EASTERN
Pattern to detect end of sentences followed by another one, or a link, in eastern script.private static java.util.regex.Pattern
SENTENCE_MARKS_WESTERN
Pattern to detect end of sentences followed by another one, or a link, in western script.private static java.util.regex.Pattern
SLASH
-
Fields inherited from class org.openstreetmap.josm.gui.layer.AbstractModifiableLayer
IS_DIRTY_SYMBOL, REQUIRES_SAVE_TO_DISK_PROP
-
Fields inherited from class org.openstreetmap.josm.gui.layer.Layer
FILTER_STATE_PROP, NAME_PROP, OPACITY_PROP, propertyChangeSupport, VISIBLE_PROP
-
-
Constructor Summary
Constructors Constructor Description NoteLayer()
Convenience constructor that creates a layer with an empty note listNoteLayer(java.util.Collection<Note> notes, java.lang.String name)
Create a new note layer with a set of notesNoteLayer(NoteData noteData, java.lang.String name)
Create a new note layer with a notes data
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
autosave(java.io.File file)
Perform the autosave action for the layerjava.io.File
createAndOpenSaveFileChooser()
Creates a new "Save" dialog for this layer and makes it visible.AbstractIOTask
createUploadTask(ProgressMonitor monitor)
Creates a newAbstractIOTask
for uploading data.void
destroy()
Called, when the layer is removed from the mapview and is going to be destroyed.private java.awt.Point
fixPanelSizeAndLocation(MapView mv, java.lang.String text, int xl, int xr, int yt, int yb)
java.lang.String
getChangesetSourceTag()
Get the source for the layerData
getData()
Get the data for the modifiable layerjavax.swing.Icon
getIcon()
Return a representative small image for this layer.java.lang.Object
getInfoComponent()
Gets the layer information to display to the user.javax.swing.Action[]
getMenuEntries()
Returns list of actions.NoteData
getNoteData()
Returns the note data store being used by this layerstatic java.lang.String
getNoteToolTip(Note note)
Returns the HTML-formatted tooltip text for the given note.java.lang.String
getToolTipText()
Returns a small tooltip hint about some statistics for this layer.private void
hideNoteWindow()
void
hookUpMapView()
Initialization code, that depends on Main.map.mapView.(package private) static java.lang.String
insertLineBreaks(java.lang.String longText)
Inserts HTML line breaks (<br>
at the end of each sentence mark (period, interrogation mark, exclamation mark, ideographic full stop).boolean
isDownloadable()
Determines if the layer is able to download data and implements theDownloadFromServer
interface.boolean
isMergable(Layer other)
Determines if the other layer can be merged into this layer.boolean
isModified()
Determines if data managed by this layer has been modified.boolean
isSavable()
Replies the savable state of this layer (i.e., if it can be saved through a "File → Save" dialog).boolean
isUploadable()
Determines if the layer is able to upload data and implements theUploadToServer
interface.void
mergeFrom(Layer from)
Merges the given layer into this layer.void
mouseClicked(java.awt.event.MouseEvent e)
void
mouseEntered(java.awt.event.MouseEvent e)
void
mouseExited(java.awt.event.MouseEvent e)
void
mousePressed(java.awt.event.MouseEvent e)
void
mouseReleased(java.awt.event.MouseEvent e)
void
noteDataUpdated(NoteData data)
Called when the note data is updatedvoid
paint(java.awt.Graphics2D g, MapView mv, Bounds box)
Paint the dataset using the engine set.private void
paintSelectedNote(java.awt.Graphics2D g, MapView mv, int iconHeight, int iconWidth, Note selectedNote)
(package private) static java.lang.String
replaceLinks(java.lang.String htmlText)
boolean
requiresSaveToFile()
Determines if the data managed by this layer needs to be saved to a file.boolean
requiresUploadToServer()
Determines if the data managed by this layer needs to be uploaded to the server because it contains modified data.void
selectedNoteChanged(NoteData noteData)
The selected node was changedvoid
visitBoundingBox(BoundingXYVisitor v)
Visits the content bounds of this layer.-
Methods inherited from class org.openstreetmap.josm.gui.layer.AbstractModifiableLayer
getUploadDialog, isDirty, isLocked, isUploadDiscouraged, isUploadInProgress, lock, onPostSaveToFile, onPostUploadToServer, unlock
-
Methods inherited from class org.openstreetmap.josm.gui.layer.Layer
addPropertyChangeListener, checkSaveConditions, fireFilterStateChanged, fireOpacityChanged, fireVisibleChanged, getAssociatedFile, getColor, getDefaultLayerPosition, getLabel, getName, getOpacity, getViewProjectionBounds, hasColor, isBackgroundLayer, isInfoResizable, isProjectionSupported, isRenamed, isVisible, nameSupportedProjections, onPostLoadFromFile, projectionChanged, removePropertyChangeListener, rename, setAssociatedFile, setBackgroundLayer, setColor, setFilterStateChanged, setName, setOpacity, setVisible, toggleVisible, toString
-
Methods inherited from class org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable
addInvalidationListener, attachToMapView, createMapViewPainter, invalidate, removeInvalidationListener
-
-
-
-
Field Detail
-
SENTENCE_MARKS_WESTERN
private static final java.util.regex.Pattern SENTENCE_MARKS_WESTERN
Pattern to detect end of sentences followed by another one, or a link, in western script. Group 1 (capturing): period, interrogation mark, exclamation mark Group non capturing: at least one horizontal or vertical whitespace Group 2 (capturing): a letter (any script), or any punctuation
-
SENTENCE_MARKS_EASTERN
private static final java.util.regex.Pattern SENTENCE_MARKS_EASTERN
Pattern to detect end of sentences followed by another one, or a link, in eastern script. Group 1 (capturing): ideographic full stop Group 2 (capturing): a letter (any script), or any punctuation
-
HTTP_LINK
private static final java.util.regex.Pattern HTTP_LINK
-
HTML_LINK
private static final java.util.regex.Pattern HTML_LINK
-
HTML_LINK_MARK
private static final java.util.regex.Pattern HTML_LINK_MARK
-
SLASH
private static final java.util.regex.Pattern SLASH
-
displayedNote
private Note displayedNote
-
displayedPanel
private HtmlPanel displayedPanel
-
displayedWindow
private javax.swing.JWindow displayedWindow
-
-
Constructor Detail
-
NoteLayer
public NoteLayer(java.util.Collection<Note> notes, java.lang.String name)
Create a new note layer with a set of notes- Parameters:
notes
- A list of notes to show in this layername
- The name of the layer. Typically "Notes"
-
NoteLayer
public NoteLayer(NoteData noteData, java.lang.String name)
Create a new note layer with a notes data- Parameters:
noteData
- Notes dataname
- The name of the layer. Typically "Notes"- Since:
- 14101
-
NoteLayer
public NoteLayer()
Convenience constructor that creates a layer with an empty note list
-
-
Method Detail
-
hookUpMapView
public void hookUpMapView()
Description copied from class:Layer
Initialization code, that depends on Main.map.mapView.It is always called in the event dispatching thread. Note that Main.map is null as long as no layer has been added, so do not execute code in the constructor, that assumes Main.map.mapView is not null.
If you need to execute code when this layer is added to the map view, use
AbstractMapViewPaintable.attachToMapView(org.openstreetmap.josm.gui.layer.MapViewPaintable.MapViewEvent)
- Overrides:
hookUpMapView
in classLayer
-
destroy
public void destroy()
Description copied from class:Layer
Called, when the layer is removed from the mapview and is going to be destroyed.This is because the Layer constructor cannot add itself safely as a listener to the layerlist dialog, because there may be no such dialog yet (loaded via command line parameter).
- Specified by:
destroy
in interfaceDestroyable
- Overrides:
destroy
in classLayer
-
getNoteData
public NoteData getNoteData()
Returns the note data store being used by this layer- Returns:
- noteData containing layer notes
-
isModified
public boolean isModified()
Description copied from class:AbstractModifiableLayer
Determines if data managed by this layer has been modified.- Specified by:
isModified
in classAbstractModifiableLayer
- Returns:
- true if data has been modified; false, otherwise
-
isDownloadable
public boolean isDownloadable()
Description copied from interface:DownloadFromServer
Determines if the layer is able to download data and implements theDownloadFromServer
interface. A layer that implements theDownloadFromServer
interface must returntrue
.- Specified by:
isDownloadable
in interfaceDownloadFromServer
- Overrides:
isDownloadable
in classAbstractModifiableLayer
- Returns:
true
if the layer is able to download data;false
, otherwise
-
isUploadable
public boolean isUploadable()
Description copied from interface:UploadToServer
Determines if the layer is able to upload data and implements theUploadToServer
interface. A layer that implements theUploadToServer
interface must returntrue
.- Specified by:
isUploadable
in interfaceUploadToServer
- Overrides:
isUploadable
in classAbstractModifiableLayer
- Returns:
true
if the layer is able to upload data;false
, otherwise
-
requiresUploadToServer
public boolean requiresUploadToServer()
Description copied from interface:UploadToServer
Determines if the data managed by this layer needs to be uploaded to the server because it contains modified data.- Specified by:
requiresUploadToServer
in interfaceUploadToServer
- Overrides:
requiresUploadToServer
in classAbstractModifiableLayer
- Returns:
true
if the data managed by this layer needs to be uploaded to the server because it contains modified data;false
, otherwise
-
isSavable
public boolean isSavable()
Description copied from class:Layer
Replies the savable state of this layer (i.e., if it can be saved through a "File → Save" dialog).- Specified by:
isSavable
in interfaceSaveToFile
- Overrides:
isSavable
in classLayer
- Returns:
- true if this layer can be saved to a file
-
requiresSaveToFile
public boolean requiresSaveToFile()
Description copied from interface:SaveToFile
Determines if the data managed by this layer needs to be saved to a file. Only replies true if a file is assigned to this layer and if the data managed by this layer has been modified since the last save operation to the file.- Specified by:
requiresSaveToFile
in interfaceSaveToFile
- Overrides:
requiresSaveToFile
in classAbstractModifiableLayer
- Returns:
true
if the data managed by this layer needs to be saved to a file;false
, otherwise
-
paint
public void paint(java.awt.Graphics2D g, MapView mv, Bounds box)
Description copied from interface:MapViewPaintable
Paint the dataset using the engine set.- Specified by:
paint
in interfaceMapViewPaintable
- Parameters:
g
- Graphicsmv
- The object that can translate GeoPoints to screen coordinates.box
- Bounding box
-
hideNoteWindow
private void hideNoteWindow()
-
paintSelectedNote
private void paintSelectedNote(java.awt.Graphics2D g, MapView mv, int iconHeight, int iconWidth, Note selectedNote)
-
fixPanelSizeAndLocation
private java.awt.Point fixPanelSizeAndLocation(MapView mv, java.lang.String text, int xl, int xr, int yt, int yb)
-
insertLineBreaks
static java.lang.String insertLineBreaks(java.lang.String longText)
Inserts HTML line breaks (<br>
at the end of each sentence mark (period, interrogation mark, exclamation mark, ideographic full stop).- Parameters:
longText
- a long text that does not fit on a single line without exceeding half of the map view- Returns:
- text with line breaks
-
getNoteToolTip
public static java.lang.String getNoteToolTip(Note note)
Returns the HTML-formatted tooltip text for the given note.- Parameters:
note
- note to display- Returns:
- the HTML-formatted tooltip text for the given note
- Since:
- 13111
-
replaceLinks
static java.lang.String replaceLinks(java.lang.String htmlText)
-
getIcon
public javax.swing.Icon getIcon()
Description copied from class:Layer
Return a representative small image for this layer. The image must not be larger than 64 pixel in any dimension.
-
getToolTipText
public java.lang.String getToolTipText()
Description copied from class:Layer
Returns a small tooltip hint about some statistics for this layer.- Specified by:
getToolTipText
in classLayer
- Returns:
- A small tooltip hint about some statistics for this layer.
-
mergeFrom
public void mergeFrom(Layer from)
Description copied from class:Layer
Merges the given layer into this layer. Throws if the layer types are incompatible.
-
isMergable
public boolean isMergable(Layer other)
Description copied from class:Layer
Determines if the other layer can be merged into this layer.- Specified by:
isMergable
in classLayer
- Parameters:
other
- The other layer that is tested to be mergable with this.- Returns:
- Whether the other layer can be merged into this layer.
-
visitBoundingBox
public void visitBoundingBox(BoundingXYVisitor v)
Description copied from class:Layer
Visits the content bounds of this layer. The behavior of this method depends on the layer, but each implementation should attempt to cover the relevant content of the layer in this method.- Specified by:
visitBoundingBox
in classLayer
- Parameters:
v
- The visitor that gets notified about the contents of this layer.
-
getInfoComponent
public java.lang.Object getInfoComponent()
Description copied from class:Layer
Gets the layer information to display to the user. This is used if the user requests information about this layer. It should display a description of the layer content.- Specified by:
getInfoComponent
in classLayer
- Returns:
- Either a String or a
Component
describing the layer.
-
getMenuEntries
public javax.swing.Action[] getMenuEntries()
Description copied from class:Layer
Returns list of actions. Action can implement LayerAction interface when it needs to be represented by other menu component than JMenuItem or when it supports multiple layers. Actions that support multiple layers should also have correct equals implementation.Use
Layer.SeparatorLayerAction.INSTANCE
instead of new JSeparator- Specified by:
getMenuEntries
in classLayer
- Returns:
- menu actions for this layer
-
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent e)
- Specified by:
mouseClicked
in interfacejava.awt.event.MouseListener
-
createAndOpenSaveFileChooser
public java.io.File createAndOpenSaveFileChooser()
Description copied from class:Layer
Creates a new "Save" dialog for this layer and makes it visible.When the user has chosen a file, checks the file extension, and confirms overwriting if needed.
- Overrides:
createAndOpenSaveFileChooser
in classLayer
- Returns:
- The output
File
- See Also:
SaveActionBase.createAndOpenSaveFileChooser(java.lang.String, org.openstreetmap.josm.actions.ExtensionFileFilter)
-
createUploadTask
public AbstractIOTask createUploadTask(ProgressMonitor monitor)
Description copied from interface:UploadToServer
Creates a newAbstractIOTask
for uploading data.- Specified by:
createUploadTask
in interfaceUploadToServer
- Overrides:
createUploadTask
in classAbstractModifiableLayer
- Parameters:
monitor
- The progress monitor- Returns:
- a new
AbstractIOTask
for uploading data, ornull
if not applicable
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent e)
- Specified by:
mousePressed
in interfacejava.awt.event.MouseListener
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent e)
- Specified by:
mouseReleased
in interfacejava.awt.event.MouseListener
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent e)
- Specified by:
mouseEntered
in interfacejava.awt.event.MouseListener
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent e)
- Specified by:
mouseExited
in interfacejava.awt.event.MouseListener
-
noteDataUpdated
public void noteDataUpdated(NoteData data)
Description copied from interface:NoteData.NoteDataUpdateListener
Called when the note data is updated- Specified by:
noteDataUpdated
in interfaceNoteData.NoteDataUpdateListener
- Parameters:
data
- The data that was changed
-
selectedNoteChanged
public void selectedNoteChanged(NoteData noteData)
Description copied from interface:NoteData.NoteDataUpdateListener
The selected node was changed- Specified by:
selectedNoteChanged
in interfaceNoteData.NoteDataUpdateListener
- Parameters:
noteData
- The data of which the selected node was changed
-
getChangesetSourceTag
public java.lang.String getChangesetSourceTag()
Description copied from class:Layer
Get the source for the layer- Overrides:
getChangesetSourceTag
in classLayer
- Returns:
- The string for the changeset source tag or
null
-
autosave
public boolean autosave(java.io.File file) throws java.io.IOException
Description copied from class:AbstractModifiableLayer
Perform the autosave action for the layer- Overrides:
autosave
in classAbstractModifiableLayer
- Parameters:
file
- The file to save to- Returns:
true
if the layer was successfully saved- Throws:
java.io.IOException
- If there was an IO exception from saving
-
getData
public Data getData()
Description copied from class:AbstractModifiableLayer
Get the data for the modifiable layer- Overrides:
getData
in classAbstractModifiableLayer
- Returns:
- The data object
-
-