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 booleanquiet-
Fields inherited from class org.openstreetmap.josm.actions.JosmAction
sc
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedSaveActionBase(java.lang.String name, java.lang.String iconName, java.lang.String tooltip, Shortcut shortcut)Constructs a newSaveActionBase.protectedSaveActionBase(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 voidactionPerformed(java.awt.event.ActionEvent e)(package private) static voidaddToFileOpenHistory(java.io.File file)static java.io.FilecheckFileAndConfirmOverWrite(AbstractFileChooser fc, java.lang.String extension)Checks if selected filename has the given extension.static booleanconfirmOverwrite(java.io.File file)Asks user to confirm overwiting a file.static java.io.FilecreateAndOpenSaveFileChooser(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.FilecreateAndOpenSaveFileChooser(java.lang.String title, ExtensionFileFilter filter)Creates a new "Save" dialog for a singleExtensionFileFilterand makes it visible.
When the user has chosen a file, checks the file extension, and confirms overwrite if needed.private static booleandoInternalSave(Layer layer, java.io.File file, boolean quiet)booleandoSave()Saves the active layer.booleandoSave(boolean quiet)Saves the active layer.booleandoSave(Layer layer)Saves the given layer.booleandoSave(Layer layer, boolean quiet)Saves the given layer.static booleandoSave(Layer layer, java.io.File file, boolean checkSaveConditions)Saves a layer to a given file.protected abstract java.io.FilegetFile(Layer layer)protected booleanlistenToSelectionChange()Overwrite this ifJosmAction.updateEnabledState()should be called when the selection changed.(package private) static voidshowAndLogException(java.lang.Exception e)protected voidupdateEnabledState()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 ornullif 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 ornullif 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:
trueif 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:
trueif the save operation succeeds- Since:
- 15496
-
doSave
public boolean doSave(Layer layer)
Saves the given layer.- Parameters:
layer- layer to save- Returns:
trueif 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:
trueif 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 tofalseto skip it and prevent dialogs from being shown.- Returns:
trueif the layer has been successfully saved,falseotherwise- Since:
- 7204
-
doInternalSave
private static boolean doInternalSave(Layer layer, java.io.File file, boolean quiet)
-
listenToSelectionChange
protected boolean listenToSelectionChange()
Description copied from class:JosmActionOverwrite this ifJosmAction.updateEnabledState()should be called when the selection changed. Default is true.- Overrides:
listenToSelectionChangein classJosmAction- Returns:
trueif aDataSelectionListenershould be registered.
-
updateEnabledState
protected final 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()
-
createAndOpenSaveFileChooser
public static java.io.File createAndOpenSaveFileChooser(java.lang.String title, ExtensionFileFilter filter)
Creates a new "Save" dialog for a singleExtensionFileFilterand 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
Fileornullif 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:
trueif the file can be written
-
addToFileOpenHistory
static void addToFileOpenHistory(java.io.File file)
-
showAndLogException
static void showAndLogException(java.lang.Exception e)
-
-