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

COVERAGE SUMMARY FOR SOURCE FILE [TitleImageView.java]

nameclass, %method, %block, %line, %
TitleImageView.java100% (1/1)50%  (2/4)33%  (55/169)38%  (13.4/35)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TitleImageView100% (1/1)50%  (2/4)33%  (55/169)38%  (13.4/35)
imageCached (File): void 0%   (0/1)0%   (0/22)0%   (0/5)
setComicFile (File): void 0%   (0/1)0%   (0/57)0%   (0/12)
paintComponent (Graphics): void 100% (1/1)30%  (15/50)49%  (4.4/9)
TitleImageView (): void 100% (1/1)100% (40/40)100% (9/9)

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.ui;
17 
18import java.awt.Color;
19import java.awt.Dimension;
20import java.awt.Graphics;
21import java.awt.Graphics2D;
22import java.awt.geom.AffineTransform;
23import java.awt.image.RenderedImage;
24import java.io.File;
25import java.io.IOException;
26 
27import javax.swing.JComponent;
28 
29import net.sf.jomic.comic.ComicCache;
30import net.sf.jomic.tools.ImageInCacheListener;
31import net.sf.jomic.tools.ImageTools;
32import net.sf.wraplog.Logger;
33 
34/**
35 *  JComponent to show a title image for a comic.
36 *
37 * @author    Thomas Aglassinger
38 */
39class TitleImageView extends JComponent implements ImageInCacheListener
40{
41    private ComicCache comicCache;
42    private File comicFile;
43    private RenderedImage image;
44    private ImageTools imageTools;
45    private Logger logger;
46    private Object setMutex;
47 
48    public TitleImageView() {
49        logger = Logger.getLogger(TitleImageView.class);
50        comicCache = ComicCache.instance();
51        imageTools = ImageTools.instance();
52 
53        int preferredWidth = comicCache.getThumbWidth();
54        int preferredHeight = comicCache.getThumbHeight();
55 
56        setMutex = new Object();
57        setPreferredSize(new Dimension(preferredWidth, preferredHeight));
58    }
59 
60    public void setComicFile(File newComicFile) {
61        synchronized (setMutex) {
62            comicFile = newComicFile;
63            if (comicFile == null) {
64                image = null;
65            } else {
66                try {
67                    image = comicCache.getTitleCache().get(comicFile, this);
68                } catch (IOException error) {
69                    logger.warn("cannot read title thumbnail for {}", comicFile, error);
70                    image = imageTools.createBrokenImage(getPreferredSize().width, getPreferredSize().height,
71                            Color.RED, Color.WHITE);
72                }
73            }
74        }
75        repaint();
76    }
77 
78    public void imageCached(File baseComicFile) {
79        synchronized (setMutex) {
80            if (baseComicFile.equals(comicFile)) {
81                setComicFile(baseComicFile);
82            }
83        }
84    }
85 
86    protected void paintComponent(Graphics g) {
87        super.paintComponents(g);
88        synchronized (setMutex) {
89            if (image != null) {
90                Graphics2D g2d = (Graphics2D) g;
91                int topX = (getWidth() - image.getWidth()) / 2;
92                int topY = (getHeight() - image.getHeight()) / 2;
93 
94                g2d.drawRenderedImage(image, AffineTransform.getTranslateInstance(topX, topY));
95            }
96        }
97    }
98}

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