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

COVERAGE SUMMARY FOR SOURCE FILE [ImageComparisonViewer.java]

nameclass, %method, %block, %line, %
ImageComparisonViewer.java100% (1/1)33%  (4/12)65%  (181/280)59%  (37.1/63)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ImageComparisonViewer100% (1/1)33%  (4/12)65%  (181/280)59%  (37.1/63)
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)
showImages (): void 100% (1/1)35%  (28/79)27%  (4/15)
<static initializer> 100% (1/1)80%  (12/15)80%  (0.8/1)
ImageComparisonViewer (RenderedImage, RenderedImage, Class, String): void 100% (1/1)86%  (124/145)94%  (27.3/29)
createImagePanel (RenderedImage): JScrollPane 100% (1/1)100% (17/17)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.jaiunit;
17 
18import java.awt.GridBagConstraints;
19import java.awt.GridBagLayout;
20import java.awt.event.WindowEvent;
21import java.awt.event.WindowListener;
22import java.awt.image.RenderedImage;
23 
24import javax.swing.BorderFactory;
25import javax.swing.JFrame;
26import javax.swing.JPanel;
27import javax.swing.JScrollPane;
28import javax.swing.WindowConstants;
29 
30import net.sf.jomic.ui.RenderedImageView;
31import net.sf.wraplog.Logger;
32 
33/**
34 *  JFrame to show two images and their differences.
35 *
36 * @author    Thomas Aglassinger
37 */
38public class ImageComparisonViewer extends JFrame implements WindowListener
39{
40    private boolean closed;
41    private RenderedImage image1;
42    private RenderedImage image2;
43    private Logger logger;
44    private Tools tools;
45 
46    public ImageComparisonViewer(RenderedImage newImage1, RenderedImage newImage2, Class clazz, String id) {
47        super("" + clazz.getName() + "." + id);
48        assert clazz != null;
49        assert id != null;
50        assert newImage1 != null;
51        assert newImage2 != null;
52 
53        tools = Tools.instance();
54        logger = Logger.getLogger(ImageComparisonViewer.class);
55        image1 = newImage1;
56        image2 = newImage2;
57 
58        RenderedImage deltaImage = tools.getDeltaImage(image1, image2);
59        JScrollPane scrollPane1 = createImagePanel(image1);
60        JScrollPane scrollPane2 = createImagePanel(image2);
61        JScrollPane deltaScrollPane = createImagePanel(deltaImage);
62        JPanel pane = new JPanel(new GridBagLayout());
63        GridBagConstraints c = new GridBagConstraints();
64 
65        pane.setBorder(BorderFactory.createEmptyBorder());
66 
67        c.anchor = GridBagConstraints.CENTER;
68        c.gridx = 0;
69        c.gridy = 0;
70        pane.add(scrollPane1, c);
71        c.gridx = 1;
72        pane.add(scrollPane2, c);
73        c.gridx = 0;
74        c.gridy = 1;
75        pane.add(deltaScrollPane, c);
76 
77        getContentPane().add(pane);
78        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
79        addWindowListener(this);
80    }
81 
82    public void dispose() {
83        removeWindowListener(this);
84        super.dispose();
85    }
86 
87    /**
88     *  If property "net.sf.jaiunit.showImage" is <code>true</code>, show the images.
89     */
90    public void showImages() {
91        if (Boolean.getBoolean(TestCase.PROPERTY_SHOW_IMAGE)) {
92            try {
93                pack();
94                setVisible(true);
95 
96                int timeout = Integer.getInteger(TestCase.PROPERTY_TIMEOUT, TestCase.DEFAULT_TIMEOUT).intValue();
97                int ticks = Math.max(1, timeout / ImageViewer.TICK);
98 
99                while ((!closed && (ticks > 0)) || (timeout == 0)) {
100                    Thread.sleep(ImageViewer.TICK);
101                    ticks -= 1;
102                }
103            } catch (InterruptedException error) {
104                logger.warn("sleep interrupted: " + error);
105            } finally {
106                dispose();
107            }
108        } else {
109            if (logger.isDebugEnabled()) {
110                logger.debug("showImage: to show " + getTitle()
111                        + ", set " + TestCase.PROPERTY_SHOW_IMAGE + " to " + Boolean.TRUE);
112            }
113        }
114    }
115 
116    public void windowActivated(WindowEvent event) {
117        // do nothing
118    }
119 
120    public void windowClosed(WindowEvent event) {
121        // do nothing
122    }
123 
124    public void windowClosing(WindowEvent event) {
125        if (logger.isDebugEnabled()) {
126            logger.debug("received event: WindowClosed");
127        }
128        closed = true;
129    }
130 
131    public void windowDeactivated(WindowEvent event) {
132        // do nothing
133    }
134 
135    public void windowDeiconified(WindowEvent event) {
136        // do nothing
137    }
138 
139    public void windowIconified(WindowEvent event) {
140        // do nothing
141    }
142 
143    public void windowOpened(WindowEvent event) {
144        // do nothing
145    }
146 
147    private JScrollPane createImagePanel(RenderedImage image) {
148        RenderedImageView imageView = new RenderedImageView();
149        JScrollPane scrollPane = new JScrollPane(imageView);
150 
151        imageView.set(image);
152        scrollPane.setBorder(BorderFactory.createEmptyBorder());
153        return scrollPane;
154    }
155 
156}

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