PageRenderTime 68ms CodeModel.GetById 36ms app.highlight 4ms RepoModel.GetById 26ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/datatransfer/JEditTransferable.java

#
Java | 61 lines | 29 code | 7 blank | 25 comment | 1 complexity | a2c278c63a0f07a5df1a349b683f7d5b MD5 | raw file
 1/*
 2 * JEditTransferable.java
 3 * :tabSize=8:indentSize=8:noTabs=false:
 4 * :folding=explicit:collapseFolds=1:
 5 *
 6 * Copyright (C) 2010 Matthieu Casanova
 7 *
 8 * This program is free software; you can redistribute it and/or
 9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 */
22package org.gjt.sp.jedit.datatransfer;
23
24import java.awt.datatransfer.*;
25import java.io.IOException;
26import java.util.Map;
27
28/**
29 * @author Matthieu Casanova
30 * @since jEdit 4.4.x
31 */
32public class JEditTransferable implements Transferable
33{
34	private final DataFlavor[] dataFlavors;
35
36	private final Map<DataFlavor, Transferable> flavors;
37
38	public JEditTransferable(Map<DataFlavor, Transferable> flavors)
39	{
40		this.flavors = flavors;
41		dataFlavors = flavors.keySet().toArray(new DataFlavor[flavors.size()]);
42	}
43
44	public DataFlavor[] getTransferDataFlavors()
45	{
46		return dataFlavors;
47	}
48
49	public boolean isDataFlavorSupported(DataFlavor flavor)
50	{
51		return flavors.containsKey(flavor);
52	}
53
54	public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException
55	{
56		if (!isDataFlavorSupported(flavor))
57			throw new UnsupportedFlavorException(flavor);
58		Transferable transferable = flavors.get(flavor);
59		return transferable.getTransferData(flavor);
60	}
61}