1 | // Jomic - a viewer for comic book archives. |
2 | // Copyright (C) 2004-2011 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/>. |
16 | package net.sf.jomic.comic; |
17 | |
18 | import java.io.File; |
19 | import java.util.Map; |
20 | |
21 | import net.sf.jomic.tools.AbstractTask; |
22 | import net.sf.jomic.tools.ProgressChangeListener; |
23 | import net.sf.jomic.tools.Task; |
24 | |
25 | /** |
26 | * Task to create a comic. |
27 | * |
28 | * @author Thomas Aglassinger. |
29 | */ |
30 | public class CreateComicTask extends AbstractTask implements ProgressChangeListener |
31 | { |
32 | private Task delegatedTask; |
33 | |
34 | public CreateComicTask(File sourceFolder, String[] imageNames, File targetComic, String targetFormat) { |
35 | this(sourceFolder, imageNames, targetComic, new Conversion(targetFormat)); |
36 | } |
37 | |
38 | public CreateComicTask(File sourceFolder, String[] imageNames, File targetComic, Conversion conversion) { |
39 | this(sourceFolder, imageNames, null, targetComic, conversion); |
40 | } |
41 | |
42 | public CreateComicTask(File sourceFolder, String[] imageNames, Map imageInfoMap, File targetComic, |
43 | Conversion conversion) { |
44 | this(); |
45 | String comicFormat = conversion.getComicFormat(); |
46 | |
47 | if (comicFormat.equals(Conversion.COMIC_FORMAT_CBZ)) { |
48 | delegatedTask = new CreateCbzComicTask(sourceFolder, imageNames, imageInfoMap, targetComic, conversion); |
49 | } else if (comicFormat.equals(Conversion.COMIC_FORMAT_PDF)) { |
50 | delegatedTask = new CreatePdfComicTask(sourceFolder, imageNames, imageInfoMap, targetComic, conversion); |
51 | } else { |
52 | assert false : "targetFormat=" + comicFormat; |
53 | } |
54 | setMaxProgress(delegatedTask.getMaxProgress()); |
55 | } |
56 | |
57 | private CreateComicTask() { |
58 | super(); |
59 | } |
60 | |
61 | public void progressChanged(Task source) { |
62 | setProgress(source.getProgress()); |
63 | } |
64 | |
65 | public void start() |
66 | throws Exception { |
67 | delegatedTask.addProgressChangeListener(this); |
68 | try { |
69 | delegatedTask.start(); |
70 | } finally { |
71 | delegatedTask.removeProgressChangeListener(this); |
72 | } |
73 | } |
74 | } |