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();
}
}
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 jabref by JabRef.
the class CitationStyleToClipboardWorker method done.
@Override
public void done() {
try {
List<String> citations = get();
// if it's not a citation style take care of the preview
if (!CitationStyle.isCitationStyleFile(style)) {
new ClipBoardManager().setTransferableClipboardContents(processPreview(citations));
} else {
// if it's generated by a citation style take care of each output format
Transferable transferable;
switch(outputFormat) {
case HTML:
transferable = processHtml(citations);
break;
case RTF:
transferable = processRtf(citations);
break;
case XSL_FO:
transferable = processXslFo(citations);
break;
case ASCII_DOC:
case TEXT:
transferable = processText(citations);
break;
default:
LOGGER.warn("unknown output format: '" + outputFormat + "', processing it via the default.");
transferable = processText(citations);
break;
}
new ClipBoardManager().setTransferableClipboardContents(transferable);
}
basePanel.frame().setStatus(Localization.lang("Copied %0 citations.", String.valueOf(selectedEntries.size())));
} catch (InterruptedException | ExecutionException e) {
LOGGER.error("Error while copying citations to the clipboard", e);
}
}
use of java.awt.datatransfer.Transferable in project pcgen by PCGen.
the class NotesTreeNode method handleDropJavaFileList.
//Listener functions
/**
* handles a drop of a java file list
*
* @param dtde
* drop target drop even - a java dile list has been dropped on
* something that represents this node.
* @return returns true if the drop takes place, false if not
*/
public boolean handleDropJavaFileList(DropTargetDropEvent dtde) {
dtde.acceptDrop(dtde.getDropAction());
Transferable t = dtde.getTransferable();
try {
List fileList = ((List) t.getTransferData(DataFlavor.javaFileListFlavor));
for (int i = 0; i < fileList.size(); i++) {
File newFile = (File) fileList.get(i);
if (newFile.exists()) {
MiscUtilities.copy(newFile, new File(dir.getAbsolutePath() + File.separator + newFile.getName()));
}
}
} catch (Exception e) {
Logging.errorPrint(e.getMessage(), e);
return false;
}
return true;
}
Aggregations