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

COVERAGE SUMMARY FOR SOURCE FILE [ComicViewTransferable.java]

nameclass, %method, %block, %line, %
ComicViewTransferable.java100% (1/1)80%  (4/5)71%  (60/84)78%  (14/18)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ComicViewTransferable100% (1/1)80%  (4/5)71%  (60/84)78%  (14/18)
isDataFlavorSupported (DataFlavor): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
<static initializer> 100% (1/1)68%  (17/25)70%  (1.4/2)
getTransferData (DataFlavor): Object 100% (1/1)72%  (21/29)78%  (7/9)
ComicViewTransferable (JComponent): void 100% (1/1)79%  (15/19)93%  (4.6/5)
getTransferDataFlavors (): DataFlavor [] 100% (1/1)100% (7/7)100% (1/1)

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.comic;
17 
18import java.awt.datatransfer.DataFlavor;
19import java.awt.datatransfer.Transferable;
20import java.awt.datatransfer.UnsupportedFlavorException;
21import java.awt.image.RenderedImage;
22import java.io.IOException;
23 
24import javax.swing.JComponent;
25 
26import net.sf.jomic.tools.ImageTools;
27 
28import org.apache.commons.logging.Log;
29import org.apache.commons.logging.LogFactory;
30 
31/**
32 *  Transferable to transfer the currently visible image from a ComicView.
33 *
34 * @see    ComicView
35 */
36public class ComicViewTransferable implements Transferable
37{
38    private static Log logger = LogFactory.getLog(ComicViewTransferable.class);
39    private ComicView comicView;
40    private ImageTools imageTools;
41 
42    public ComicViewTransferable(JComponent component) {
43        assert component instanceof ComicView;
44        imageTools = ImageTools.instance();
45        comicView = (ComicView) component;
46    }
47 
48    public Object getTransferData(DataFlavor flavor)
49        throws IOException, UnsupportedFlavorException {
50        Object result = null;
51 
52        if (DataFlavor.imageFlavor.equals(flavor)) {
53            RenderedImage renderedImage = comicView.getRenderedImage();
54 
55            if (renderedImage != null) {
56                result = imageTools.getAsBufferedImage(renderedImage);
57            } else {
58                logger.warn("ComicView has no image to transfer");
59            }
60        } else {
61            throw new UnsupportedFlavorException(flavor);
62        }
63        return result;
64    }
65 
66    public DataFlavor[] getTransferDataFlavors() {
67        return new DataFlavor[]{DataFlavor.imageFlavor};
68    }
69 
70    public boolean isDataFlavorSupported(DataFlavor flavor) {
71        return DataFlavor.imageFlavor.equals(flavor);
72    }
73}

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