List of usage examples for java.awt.datatransfer DataFlavor javaFileListFlavor
DataFlavor javaFileListFlavor
To view the source code for java.awt.datatransfer DataFlavor javaFileListFlavor.
Click Source Link
From source file:FileTreeDragSource.java
public boolean isDataFlavorSupported(DataFlavor fl) { return fl.equals(DataFlavor.javaFileListFlavor); }
From source file:com.igormaznitsa.sciareto.ui.editors.MMDEditor.java
@Override public void drop(@Nonnull final DropTargetDropEvent dtde) { dtde.acceptDrop(DnDConstants.ACTION_MOVE); File detectedFileObject = null; for (final DataFlavor df : dtde.getCurrentDataFlavors()) { final Class<?> representation = df.getRepresentationClass(); if (FileTransferable.class.isAssignableFrom(representation)) { final FileTransferable t = (FileTransferable) dtde.getTransferable(); final List<File> listOfFiles = t.getFiles(); detectedFileObject = listOfFiles.isEmpty() ? null : listOfFiles.get(0); break; } else if (df.isFlavorJavaFileListType()) { try { final List list = (List) dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); if (list != null && !list.isEmpty()) { detectedFileObject = (File) list.get(0); }//from www .ja v a 2 s .com break; } catch (Exception ex) { LOGGER.error("Can't extract file from DnD", ex); } } } if (detectedFileObject != null) { addFileToElement(detectedFileObject, this.mindMapPanel.findTopicUnderPoint(dtde.getLocation())); } }
From source file:gdt.jgui.entity.folder.JFolderPanel.java
private boolean hasToInsert() { try {/*w ww . j a v a 2 s . c o m*/ Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable clipboardContents = systemClipboard.getContents(null); if (clipboardContents == null) return false; Object transferData = clipboardContents.getTransferData(DataFlavor.javaFileListFlavor); @SuppressWarnings("unchecked") List<File> files = (List<File>) transferData; for (int i = 0; i < files.size(); i++) { File file = (File) files.get(i); if (file.exists() && file.isFile()) return true; } } catch (Exception ee) { LOGGER.severe(ee.toString()); } return false; }
From source file:pkgrenamer.Main.java
static void onDropFiles(DropTargetDropEvent dtde, FileDropListener onDrop) { try {/*ww w. ja va 2s .c o m*/ Transferable transferable = dtde.getTransferable(); if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_MOVE); java.util.List<?> files = (java.util.List<?>) transferable .getTransferData(DataFlavor.javaFileListFlavor); File[] fa = new File[files.size()]; for (int i = 0; i < fa.length; i++) { fa[i] = (File) files.get(i); } onDrop.onDropFile(fa); dtde.getDropTargetContext().dropComplete(true); } else { if (sNixFileDataFlavor == null) { sNixFileDataFlavor = new DataFlavor("text/uri-list;class=java.lang.String"); } dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); String data = (String) transferable.getTransferData(sNixFileDataFlavor); if (data != null) { ArrayList<File> fs = new ArrayList<>(); for (StringTokenizer st = new StringTokenizer(data, "\r\n"); st.hasMoreTokens();) { String token = st.nextToken().trim(); if (token.startsWith("#") || token.isEmpty()) { continue; } try { fs.add(new File(new URI(token))); } catch (Exception e) { } } onDrop.onDropFile(fs.toArray(new File[0])); dtde.getDropTargetContext().dropComplete(true); } else { dtde.rejectDrop(); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:at.becast.youploader.gui.FrmMain.java
public void initMainTab() { cmbCategory = new JComboBox<Categories>(); cmbCategory.setModel(new DefaultComboBoxModel<Categories>(Categories.values())); SideBar sideBar = new SideBar(SideBar.SideBarMode.TOP_LEVEL, true, 300, true); ss1 = new SidebarSection(sideBar, LANG.getString("frmMain.Sidebar.Settings"), new EditPanel(this), new ImageIcon(getClass().getResource("/pencil.png"))); ss2 = new SidebarSection(sideBar, LANG.getString("frmMain.Sidebar.Playlists"), new PlaylistPanel(this), new ImageIcon(getClass().getResource("/layers.png"))); ss3 = new SidebarSection(sideBar, LANG.getString("frmMain.Sidebar.Monetisation"), new MonetPanel(), new ImageIcon(getClass().getResource("/money.png"))); sideBar.addSection(ss1, false);//from w w w .ja v a 2 s .c om sideBar.addSection(ss2); sideBar.addSection(ss3); JPanel mainTab = new JPanel(); JPanel panel = new JPanel(); GroupLayout mainTabLayout = new GroupLayout(mainTab); mainTabLayout.setHorizontalGroup(mainTabLayout.createParallelGroup(Alignment.TRAILING) .addGroup(mainTabLayout.createSequentialGroup() .addComponent(panel, GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(sideBar, GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE))); mainTabLayout.setVerticalGroup(mainTabLayout.createParallelGroup(Alignment.LEADING) .addComponent(panel, GroupLayout.DEFAULT_SIZE, 492, Short.MAX_VALUE) .addGroup(mainTabLayout.createSequentialGroup() .addComponent(sideBar, GroupLayout.DEFAULT_SIZE, 469, Short.MAX_VALUE).addContainerGap())); panel.setLayout(new FormLayout( new ColumnSpec[] { ColumnSpec.decode("2px"), FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("20px:grow"), FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("23px"), ColumnSpec.decode("33px"), FormSpecs.UNRELATED_GAP_COLSPEC, ColumnSpec.decode("61px"), FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("24px"), ColumnSpec.decode("28px"), ColumnSpec.decode("40px"), ColumnSpec.decode("36px"), FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("28px"), FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("58px"), }, new RowSpec[] { RowSpec.decode("2px"), FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("14px"), RowSpec.decode("25px"), FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("14px"), RowSpec.decode("25px"), FormSpecs.LINE_GAP_ROWSPEC, RowSpec.decode("14px"), RowSpec.decode("25px"), FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, RowSpec.decode("64dlu:grow"), FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, RowSpec.decode("max(64dlu;default)"), FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, RowSpec.decode("25px"), FormSpecs.PARAGRAPH_GAP_ROWSPEC, RowSpec.decode("24px"), RowSpec.decode("23px"), })); lbltitlelenght = new JLabel("(0/100)"); panel.add(lbltitlelenght, "14, 6, 3, 1, right, top"); txtTitle = new JTextField(); contextMenu.add(txtTitle); panel.add(txtTitle, "3, 7, 14, 1, fill, fill"); txtTitle.setColumns(10); txtTitle.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { calcNotifies(); } }); JLabel lblCategory = new JLabel(LANG.getString("frmMain.Category")); panel.add(lblCategory, "3, 9, 4, 1, left, bottom"); panel.add(cmbCategory, "3, 10, 14, 1, fill, fill"); JLabel lblDescription = new JLabel(LANG.getString("frmMain.Description")); panel.add(lblDescription, "3, 12, 4, 1, left, bottom"); lblDesclenght = new JLabel("(0/5000)"); panel.add(lblDesclenght, "14, 12, 3, 1, right, bottom"); JScrollPane DescriptionScrollPane = new JScrollPane(); panel.add(DescriptionScrollPane, "3, 13, 14, 1, fill, fill"); txtDescription = new JTextArea(); contextMenu.add(txtDescription); txtDescription.setFont(new Font("SansSerif", Font.PLAIN, 13)); DescriptionScrollPane.setViewportView(txtDescription); txtDescription.setWrapStyleWord(true); txtDescription.setLineWrap(true); txtDescription.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { calcNotifies(); } }); JLabel lblTags = new JLabel(LANG.getString("frmMain.Tags")); panel.add(lblTags, "3, 15, 4, 1, left, bottom"); lblTagslenght = new JLabel("(0/500)"); panel.add(lblTagslenght, "14, 15, 3, 1, right, top"); JScrollPane TagScrollPane = new JScrollPane(); panel.add(TagScrollPane, "3, 16, 14, 1, fill, fill"); txtTags = new JTextArea(); contextMenu.add(txtTags); txtTags.setFont(new Font("SansSerif", Font.PLAIN, 13)); TagScrollPane.setViewportView(txtTags); txtTags.setWrapStyleWord(true); txtTags.setLineWrap(true); txtTags.setBorder(BorderFactory.createEtchedBorder()); txtTags.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { calcNotifies(); } }); JLabel lblAccount = new JLabel(LANG.getString("frmMain.Account")); panel.add(lblAccount, "3, 18, 4, 1, left, bottom"); cmbAccount = new JComboBox<AccountType>(); panel.add(getCmbAccount(), "3, 19, 14, 1, fill, fill"); cmbAccount.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { changeUser(); } }); btnAddToQueue = new JButton(LANG.getString("frmMain.addtoQueue")); btnAddToQueue.setEnabled(false); panel.add(btnAddToQueue, "3, 21, 6, 1, fill, fill"); btnAddToQueue.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { queueButton(); } }); JLabel lblSelectVideo = new JLabel(); panel.add(lblSelectVideo, "3, 3, 4, 1, left, bottom"); lblSelectVideo.setText(LANG.getString("frmMain.selectVideoFile")); cmbFile = new JComboBox<String>(); cmbFile.setDropTarget(new DropTarget() { private static final long serialVersionUID = 8809983794742040683L; public synchronized void drop(DropTargetDropEvent evt) { try { evt.acceptDrop(DnDConstants.ACTION_COPY); @SuppressWarnings("unchecked") List<File> droppedFiles = (List<File>) evt.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); for (File file : droppedFiles) { cmbFile.removeAllItems(); cmbFile.addItem(file.getAbsolutePath()); } } catch (Exception ex) { LOG.error("Error dropping video file", ex); } } }); panel.add(cmbFile, "3, 4, 14, 1, fill, fill"); JButton btnSelectMovie = new JButton(); btnSelectMovie.setToolTipText("Select Video File"); panel.add(btnSelectMovie, "18, 4, center, top"); btnSelectMovie.setIcon(new ImageIcon(getClass().getResource("/film_add.png"))); JLabel lblTitle = new JLabel(LANG.getString("frmMain.Title")); panel.add(lblTitle, "3, 6, 4, 1, left, bottom"); JButton btnReset = new JButton(LANG.getString("frmMain.Reset")); btnReset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { resetEdit(); } }); panel.add(btnReset, "11, 21, 6, 1, fill, fill"); btnSelectMovie.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { EditPanel edit = (EditPanel) ss1.contentPane; NativeJFileChooser chooser; if (edit.getTxtStartDir() != null && !edit.getTxtStartDir().equals("")) { chooser = new NativeJFileChooser(edit.getTxtStartDir().getText().trim()); } else { chooser = new NativeJFileChooser(); } int returnVal = chooser.showOpenDialog((Component) self); if (returnVal == JFileChooser.APPROVE_OPTION) { cmbFile.removeAllItems(); cmbFile.addItem(chooser.getSelectedFile().getAbsolutePath().toString()); } } }); mainTab.setLayout(mainTabLayout); mainTab.revalidate(); mainTab.repaint(); TabbedPane.addTab(LANG.getString("frmMain.Tabs.VideoSettings"), mainTab); }
From source file:com.ftb2om2.view.MultiplePane.java
private String getDragAndDropPath(DropTargetDropEvent evt) throws IOException, UnsupportedFlavorException { evt.acceptDrop(DnDConstants.ACTION_COPY); List<File> droppedFile = (List<File>) evt.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); return droppedFile.get(0).getAbsolutePath(); }
From source file:DragDropTreeExample.java
protected void checkTransferType(DropTargetDragEvent dtde) { // Accept a list of files acceptableType = false;/*from w ww . ja va 2 s . c o m*/ if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { acceptableType = true; } DnDUtils.debugPrintln("Data type acceptable - " + acceptableType); }
From source file:DragDropTreeExample.java
protected boolean dropFile(int action, Transferable transferable, Point location) throws IOException, UnsupportedFlavorException, MalformedURLException { List files = (List) transferable.getTransferData(DataFlavor.javaFileListFlavor); TreePath treePath = tree.getPathForLocation(location.x, location.y); File targetDirectory = findTargetDirectory(location); if (treePath == null || targetDirectory == null) { return false; }/*from w ww . j av a 2 s. c om*/ FileTree.FileTreeNode node = (FileTree.FileTreeNode) treePath.getLastPathComponent(); // Highlight the drop location while we perform the drop tree.setSelectionPath(treePath); // Get File objects for all files being // transferred, eliminating duplicates. File[] fileList = getFileList(files); // Don't overwrite files by default copyOverExistingFiles = false; // Copy or move each source object to the target for (int i = 0; i < fileList.length; i++) { File f = fileList[i]; if (f.isDirectory()) { transferDirectory(action, f, targetDirectory, node); } else { try { transferFile(action, fileList[i], targetDirectory, node); } catch (IllegalStateException e) { // Cancelled by user return false; } } } return true; }
From source file:plugin.notes.gui.NotesTreeNode.java
/** * handles a drop of a java file list/* ww w. j a v a 2s . c o m*/ * * @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 (Object aFileList : fileList) { File newFile = (File) aFileList; if (newFile.exists()) { FileUtils.copyFile(newFile, new File(dir.getAbsolutePath() + File.separator + newFile.getName())); } } } catch (Exception e) { Logging.errorPrint(e.getMessage(), e); return false; } return true; }
From source file:view.MainWindow.java
private void setupDropListener() { this.setDropTarget(new DropTarget() { @Override/*from ww w .ja v a 2s . co m*/ public synchronized void drop(DropTargetDropEvent evt) { try { evt.acceptDrop(DnDConstants.ACTION_COPY); List<File> droppedFiles = (List<File>) evt.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); if (!droppedFiles.isEmpty()) { for (File file : droppedFiles) { if (file.exists() && file.isFile() && file.getAbsolutePath().endsWith(".pdf")) { if (loadPdf(file, false)) { ctrl.openDocument(file.getAbsolutePath()); workspacePanel.setDocument(ctrl.getDocument()); } else { errorList.add(file.getAbsolutePath()); } } else if (file.exists() && file.isDirectory()) { loadFolder(file, true); } } showErrors(); } } catch (UnsupportedFlavorException | IOException ex) { controller.Logger.getLogger().addEntry(ex); } } }); }