mirror of
https://github.com/igniterealtime/Spark.git
synced 2025-12-01 12:27:58 +00:00
add generics git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@11433 b35dd754-fafc-0310-a699-88a17e54d16e
71 lines
2.1 KiB
Java
71 lines
2.1 KiB
Java
/**
|
|
* $Revision: $
|
|
* $Date: $
|
|
*
|
|
* Copyright (C) 2006 Jive Software. All rights reserved.
|
|
*
|
|
* This software is published under the terms of the GNU Lesser Public License (LGPL),
|
|
* a copy of which is included in this distribution.
|
|
*/
|
|
|
|
package org.jivesoftware.spark.ui;
|
|
|
|
import javax.swing.JComponent;
|
|
import javax.swing.TransferHandler;
|
|
|
|
import java.awt.datatransfer.DataFlavor;
|
|
import java.awt.datatransfer.StringSelection;
|
|
import java.awt.datatransfer.Transferable;
|
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
|
import java.io.IOException;
|
|
|
|
/**
|
|
* Used for String Drag and Drop functionality.
|
|
*/
|
|
public abstract class StringTransferHandler extends TransferHandler {
|
|
private static final long serialVersionUID = 4783002180033288533L;
|
|
|
|
protected abstract String exportString(JComponent c);
|
|
|
|
protected abstract void importString(JComponent c, String str);
|
|
|
|
protected abstract void cleanup(JComponent c, boolean remove);
|
|
|
|
protected Transferable createTransferable(JComponent c) {
|
|
return new StringSelection(exportString(c));
|
|
}
|
|
|
|
public int getSourceActions(JComponent c) {
|
|
return COPY_OR_MOVE;
|
|
}
|
|
|
|
public boolean importData(JComponent c, Transferable t) {
|
|
if (canImport(c, t.getTransferDataFlavors())) {
|
|
try {
|
|
String str = (String)t.getTransferData(DataFlavor.stringFlavor);
|
|
importString(c, str);
|
|
return true;
|
|
}
|
|
catch (UnsupportedFlavorException ufe) {
|
|
// Nothing to do
|
|
}
|
|
catch (IOException ioe) {
|
|
// Nothing to do
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
protected void exportDone(JComponent c, Transferable data, int action) {
|
|
cleanup(c, action == MOVE);
|
|
}
|
|
|
|
public boolean canImport(JComponent c, DataFlavor[] flavors) {
|
|
for (DataFlavor flavor : flavors) {
|
|
if (DataFlavor.stringFlavor.equals(flavor)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
} |