]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/dnd/LocalObjectTransferable.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / dnd / LocalObjectTransferable.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.ui.dnd;
13
14 import java.awt.datatransfer.Clipboard;
15 import java.awt.datatransfer.ClipboardOwner;
16 import java.awt.datatransfer.DataFlavor;
17 import java.awt.datatransfer.Transferable;
18 import java.awt.datatransfer.UnsupportedFlavorException;
19 import java.io.ByteArrayInputStream;
20 import java.io.IOException;
21
22 public class LocalObjectTransferable implements Transferable, ClipboardOwner {
23
24     //public static final String     TYPE_NAME = "application/x-java-jvm-local-objectref" + (new Long(System.currentTimeMillis())).toString() + ";class=java.lang.Object"; //$NON-NLS-1$;
25     /**
26      * For transferring JVM local objects as references, does not work between
27      * applications. The System.currentTimeMillis suffix is added to prevent
28      * application to application transfer.
29      */
30     public static final String     TYPE_NAME = "application/local-object-transfer-format" + (new Long(System.currentTimeMillis())).toString(); //$NON-NLS-1$;
31     public static final DataFlavor FLAVOR    = new DataFlavor(TYPE_NAME, null);
32
33     Object object;
34
35     public LocalObjectTransferable(Object object) {
36         this.object = new ByteArrayInputStream(new byte[0]);
37         LocalObjectTransfer.getTransfer().setObject(object);
38     }
39
40     /**
41      * Returns an array of flavors in which this <code>Transferable</code> can
42      * provide the data. <code>DataFlavor.stringFlavor</code> is properly
43      * supported. Support for <code>DataFlavor.plainTextFlavor</code> is
44      * <b>deprecated</b>.
45      * 
46      * @return an array of length two, whose elements are <code>DataFlavor.
47      *         stringFlavor</code> and <code>DataFlavor.plainTextFlavor</code>
48      */
49     public DataFlavor[] getTransferDataFlavors() {
50         return new DataFlavor[] { FLAVOR };
51     }
52
53     public boolean isDataFlavorSupported(DataFlavor flavor) {
54         return flavor.equals(FLAVOR);
55     }
56
57     public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
58         if (flavor.equals(FLAVOR))
59             return object;
60         throw new UnsupportedFlavorException(flavor);
61     }
62
63     public void lostOwnership(Clipboard clipboard, Transferable contents) {
64     }
65
66 }