Example usage for java.awt.datatransfer DataFlavor javaFileListFlavor

List of usage examples for java.awt.datatransfer DataFlavor javaFileListFlavor

Introduction

In this page you can find the example usage for java.awt.datatransfer DataFlavor javaFileListFlavor.

Prototype

DataFlavor javaFileListFlavor

To view the source code for java.awt.datatransfer DataFlavor javaFileListFlavor.

Click Source Link

Document

To transfer a list of files to/from Java (and the underlying platform) a DataFlavor of this type/subtype and representation class of java.util.List is used.

Usage

From source file:DragFileDemo.java

FileAndTextTransferHandler(TabbedPaneController t) {
    tpc = t;
    fileFlavor = DataFlavor.javaFileListFlavor;
    stringFlavor = DataFlavor.stringFlavor;
}

From source file:com.mirth.connect.client.ui.EditMessageDialog.java

public void drop(DropTargetDropEvent dtde) {
    try {/*from www.  j av a2s . co  m*/
        Transferable tr = dtde.getTransferable();
        if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {

            dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

            List<File> fileList = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
            Iterator<File> iterator = fileList.iterator();
            while (iterator.hasNext()) {
                File file = iterator.next();
                messageContent.setText(
                        messageContent.getText() + FileUtils.readFileToString(file, UIConstants.CHARSET));
            }
        }
    } catch (Exception e) {
        dtde.rejectDrop();
    }
}

From source file:com.mirth.connect.client.ui.editors.transformer.TransformerPane.java

public void dragEnter(DropTargetDragEvent dtde) {
    try {// w  w  w  .j  a v  a 2  s.com
        Transferable tr = dtde.getTransferable();
        if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {

            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);

            List fileList = (List) tr.getTransferData(DataFlavor.javaFileListFlavor);
            Iterator iterator = fileList.iterator();
            if (iterator.hasNext() && fileList.size() == 1) {
                String fileName = ((File) iterator.next()).getName();
                if (!fileName.substring(fileName.lastIndexOf(".")).equalsIgnoreCase(".xml")) {
                    dtde.rejectDrag();
                }
            } else {
                dtde.rejectDrag();
            }
        } else if (tr.isDataFlavorSupported(TreeTransferable.MAPPER_DATA_FLAVOR)
                || tr.isDataFlavorSupported(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR)) {
            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
        } else {
            dtde.rejectDrag();
        }
    } catch (Exception e) {
        dtde.rejectDrag();
    }
}

From source file:com.mirth.connect.client.ui.editors.filter.FilterPane.java

public void dragEnter(DropTargetDragEvent dtde) {
    try {/*from w w  w .ja  v  a2  s  .c  o m*/
        Transferable tr = dtde.getTransferable();
        if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {

            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);

            List fileList = (List) tr.getTransferData(DataFlavor.javaFileListFlavor);
            Iterator iterator = fileList.iterator();
            if (iterator.hasNext() && fileList.size() == 1) {
                String fileName = ((File) iterator.next()).getName();
                if (!fileName.substring(fileName.lastIndexOf(".")).equalsIgnoreCase(".xml")) {
                    dtde.rejectDrag();
                }
            } else {
                dtde.rejectDrag();
            }
        } else if (tr.isDataFlavorSupported(TreeTransferable.RULE_DATA_FLAVOR)) {
            dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
        } else {
            dtde.rejectDrag();
        }
    } catch (Exception e) {
        dtde.rejectDrag();
    }
}

From source file:de.mycrobase.jcloudapp.Main.java

@SuppressWarnings("unchecked")
public boolean doUploadClipboard() {
    Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable t = cb.getContents(null);

    if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        try {/* ww w.  j a  v a 2 s. co m*/
            List<File> data = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
            uploadFilesFromClipboard(data);
        } catch (UnsupportedFlavorException ex) {
        } catch (IOException ex) {
        }
        return true;
    } else if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
        try {
            Image data = (Image) t.getTransferData(DataFlavor.imageFlavor);
            BufferedImage bi = (BufferedImage) data;
            uploadImageFromClipboard(bi);
        } catch (UnsupportedFlavorException ex) {
        } catch (IOException ex) {
        }
        return true;
    } else if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        try {
            String data = (String) t.getTransferData(DataFlavor.stringFlavor);
            if (isValidURL(data)) {
                createBookmarkFromClipboard(data);
            } else {
                uploadStringFromClipboard(data);
            }
        } catch (UnsupportedFlavorException ex) {
        } catch (IOException ex) {
        }
        return true;
    }
    return false;
}

From source file:com.mirth.connect.client.ui.editors.transformer.TransformerPane.java

public void drop(DropTargetDropEvent dtde) {
    try {/*  w  w  w .  ja  v  a 2 s  . c  om*/
        Transferable tr = dtde.getTransferable();
        if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

            List<File> fileList = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
            Iterator<File> iterator = fileList.iterator();

            if (fileList.size() == 1) {
                File file = (File) iterator.next();
                importTransformer(parent.readFileToString(file));
            }
        } else if (tr.isDataFlavorSupported(TreeTransferable.MAPPER_DATA_FLAVOR)
                || tr.isDataFlavorSupported(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR)) {
            dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

            Object mapperTransferData = tr.getTransferData(TreeTransferable.MAPPER_DATA_FLAVOR);
            Object messageBuilderTransferData = tr
                    .getTransferData(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR);

            if (mapperTransferData != null && !parent.isAcceleratorKeyPressed()) {
                Object transferData = tr.getTransferData(TreeTransferable.MAPPER_DATA_FLAVOR);
                MapperDropData data = (MapperDropData) transferData;
                addNewStep(data.getVariable(), data.getVariable(), data.getMapping(), MAPPER);
            } else if (mapperTransferData != null && parent.isAcceleratorKeyPressed()) {
                Object transferData = tr.getTransferData(TreeTransferable.MAPPER_DATA_FLAVOR);
                MapperDropData data2 = (MapperDropData) transferData;
                MessageBuilderDropData data = new MessageBuilderDropData(data2.getNode(),
                        MirthTree.constructPath(data2.getNode().getParent(), "msg", "").toString(), "");
                addNewStep(MirthTree.constructMessageBuilderStepName(null, data.getNode()),
                        data.getMessageSegment(), data.getMapping(), MESSAGE_BUILDER);
            } else if (messageBuilderTransferData != null) {
                Object transferData = tr.getTransferData(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR);
                MessageBuilderDropData data = (MessageBuilderDropData) transferData;
                addNewStep(MirthTree.constructMessageBuilderStepName(null, data.getNode()),
                        data.getMessageSegment(), data.getMapping(), MESSAGE_BUILDER);
            }
        }
    } catch (Exception e) {
        dtde.rejectDrop();
    }
}

From source file:com.mirth.connect.client.ui.editors.filter.FilterPane.java

public void drop(DropTargetDropEvent dtde) {
    try {/*from  w w w. j a va 2s . c  o  m*/
        dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
        Transferable tr = dtde.getTransferable();

        if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            List<File> fileList = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
            Iterator<File> iterator = fileList.iterator();

            if (fileList.size() == 1) {
                File file = (File) iterator.next();
                importFilter(parent.readFileToString(file));
            }
        } else if (tr.isDataFlavorSupported(TreeTransferable.RULE_DATA_FLAVOR)) {
            Object transferData = tr.getTransferData(TreeTransferable.RULE_DATA_FLAVOR);

            if (transferData instanceof RuleDropData) {
                RuleDropData data = (RuleDropData) transferData;
                addNewRule(MirthTree.constructNodeDescription(data.getNode()), data.getMapping());
            }
        }
    } catch (Exception e) {
        dtde.rejectDrop();
    }
}

From source file:org.apache.pdfbox.debugger.PDFDebugger.java

/**
 * This method is called from within the constructor to initialize the form.
 */// w ww.  jav  a 2  s  . co  m
private void initComponents() {
    jSplitPane1 = new javax.swing.JSplitPane();
    jScrollPane1 = new JScrollPane();
    tree = new Tree(this);
    jScrollPane2 = new JScrollPane();
    jTextPane1 = new javax.swing.JTextPane();

    tree.setCellRenderer(new PDFTreeCellRenderer());
    tree.setModel(null);

    setTitle("Apache PDFBox Debugger");

    addWindowListener(new java.awt.event.WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent windowEvent) {
            tree.requestFocusInWindow();
            super.windowOpened(windowEvent);
        }

        @Override
        public void windowClosing(WindowEvent evt) {
            exitForm(evt);
        }
    });

    jScrollPane1.setBorder(new BevelBorder(BevelBorder.RAISED));
    jScrollPane1.setPreferredSize(new Dimension(350, 500));
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent evt) {
            jTree1ValueChanged(evt);
        }
    });

    jScrollPane1.setViewportView(tree);

    jSplitPane1.setRightComponent(jScrollPane2);
    jSplitPane1.setDividerSize(3);

    jScrollPane2.setPreferredSize(new Dimension(300, 500));
    jScrollPane2.setViewportView(jTextPane1);

    jSplitPane1.setLeftComponent(jScrollPane1);

    JScrollPane documentScroller = new JScrollPane();
    documentScroller.setViewportView(documentPanel);

    statusPane = new TreeStatusPane(tree);
    statusPane.getPanel().setBorder(new BevelBorder(BevelBorder.RAISED));
    statusPane.getPanel().setPreferredSize(new Dimension(300, 25));
    getContentPane().add(statusPane.getPanel(), BorderLayout.PAGE_START);

    getContentPane().add(jSplitPane1, BorderLayout.CENTER);

    statusBar = new ReaderBottomPanel();
    getContentPane().add(statusBar, BorderLayout.SOUTH);

    // create menus
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(createFileMenu());
    menuBar.add(createEditMenu());
    menuBar.add(createViewMenu());
    setJMenuBar(menuBar);

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int width = 1000;
    int height = 970;
    setBounds((screenSize.width - width) / 2, (screenSize.height - height) / 2, width, height);

    // drag and drop to open files
    setTransferHandler(new TransferHandler() {
        @Override
        public boolean canImport(TransferSupport transferSupport) {
            return transferSupport.isDataFlavorSupported(DataFlavor.javaFileListFlavor);
        }

        @Override
        @SuppressWarnings("unchecked")
        public boolean importData(TransferSupport transferSupport) {
            try {
                Transferable transferable = transferSupport.getTransferable();
                List<File> files = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
                readPDFFile(files.get(0), "");
                return true;
            } catch (IOException e) {
                new ErrorDialog(e).setVisible(true);
                return true;
            } catch (UnsupportedFlavorException e) {
                throw new RuntimeException(e);
            }
        }
    });

    // Mac OS X file open/quit handler
    if (IS_MAC_OS) {
        try {
            Method osxOpenFiles = getClass().getDeclaredMethod("osxOpenFiles", String.class);
            osxOpenFiles.setAccessible(true);
            OSXAdapter.setFileHandler(this, osxOpenFiles);

            Method osxQuit = getClass().getDeclaredMethod("osxQuit");
            osxQuit.setAccessible(true);
            OSXAdapter.setQuitHandler(this, osxQuit);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:se.trixon.pacoma.ui.MainFrame.java

private void initListeners() {
    mActionManager.addAppListener(new ActionManager.AppListener() {
        @Override//from   w  ww .  j  a v a  2 s . co m
        public void onCancel(ActionEvent actionEvent) {
        }

        @Override
        public void onMenu(ActionEvent actionEvent) {
            if (actionEvent.getSource() != menuButton) {
                menuButtonMousePressed(null);
            }
        }

        @Override
        public void onOptions(ActionEvent actionEvent) {
            showOptions();
        }

        @Override
        public void onQuit(ActionEvent actionEvent) {
            quit();
        }

        @Override
        public void onRedo(ActionEvent actionEvent) {
            mCollage.nextHistory();
            updateToolButtons();
        }

        @Override
        public void onStart(ActionEvent actionEvent) {
        }

        @Override
        public void onUndo(ActionEvent actionEvent) {
            mCollage.prevHistory();
            updateToolButtons();
        }
    });

    mActionManager.addProfileListener(new ActionManager.ProfileListener() {
        @Override
        public void onAdd(ActionEvent actionEvent) {
            addImages();
        }

        @Override
        public void onClear(ActionEvent actionEvent) {
            mCollage.clearFiles();
        }

        @Override
        public void onClose(ActionEvent actionEvent) {
            setTitle("pacoma");
            mActionManager.setEnabledDocumentActions(false);
            canvasPanel.close();
        }

        @Override
        public void onEdit(ActionEvent actionEvent) {
            editCollage(mCollage);
        }

        @Override
        public void onRegenerate(ActionEvent actionEvent) {
            //TODO
        }

        @Override
        public void onNew(ActionEvent actionEvent) {
            editCollage(null);
            if (mCollage != null && mCollage.getName() != null) {
                setTitle(mCollage);
                canvasPanel.open(mCollage);
                mActionManager.getAction(ActionManager.CLEAR).setEnabled(false);
                mActionManager.getAction(ActionManager.REGENERATE).setEnabled(false);
            }
        }

        @Override
        public void onOpen(ActionEvent actionEvent) {
            initFileDialog(mCollageFileNameExtensionFilter);

            if (SimpleDialog.openFile()) {
                try {
                    open(SimpleDialog.getPath());
                } catch (IOException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        @Override
        public void onSave(ActionEvent actionEvent) {
            save();
        }

        @Override
        public void onSaveAs(ActionEvent actionEvent) {
            saveAs();
        }
    });

    mCollagePropertyChangeListener = () -> {
        if (mCollage != null) {
            setTitle(mCollage);
            mActionManager.getAction(ActionManager.SAVE).setEnabled(true);
            mActionManager.getAction(ActionManager.CLEAR).setEnabled(mCollage.hasImages());
            mActionManager.getAction(ActionManager.REGENERATE).setEnabled(mCollage.hasImages());
        }
    };

    mDropTarget = new DropTarget() {
        @Override
        public synchronized void drop(DropTargetDropEvent evt) {
            try {
                evt.acceptDrop(DnDConstants.ACTION_COPY);
                LinkedList<File> droppedFiles = new LinkedList<>(
                        (List<File>) evt.getTransferable().getTransferData(DataFlavor.javaFileListFlavor));
                List<File> invalidFiles = new LinkedList<>();

                droppedFiles.forEach((droppedFile) -> {
                    if (droppedFile.isFile() && FilenameUtils.isExtension(
                            droppedFile.getName().toLowerCase(Locale.getDefault()), Collage.FILE_EXT)) {
                        //all ok
                    } else {
                        invalidFiles.add(droppedFile);
                    }
                });

                invalidFiles.forEach((invalidFile) -> {
                    droppedFiles.remove(invalidFile);
                });

                switch (droppedFiles.size()) {
                case 0:
                    Message.error(MainFrame.this, Dict.Dialog.TITLE_IO_ERROR.toString(),
                            "Not a valid collage file.");
                    break;
                case 1:
                    open(droppedFiles.getFirst());
                    break;
                default:
                    Message.error(MainFrame.this, Dict.Dialog.TITLE_IO_ERROR.toString(),
                            "Too many files dropped.");
                    break;
                }
            } catch (UnsupportedFlavorException | IOException ex) {
                System.err.println(ex.getMessage());
            }
        }
    };

    canvasPanel.setDropTarget(mDropTarget);
}

From source file:FileTreeDragSource.java

public DataFlavor[] getTransferDataFlavors() {
    return new DataFlavor[] { DataFlavor.javaFileListFlavor };
}