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

COVERAGE SUMMARY FOR SOURCE FILE [ComicViewTransferable.java]

nameclass, %method, %block, %line, %
ComicViewTransferable.java100% (1/1)80%  (4/5)75%  (63/84)84%  (15/18)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ComicViewTransferable100% (1/1)80%  (4/5)75%  (63/84)84%  (15/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)
ComicViewTransferable (JComponent): void 100% (1/1)79%  (15/19)93%  (4.6/5)
getTransferData (DataFlavor): Object 100% (1/1)83%  (24/29)89%  (8/9)
getTransferDataFlavors (): DataFlavor [] 100% (1/1)100% (7/7)100% (1/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.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.wraplog.Logger;
27import net.sf.jomic.tools.ImageTools;
28 
29/**
30 *  Transferable to transfer the currently visible image from a ComicView.
31 *
32 * @see    ComicView
33 */
34public class ComicViewTransferable implements Transferable
35{
36    private static Logger logger = Logger.getLogger(ComicViewTransferable.class);
37    private ComicView comicView;
38    private ImageTools imageTools;
39 
40    public ComicViewTransferable(JComponent component) {
41        assert component instanceof ComicView;
42        imageTools = ImageTools.instance();
43        comicView = (ComicView) component;
44    }
45 
46    public Object getTransferData(DataFlavor flavor)
47        throws IOException, UnsupportedFlavorException {
48        Object result = null;
49 
50        if (DataFlavor.imageFlavor.equals(flavor)) {
51            RenderedImage renderedImage = comicView.getRenderedImage();
52 
53            if (renderedImage != null) {
54                result = imageTools.getAsBufferedImage(renderedImage);
55            } else {
56                logger.warn("ComicView has no image to transfer");
57            }
58        } else {
59            throw new UnsupportedFlavorException(flavor);
60        }
61        return result;
62    }
63 
64    public DataFlavor[] getTransferDataFlavors() {
65        return new DataFlavor[]{DataFlavor.imageFlavor};
66    }
67 
68    public boolean isDataFlavorSupported(DataFlavor flavor) {
69        return DataFlavor.imageFlavor.equals(flavor);
70    }
71}

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