use of java.awt.datatransfer.Transferable in project jdk8u_jdk by JetBrains.
the class TargetPanel method drop.
public void drop(DropTargetDropEvent dtde) {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
if (dtde.isDataFlavorSupported(dataFlavor)) {
String result = null;
try {
Transferable t = dtde.getTransferable();
byte[] data = (byte[]) dtde.getTransferable().getTransferData(dataFlavor);
result = new String(data, "UTF-16");
repaint();
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
dtde.dropComplete(true);
if (result != null && result.contains(MyTransferable.TEST_DATA)) {
System.err.println(InterprocessMessages.EXECUTION_IS_SUCCESSFULL);
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
System.exit(0);
}
}, 2000);
return;
}
}
dtde.rejectDrop();
System.err.println(InterprocessMessages.DATA_IS_CORRUPTED);
System.exit(InterprocessMessages.DATA_IS_CORRUPTED);
}
use of java.awt.datatransfer.Transferable in project jabref by JabRef.
the class ClipBoardManager method getClipboardContents.
/**
* Get the String residing on the clipboard.
*
* @return any text found on the Clipboard; if none found, return an
* empty String.
*/
public String getClipboardContents() {
String result = "";
//odd: the Object param of getContents is not currently used
Transferable contents = CLIPBOARD.getContents(null);
if ((contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
result = (String) contents.getTransferData(DataFlavor.stringFlavor);
} catch (UnsupportedFlavorException | IOException e) {
//highly unlikely since we are using a standard DataFlavor
LOGGER.info("problem with getting clipboard contents", e);
}
}
return result;
}
use of java.awt.datatransfer.Transferable in project jdk8u_jdk by JetBrains.
the class DragSourceContext method readObject.
/**
* Deserializes this <code>DragSourceContext</code>. This method first
* performs default deserialization for all non-<code>transient</code>
* fields. This object's <code>Transferable</code> and
* <code>DragSourceListener</code> are then deserialized as well by using
* the next two objects in the stream. If the resulting
* <code>Transferable</code> is <code>null</code>, this object's
* <code>Transferable</code> is set to a dummy <code>Transferable</code>
* which supports no <code>DataFlavor</code>s.
*
* @since 1.4
*/
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
ObjectInputStream.GetField f = s.readFields();
DragGestureEvent newTrigger = (DragGestureEvent) f.get("trigger", null);
if (newTrigger == null) {
throw new InvalidObjectException("Null trigger");
}
if (newTrigger.getDragSource() == null) {
throw new InvalidObjectException("Null DragSource");
}
if (newTrigger.getComponent() == null) {
throw new InvalidObjectException("Null trigger component");
}
int newSourceActions = f.get("sourceActions", 0) & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);
if (newSourceActions == DnDConstants.ACTION_NONE) {
throw new InvalidObjectException("Invalid source actions");
}
int triggerActions = newTrigger.getDragAction();
if (triggerActions != DnDConstants.ACTION_COPY && triggerActions != DnDConstants.ACTION_MOVE && triggerActions != DnDConstants.ACTION_LINK) {
throw new InvalidObjectException("No drag action");
}
trigger = newTrigger;
cursor = (Cursor) f.get("cursor", null);
useCustomCursor = f.get("useCustomCursor", false);
sourceActions = newSourceActions;
transferable = (Transferable) s.readObject();
listener = (DragSourceListener) s.readObject();
// Implementation assumes 'transferable' is never null.
if (transferable == null) {
if (emptyTransferable == null) {
emptyTransferable = new Transferable() {
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[0];
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
return false;
}
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
throw new UnsupportedFlavorException(flavor);
}
};
}
transferable = emptyTransferable;
}
}
use of java.awt.datatransfer.Transferable in project jdk8u_jdk by JetBrains.
the class DropTargetContext method getTransferable.
/**
* get the Transferable (proxy) operand of this operation
* <P>
* @throws InvalidDnDOperationException if a drag is not outstanding/extant
* <P>
* @return the <code>Transferable</code>
*/
protected Transferable getTransferable() throws InvalidDnDOperationException {
DropTargetContextPeer peer = getDropTargetContextPeer();
if (peer == null) {
throw new InvalidDnDOperationException();
} else {
if (transferable == null) {
Transferable t = peer.getTransferable();
boolean isLocal = peer.isTransferableJVMLocal();
synchronized (this) {
if (transferable == null) {
transferable = createTransferableProxy(t, isLocal);
}
}
}
return transferable;
}
}
use of java.awt.datatransfer.Transferable in project JMRI by JMRI.
the class DropJLabel method drop.
@Override
public void drop(DropTargetDropEvent e) {
try {
Transferable tr = e.getTransferable();
if (e.isDataFlavorSupported(_dataFlavor)) {
NamedIcon newIcon = new NamedIcon((NamedIcon) tr.getTransferData(_dataFlavor));
accept(e, newIcon);
} else if (e.isDataFlavorSupported(DataFlavor.stringFlavor)) {
String text = (String) tr.getTransferData(DataFlavor.stringFlavor);
if (log.isDebugEnabled()) {
log.debug("drop for stringFlavor " + text);
}
NamedIcon newIcon = new NamedIcon(text, text);
accept(e, newIcon);
} else {
if (log.isDebugEnabled()) {
log.debug("DropJLabel.drop REJECTED!");
}
e.rejectDrop();
}
} catch (IOException ioe) {
if (log.isDebugEnabled()) {
log.debug("DropPanel.drop REJECTED!");
}
e.rejectDrop();
} catch (UnsupportedFlavorException ufe) {
if (log.isDebugEnabled()) {
log.debug("DropJLabel.drop REJECTED!");
}
e.rejectDrop();
}
}
Aggregations