use of java.awt.datatransfer.UnsupportedFlavorException in project sldeditor by robward-scisys.
the class TreeTransferHandler method importData.
/*
* (non-Javadoc)
*
* @see javax.swing.TransferHandler#importData(javax.swing.JComponent, java.awt.datatransfer.Transferable)
*/
@Override
public boolean importData(JComponent comp, Transferable t) {
if (!(comp instanceof JTree) || (t == null)) {
return false;
}
boolean result = false;
JTree tree = (JTree) comp;
NodeInterface destinationTreeNode = (NodeInterface) tree.getLastSelectedPathComponent();
DataFlavor destDataFlavour = destinationTreeNode.getDataFlavour();
TransferredData transferredData = null;
try {
transferredData = (TransferredData) t.getTransferData(destDataFlavour);
result = DataFlavourManager.copy(destinationTreeNode, transferredData);
} catch (UnsupportedFlavorException e) {
ConsoleManager.getInstance().exception(this, e);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
return result;
}
use of java.awt.datatransfer.UnsupportedFlavorException in project sldeditor by robward-scisys.
the class TreeTransferHandler method canImport.
/*
* (non-Javadoc)
*
* @see javax.swing.TransferHandler#canImport(javax.swing.TransferHandler.TransferSupport)
*/
@Override
public boolean canImport(TransferSupport support) {
if (support == null) {
return false;
}
JTree.DropLocation dropLocation = (JTree.DropLocation) support.getDropLocation();
TreePath destinationPath = dropLocation.getPath();
NodeInterface destinationTreeNode = null;
try {
destinationTreeNode = (NodeInterface) destinationPath.getLastPathComponent();
} catch (ClassCastException e) {
return false;
}
Transferable transferable = support.getTransferable();
DataFlavor destDataFlavour = destinationTreeNode.getDataFlavour();
TransferredData transferredData = null;
try {
transferredData = (TransferredData) transferable.getTransferData(destDataFlavour);
} catch (UnsupportedFlavorException e) {
ConsoleManager.getInstance().exception(this, e);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
if (transferredData == null) {
return false;
}
TreePath treePath = transferredData.getTreePath(0);
if (isSameTreePath(treePath, destinationPath)) {
return false;
}
return DataFlavourManager.isSupported(transferredData.getDataFlavour(0), destDataFlavour);
}
use of java.awt.datatransfer.UnsupportedFlavorException in project sldeditor by robward-scisys.
the class TransferableDataItemTest method testTransferableDataItem.
/**
* Test method for
* {@link com.sldeditor.datasource.extension.filesystem.node.TransferableDataItem#TransferableDataItem()}.
*/
@Test
public void testTransferableDataItem() {
Map<NodeInterface, TreePath> selectedData = new HashMap<NodeInterface, TreePath>();
FileTreeNode fileTreeNode1 = null;
FileTreeNode fileTreeNode2 = null;
FileTreeNode fileTreeNode3 = null;
FileTreeNode fileTreeNode4 = null;
try {
fileTreeNode1 = new FileTreeNode(new File(System.getProperty("user.dir")), "file1.txt");
fileTreeNode2 = new FileTreeNode(new File(System.getProperty("user.dir")), "file2.txt");
fileTreeNode3 = new FileTreeNode(new File(System.getProperty("user.dir")), "file3.txt");
fileTreeNode4 = new FileTreeNode(new File(System.getProperty("user.dir")), "file4.txt");
selectedData.put(fileTreeNode1, new TreePath(new DefaultMutableTreeNode("branch1")));
selectedData.put(fileTreeNode2, new TreePath(new DefaultMutableTreeNode("branch2")));
selectedData.put(fileTreeNode3, new TreePath(new DefaultMutableTreeNode("branch3")));
selectedData.put(fileTreeNode4, new TreePath(new DefaultMutableTreeNode("branch4")));
TransferableDataItem dataItem = new TransferableDataItem(selectedData);
DataFlavor dataFlavour = dataItem.getDataFlavour();
assertEquals(FileTreeNode.class, dataFlavour.getRepresentationClass());
try {
Object data = dataItem.getTransferData(DataFlavourManager.FOLDER_DATAITEM_FLAVOR);
assertTrue(data instanceof TransferredData);
assertEquals(selectedData.size(), ((TransferredData) data).getDataListSize());
assertFalse(dataItem.isDataFlavorSupported(BuiltInDataFlavour.GEOSERVER_DATAITEM_FLAVOUR));
assertTrue(dataItem.isDataFlavorSupported(DataFlavourManager.FOLDER_DATAITEM_FLAVOR));
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
} catch (SecurityException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (FileNotFoundException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project keystore-explorer by kaikramer.
the class ExamineClipboardAction method doAction.
/**
* Do action.
*/
@Override
protected void doAction() {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
// get clipboard contents, but only string types, not files
Transferable t = clipboard.getContents(null);
try {
if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
String data;
data = (String) t.getTransferData(DataFlavor.stringFlavor);
show(data);
}
// TODO handle other flavor types
} catch (UnsupportedFlavorException e) {
// ignore
} catch (IOException e) {
e.printStackTrace();
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project cytoscape-impl by cytoscape.
the class DragHandler method dragEnter.
@SuppressWarnings("unchecked")
@Override
public void dragEnter(DropTargetDragEvent event) {
JComponent lastComponent = controller.getLastHoveredComponent();
if (lastComponent != null) {
setBackground(lastComponent, ViewUtil.UNSELECTED_BACKGROUND_COLOR);
}
JComponent target = getPrimaryView(view);
try {
List<Integer> sourcePath = (List<Integer>) event.getTransferable().getTransferData(PathDataFlavor.instance);
List<Integer> targetPath = controller.getPath(parent, target);
JComponent sourceView = controller.getChild(parent, sourcePath);
if (!controller.supportsDrop(parent, sourcePath, sourceView, targetPath, target) || isEquivalentLocation(sourcePath, targetPath, target)) {
setCursor(DragSource.DefaultCopyNoDrop, target);
return;
}
if (controller.isDropMove(parent, sourceView, sourcePath, target, targetPath)) {
// Move
event.acceptDrag(DnDConstants.ACTION_MOVE);
setCursor(DragSource.DefaultMoveDrop, view);
} else {
// Group (+)
event.acceptDrag(DnDConstants.ACTION_COPY);
setCursor(DragSource.DefaultCopyDrop, view);
}
} catch (UnsupportedFlavorException e) {
logger.error("Unexpected error", e);
} catch (IOException e) {
logger.error("Unexpected error", e);
} finally {
controller.setLastHoveredComponent(view);
}
target.setBackground(ViewUtil.SELECTED_BACKGROUND_COLOR);
}
Aggregations