Package pulse.io.export
Interface Exporter<T extends Descriptive>
-
- All Superinterfaces:
Reflexive
- All Known Implementing Classes:
CurveExporter,LogExporter,MetadataExporter,RawDataExporter,ResidualStatisticExporter,ResultExporter,ResultTableExporter,TextLogPaneExporter
public interface Exporter<T extends Descriptive> extends Reflexive
AnExporterdefines a set of rules to enable exporting of a certain type of PULsE objects (typically, instances of the PropertyHolder class).
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default FileaskToExport(T target, JFrame parentWindow, String fileTypeLabel, File directory)Provides aJFileChooserfor the user to select the export destination fortarget.default voidexport(T target, File directory, Extension extension)Exports the available contents todirectorywithout asking a confirmation from the user.static ExtensiongetDefaultExportExtension()Gets the default export extension.default Extension[]getSupportedExtensions()Returns an array of supported extensions, which by default contains only the default extension.voidprintToStream(T target, FileOutputStream fos, Extension extension)The interface method is implemented by the subclasses to define the exportable content in detail.Class<T>target()Defines the class, instances of which can be fed into the exporter to produce a result.
-
-
-
Method Detail
-
getDefaultExportExtension
static Extension getDefaultExportExtension()
Gets the default export extension.- Returns:
Extension.CSVby default
-
getSupportedExtensions
default Extension[] getSupportedExtensions()
Returns an array of supported extensions, which by default contains only the default extension.- Returns:
- an array with
Extensiontype objects.
-
export
default void export(T target, File directory, Extension extension)
Exports the available contents todirectorywithout asking a confirmation from the user.A file is created with the name specified by the
describe()method oftargetwith the extension equal to the third argument of this method. AFileOutputStreamwrites the contents to the file by invokingprintToStreamand is closed upon completion.- Parameters:
directory- the directory where the contents will be exported to.target- aDescriptivetargetextension- the file extension. If it is not supported, the exporter will revert to its default extension- Throws:
IllegalArgumentException- ifdirectoryis not really a directory- See Also:
printToStream(T,java.io.FileOutputStream,pulse.io.export.Extension)
-
askToExport
default File askToExport(T target, JFrame parentWindow, String fileTypeLabel, File directory)
Provides aJFileChooserfor the user to select the export destination fortarget. The name of the file and its extension come from the selection the user makes by interacting with the dialog.- Parameters:
target- the exported targetparentWindow- the parent frame.fileTypeLabel- the label describing the specific type of files thatdirectory- the default directory of the file will be saved.- Returns:
- the directory where files were exported
-
target
Class<T> target()
Defines the class, instances of which can be fed into the exporter to produce a result.- Returns:
- a class implementing the
Descriptiveinterface.
-
printToStream
void printToStream(T target, FileOutputStream fos, Extension extension)
The interface method is implemented by the subclasses to define the exportable content in detail. Depending on the supported extensions, this will typically involve a switch statement that will invoke private methods defined in the subclass handling the different choices. The streamfosis usually closed implicitly in a try-with-resource clause.- Parameters:
target- the exported targetfos- a FileOutputStream created by theexportmethodextension- an extension of the file saved on disk- See Also:
export(T,java.io.File,pulse.io.export.Extension),askToExport(T,javax.swing.JFrame,java.lang.String,java.io.File)
-
-