1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.ui.dnd;
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;
22 public class LocalObjectTransferable implements Transferable, ClipboardOwner {
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$;
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.
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);
35 public LocalObjectTransferable(Object object) {
36 this.object = new ByteArrayInputStream(new byte[0]);
37 LocalObjectTransfer.getTransfer().setObject(object);
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
46 * @return an array of length two, whose elements are <code>DataFlavor.
47 * stringFlavor</code> and <code>DataFlavor.plainTextFlavor</code>
49 public DataFlavor[] getTransferDataFlavors() {
50 return new DataFlavor[] { FLAVOR };
53 public boolean isDataFlavorSupported(DataFlavor flavor) {
54 return flavor.equals(FLAVOR);
57 public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
58 if (flavor.equals(FLAVOR))
60 throw new UnsupportedFlavorException(flavor);
63 public void lostOwnership(Clipboard clipboard, Transferable contents) {