Class Save
- java.lang.Object
-
- org.faceless.pdf2.viewer2.ViewerFeature
-
- org.faceless.pdf2.viewer2.ViewerWidget
-
- org.faceless.pdf2.viewer2.feature.Save
-
- All Implemented Interfaces:
PropertyChangeListener
,EventListener
,DocumentPanelListener
public class Save extends ViewerWidget implements DocumentPanelListener, PropertyChangeListener
Create a button that will allow the PDF to be saved to disk. If the PDF was originally loaded from a File, the user will not be prompted for a filename, otherwise this feature functions like
SaveAs
.The following initialization parameters can be specified to configure this feature.The name of this feature is SavepromptOnOverwrite true to prompt before overwriting files, false otherwise (the default) disableUnlessDirty true to disable this feature until the PDF has been marked as "dirty" (ie it has been altered), false to always enable this feature (the defualt) alwaysCopy true to always do an inefficient copy from the temporary file to the actual file, to work around a reported issue with saving to Windows Network Drives This code is copyright the Big Faceless Organization. You're welcome to use, modify and distribute it in any form in your own projects, provided those projects continue to make use of the Big Faceless PDF library.
- Since:
- 2.8
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
Save.SaveFileChooser
Extends the abomination that is JFileChooser to allow an options panel in the main dialog.
-
Field Summary
-
Fields inherited from class org.faceless.pdf2.viewer2.ViewerWidget
propertyChangeSupport
-
-
Constructor Summary
Constructors Constructor Description Save()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
action(ViewerEvent event)
The method that's run when this feature is activated.protected ActionListener
createActionListener()
Return an ActionListener that will be called when this Widget is activated.void
documentUpdated(DocumentPanelEvent event)
Called when anDocumentPanelEvent
is raisedvoid
initialize(PDFViewer viewer)
Called when the feature is first added to a viewerboolean
isEnabledByDefault()
Return true if this feature is enabled by default (the default).boolean
isPromptOnOverwrite()
Indicates whether this feature should prompt before overwriting a filevoid
propertyChange(PropertyChangeEvent event)
static boolean
save(File file, ViewerEvent event, List<Exporter> exporters, boolean displayprompt, boolean overwriteprompt)
Save the Document.static boolean
save(ViewerEvent event, Exporter exporter, String initialpath, boolean displayprompt, boolean overwriteprompt)
Save the Document.void
setDisableUnlessDirty(boolean value)
Set whether this feature should be disabled unless the PDF is marked as "dirty", i.e. it has been changed since it was loaded.void
setEnabledForNewFiles(boolean value)
Set whether this feature is disabled when the PDF is marked as "new", i.e. it was not loaded from a local PDF file originally.void
setPromptOnOverwrite(boolean prompt)
Set whether this feature should prompt before overwriting a file-
Methods inherited from class org.faceless.pdf2.viewer2.ViewerWidget
addPropertyChangeListener, firePropertyChange, getComponent, getIcon, getViewer, isButtonEnabledByDefault, isDocumentRequired, isMenuEnabledByDefault, removePropertyChangeListener, setButton, setComponent, setDocumentRequired, setMenu, setMenu, setToolBarEnabled, setToolBarEnabledAlways, setToolBarFloatable, setToolBarFloating, toString
-
Methods inherited from class org.faceless.pdf2.viewer2.ViewerFeature
getAllEnabledFeatures, getAllFeatures, getCustomJavaScript, getFeatureProperty, getFeatureURLProperty, getName, setFeatureName, teardown
-
-
-
-
Method Detail
-
action
public void action(ViewerEvent event)
Description copied from class:ViewerWidget
The method that's run when this feature is activated. This method is called by theActionListener
returned by the default implementation ofViewerWidget.createActionListener()
, and by default is a no-op.- Overrides:
action
in classViewerWidget
-
isEnabledByDefault
public boolean isEnabledByDefault()
Description copied from class:ViewerFeature
Return true if this feature is enabled by default (the default). Disabled features are excluded from the list returned byViewerFeature.getAllEnabledFeatures()
and byPDFTool
- Overrides:
isEnabledByDefault
in classViewerFeature
-
createActionListener
protected ActionListener createActionListener()
Description copied from class:ViewerWidget
Return an ActionListener that will be called when this Widget is activated. Subclasses will typically not need to override this method except in special cases.- Overrides:
createActionListener
in classViewerWidget
- Returns:
- ActionListener the ActionListener to be notified when an event fires
- See Also:
Quit.createActionListener()
-
initialize
public void initialize(PDFViewer viewer)
Description copied from class:ViewerFeature
Called when the feature is first added to a viewer- Overrides:
initialize
in classViewerWidget
-
documentUpdated
public void documentUpdated(DocumentPanelEvent event)
Description copied from interface:DocumentPanelListener
Called when anDocumentPanelEvent
is raised- Specified by:
documentUpdated
in interfaceDocumentPanelListener
-
propertyChange
public void propertyChange(PropertyChangeEvent event)
- Specified by:
propertyChange
in interfacePropertyChangeListener
-
setPromptOnOverwrite
public void setPromptOnOverwrite(boolean prompt)
Set whether this feature should prompt before overwriting a file- Parameters:
prompt
- whether to prompt before overwriting a file (detault is false)- Since:
- 2.11.25
-
isPromptOnOverwrite
public boolean isPromptOnOverwrite()
Indicates whether this feature should prompt before overwriting a file- Since:
- 2.18
-
setDisableUnlessDirty
public void setDisableUnlessDirty(boolean value)
Set whether this feature should be disabled unless the PDF is marked as "dirty", i.e. it has been changed since it was loaded. The default is false.- Parameters:
value
- whether to disable this feature unless the PDF is marked as dirty.- Since:
- 2.16.1
-
setEnabledForNewFiles
public void setEnabledForNewFiles(boolean value)
Set whether this feature is disabled when the PDF is marked as "new", i.e. it was not loaded from a local PDF file originally. Prior to 2.24.3 this was false, so the "Save" prompt was always available even for new files. In 2.24.3 this value defaults to true - Save is disabled if the file was imported from an image, or from a URL (although the "Save As" option still allows the file to be saved)- Since:
- 2.24.3
-
save
public static boolean save(ViewerEvent event, Exporter exporter, String initialpath, boolean displayprompt, boolean overwriteprompt)
Save the Document. Callssave(File,ViewerEvent,List,boolean,boolean)
with a list of all the exporters availabe in the viewer, and the specified one first. Note this method is no longer called from within the API, it's here for legacy reasons only.- Parameters:
event
- the ViewerEvent that launched this actionexporter
- if not null, the initial exporter to use.initialpath
- the Path to display by default, ornull
to use the same path as the source filedisplayprompt
- whether to prompt the user for a filename. We will always prompt anyway if the document has not yet been saved.overwriteprompt
- whether to prompt the user if we are about to overwrite a filename.- Returns:
- true if the file was saved, false otherwise
- Since:
- 2.11.10
-
save
public static boolean save(File file, ViewerEvent event, List<Exporter> exporters, boolean displayprompt, boolean overwriteprompt)
Save the Document.- Parameters:
file
- the File to save to, or null to use the existing file (if there is one) or prompt otherwise.event
- the ViewerEvent that launched this actionexporters
- the list ofExporter
objects. If a dialog is displayed the list will be presented as options for users, otherwise the first exporter will be used. The list must have at least one item.displayprompt
- whether to prompt the user for a filename. We will always prompt anyway if the document has not yet been saved.overwriteprompt
- whether to prompt the user if we are about to overwrite a filename.- Returns:
- true if the file was saved, false otherwise
- Since:
- 2.24.3
-
-