Example usage for javax.swing JFileChooser setMultiSelectionEnabled

List of usage examples for javax.swing JFileChooser setMultiSelectionEnabled

Introduction

In this page you can find the example usage for javax.swing JFileChooser setMultiSelectionEnabled.

Prototype

@BeanProperty(description = "Sets multiple file selection mode.")
public void setMultiSelectionEnabled(boolean b) 

Source Link

Document

Sets the file chooser to allow multiple file selections.

Usage

From source file:ca.canucksoftware.clockthemebuilder.ThemeBuilderView.java

private File loadFileChooser(javax.swing.filechooser.FileFilter ff, String saveName) {
    File result;/*w  ww .ja va  2s  .  c  om*/
    JFileChooser fc = new JFileChooser(); //Create a file chooser
    fc.setMultiSelectionEnabled(false);
    if (ff != null) {
        fc.setAcceptAllFileFilterUsed(false);
        fc.setFileFilter(ff);
    } else {
        fc.setAcceptAllFileFilterUsed(true);
    }
    if (saveName == null) {
        fc.setDialogTitle("");
        if (fc.showDialog(null, "Select") == JFileChooser.APPROVE_OPTION) {
            result = fc.getSelectedFile();
        } else {
            result = null;
        }
    } else {
        fc.setDialogTitle("Save As...");
        fc.setSelectedFile(new File(saveName));
        if (fc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
            result = fc.getSelectedFile();
        } else {
            result = null;
        }
    }
    return result;
}

From source file:ch.tatool.app.export.FileDataExporter.java

private String getStorageDirectory(Component parentFrame) {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileFilter(new FileFilter() {

        @Override//from   w  ww.  ja va 2 s  .  c om
        public String getDescription() {
            return "CSV (*.csv)";
        }

        @Override
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return true;
            }

            String extension = getExtension(f);
            if (extension != null) {
                if (extension.equals("csv")) {
                    return true;
                } else {
                    return false;
                }
            }

            return false;

        }
    });
    chooser.setAcceptAllFileFilterUsed(false);
    // chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    int returnVal = chooser.showSaveDialog(parentFrame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {

        File f = chooser.getSelectedFile();
        String filename = "";
        if (f == null) {
            throw new RuntimeException();
        }
        String extension = getExtension(f);
        if (extension == null || !getExtension(f).equals("csv")) {
            filename = f + ".csv";
        } else {
            filename = f.getPath();
        }
        return filename;
    } else {
        return null;
    }
}

From source file:net.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java

protected JFileChooser initFileChooser() {
    ExtensionFileFilter filter = new ExtensionFileFilter("log,txt", true, true);
    filter.setDescription("?");
    JFileChooser jfc = new JFileChooser();
    FileSystemView fsv = FileSystemView.getFileSystemView();
    //?//  w  w  w . j  a v a  2 s. co m
    jfc.setCurrentDirectory(fsv.getHomeDirectory());
    jfc.setDialogTitle("?");
    jfc.setMultiSelectionEnabled(false);
    jfc.setDialogType(JFileChooser.OPEN_DIALOG);
    jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);//JFileChooser.FILES_AND_DIRECTORIES
    jfc.setFileFilter(filter);
    return jfc;
}

From source file:duthientan.mmanm.com.Main.java

private void BntOpenFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BntOpenFileActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setMultiSelectionEnabled(true);
    int returnValue = fileChooser.showOpenDialog(null);

    if (returnValue == JFileChooser.APPROVE_OPTION) {
        File[] selectedFiles = fileChooser.getSelectedFiles();
        JLFILEPATH.setText(selectedFiles.length + " files is selected");
        JLMD5.setText("Caculating");
        filePath = new ArrayList<>();
        new Thread(new Runnable() {
            @Override//from  www  . j av  a 2 s.  c  o  m
            public void run() {
                try {
                    String mD5 = "";
                    for (File f : selectedFiles) {
                        filePath.add(f.getPath());
                        FileInputStream fis = new FileInputStream(f);
                        mD5 += f.getName() + " : " + org.apache.commons.codec.digest.DigestUtils.md5Hex(fis)
                                + "<br>";
                        fis.close();
                    }
                    JLMD5.setText("<html>" + mD5 + "</html>");
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }).start();
    }
}

From source file:com.igormaznitsa.sciareto.ui.MainFrame.java

@Nullable
@Override/* ww w .java2s .c  o  m*/
public File createMindMapFile(@Nullable final File folder) {
    final JFileChooser chooser = new JFileChooser(folder);
    chooser.setDialogTitle("Create new Mind Map");
    chooser.setFileFilter(MMDEditor.MMD_FILE_FILTER);
    chooser.setMultiSelectionEnabled(false);
    chooser.setApproveButtonText("Create");

    File result = null;

    if (chooser.showSaveDialog(Main.getApplicationFrame()) == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        if (!file.getName().endsWith(".mmd")) {
            file = new File(file.getAbsolutePath() + ".mmd");
        }

        if (file.exists()) {
            DialogProviderManager.getInstance().getDialogProvider()
                    .msgError("File '" + file + "' already exists!");
        } else {
            try {
                final MindMap mindMap = new MindMap(null, true);
                final String text = mindMap.write(new StringWriter()).toString();
                SystemUtils.saveUTFText(file, text);
                result = file;
            } catch (IOException ex) {
                DialogProviderManager.getInstance().getDialogProvider()
                        .msgError("Can't save mind map into file '" + file.getName() + "'");
            }
        }
    }
    return result;
}

From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java

private JButton createCaptureButton() {
    JButton capture = new JButton("Capture");
    capture.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            JFileChooser chooser = new JFileChooser(currentDir);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            chooser.setMultiSelectionEnabled(false);
            chooser.setFileFilter(new PngFileFilter());
            int result = chooser.showSaveDialog(GraphViewerPanel.this);
            if (result == JFileChooser.APPROVE_OPTION) {
                currentDir = chooser.getCurrentDirectory();
                String absolutePath = chooser.getSelectedFile().getAbsolutePath();
                if (!absolutePath.endsWith(".png")) {
                    absolutePath += ".png";
                }/*from  w  w  w  . j av a2  s. c o m*/
                try {
                    vv.setDoubleBuffered(false);
                    writeToImageFile(absolutePath);
                    vv.setDoubleBuffered(true);
                } catch (AWTException e1) {
                    e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                }
                //                        captureToFile(absolutePath);
                //                        writeJPEGImage(absolutePath + ".JPEG");
                //                        captureScreen(absolutePath);
            }
        }
    });
    return capture;
}

From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java

private JButton createSaveButton() {
    JButton save = new JButton("Save");
    save.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            PersistentLayout pl = (PersistentLayout) vv.getGraphLayout();
            try {
                JFileChooser chooser = new JFileChooser(currentDir);
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                chooser.setMultiSelectionEnabled(false);
                chooser.setFileFilter(new LayoutFileFilter());
                int result = chooser.showSaveDialog(GraphViewerPanel.this);
                if (result == JFileChooser.APPROVE_OPTION) {
                    currentDir = chooser.getCurrentDirectory();
                    String absolutePath = chooser.getSelectedFile().getAbsolutePath();
                    if (!absolutePath.endsWith(".layout")) {
                        absolutePath += ".layout";
                    }//from   ww w . j av  a2 s. c o  m
                    pl.persist(absolutePath);
                }
            } catch (IOException e1) {
                e1.printStackTrace();
                JOptionPane.showMessageDialog(GraphViewerPanel.this, "Error saving layout: " + e1.getMessage());
            }
        }
    });
    return save;
}

From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java

private JButton createLoadButton() {
    JButton load = new JButton("Load");
    load.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            PersistentLayout pl = (PersistentLayout) vv.getGraphLayout();
            try {
                JFileChooser chooser = new JFileChooser(currentDir);
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                chooser.setMultiSelectionEnabled(false);
                chooser.setFileFilter(new LayoutFileFilter());
                int result = chooser.showOpenDialog(GraphViewerPanel.this);
                if (result == JFileChooser.APPROVE_OPTION) {
                    currentDir = chooser.getCurrentDirectory();
                    String absolutePath = chooser.getSelectedFile().getAbsolutePath();
                    if (!absolutePath.endsWith(".layout")) {
                        absolutePath += ".layout";
                    }/*  ww w.j  a v a2  s.c  o m*/
                    pl.restore(absolutePath);
                    vv.repaint();
                }
            } catch (Exception e1) {
                e1.printStackTrace();
                JOptionPane.showMessageDialog(GraphViewerPanel.this,
                        "Error restoring layout: " + e1.getMessage());
            }
        }
    });
    return load;
}

From source file:de.juwimm.cms.content.panel.PanDocuments.java

private void upload(String prosa, Integer unit, Integer viewComponentId, Integer documentId) {
    this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    JFileChooser fc = new JFileChooser();
    int ff = fc.getChoosableFileFilters().length;
    FileFilter[] fft = fc.getChoosableFileFilters();
    for (int i = 0; i < ff; i++) {
        fc.removeChoosableFileFilter(fft[i]);
    }/*from   w w  w. j a v a2 s  .c  o  m*/
    fc.addChoosableFileFilter(new DocumentFilter());
    fc.setAccessory(new ImagePreview(fc));
    fc.setDialogTitle(prosa);
    fc.setMultiSelectionEnabled(true);
    fc.setCurrentDirectory(Constants.LAST_LOCAL_UPLOAD_DIR);
    int returnVal = fc.showDialog(this, Messages.getString("panel.content.documents.addDocument"));

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File[] files = fc.getSelectedFiles();
        uploadFiles(files, unit, viewComponentId, documentId);
        Constants.LAST_LOCAL_UPLOAD_DIR = fc.getCurrentDirectory();
    }
    this.setCursor(Cursor.getDefaultCursor());
}

From source file:ca.osmcanada.osvuploadr.JPMain.java

private void jbAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAddActionPerformed
    try {// w  ww  .  j a  v a  2 s  .c  o  m
        JFileChooser fc = new JFileChooser();
        if (!last_dir.isEmpty()) {
            fc.setCurrentDirectory(new java.io.File(last_dir)); // start at application current directory
        }
        fc.setMultiSelectionEnabled(true);
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = fc.showSaveDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            if (fc.getSelectedFiles().length == 1) {
                int response = JOptionPane.showConfirmDialog(null,
                        new String(r.getString("immediate_sub_folders").getBytes(), "UTF-8"),
                        new String(r.getString("add_subfolders").getBytes(), "UTF-8"),
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (response == JOptionPane.NO_OPTION) {
                    File folder = fc.getSelectedFile();
                    listDir.add(folder.getPath());
                    last_dir = folder.getPath();
                } else if (response == JOptionPane.YES_OPTION) {
                    //Get a list of subdirectories
                    String[] subDirs = fc.getSelectedFile().list(new FilenameFilter() {
                        @Override
                        public boolean accept(File current, String name) {
                            return new File(current, name).isDirectory();
                        }
                    });

                    for (String subDir : subDirs) {
                        listDir.add(new File(fc.getSelectedFile() + "/" + subDir).getPath());
                    }
                }
            } else if (fc.getSelectedFiles().length > 1) {
                File[] folders = fc.getSelectedFiles();
                for (File folder : folders) {
                    listDir.add(folder.getPath());
                    last_dir = folder.getPath();
                }
            }

        }
    } catch (UnsupportedEncodingException ex) {
    }
}