net.sf.jomic.comic
Class AbstractCreateComicTask

java.lang.Object
  extended by net.sf.jomic.tools.AbstractTask
      extended by net.sf.jomic.comic.AbstractCreateComicTask
All Implemented Interfaces:
Task
Direct Known Subclasses:
CreateCbzComicTask, CreatePdfComicTask

public abstract class AbstractCreateComicTask
extends AbstractTask

Task to create comic from a set of image files.

Author:
Thomas Aglassinger

Constructor Summary
AbstractCreateComicTask(java.io.File newSourceBaseDir, java.lang.String[] newSourceFileNames, java.util.Map newImageInfoMap, java.io.File newTargetComicFile, Conversion newConversion)
          Create a new task to create a comic.
 
Method Summary
protected abstract  void addImageFile(java.lang.String outImageName, java.io.File sourceImageFile)
          Add an image file to the target comic stream/document/file/whatever.
protected abstract  void cleanUpComic()
          Release all resources need allocated by setUpComic() to create the target comic stream/document/file/whatever.
protected  void enableAddedAtLeastOneImage()
          Must be called by addImageFile when an image actually was added.
protected  Conversion getConversion()
           
protected  ImageInfo getImageInfo(java.io.File imageFile)
          Obtain the imageInfo for imageFile, preferably from the newImageInfoMap passed to the constructor.
protected  java.io.File getSourceBaseDir()
           
protected  java.io.File getTargetComicFile()
           
protected  boolean hasAddedAtLeastOneImage()
           
protected abstract  void setUpComic()
          Allocate all resources needed to create the target comic file.
 void start()
          Start the task, which will cause the progress to iterate from 0 to getMaximum.
 
Methods inherited from class net.sf.jomic.tools.AbstractTask
addProgressChangeListener, getMaxProgress, getProgress, getProgressMessage, isInterrupted, removeProgressChangeListener, setMaxProgress, setProgress, setProgressMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCreateComicTask

public AbstractCreateComicTask(java.io.File newSourceBaseDir,
                               java.lang.String[] newSourceFileNames,
                               java.util.Map newImageInfoMap,
                               java.io.File newTargetComicFile,
                               Conversion newConversion)
Create a new task to create a comic.

Parameters:
newSourceBaseDir - the base directory where the source files are located
newSourceFileNames - the names of the files relative to newSourceBaseDir that should be included in the archive
newImageInfoMap - a map of ImageInfos used to decide if images can be added. If this is null, the ImageInfo is filled during start() .
newTargetComicFile - the comic file to create
newConversion - a conversion specifying the format and image manipulations of the new comic; if null, the default will be a conversion creating a CBZ including all the images specified.
See Also:
ImageInfo
Method Detail

setUpComic

protected abstract void setUpComic()
                            throws java.lang.Exception
Allocate all resources needed to create the target comic file. They will be released when done by calling cleanUpComic() either when done or an error occurs.

Throws:
java.lang.Exception
See Also:
cleanUpComic()

getConversion

protected final Conversion getConversion()

getSourceBaseDir

protected final java.io.File getSourceBaseDir()

getTargetComicFile

protected final java.io.File getTargetComicFile()

getImageInfo

protected ImageInfo getImageInfo(java.io.File imageFile)
Obtain the imageInfo for imageFile, preferably from the newImageInfoMap passed to the constructor. If the image can not be found in the map, obtain a new ImageInfo for it and put it in the map for later reuse.


start

public void start()
           throws java.lang.Exception
Description copied from interface: Task
Start the task, which will cause the progress to iterate from 0 to getMaximum.

Specified by:
start in interface Task
Specified by:
start in class AbstractTask
Throws:
java.lang.Exception

addImageFile

protected abstract void addImageFile(java.lang.String outImageName,
                                     java.io.File sourceImageFile)
                              throws java.lang.Exception
Add an image file to the target comic stream/document/file/whatever.

Parameters:
outImageName - the name under which the image should be stored (if applicable for the output format)
sourceImageFile - the source image file to be added
Throws:
java.lang.Exception

cleanUpComic

protected abstract void cleanUpComic()
                              throws java.lang.Exception
Release all resources need allocated by setUpComic() to create the target comic stream/document/file/whatever. This will be called in any case even if something went wrong during setUpComic() so this routine must be able to handle null values without resulting in NullPointerExceptions.

Throws:
java.lang.Exception
See Also:
setUpComic()

enableAddedAtLeastOneImage

protected void enableAddedAtLeastOneImage()
Must be called by addImageFile when an image actually was added.

See Also:
addImageFile(String, File)

hasAddedAtLeastOneImage

protected boolean hasAddedAtLeastOneImage()