Package org.faceless.pdf2.viewer2
Class Importer.ImporterTask
- java.lang.Object
-
- org.faceless.pdf2.viewer2.util.LongRunningTask
-
- org.faceless.pdf2.viewer2.Importer.ImporterTask
-
- All Implemented Interfaces:
DocumentPanelListener
- Enclosing class:
- Importer
public abstract class Importer.ImporterTask extends LongRunningTask implements DocumentPanelListener
This class is aLongRunningTask
that can be run to load a PDF into the viewer. Subclasses ofImporter
need to implement a concrete subclass of this which implemented theloadPDF()
method. By default this task is cancellable, but that may be overridden too.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.10.2
-
-
Field Summary
Fields Modifier and Type Field Description protected File
file
The file passed to the constructorprotected InputStream
in
The InputStream passed to the constructorprotected int
pagenumber
The initial pagenumber to requestprotected String
title
The title passed to the constructorprotected PDFViewer
viewer
The viewer passed to the constructor
-
Constructor Summary
Constructors Modifier Constructor Description protected
ImporterTask(PDFViewer viewer, InputStream in, String title, File file)
Create a new ImporterTask which will read it's input from a File (ifin
is null) or from an InputStream.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
addToMostRecent()
Return true if the file should be added to the "Most Recent" list of files, false otherwise.void
documentUpdated(DocumentPanelEvent event)
This event listener will be called when the PDF has been imported.File
getFile()
Return the file previously set bysetFile(java.io.File)
String
getTitle()
Return the title, as set bysetTitle(java.lang.String)
boolean
isCancellable()
Return true if this task can be cancelled before completion by the user.abstract PDF
loadPDF()
Load and return a PDF.void
run()
Run the current task.void
setFile(File file)
Set the default file to save the file to if the PDF is later saved.void
setPageNumber(int pagenumber)
Set the initial pagenumber to display.void
setTitle(String title)
Set the title which is displayed in the window decoration of the imported file.-
Methods inherited from class org.faceless.pdf2.viewer2.util.LongRunningTask
addPropertyChangeListener, cancel, getProgress, isCancelled, isModal, isRunning, removePropertyChangeListener, setCancellable, setModal, start, start
-
-
-
-
Field Detail
-
viewer
protected final PDFViewer viewer
The viewer passed to the constructor
-
file
protected final File file
The file passed to the constructor
-
in
protected final InputStream in
The InputStream passed to the constructor
-
title
protected String title
The title passed to the constructor
-
pagenumber
protected int pagenumber
The initial pagenumber to request
-
-
Constructor Detail
-
ImporterTask
protected ImporterTask(PDFViewer viewer, InputStream in, String title, File file)
Create a new ImporterTask which will read it's input from a File (ifin
is null) or from an InputStream.- Parameters:
viewer
- the Viewer this task is going to add the PDF toin
- the InputStream to read the PDF from, ornull
to read the PDF from thefile
parametertitle
- the title of the PDF - may be nullfile
- Ifin
is null, the File to read the PDF from (may not be null). Ifin
is not null, the file that is used as the default when this PDF is save, in which case it may be null.
-
-
Method Detail
-
isCancellable
public boolean isCancellable()
Description copied from class:LongRunningTask
Return true if this task can be cancelled before completion by the user.- Overrides:
isCancellable
in classLongRunningTask
-
run
public void run() throws IOException
Description copied from class:LongRunningTask
Run the current task. Called byLongRunningTask.start(javax.swing.JComponent, java.lang.String)
, this method should typically not be called directly.- Specified by:
run
in classLongRunningTask
- Throws:
IOException
-
setPageNumber
public void setPageNumber(int pagenumber)
Set the initial pagenumber to display. This may be overridden by a PDF openaction or if it is out of range- Since:
- 2.11.10
-
setFile
public void setFile(File file)
Set the default file to save the file to if the PDF is later saved. For PDFs loaded from a File, this defaults to the same file. If the specified File does not have an absolute path, the directory it will be resolved against is undefined. TheSave
feature will try to resolve it against the last directory used by the user- Parameters:
file
- If the PDF is later saved, the file to initialize the path to. Should be an absolute file if one is required, and may also benull
.- Since:
- 2.11.22
-
setTitle
public void setTitle(String title)
Set the title which is displayed in the window decoration of the imported file.- Since:
- 2.24.3
-
getFile
public File getFile()
Return the file previously set bysetFile(java.io.File)
- Since:
- 2.24.3
-
getTitle
public String getTitle()
Return the title, as set bysetTitle(java.lang.String)
-
loadPDF
public abstract PDF loadPDF() throws IOException
Load and return a PDF. Subclasses must implement this method, loading the PDF from theInputStream
in
if it's specified of theFile
file
if it's not- Returns:
- the PDF
- Throws:
IOException
-
addToMostRecent
public boolean addToMostRecent()
Return true if the file should be added to the "Most Recent" list of files, false otherwise. The default is true- Since:
- 2.16.1
-
documentUpdated
public void documentUpdated(DocumentPanelEvent event)
This event listener will be called when the PDF has been imported. By default it does nothing, but can be overriden in subclasses.- Specified by:
documentUpdated
in interfaceDocumentPanelListener
- Since:
- 2.24.3
-
-