EMMA Coverage Report (generated Sun Apr 20 22:38:01 CEST 2008)
[all classes][net.sf.jomic.comic]

COVERAGE SUMMARY FOR SOURCE FILE [ExtractComicTask.java]

nameclass, %method, %block, %line, %
ExtractComicTask.java100% (1/1)100% (5/5)87%  (113/130)96%  (25.8/27)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ExtractComicTask100% (1/1)100% (5/5)87%  (113/130)96%  (25.8/27)
<static initializer> 100% (1/1)80%  (12/15)80%  (0.8/1)
ExtractComicTask (File, File): void 100% (1/1)83%  (70/84)94%  (15/16)
ExtractComicTask (): void 100% (1/1)100% (6/6)100% (3/3)
progressChanged (Task): void 100% (1/1)100% (5/5)100% (2/2)
start (): void 100% (1/1)100% (20/20)100% (5/5)

1// Jomic - a viewer for comic book archives.
2// Copyright (C) 2004-2008 Thomas Aglassinger
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16package net.sf.jomic.comic;
17 
18import java.io.File;
19import java.io.IOException;
20 
21import net.sf.jomic.common.Settings;
22import net.sf.jomic.tools.AbstractTask;
23import net.sf.jomic.tools.FileTools;
24import net.sf.jomic.tools.ExtractPdfImagesTask;
25import net.sf.jomic.tools.ExtractRarTask;
26import net.sf.jomic.tools.ExtractZipTask;
27import net.sf.jomic.tools.ProgressChangeListener;
28import net.sf.jomic.tools.Task;
29 
30/**
31 *  Task to extract a comic independent of its format.
32 *
33 * @see       net.sf.jomic.tools.ExtractPdfImagesTask
34 * @see       net.sf.jomic.tools.ExtractRarTask
35 * @see       net.sf.jomic.tools.ExtractZipTask
36 * @author    Thomas Aglassinger
37 */
38public class ExtractComicTask extends AbstractTask implements ProgressChangeListener
39{
40    private File comicFile;
41    private Task delegateTask;
42    private FileTools fileTools;
43    private File targetFolder;
44 
45    public ExtractComicTask(File newComicFile, File newTargetFolder)
46        throws IOException {
47        this();
48        comicFile = newComicFile;
49        targetFolder = newTargetFolder;
50 
51        String comicFormat = fileTools.obtainComicFormat(comicFile);
52 
53        if (comicFormat.equals(FileTools.FORMAT_PDF)) {
54            delegateTask = new ExtractPdfImagesTask(comicFile, targetFolder);
55        } else if (comicFormat.equals(FileTools.FORMAT_RAR)) {
56            ExtractRarTask extractRarTask = new ExtractRarTask(comicFile, targetFolder);
57            Settings settings = Settings.instance();
58 
59            extractRarTask.setUnrarCommand(settings.getUnrarCommand());
60            delegateTask = extractRarTask;
61        } else if (comicFormat.equals(FileTools.FORMAT_ZIP)) {
62            delegateTask = new ExtractZipTask(comicFile, targetFolder);
63        } else {
64            assert false : "fileType=" + comicFormat;
65        }
66        setMaxProgress(delegateTask.getMaxProgress());
67    }
68 
69    private ExtractComicTask() {
70        super();
71        fileTools = FileTools.instance();
72    }
73 
74    /**
75     *  Set progress to progress of <code>source</code> task, which does the actual extraction.
76     */
77    public void progressChanged(Task source) {
78        setProgress(source.getProgress());
79    }
80 
81    public void start()
82        throws Exception {
83        delegateTask.addProgressChangeListener(this);
84        try {
85            delegateTask.start();
86        } finally {
87            delegateTask.removeProgressChangeListener(this);
88        }
89    }
90}

[all classes][net.sf.jomic.comic]
EMMA 2.0.4217 (C) Vladimir Roubtsov