use of java.awt.datatransfer.Transferable in project gephi by gephi.
the class RootNode method getDropType.
@Override
public PasteType getDropType(Transferable t, int action, int index) {
final Node dropNode = NodeTransfer.node(t, DnDConstants.ACTION_COPY_OR_MOVE);
if (t.isDataFlavorSupported(FilterBuilderNode.DATA_FLAVOR)) {
try {
final FilterBuilder fb = (FilterBuilder) t.getTransferData(FilterBuilderNode.DATA_FLAVOR);
return new PasteType() {
@Override
public Transferable paste() throws IOException {
FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
Query f = filterController.createQuery(fb);
filterController.add(f);
return null;
}
};
} catch (UnsupportedFlavorException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
} else if (dropNode != null && dropNode instanceof SavedQueryNode) {
return new PasteType() {
@Override
public Transferable paste() throws IOException {
SavedQueryNode node = (SavedQueryNode) dropNode;
FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
filterController.add(node.getQuery());
return null;
}
};
} else if (dropNode != null && dropNode instanceof QueryNode && ((QueryNode) dropNode).getQuery().getParent() != null) {
return new PasteType() {
@Override
public Transferable paste() throws IOException {
QueryNode queryNode = (QueryNode) dropNode;
FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
filterController.removeSubQuery(queryNode.getQuery(), queryNode.getQuery().getParent());
filterController.add(queryNode.getQuery());
return null;
}
};
}
return null;
}
use of java.awt.datatransfer.Transferable in project gephi by gephi.
the class SlotNode method getDropType.
@Override
public PasteType getDropType(final Transferable t, int action, int index) {
final Node dropNode = NodeTransfer.node(t, DnDConstants.ACTION_COPY_OR_MOVE);
if (dropNode != null && dropNode instanceof QueryNode) {
Query q = ((QueryNode) dropNode).getQuery();
if (!Arrays.asList(q.getDescendantsAndSelf()).contains(parent)) {
//Check if not parent
return new PasteType() {
@Override
public Transferable paste() throws IOException {
QueryNode queryNode = (QueryNode) dropNode;
FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
filterController.setSubQuery(parent, queryNode.getQuery());
return null;
}
};
}
} else if (t.isDataFlavorSupported(FilterBuilderNode.DATA_FLAVOR)) {
return new PasteType() {
@Override
public Transferable paste() throws IOException {
try {
FilterBuilder builder = (FilterBuilder) t.getTransferData(FilterBuilderNode.DATA_FLAVOR);
FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
Query query = filterController.createQuery(builder);
filterController.setSubQuery(parent, query);
} catch (UnsupportedFlavorException ex) {
Exceptions.printStackTrace(ex);
}
return null;
}
};
}
return null;
}
use of java.awt.datatransfer.Transferable in project languagetool by languagetool-org.
the class Main method getClipboardText.
private String getClipboardText() {
// get text from clipboard or selection:
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemSelection();
if (clipboard == null) {
// on Windows
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
}
String s;
Transferable data = clipboard.getContents(this);
try {
if (data != null && data.isDataFlavorSupported(DataFlavor.getTextPlainUnicodeFlavor())) {
DataFlavor df = DataFlavor.getTextPlainUnicodeFlavor();
try (Reader sr = df.getReaderForText(data)) {
s = StringTools.readerToString(sr);
}
} else {
s = "";
}
} catch (Exception ex) {
s = data.toString();
}
return s;
}
use of java.awt.datatransfer.Transferable in project AozoraEpub3 by hmdev.
the class JCoverImagePanel method drop.
@Override
public void drop(DropTargetDropEvent dtde) {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
Transferable transfer = dtde.getTransferable();
try {
if (transfer.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
@SuppressWarnings("unchecked") List<File> files = (List<File>) transfer.getTransferData(DataFlavor.javaFileListFlavor);
if (files.size() > 0) {
bookInfo.coverFileName = files.get(0).getAbsolutePath();
bookInfo.loadCoverImage(bookInfo.coverFileName);
bookInfo.coverImageIndex = -1;
this.fitType = FIT_ZOOM;
this.setFitType(FIT_ALL, true);
repaint();
if (this.linstener != null)
this.linstener.actionPerformed(this.changeAction);
return;
}
}
if (transfer.isDataFlavorSupported(DataFlavor.stringFlavor)) {
bookInfo.coverFileName = transfer.getTransferData(DataFlavor.stringFlavor).toString();
if (bookInfo.coverFileName.startsWith("file://"))
bookInfo.coverFileName = URLDecoder.decode(bookInfo.coverFileName.substring(0, bookInfo.coverFileName.indexOf('\n') - 1).substring(7).trim(), "UTF-8");
bookInfo.loadCoverImage(bookInfo.coverFileName);
bookInfo.coverImageIndex = -1;
this.setFitType(FIT_ALL, true);
repaint();
if (this.linstener != null)
this.linstener.actionPerformed(changeAction);
return;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
}
this.requestFocus();
}
use of java.awt.datatransfer.Transferable in project libgdx by libgdx.
the class JglfwClipboard method getContents.
public String getContents() {
try {
java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return (String) contents.getTransferData(DataFlavor.stringFlavor);
}
} catch (Exception ignored) {
// Ignore JDK crashes sorting data flavors.
}
return "";
}
Aggregations