use of java.awt.datatransfer.UnsupportedFlavorException in project AndrOBD by fr3ts0n.
the class PvTransferHandler method importData.
/* (non-Javadoc)
* @see javax.swing.TransferHandler#importData(javax.swing.TransferHandler.TransferSupport)
*/
@Override
public boolean importData(TransferSupport support) {
try {
if (support.getComponent() instanceof JTree) {
JTree tree = (JTree) support.getComponent();
Point dropPoint = support.getDropLocation().getDropPoint();
TreePath path = tree.getPathForLocation(dropPoint.x, dropPoint.y);
Object node = path.getLastPathComponent();
if (support.isDataFlavorSupported(processVarFlavor)) {
ProcessVar tVar = (ProcessVar) ((PvTreeNode) node).getUserObject();
ProcessVar chldPv = (ProcessVar) support.getTransferable().getTransferData(processVarFlavor);
Object chldKey = chldPv.getKeyValue();
tVar.put(chldKey, chldPv, PvChangeEvent.PV_ADDED);
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
model.nodeStructureChanged((TreeNode) model.getRoot());
return true;
}
}
} catch (UnsupportedFlavorException e) {
ProcessVar.log.severe(this.toString() + ":" + e.getMessage());
} catch (IOException e) {
ProcessVar.log.severe(this.toString() + ":" + e.getMessage());
}
// anything else is handled by superclass
return super.importData(support);
}
use of java.awt.datatransfer.UnsupportedFlavorException in project freeplane by freeplane.
the class MClipboardController method getFlavorHandler.
private IDataFlavorHandler getFlavorHandler(final Transferable t) {
if (t.isDataFlavorSupported(MindMapNodesSelection.mindMapNodesFlavor)) {
try {
final String textFromClipboard = t.getTransferData(MindMapNodesSelection.mindMapNodesFlavor).toString();
return new MindMapNodesFlavorHandler(textFromClipboard);
} catch (final UnsupportedFlavorException e) {
} catch (final IOException e) {
}
}
final ResourceController resourceController = ResourceController.getResourceController();
DataFlavor supportedHtmlFlavor = getSupportedHtmlFlavor(t);
if (supportedHtmlFlavor != null) {
try {
final String textFromClipboard = t.getTransferData(supportedHtmlFlavor).toString();
if (textFromClipboard.charAt(0) != 65533) {
if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
final MTextController textController = (MTextController) TextController.getController();
final boolean richText = textController.useRichTextInEditor(RESOURCES_REMIND_USE_RICH_TEXT_IN_NEW_NODES);
if (richText) {
final boolean structuredHtmlImport = resourceController.getBooleanProperty("structured_html_import");
final IDataFlavorHandler htmlFlavorHandler;
if (structuredHtmlImport) {
htmlFlavorHandler = new StructuredHtmlFlavorHandler(textFromClipboard);
} else {
htmlFlavorHandler = new DirectHtmlFlavorHandler(textFromClipboard);
}
return htmlFlavorHandler;
}
}
}
} catch (final UnsupportedFlavorException e) {
} catch (final IOException e) {
}
}
if (t.isDataFlavorSupported(MindMapNodesSelection.fileListFlavor)) {
try {
final List<File> fileList = castToFileList(t.getTransferData(MindMapNodesSelection.fileListFlavor));
if (!shouldIgnoreFileListFlavor(fileList))
return new FileListFlavorHandler(fileList);
} catch (final UnsupportedFlavorException e) {
} catch (final IOException e) {
}
}
if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
final String plainTextFromClipboard = t.getTransferData(DataFlavor.stringFlavor).toString();
return new StringFlavorHandler(plainTextFromClipboard);
} catch (final UnsupportedFlavorException e) {
} catch (final IOException e) {
}
}
if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
try {
Image image = (Image) t.getTransferData(DataFlavor.imageFlavor);
return new ImageFlavorHandler(image);
} catch (final UnsupportedFlavorException e) {
} catch (final IOException e) {
}
}
return null;
}
use of java.awt.datatransfer.UnsupportedFlavorException in project zaproxy by zaproxy.
the class ExtensionStdMenus method getClipboardContents.
private String getClipboardContents() {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
return (String) contents.getTransferData(DataFlavor.stringFlavor);
} catch (UnsupportedFlavorException | IOException e) {
log.error("Unable to get data from clipboard");
}
}
return "";
}
use of java.awt.datatransfer.UnsupportedFlavorException in project binnavi by google.
the class AbstractTreeTransferHandler method drop.
@Override
public final void drop(final DropTargetDropEvent dtde) {
if (drawImage) {
clearImage();
}
final int action = dtde.getDropAction();
final Transferable transferable = dtde.getTransferable();
final Point pt = dtde.getLocation();
if (transferable.isDataFlavorSupported(TransferableNode.NODE_FLAVOR) && canPerformAction(tree, draggedNode, action, pt)) {
boolean gotData = false;
DefaultMutableTreeNode node = null;
try {
node = (DefaultMutableTreeNode) transferable.getTransferData(TransferableNode.NODE_FLAVOR);
gotData = true;
} catch (final IOException e) {
// TODO: This should be properly logged
System.out.println(e);
} catch (final UnsupportedFlavorException e) {
// TODO: This should be properly logged
System.out.println(e);
}
if (gotData) {
final TreePath pathTarget = tree.getPathForLocation(pt.x, pt.y);
final DefaultMutableTreeNode newParentNode = (DefaultMutableTreeNode) pathTarget.getLastPathComponent();
if (executeDrop(tree, node, newParentNode, action)) {
dtde.acceptDrop(action);
dtde.dropComplete(true);
return;
}
}
} else if (canPerformAction(tree, dtde.getCurrentDataFlavors()[0], dtde.getTransferable(), action, pt)) {
final TreePath pathTarget = tree.getPathForLocation(pt.x, pt.y);
final DefaultMutableTreeNode newParentNode = (DefaultMutableTreeNode) pathTarget.getLastPathComponent();
if (executeDrop(tree, dtde.getTransferable(), newParentNode, action)) {
dtde.acceptDrop(action);
dtde.dropComplete(true);
return;
}
}
dtde.rejectDrop();
dtde.dropComplete(false);
}
use of java.awt.datatransfer.UnsupportedFlavorException in project jmeter by apache.
the class ProxyControlGui method addFromClipboard.
/**
* Add values from the clipboard to table
* @param table {@link JTable}
*/
protected void addFromClipboard(JTable table) {
GuiUtils.stopTableEditing(table);
int rowCount = table.getRowCount();
try {
String clipboardContent = GuiUtils.getPastedText();
if (clipboardContent != null) {
PowerTableModel model = null;
String[] clipboardLines = clipboardContent.split(NEW_LINE);
for (String clipboardLine : clipboardLines) {
model = (PowerTableModel) table.getModel();
model.addRow(new Object[] { clipboardLine });
}
if (model != null && table.getRowCount() > rowCount) {
// Highlight (select) the appropriate rows.
int rowToSelect = model.getRowCount() - 1;
table.setRowSelectionInterval(rowCount, rowToSelect);
}
}
} catch (IOException ioe) {
JOptionPane.showMessageDialog(this, // $NON-NLS-1$
JMeterUtils.getResString("proxy_daemon_error_read_args") + "\n" + // $NON-NLS-1$ $NON-NLS-2$
ioe.getLocalizedMessage(), // $NON-NLS-1$ $NON-NLS-2$
JMeterUtils.getResString("error_title"), JOptionPane.ERROR_MESSAGE);
} catch (UnsupportedFlavorException ufe) {
JOptionPane.showMessageDialog(this, // $NON-NLS-1$
JMeterUtils.getResString("proxy_daemon_error_not_retrieve") + SPACE + DataFlavor.stringFlavor.getHumanPresentableName() + SPACE + // $NON-NLS-1$
JMeterUtils.getResString("proxy_daemon_error_from_clipboard") + // $NON-NLS-1$
ufe.getLocalizedMessage(), // $NON-NLS-1$
JMeterUtils.getResString("error_title"), JOptionPane.ERROR_MESSAGE);
}
}
Aggregations