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/>. |
16 | package net.sf.jomic.comic; |
17 | |
18 | import java.awt.datatransfer.DataFlavor; |
19 | import java.awt.datatransfer.Transferable; |
20 | |
21 | import javax.swing.JComponent; |
22 | import javax.swing.TransferHandler; |
23 | |
24 | /** |
25 | * TransferHandler to support clipboard operations in a ComicView. |
26 | * |
27 | * @see net.sf.jomic.comic.ComicView |
28 | * @author Thomas Aglassinger |
29 | */ |
30 | public class ComicViewTransferHandler extends TransferHandler |
31 | { |
32 | public ComicViewTransferHandler() { |
33 | super(); |
34 | } |
35 | |
36 | public ComicViewTransferHandler(String property) { |
37 | super(property); |
38 | } |
39 | |
40 | public int getSourceActions(JComponent c) { |
41 | return COPY; |
42 | } |
43 | |
44 | public boolean canImport(JComponent component, DataFlavor[] flavors) { |
45 | assert component != null; |
46 | assert flavors != null; |
47 | boolean result = false; |
48 | int i = 0; |
49 | |
50 | while (!result && (i < flavors.length)) { |
51 | if (DataFlavor.imageFlavor.equals(flavors[i])) { |
52 | result = true; |
53 | } else { |
54 | i += 1; |
55 | } |
56 | } |
57 | return result; |
58 | } |
59 | |
60 | protected Transferable createTransferable(JComponent component) { |
61 | assert component != null; |
62 | assert component instanceof ComicView; |
63 | ComicView comicView = (ComicView) component; |
64 | |
65 | return new ComicViewTransferable(comicView); |
66 | } |
67 | } |