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.diagram.ui;
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.IOException;
20 import java.io.Serializable;
22 public class ElementClassTransferable implements Transferable, ClipboardOwner {
24 public static final DataFlavor FLAVOR = new DataFlavor( ResourceElementClassTransferData.class, "Element Class" );
26 public static class ResourceElementClassTransferData implements Serializable {
27 private static final long serialVersionUID = -4990050837054070697L;
28 public String elementClassResourceRandomAccessReference[];
31 private ResourceElementClassTransferData data;
34 * Creates a <code>Transferable</code> capable of transferring the specified
35 * <code>String</code>.
37 public ElementClassTransferable(ResourceElementClassTransferData data) {
42 * Returns an array of flavors in which this <code>Transferable</code> can
43 * provide the data. <code>DataFlavor.stringFlavor</code> is properly
44 * supported. Support for <code>DataFlavor.plainTextFlavor</code> is
47 * @return an array of length two, whose elements are <code>DataFlavor.
48 * stringFlavor</code> and <code>DataFlavor.plainTextFlavor</code>
50 public DataFlavor[] getTransferDataFlavors() {
51 return new DataFlavor[] { FLAVOR };
54 public boolean isDataFlavorSupported(DataFlavor flavor) {
55 return flavor.equals(FLAVOR);
58 public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
59 if (flavor.equals(FLAVOR))
60 return (ResourceElementClassTransferData) data;
61 throw new UnsupportedFlavorException(flavor);
64 public void lostOwnership(Clipboard clipboard, Transferable contents) {