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

COVERAGE SUMMARY FOR SOURCE FILE [ImageViewer.java]

nameclass, %method, %block, %line, %
ImageViewer.java100% (1/1)27%  (3/11)51%  (104/202)40%  (17.5/44)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ImageViewer100% (1/1)27%  (3/11)51%  (104/202)40%  (17.5/44)
dispose (): void 0%   (0/1)0%   (0/6)0%   (0/3)
windowActivated (WindowEvent): void 0%   (0/1)0%   (0/1)0%   (0/1)
windowClosed (WindowEvent): void 0%   (0/1)0%   (0/1)0%   (0/1)
windowClosing (WindowEvent): void 0%   (0/1)0%   (0/12)0%   (0/4)
windowDeactivated (WindowEvent): void 0%   (0/1)0%   (0/1)0%   (0/1)
windowDeiconified (WindowEvent): void 0%   (0/1)0%   (0/1)0%   (0/1)
windowIconified (WindowEvent): void 0%   (0/1)0%   (0/1)0%   (0/1)
windowOpened (WindowEvent): void 0%   (0/1)0%   (0/1)0%   (0/1)
showImage (): void 100% (1/1)34%  (28/82)25%  (4/16)
ImageViewer (RenderedImage, Class, String): void 100% (1/1)79%  (64/81)91%  (12.7/14)
<static initializer> 100% (1/1)80%  (12/15)80%  (0.8/1)

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.jaiunit;
17 
18import java.awt.event.WindowEvent;
19import java.awt.event.WindowListener;
20import java.awt.image.RenderedImage;
21 
22import javax.swing.BorderFactory;
23import javax.swing.JFrame;
24import javax.swing.JScrollPane;
25import javax.swing.WindowConstants;
26 
27import net.sf.jomic.ui.RenderedImageView;
28import net.sf.wraplog.Logger;
29 
30/**
31 *  JFrame to show an image during testing. The window title identifies the class and test that
32 *  created the image. Call <code>showImage()</code> to conveniently show the image only if
33 *  requested and with a timeout.
34 *
35 * @see       #showImage()
36 * @author    Thomas Aglassinger
37 */
38public class ImageViewer extends JFrame implements WindowListener
39{
40    // TODO: Move to JAIUnit, JAIUnitConstants or where ever.
41    public static final int TICK = 50;
42    private boolean closed;
43    private RenderedImage image;
44    private Logger logger;
45 
46    public ImageViewer(RenderedImage newImage, Class clazz, String id) {
47        super("" + clazz.getName() + "." + id);
48        assert clazz != null;
49        assert id != null;
50        assert newImage != null;
51        logger = Logger.getLogger(ImageViewer.class);
52        image = newImage;
53 
54        RenderedImageView icon = new RenderedImageView();
55        JScrollPane scrollPane = new JScrollPane(icon);
56 
57        icon.set(image);
58        scrollPane.setBorder(BorderFactory.createEmptyBorder());
59        getContentPane().add(scrollPane);
60        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
61        addWindowListener(this);
62    }
63 
64    public void dispose() {
65        removeWindowListener(this);
66        super.dispose();
67    }
68 
69    /**
70     *  If property "net.sf.jaiunit.showImage" is <code>true</code>, show <code>image</code>. The
71     *  window closes automatically after <code>PROPERTY_TIMEOUT</code> milliseconds, or when the
72     *  user clicks the close button.
73     */
74    public void showImage() {
75        if (Boolean.getBoolean(TestCase.PROPERTY_SHOW_IMAGE)) {
76            try {
77                pack();
78                setResizable(false);
79                setVisible(true);
80 
81                int timeout = Integer.getInteger(TestCase.PROPERTY_TIMEOUT, TestCase.DEFAULT_TIMEOUT).intValue();
82                int ticks = Math.max(1, timeout / TICK);
83 
84                while ((!closed && (ticks > 0)) || (timeout == 0)) {
85                    Thread.sleep(TICK);
86                    ticks -= 1;
87                }
88            } catch (InterruptedException error) {
89                logger.warn("sleep interrupted: " + error);
90            } finally {
91                dispose();
92            }
93        } else {
94            if (logger.isDebugEnabled()) {
95                logger.debug("showImage: to show " + getTitle()
96                        + ", set " + TestCase.PROPERTY_SHOW_IMAGE + " to " + Boolean.TRUE);
97            }
98        }
99    }
100 
101    public void windowActivated(WindowEvent event) {
102        // do nothing
103    }
104 
105    public void windowClosed(WindowEvent event) {
106        // do nothing
107    }
108 
109    public void windowClosing(WindowEvent event) {
110        if (logger.isDebugEnabled()) {
111            logger.debug("received event: WindowClosed");
112        }
113        closed = true;
114    }
115 
116    public void windowDeactivated(WindowEvent event) {
117        // do nothing
118    }
119 
120    public void windowDeiconified(WindowEvent event) {
121        // do nothing
122    }
123 
124    public void windowIconified(WindowEvent event) {
125        // do nothing
126    }
127 
128    public void windowOpened(WindowEvent event) {
129        // do nothing
130    }
131}

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