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 classSessionSaveAction.SessionSaveAsDialogThe "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>dependenciesprivate java.util.Map<Layer,SessionLayerExporter>exportersprivate static SessionSaveActioninstance(package private) static booleanisZipSessionFileprotected javax.swing.filechooser.FileFilterjosprotected javax.swing.filechooser.FileFilterjozprivate java.util.List<Layer>layers(package private) static java.util.List<java.lang.ref.WeakReference<Layer>>layersInSessionFileprivate static booleanpluginDataprivate java.io.FileremoveFileOnSuccessprivate static BooleanPropertySAVE_LOCAL_FILES_PROPERTYprivate static BooleanPropertySAVE_PLUGIN_INFORMATION_PROPERTYprivate static java.lang.StringSAVE_SESSION(package private) static java.io.FilesessionFileprivate static java.lang.Stringtooltipprivate static java.lang.StringTOOLTIP_DEFAULT-
Fields inherited from class org.openstreetmap.josm.actions.JosmAction
sc
-
-
Constructor Summary
Constructors Modifier Constructor Description SessionSaveAction()Constructs a newSessionSaveAction.protectedSessionSaveAction(boolean toolbar, boolean installAdapters)Constructs a newSessionSaveAction.protectedSessionSaveAction(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 voidactionPerformed(java.awt.event.ActionEvent e)protected voidaddListeners()protected voidcleanup()voiddestroy()Called when the object has been destroyed.protected booleandoGetFile(boolean saveAs, boolean zipRequired)Sets the current session file.protected voiddoGetFileChooser(boolean zipRequired)static SessionSaveActiongetInstance()Returns the instancestatic java.lang.StringgetTooltip()Returns the tooltip for the componentvoidlayerAdded(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.voidmapFrameInitialized(MapFrame oldFrame, MapFrame newFrame)Called after Main.mapFrame is initialized.private static booleanpluginsWantToSave()Check to see if any plugins want to save their stateprotected voidremoveListeners()booleansaveSession(boolean saveAs, boolean forceSaveAll)Attempts to save the session.private booleansaveSessionImpl(boolean saveAs, boolean forceSaveAll)static voidsetCurrentLayers(java.util.List<Layer> layers)Sets the layers that are currently represented in the session filestatic voidsetCurrentSession(java.io.File file, boolean zip)Sets the current session filestatic voidsetCurrentSession(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 voidsetCurrentSession(java.io.File file, java.util.List<Layer> layers, SessionWriter.SessionWriterFlags... flags)Sets the current session file and the layers included in that fileprotected voidupdateEnabledState()Override in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e.private static voidupdateSessionFile(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:
actionPerformedin interfacejava.awt.event.ActionListener
-
destroy
public void destroy()
Description copied from interface:DestroyableCalled when the object has been destroyed.- Specified by:
destroyin interfaceDestroyable- Overrides:
destroyin 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:JosmActionOverride 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:
updateEnabledStatein classJosmAction- See Also:
JosmAction.updateEnabledState(Collection),JosmAction.initEnabledState(),JosmAction.listenToLayerChange()
-
mapFrameInitialized
public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame)
Description copied from interface:MapFrameListenerCalled 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:
mapFrameInitializedin interfaceMapFrameListener- Parameters:
oldFrame- The old MapFramenewFrame- The new MapFrame
-
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.
-
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:
trueif the plugin wants to save their state
-
cleanup
protected void cleanup()
-
-