Package org.openstreetmap.josm.actions
Class SessionSaveAction
- java.lang.Object
-
- javax.swing.AbstractAction
-
- org.openstreetmap.josm.actions.JosmAction
-
- org.openstreetmap.josm.actions.DiskAccessAction
-
- org.openstreetmap.josm.actions.SessionSaveAction
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.io.Serializable
,java.lang.Cloneable
,java.util.EventListener
,javax.swing.Action
,LayerManager.LayerChangeListener
,MapFrameListener
,Destroyable
- Direct Known Subclasses:
SessionSaveAsAction
public class SessionSaveAction extends DiskAccessAction implements MapFrameListener, LayerManager.LayerChangeListener
Saves a JOSM session- Since:
- 18466
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
SessionSaveAction.SessionSaveAsDialog
The "Save Session" dialog-
Nested classes/interfaces inherited from class org.openstreetmap.josm.actions.JosmAction
JosmAction.ActiveLayerChangeAdapter, JosmAction.LayerChangeAdapter, JosmAction.SelectionChangeAdapter
-
-
Field Summary
Fields Modifier and Type Field Description private MultiMap<Layer,Layer>
dependencies
private java.util.Map<Layer,SessionLayerExporter>
exporters
private static SessionSaveAction
instance
(package private) static boolean
isZipSessionFile
protected javax.swing.filechooser.FileFilter
jos
protected javax.swing.filechooser.FileFilter
joz
private java.util.List<Layer>
layers
(package private) static java.util.List<java.lang.ref.WeakReference<Layer>>
layersInSessionFile
private static boolean
pluginData
private java.io.File
removeFileOnSuccess
private static BooleanProperty
SAVE_LOCAL_FILES_PROPERTY
private static BooleanProperty
SAVE_PLUGIN_INFORMATION_PROPERTY
private static java.lang.String
SAVE_SESSION
(package private) static java.io.File
sessionFile
private static java.lang.String
tooltip
private static java.lang.String
TOOLTIP_DEFAULT
-
Fields inherited from class org.openstreetmap.josm.actions.JosmAction
sc
-
-
Constructor Summary
Constructors Modifier Constructor Description SessionSaveAction()
Constructs a newSessionSaveAction
.protected
SessionSaveAction(boolean toolbar, boolean installAdapters)
Constructs a newSessionSaveAction
.protected
SessionSaveAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean register, java.lang.String toolbarId, boolean installAdapters)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
protected void
addListeners()
protected void
cleanup()
void
destroy()
Called when the object has been destroyed.protected boolean
doGetFile(boolean saveAs, boolean zipRequired)
Sets the current session file.protected void
doGetFileChooser(boolean zipRequired)
static SessionSaveAction
getInstance()
Returns the instancestatic java.lang.String
getTooltip()
Returns the tooltip for the componentvoid
layerAdded(LayerManager.LayerAddEvent e)
Notifies this listener that a layer has been added.void
layerOrderChanged(LayerManager.LayerOrderChangeEvent e)
Notifies this listener that the order of layers was changed.void
layerRemoving(LayerManager.LayerRemoveEvent e)
Notifies this listener that a layer was just removed.void
mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame)
Called after Main.mapFrame is initialized.private static boolean
pluginsWantToSave()
Check to see if any plugins want to save their stateprotected void
removeListeners()
boolean
saveSession(boolean saveAs, boolean forceSaveAll)
Attempts to save the session.private boolean
saveSessionImpl(boolean saveAs, boolean forceSaveAll)
static void
setCurrentLayers(java.util.List<Layer> layers)
Sets the layers that are currently represented in the session filestatic void
setCurrentSession(java.io.File file, boolean zip)
Sets the current session filestatic void
setCurrentSession(java.io.File file, java.util.List<Layer> layers, java.util.Set<SessionWriter.SessionWriterFlags> flags)
Sets the current session file and the layers included in that filestatic void
setCurrentSession(java.io.File file, java.util.List<Layer> layers, SessionWriter.SessionWriterFlags... flags)
Sets the current session file and the layers included in that fileprotected void
updateEnabledState()
Override in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e.private static void
updateSessionFile(java.lang.String fileName)
Update the session file-
Methods inherited from class org.openstreetmap.josm.actions.DiskAccessAction
createAndOpenFileChooser, createAndOpenFileChooser, createAndOpenFileChooser, createAndOpenFileChooser, createAndOpenFileChooser, showSavedNotification, showSavingNotification
-
Methods inherited from class org.openstreetmap.josm.actions.JosmAction
buildActiveLayerChangeAdapter, buildLayerChangeAdapter, checkAndConfirmOutlyingOperation, getLayerManager, getShortcut, initEnabledState, installAdapters, listenToLayerChange, listenToSelectionChange, setHelpId, setToolbarId, setTooltip, updateEnabledState, updateEnabledStateOnCurrentSelection, updateEnabledStateOnCurrentSelection, updateEnabledStateOnModifiableSelection, waitFuture
-
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
-
-
-
Field Detail
-
exporters
private transient java.util.Map<Layer,SessionLayerExporter> exporters
-
dependencies
private transient MultiMap<Layer,Layer> dependencies
-
SAVE_LOCAL_FILES_PROPERTY
private static final BooleanProperty SAVE_LOCAL_FILES_PROPERTY
-
SAVE_PLUGIN_INFORMATION_PROPERTY
private static final BooleanProperty SAVE_PLUGIN_INFORMATION_PROPERTY
-
TOOLTIP_DEFAULT
private static final java.lang.String TOOLTIP_DEFAULT
-
SAVE_SESSION
private static final java.lang.String SAVE_SESSION
-
joz
protected transient javax.swing.filechooser.FileFilter joz
-
jos
protected transient javax.swing.filechooser.FileFilter jos
-
removeFileOnSuccess
private java.io.File removeFileOnSuccess
-
tooltip
private static java.lang.String tooltip
-
sessionFile
static java.io.File sessionFile
-
isZipSessionFile
static boolean isZipSessionFile
-
pluginData
private static boolean pluginData
-
layersInSessionFile
static java.util.List<java.lang.ref.WeakReference<Layer>> layersInSessionFile
-
instance
private static final SessionSaveAction instance
-
-
Constructor Detail
-
SessionSaveAction
public SessionSaveAction()
Constructs a newSessionSaveAction
.
-
SessionSaveAction
protected SessionSaveAction(boolean toolbar, boolean installAdapters)
Constructs a newSessionSaveAction
.- Parameters:
toolbar
- Register this action for the toolbar preferences?installAdapters
- False, if you don't want to install layer changed and selection changed adapters
-
SessionSaveAction
protected SessionSaveAction(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean register, java.lang.String toolbarId, boolean installAdapters)
-
-
Method Detail
-
getInstance
public static SessionSaveAction getInstance()
Returns the instance- Returns:
- the instance
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
- Specified by:
actionPerformed
in interfacejava.awt.event.ActionListener
-
destroy
public void destroy()
Description copied from interface:Destroyable
Called when the object has been destroyed.- Specified by:
destroy
in interfaceDestroyable
- Overrides:
destroy
in classJosmAction
-
saveSession
public boolean saveSession(boolean saveAs, boolean forceSaveAll) throws UserCancelException
Attempts to save the session.- Parameters:
saveAs
- true shows the dialogforceSaveAll
- saves all layers- Returns:
- if the session and all layers were successfully saved
- Throws:
UserCancelException
- when the user has cancelled the save process
-
saveSessionImpl
private boolean saveSessionImpl(boolean saveAs, boolean forceSaveAll) throws UserCancelException
- Throws:
UserCancelException
-
doGetFile
protected boolean doGetFile(boolean saveAs, boolean zipRequired) throws UserCancelException
Sets the current session file. Asks the user if necessary- Parameters:
saveAs
- always ask the userzipRequired
- zip- Returns:
- if the user was asked
- Throws:
UserCancelException
- when the user has cancelled the save process
-
doGetFileChooser
protected void doGetFileChooser(boolean zipRequired) throws UserCancelException
- Throws:
UserCancelException
-
addListeners
protected void addListeners()
-
removeListeners
protected void removeListeners()
-
updateEnabledState
protected void updateEnabledState()
Description copied from class:JosmAction
Override in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e. when a layer is removed or added. SeeJosmAction.updateEnabledState(Collection)
to respond to changes in the collection of selected primitives. Default behavior is empty.- Overrides:
updateEnabledState
in classJosmAction
- See Also:
JosmAction.updateEnabledState(Collection)
,JosmAction.initEnabledState()
,JosmAction.listenToLayerChange()
-
mapFrameInitialized
public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame)
Description copied from interface:MapFrameListener
Called after Main.mapFrame is initialized. (After the first data is loaded). You can use this callback to tweak the newFrame to your needs, as example install an alternative Painter.- Specified by:
mapFrameInitialized
in interfaceMapFrameListener
- Parameters:
oldFrame
- The old MapFramenewFrame
- The new MapFrame
-
layerAdded
public void layerAdded(LayerManager.LayerAddEvent e)
Description copied from interface:LayerManager.LayerChangeListener
Notifies 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:
layerAdded
in interfaceLayerManager.LayerChangeListener
- Parameters:
e
- The new added layer event
-
layerRemoving
public void layerRemoving(LayerManager.LayerRemoveEvent e)
Description copied from interface:LayerManager.LayerChangeListener
Notifies 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:
layerRemoving
in interfaceLayerManager.LayerChangeListener
- Parameters:
e
- The layer to be removed (as event)
-
layerOrderChanged
public void layerOrderChanged(LayerManager.LayerOrderChangeEvent e)
Description copied from interface:LayerManager.LayerChangeListener
Notifies 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:
layerOrderChanged
in interfaceLayerManager.LayerChangeListener
- Parameters:
e
- The order change event.
-
updateSessionFile
private static void updateSessionFile(java.lang.String fileName) throws UserCancelException
Update the session file- Parameters:
fileName
- The filename to use. If there are no periods in the file, we update the extension.- Throws:
UserCancelException
- If the user does not want to overwrite a previously existing file.
-
setCurrentSession
public static void setCurrentSession(java.io.File file, java.util.List<Layer> layers, SessionWriter.SessionWriterFlags... flags)
Sets the current session file and the layers included in that file- Parameters:
file
- filelayers
- layers that are currently represented in the session fileflags
- The flags for the current session- Since:
- 18833
-
setCurrentSession
public static void setCurrentSession(java.io.File file, java.util.List<Layer> layers, java.util.Set<SessionWriter.SessionWriterFlags> flags)
Sets the current session file and the layers included in that file- Parameters:
file
- filelayers
- layers that are currently represented in the session fileflags
- The flags for the current session- Since:
- 18833
-
setCurrentSession
public static void setCurrentSession(java.io.File file, boolean zip)
Sets the current session file- Parameters:
file
- filezip
- if it is a zip session file
-
setCurrentLayers
public static void setCurrentLayers(java.util.List<Layer> layers)
Sets the layers that are currently represented in the session file- Parameters:
layers
- layers
-
getTooltip
public static java.lang.String getTooltip()
Returns the tooltip for the component- Returns:
- the tooltip for the component
-
pluginsWantToSave
private static boolean pluginsWantToSave()
Check to see if any plugins want to save their state- Returns:
true
if the plugin wants to save their state
-
cleanup
protected void cleanup()
-
-