Package org.openstreetmap.josm.actions
Class SaveActionBase
- java.lang.Object
-
- javax.swing.AbstractAction
-
- org.openstreetmap.josm.actions.JosmAction
-
- org.openstreetmap.josm.actions.DiskAccessAction
-
- org.openstreetmap.josm.actions.SaveActionBase
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.io.Serializable
,java.lang.Cloneable
,java.util.EventListener
,javax.swing.Action
,Destroyable
- Direct Known Subclasses:
SaveAction
,SaveAsAction
public abstract class SaveActionBase extends DiskAccessAction
Abstract superclass of save actions.- Since:
- 290
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
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 boolean
quiet
-
Fields inherited from class org.openstreetmap.josm.actions.JosmAction
sc
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SaveActionBase(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut)
Constructs a newSaveActionBase
.protected
SaveActionBase(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean quiet)
Constructs a newSaveActionBase
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
(package private) static void
addToFileOpenHistory(java.io.File file)
static java.io.File
checkFileAndConfirmOverWrite(AbstractFileChooser fc, java.lang.String extension)
Checks if selected filename has the given extension.static boolean
confirmOverwrite(java.io.File file)
Asks user to confirm overwiting a file.static java.io.File
createAndOpenSaveFileChooser(java.lang.String title, java.lang.String extension)
Creates a new "Save" dialog for a given file extension and makes it visible.
When the user has chosen a file, checks the file extension, and confirms overwrite if needed.static java.io.File
createAndOpenSaveFileChooser(java.lang.String title, ExtensionFileFilter filter)
Creates a new "Save" dialog for a singleExtensionFileFilter
and makes it visible.
When the user has chosen a file, checks the file extension, and confirms overwrite if needed.private static boolean
doInternalSave(Layer layer, java.io.File file, boolean quiet)
boolean
doSave()
Saves the active layer.boolean
doSave(boolean quiet)
Saves the active layer.boolean
doSave(Layer layer)
Saves the given layer.boolean
doSave(Layer layer, boolean quiet)
Saves the given layer.static boolean
doSave(Layer layer, java.io.File file, boolean checkSaveConditions)
Saves a layer to a given file.protected abstract java.io.File
getFile(Layer layer)
protected boolean
listenToSelectionChange()
Overwrite this ifJosmAction.updateEnabledState()
should be called when the selection changed.(package private) static void
showAndLogException(java.lang.Exception e)
protected void
updateEnabledState()
Override in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e.-
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, destroy, getLayerManager, getShortcut, initEnabledState, installAdapters, listenToLayerChange, 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
-
quiet
private boolean quiet
-
-
Constructor Detail
-
SaveActionBase
protected SaveActionBase(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut)
Constructs a newSaveActionBase
.- Parameters:
name
- The action's text as displayed on the menu (if it is added to a menu)iconName
- The filename of the icon to usetooltip
- A longer description of the action that will be displayed in the tooltipshortcut
- A ready-created shortcut object ornull
if you don't want a shortcut
-
SaveActionBase
protected SaveActionBase(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut, boolean quiet)
Constructs a newSaveActionBase
.- Parameters:
name
- The action's text as displayed on the menu (if it is added to a menu)iconName
- The filename of the icon to usetooltip
- A longer description of the action that will be displayed in the tooltipshortcut
- A ready-created shortcut object ornull
if you don't want a shortcutquiet
- whether the quiet exporter is called- Since:
- 15496
-
-
Method Detail
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
-
doSave
public boolean doSave()
Saves the active layer.- Returns:
true
if the save operation succeeds
-
doSave
public boolean doSave(boolean quiet)
Saves the active layer.- Parameters:
quiet
- If the file is saved without prompting the user- Returns:
true
if the save operation succeeds- Since:
- 15496
-
doSave
public boolean doSave(Layer layer)
Saves the given layer.- Parameters:
layer
- layer to save- Returns:
true
if the save operation succeeds
-
doSave
public boolean doSave(Layer layer, boolean quiet)
Saves the given layer.- Parameters:
layer
- layer to savequiet
- If the file is saved without prompting the user- Returns:
true
if the save operation succeeds- Since:
- 15496
-
doSave
public static boolean doSave(Layer layer, java.io.File file, boolean checkSaveConditions)
Saves a layer to a given file.- Parameters:
layer
- The layer to savefile
- The destination filecheckSaveConditions
- iftrue
, checks preconditions before saving. Set it tofalse
to skip it and prevent dialogs from being shown.- Returns:
true
if the layer has been successfully saved,false
otherwise- Since:
- 7204
-
doInternalSave
private static boolean doInternalSave(Layer layer, java.io.File file, boolean quiet)
-
listenToSelectionChange
protected boolean listenToSelectionChange()
Description copied from class:JosmAction
Overwrite this ifJosmAction.updateEnabledState()
should be called when the selection changed. Default is true.- Overrides:
listenToSelectionChange
in classJosmAction
- Returns:
true
if aDataSelectionListener
should be registered.
-
updateEnabledState
protected final 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()
-
createAndOpenSaveFileChooser
public static java.io.File createAndOpenSaveFileChooser(java.lang.String title, ExtensionFileFilter filter)
Creates a new "Save" dialog for a singleExtensionFileFilter
and makes it visible.
When the user has chosen a file, checks the file extension, and confirms overwrite if needed.- Parameters:
title
- The dialog titlefilter
- The dialog file filter- Returns:
- The output
File
- Since:
- 5456
- See Also:
DiskAccessAction.createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)
-
createAndOpenSaveFileChooser
public static java.io.File createAndOpenSaveFileChooser(java.lang.String title, java.lang.String extension)
Creates a new "Save" dialog for a given file extension and makes it visible.
When the user has chosen a file, checks the file extension, and confirms overwrite if needed.- Parameters:
title
- The dialog titleextension
- The file extension- Returns:
- The output
File
- See Also:
DiskAccessAction.createAndOpenFileChooser(boolean, boolean, String, String)
-
checkFileAndConfirmOverWrite
public static java.io.File checkFileAndConfirmOverWrite(AbstractFileChooser fc, java.lang.String extension)
Checks if selected filename has the given extension. If not, adds the extension and asks for overwrite if filename exists.- Parameters:
fc
- FileChooser where file was already selectedextension
- file extension- Returns:
- the
File
ornull
if the user cancelled the dialog.
-
confirmOverwrite
public static boolean confirmOverwrite(java.io.File file)
Asks user to confirm overwiting a file.- Parameters:
file
- file to overwrite- Returns:
true
if the file can be written
-
addToFileOpenHistory
static void addToFileOpenHistory(java.io.File file)
-
showAndLogException
static void showAndLogException(java.lang.Exception e)
-
-