use of java.awt.datatransfer.Transferable in project binnavi by google.
the class AbstractTreeTransferHandler method dragEnter.
@Override
public final void dragEnter(final DropTargetDragEvent dtde) {
final Point pt = dtde.getLocation();
final int action = dtde.getDropAction();
if (drawImage) {
paintImage(pt);
}
final Transferable transferable = dtde.getTransferable();
if (!transferable.isDataFlavorSupported(TransferableNode.NODE_FLAVOR)) {
if (canPerformAction(tree, dtde.getCurrentDataFlavorsAsList().get(0), dtde.getTransferable(), action, pt)) {
dtde.acceptDrag(action);
} else {
dtde.rejectDrag();
}
} else {
if (canPerformAction(tree, draggedNode, action, pt)) {
dtde.acceptDrag(action);
} else {
dtde.rejectDrag();
}
}
}
use of java.awt.datatransfer.Transferable 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.Transferable in project zaproxy by zaproxy.
the class ScanProgressDialog method getCopyToClipboardButton.
private JButton getCopyToClipboardButton() {
if (copyToClipboardButton == null) {
copyToClipboardButton = new JButton(Constant.messages.getString("ascan.progress.copyclipboard.button.label"));
copyToClipboardButton.setToolTipText(Constant.messages.getString("ascan.progress.copyclipboard.button.tooltip"));
copyToClipboardButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
// Mimics the implementation of BasicTableUI.TableTransferHandler.createTransferable(JComponent) but copies
// all rows (including column names), not just selected rows/columns (which are none in this case).
StringBuilder plainContent = new StringBuilder();
StringBuilder htmlContent = new StringBuilder();
htmlContent.append("<html>\n<body>\n<table>\n");
TableModel tableModel = getMainPanel().getModel();
htmlContent.append("<tr>\n");
for (int col = 0; col < tableModel.getColumnCount(); col++) {
String val = tableModel.getColumnName(col);
plainContent.append(val).append('\t');
htmlContent.append(" <td>").append(val).append("</td>\n");
}
plainContent.deleteCharAt(plainContent.length() - 1).append("\n");
htmlContent.append("</tr>\n");
for (int row = 0; row < tableModel.getRowCount(); row++) {
htmlContent.append("<tr>\n");
for (int col = 0; col < tableModel.getColumnCount(); col++) {
Object obj = tableModel.getValueAt(row, col);
String val = (obj == null) ? "" : obj.toString();
plainContent.append(val).append('\t');
htmlContent.append(" <td>").append(val).append("</td>\n");
}
plainContent.deleteCharAt(plainContent.length() - 1).append("\n");
htmlContent.append("</tr>\n");
}
plainContent.deleteCharAt(plainContent.length() - 1);
htmlContent.append("</table>\n</body>\n</html>");
Transferable transferable = new BasicTransferable(plainContent.toString(), htmlContent.toString());
try {
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(transferable, null);
} catch (IllegalStateException e) {
View.getSingleton().showWarningDialog(ScanProgressDialog.this, Constant.messages.getString("ascan.progress.copyclipboard.error"));
log.warn("Failed to copy the contents to clipboard:", e);
}
}
});
}
return copyToClipboardButton;
}
use of java.awt.datatransfer.Transferable in project jdk8u_jdk by JetBrains.
the class ImageSelection method checkImage.
void checkImage(DropTargetDropEvent dtde) {
final Transferable t = dtde.getTransferable();
if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_COPY);
Image im;
try {
im = (Image) t.getTransferData(DataFlavor.imageFlavor);
System.err.println("getTransferData was successful");
} catch (Exception e) {
System.err.println("Can't getTransferData: " + e);
dtde.dropComplete(false);
notifyTransferSuccess(false);
return;
}
if (im == null) {
System.err.println("getTransferData returned null");
dtde.dropComplete(false);
notifyTransferSuccess(false);
} else if (areImagesIdentical(image, im)) {
dtde.dropComplete(true);
notifyTransferSuccess(true);
} else {
System.err.println("transferred image is different from initial image");
dtde.dropComplete(false);
notifyTransferSuccess(false);
}
} else {
System.err.println("imageFlavor is not supported by Transferable");
dtde.rejectDrop();
notifyTransferSuccess(false);
}
}
use of java.awt.datatransfer.Transferable 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 "";
}
Aggregations