use of java.awt.datatransfer.UnsupportedFlavorException in project com.revolsys.open by revolsys.
the class RecordReaderTransferable method getTransferData.
@Override
public Object getTransferData(final DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (this.reader == null) {
return null;
} else if (DATA_OBJECT_READER_FLAVOR.equals(flavor) || MapTransferable.MAP_FLAVOR.equals(flavor)) {
return this.reader;
} else if (DataFlavor.stringFlavor.equals(flavor)) {
final StringWriter out = new StringWriter();
final RecordDefinition recordDefinition = this.reader.getRecordDefinition();
if (recordDefinition != null) {
final Collection<String> fieldNames = recordDefinition.getFieldNames();
Csv.writeColumns(out, fieldNames, '\t', '\n');
for (final Record record : this.reader) {
if (record != null) {
final Collection<Object> values = record.values();
Csv.writeColumns(out, values, '\t', '\n');
}
}
}
final String text = out.toString();
return text;
} else {
throw new UnsupportedFlavorException(flavor);
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project mdw-designer by CenturyLinkCloud.
the class FlowchartPage method drop.
public void drop(DropTargetDropEvent e) {
if (process.isReadonly()) {
return;
}
try {
if (e.isDataFlavorSupported(DataFlavor.stringFlavor)) {
Transferable tr = e.getTransferable();
e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
String s = (String) tr.getTransferData(DataFlavor.stringFlavor);
int i = Integer.parseInt(s.substring(3));
ActivityImplementorVO nmi = model.getNodeMetaInfo().get(i);
Selectable object;
int x = e.getLocation().x;
int y = e.getLocation().y;
if (process.zoom != 100) {
x = x * 100 / process.zoom;
y = y * 100 / process.zoom;
}
if (nmi.getImplementorClassName().equals(NodeMetaInfo.PSEUDO_PROCESS_ACTIVITY)) {
String type = promptEmbeddedProcessType(process);
if (type != null)
object = process.addSubGraph(x, y, type, recordchange);
else
object = null;
} else {
object = process.addNode(nmi, x, y, recordchange);
}
e.dropComplete(true);
if (object != null) {
canvas.setSelectedObject(object);
canvas.requestFocus();
canvas.repaint();
}
} else {
e.rejectDrop();
}
} catch (IOException io) {
// io.printStackTrace();
e.rejectDrop();
} catch (UnsupportedFlavorException ufe) {
// ufe.printStackTrace();
e.rejectDrop();
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project deltahex-java by exbin.
the class DefaultCodeAreaCommandHandler method paste.
@Override
public void paste() {
if (!((EditationModeCapable) codeArea.getWorker()).isEditable()) {
return;
}
try {
if (clipboard.isDataFlavorAvailable(binaryDataFlavor)) {
if (codeArea.hasSelection()) {
deleteSelection();
codeArea.notifyDataChanged();
}
try {
Object object = clipboard.getData(binaryDataFlavor);
if (object instanceof BinaryData) {
DefaultCodeAreaCaret caret = (DefaultCodeAreaCaret) ((CaretCapable) codeArea.getWorker()).getCaret();
long dataPosition = caret.getDataPosition();
BinaryData clipboardData = (BinaryData) object;
long dataSize = clipboardData.getDataSize();
if (((EditationModeCapable) codeArea.getWorker()).getEditationMode() == EditationMode.OVERWRITE) {
long toRemove = dataSize;
if (dataPosition + toRemove > codeArea.getDataSize()) {
toRemove = codeArea.getDataSize() - dataPosition;
}
((EditableBinaryData) codeArea.getData()).remove(dataPosition, toRemove);
}
((EditableBinaryData) codeArea.getData()).insert(dataPosition, clipboardData);
codeArea.notifyDataChanged();
caret.setCaretPosition(caret.getDataPosition() + dataSize);
caret.setCodeOffset(0);
updateScrollBars();
notifyCaretMoved();
revealCursor();
}
} catch (UnsupportedFlavorException | IOException ex) {
Logger.getLogger(DefaultCodeAreaCommandHandler.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor)) {
if (codeArea.hasSelection()) {
deleteSelection();
codeArea.notifyDataChanged();
}
Object insertedData;
try {
insertedData = clipboard.getData(DataFlavor.stringFlavor);
if (insertedData instanceof String) {
DefaultCodeAreaCaret caret = (DefaultCodeAreaCaret) ((CaretCapable) codeArea.getWorker()).getCaret();
long dataPosition = caret.getDataPosition();
byte[] bytes = ((String) insertedData).getBytes(Charset.forName(CodeAreaUtils.DEFAULT_ENCODING));
int length = bytes.length;
if (((EditationModeCapable) codeArea.getWorker()).getEditationMode() == EditationMode.OVERWRITE) {
long toRemove = length;
if (dataPosition + toRemove > codeArea.getDataSize()) {
toRemove = codeArea.getDataSize() - dataPosition;
}
((EditableBinaryData) codeArea.getData()).remove(dataPosition, toRemove);
}
((EditableBinaryData) codeArea.getData()).insert(dataPosition, bytes);
codeArea.notifyDataChanged();
caret.setCaretPosition(caret.getDataPosition() + length);
caret.setCodeOffset(0);
updateScrollBars();
notifyCaretMoved();
revealCursor();
}
} catch (UnsupportedFlavorException | IOException ex) {
Logger.getLogger(DefaultCodeAreaCommandHandler.class.getName()).log(Level.SEVERE, null, ex);
}
}
} catch (IllegalStateException ex) {
// Clipboard not available - ignore
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project blue by kunstmusik.
the class ScoreTimelineDropTargetListener method drop.
/*
* (non-Javadoc)
*
* @see java.awt.dnd.DropTargetListener#drop(java.awt.dnd.DropTargetDropEvent)
*/
@Override
public void drop(DropTargetDropEvent dtde) {
try {
Transferable tr = dtde.getTransferable();
if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_LINK);
List list = (List) tr.getTransferData(DataFlavor.javaFileListFlavor);
if (list.size() != 1) {
dtde.dropComplete(false);
return;
}
String s = list.get(0).toString().trim();
if (!s.toLowerCase().endsWith("wav") && !s.toLowerCase().endsWith("aif") && !s.toLowerCase().endsWith("aiff")) {
dtde.dropComplete(false);
return;
}
String sObjName = s.substring(s.lastIndexOf(File.separator) + 1);
Point p = dtde.getLocation();
int index = sTimeCanvas.pObj.getLayerNumForY(p.y);
AudioFile af = new AudioFile();
af.setName(sObjName);
af.setSoundFileName(BlueSystem.getRelativePath(s));
PolyObject pObj = sTimeCanvas.getPolyObject();
float startTime = (float) p.x / timeState.getPixelSecond();
float dur = SoundFileUtilities.getDurationInSeconds(s);
af.setStartTime(startTime);
af.setSubjectiveDuration(dur);
pObj.addSoundObject(index, af);
dtde.dropComplete(true);
return;
} else if (dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_LINK);
String str = (String) tr.getTransferData(DataFlavor.stringFlavor);
if (!str.startsWith("file://")) {
dtde.dropComplete(false);
return;
}
str = str.substring(7).trim();
if (!str.toLowerCase().endsWith("wav") && !str.toLowerCase().endsWith("aif") && !str.toLowerCase().endsWith("aiff")) {
System.err.println("Could not open file: " + str);
dtde.dropComplete(false);
return;
}
str = URLDecoder.decode(str);
str = str.replaceAll(" ", "\\ ");
File f = new File(str);
if (!f.exists()) {
dtde.dropComplete(false);
return;
}
String sObjName = str.substring(str.lastIndexOf(File.separator) + 1);
Point p = dtde.getLocation();
int index = sTimeCanvas.pObj.getLayerNumForY(p.y);
AudioFile af = new AudioFile();
af.setName(sObjName);
af.setSoundFileName(str);
PolyObject pObj = sTimeCanvas.getPolyObject();
float startTime = (float) p.x / timeState.getPixelSecond();
float dur = SoundFileUtilities.getDurationInSeconds(str);
af.setStartTime(startTime);
af.setSubjectiveDuration(dur);
pObj.addSoundObject(index, af);
dtde.dropComplete(true);
return;
}
dtde.rejectDrop();
} catch (UnsupportedFlavorException | IOException | UnsupportedAudioFileException e) {
e.printStackTrace();
dtde.rejectDrop();
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project keystore-explorer by kaikramer.
the class DroppedFileHandler method drop.
public static void drop(DropTargetDropEvent evt, final KseFrame kseFrame) {
evt.acceptDrop(DnDConstants.ACTION_MOVE);
Transferable trans = evt.getTransferable();
try {
if (trans.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
@SuppressWarnings("unchecked") final List<File> droppedFiles = (List<File>) trans.getTransferData(DataFlavor.javaFileListFlavor);
// open files in new thread, so we can return quickly
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
openFiles(kseFrame, droppedFiles);
}
});
}
/* TODO
else if (trans.isDataFlavorSupported(DataFlavor.stringFlavor)) {
String str = trans.getTransferData(DataFlavor.stringFlavor).toString();
X509Certificate[] certs = X509CertUtil.loadCertificates(IOUtils.toInputStream(str, "UTF-8"));
if ((certs != null) && (certs.length > 0)) {
DViewCertificate dViewCertificate = new DViewCertificate(kseFrame.getUnderlyingFrame(),
MessageFormat.format("Title", ""), certs, kseFrame, DViewCertificate.IMPORT);
dViewCertificate.setLocationRelativeTo(kseFrame.getUnderlyingFrame());
dViewCertificate.setVisible(true);
}
}
*/
} catch (IOException | UnsupportedFlavorException e) {
DError.displayError(kseFrame.getUnderlyingFrame(), e);
}
}
Aggregations