Search in sources :

Example 76 with UnsupportedFlavorException

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);
    }
}
Also used : StringWriter(java.io.StringWriter) Record(com.revolsys.record.Record) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 77 with UnsupportedFlavorException

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();
    }
}
Also used : ActivityImplementorVO(com.centurylink.mdw.model.value.activity.ActivityImplementorVO) Selectable(com.centurylink.mdw.designer.display.Selectable) Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point)

Example 78 with UnsupportedFlavorException

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
    }
}
Also used : EditationModeCapable(org.exbin.deltahex.capability.EditationModeCapable) CaretCapable(org.exbin.deltahex.capability.CaretCapable) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) EditableBinaryData(org.exbin.utils.binary_data.EditableBinaryData) EditableBinaryData(org.exbin.utils.binary_data.EditableBinaryData) BinaryData(org.exbin.utils.binary_data.BinaryData)

Example 79 with UnsupportedFlavorException

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();
    }
}
Also used : Transferable(java.awt.datatransfer.Transferable) Point(java.awt.Point) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point) AudioFile(blue.soundObject.AudioFile) UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) List(java.util.List) AudioFile(blue.soundObject.AudioFile) File(java.io.File) PolyObject(blue.soundObject.PolyObject)

Example 80 with UnsupportedFlavorException

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);
    }
}
Also used : Transferable(java.awt.datatransfer.Transferable) List(java.util.List) IOException(java.io.IOException) File(java.io.File) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Aggregations

UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)106 IOException (java.io.IOException)92 Transferable (java.awt.datatransfer.Transferable)55 List (java.util.List)32 DataFlavor (java.awt.datatransfer.DataFlavor)26 File (java.io.File)25 Point (java.awt.Point)18 ArrayList (java.util.ArrayList)15 Clipboard (java.awt.datatransfer.Clipboard)14 JTree (javax.swing.JTree)9 TreePath (javax.swing.tree.TreePath)9 JComponent (javax.swing.JComponent)7 TransferHandler (javax.swing.TransferHandler)7 DropTargetContext (java.awt.dnd.DropTargetContext)6 URL (java.net.URL)5 DefaultTableModel (javax.swing.table.DefaultTableModel)5 Image (java.awt.Image)4 ActionEvent (java.awt.event.ActionEvent)4 MouseEvent (java.awt.event.MouseEvent)4 NodeInterface (com.sldeditor.common.NodeInterface)3