EMMA Coverage Report (generated Sat Oct 08 11:41:37 CEST 2011)
[all classes][net.sf.jomic.tools]

COVERAGE SUMMARY FOR SOURCE FILE [AbstractTask.java]

nameclass, %method, %block, %line, %
AbstractTask.java100% (1/1)91%  (10/11)81%  (79/97)88%  (22/25)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AbstractTask100% (1/1)91%  (10/11)81%  (79/97)88%  (22/25)
getProgressMessage (): String 0%   (0/1)0%   (0/3)0%   (0/1)
setMaxProgress (long): void 100% (1/1)71%  (10/14)87%  (2.6/3)
setProgressMessage (String): void 100% (1/1)71%  (10/14)80%  (4/5)
<static initializer> 100% (1/1)80%  (12/15)80%  (0.8/1)
setProgress (long): void 100% (1/1)81%  (17/21)90%  (3.6/4)
AbstractTask (): void 100% (1/1)100% (11/11)100% (4/4)
addProgressChangeListener (ProgressChangeListener): void 100% (1/1)100% (5/5)100% (2/2)
getMaxProgress (): long 100% (1/1)100% (3/3)100% (1/1)
getProgress (): long 100% (1/1)100% (3/3)100% (1/1)
isInterrupted (): boolean 100% (1/1)100% (3/3)100% (1/1)
removeProgressChangeListener (ProgressChangeListener): void 100% (1/1)100% (5/5)100% (2/2)

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/>.
16package net.sf.jomic.tools;
17 
18/**
19 *  Base for a Task already handling progress related issues.
20 *
21 * @author    Thomas Aglassinger
22 */
23public abstract class AbstractTask implements Task
24{
25    private static final String EMPTY_PROGRESS = "...";
26    private long maxProgress;
27    private long progress;
28    private ProgressChangeSupport progressChangeSupport;
29    private String progressMessage;
30 
31    protected AbstractTask() {
32        super();
33        progressChangeSupport = new ProgressChangeSupport();
34        progressMessage = EMPTY_PROGRESS;
35    }
36 
37    /**
38     *  Set maximum progress to <code>newMaxProgress</code>. This should only be called from the
39     *  constructor.
40     */
41    protected final void setMaxProgress(long newMaxProgress) {
42        assert newMaxProgress >= 0;
43 
44        maxProgress = newMaxProgress;
45    }
46 
47    /**
48     *  Set progress to <code>newProgress</code> and notify progress listeners of it.
49     */
50    protected void setProgress(long newProgress) {
51        assert newProgress >= 0;
52 
53        progress = Math.min(newProgress, getMaxProgress());
54        progressChangeSupport.fireProgressChangedEvent(this);
55    }
56 
57    protected void setProgressMessage(String newMessage) {
58        if (newMessage == null) {
59            progressMessage = EMPTY_PROGRESS;
60        } else {
61            progressMessage = newMessage;
62        }
63        progressChangeSupport.fireProgressChangedEvent(this);
64    }
65 
66    public long getMaxProgress() {
67        return maxProgress;
68    }
69 
70    public long getProgress() {
71        return progress;
72    }
73 
74    /**
75     *  Get a message describing the current progress, for example "Rendering hugo.png". This can
76     *  not be <code>null</code>.
77     */
78    public String getProgressMessage() {
79        return progressMessage;
80    }
81 
82    /**
83     *  Return <code>true</code> if the current thread was interrupted.
84     *
85     * @see    Thread#isInterrupted()
86     */
87    protected boolean isInterrupted() {
88        return Thread.currentThread().isInterrupted();
89    }
90 
91    public void addProgressChangeListener(ProgressChangeListener newListener) {
92        progressChangeSupport.addProgressChangeListener(newListener);
93    }
94 
95    public void removeProgressChangeListener(
96            ProgressChangeListener listenerToRemove) {
97        progressChangeSupport.removeProgressChangeListener(listenerToRemove);
98    }
99 
100    public abstract void start()
101        throws Exception;
102}

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