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:org.tros.logo.swing.LogoMenuBar.java

/**
 * Set up the export menu.//from   w ww  . j ava 2 s  .  com
 *
 * @return
 */
private JMenu setupExportMenu() {
    JMenu exportMenu = new JMenu(Localization.getLocalizedString("ExportMenu"));

    JMenuItem exportGif = new JMenuItem(Localization.getLocalizedString("ExportGIF"));
    JMenuItem exportPng = new JMenuItem(Localization.getLocalizedString("ExportPNG"));
    JMenuItem exportSvg = new JMenuItem(Localization.getLocalizedString("ExportSVG"));

    exportSvg.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            JFileChooser chooser = new JFileChooser();
            chooser.setMultiSelectionEnabled(false);
            java.util.prefs.Preferences prefs = java.util.prefs.Preferences
                    .userNodeForPackage(LogoMenuBar.class);
            chooser.setCurrentDirectory(new File(prefs.get("export-directory", ".")));

            chooser.setVisible(true);
            int result = chooser.showSaveDialog(parent);

            if (result == JFileChooser.APPROVE_OPTION) {
                String filename = chooser.getSelectedFile().getPath();
                prefs.put("export-directory", chooser.getSelectedFile().getParent());
                if (Drawable.class.isAssignableFrom(canvas.getClass())) {
                    try (FileOutputStream fos = new FileOutputStream(new File(filename))) {
                        generateSVG((Drawable) canvas, fos);
                        fos.flush();
                    } catch (IOException ex) {
                        org.tros.utils.logging.Logging.getLogFactory().getLogger(LogoMenuBar.class).warn(null,
                                ex);
                    }
                }
            }
        }
    });

    exportGif.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            JFileChooser chooser = new JFileChooser();
            chooser.setMultiSelectionEnabled(false);
            java.util.prefs.Preferences prefs = java.util.prefs.Preferences
                    .userNodeForPackage(LogoMenuBar.class);
            chooser.setCurrentDirectory(new File(prefs.get("export-directory", ".")));

            chooser.setVisible(true);
            int result = chooser.showSaveDialog(parent);

            if (result == JFileChooser.APPROVE_OPTION) {
                final String filename = chooser.getSelectedFile().getPath();
                prefs.put("export-directory", chooser.getSelectedFile().getParent());
                Thread t = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        if (Drawable.class.isAssignableFrom(canvas.getClass())
                                && BufferedImageProvider.class.isAssignableFrom((canvas.getClass()))) {
                            try {
                                generateGIF(((Drawable) canvas).cloneDrawable(), (BufferedImageProvider) canvas,
                                        filename);
                            } catch (SVGGraphics2DIOException ex) {
                                Logger.getLogger(LogoMenuBar.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (IOException ex) {
                                Logger.getLogger(LogoMenuBar.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    }
                });
                t.setDaemon(true);
                t.start();
            }
        }
    });
    exportPng.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            JFileChooser chooser = new JFileChooser();
            chooser.setMultiSelectionEnabled(false);
            java.util.prefs.Preferences prefs = java.util.prefs.Preferences
                    .userNodeForPackage(LogoMenuBar.class);
            chooser.setCurrentDirectory(new File(prefs.get("export-directory", ".")));

            chooser.setVisible(true);
            int result = chooser.showSaveDialog(parent);

            if (result == JFileChooser.APPROVE_OPTION) {
                String filename = chooser.getSelectedFile().getPath();
                prefs.put("export-directory", chooser.getSelectedFile().getParent());
                // retrieve image
                if (BufferedImageProvider.class.isAssignableFrom(canvas.getClass())) {
                    generatePNG((BufferedImageProvider) canvas, filename);
                }
            }
        }
    });

    exportMenu.add(exportSvg);
    exportMenu.add(exportGif);
    exportMenu.add(exportPng);
    exportMenu.setMnemonic('X');
    exportSvg.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.ALT_MASK));
    exportGif.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.ALT_MASK));
    exportPng.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.ALT_MASK));
    return (exportMenu);
}

From source file:org.tros.torgo.ControllerBase.java

/**
 * Open a file.//from w  ww .  j  av  a  2  s.  c o  m
 */
@Override
public void openFile() {
    JFileChooser chooser = new JFileChooser();
    chooser.setMultiSelectionEnabled(false);
    java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userNodeForPackage(ControllerBase.class);
    chooser.setCurrentDirectory(
            new File(prefs.get(ControllerBase.class.getName() + "-working-directory", ".")));

    if (chooser.showOpenDialog(window) == JFileChooser.APPROVE_OPTION) {
        filename = chooser.getSelectedFile().getPath();
        prefs.put(ControllerBase.class.getName() + "-working-directory", chooser.getSelectedFile().getParent());
        openFile(chooser.getSelectedFile());
    }
}

From source file:org.tros.torgo.ControllerBase.java

/**
 * Save the script as a new file.//from  ww w.ja  v a2 s  . c  om
 */
@Override
public void saveFileAs() {
    JFileChooser chooser = new JFileChooser();
    chooser.setMultiSelectionEnabled(false);
    java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userNodeForPackage(ControllerBase.class);
    chooser.setCurrentDirectory(
            new File(prefs.get(ControllerBase.class.getName() + "-working-directory", ".")));

    int result = chooser.showSaveDialog(window);

    if (result == JFileChooser.APPROVE_OPTION) {
        filename = chooser.getSelectedFile().getPath();
        prefs.put(ControllerBase.class.getName() + "-working-directory", chooser.getSelectedFile().getParent());
        saveFile();
    }
}

From source file:org.trzcinka.intellitrac.view.toolwindow.tickets.ticket_editor.NewAttachmentPopup.java

public NewAttachmentPopup(Window parent, Integer id) {
    super(parent);
    ticketId = id;/* w  w w  . jav a  2s.c o m*/
    setContentPane(contentPane);
    setModal(true);
    getRootPane().setDefaultButton(buttonOK);

    buttonOK.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            onOK();
        }
    });

    buttonCancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            onCancel();
        }
    });

    // call onCancel() when cross is clicked
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            onCancel();
        }
    });

    // call onCancel() on ESCAPE
    contentPane.registerKeyboardAction(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            onCancel();
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    selectFileButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = new JFileChooser();
            fc.setMultiSelectionEnabled(false);
            int ret = fc.showOpenDialog(contentPane);
            if (ret == JFileChooser.APPROVE_OPTION) {
                selectedFile = fc.getSelectedFile();
                fileName.setText(selectedFile.getName());
                buttonOK.setEnabled(true);
                pack();
            }
        }
    });
}

From source file:org.ut.biolab.medsavant.client.view.dialog.SavantExportForm.java

private void chooseFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseFileButtonActionPerformed
    JFileChooser fc = new JFileChooser();
    fc.setDialogTitle("Save Savant Project");
    fc.setDialogType(JFileChooser.SAVE_DIALOG);
    fc.addChoosableFileFilter(new ExtensionsFileFilter(new String[] { "svp" }));
    fc.setMultiSelectionEnabled(false);

    int result = fc.showDialog(null, null);
    if (result == JFileChooser.CANCEL_OPTION || result == JFileChooser.ERROR_OPTION) {
        return;//  ww  w  .j  a v  a  2  s.  co  m
    }

    outputFile = fc.getSelectedFile();
    String path = outputFile.getAbsolutePath();
    outputFileField.setText(path);
    exportButton.setEnabled(true);
}

From source file:org.zaproxy.zap.extension.dynssl.DynamicSSLPanel.java

/**
 * Import Root CA certificate from other ZAP configuration files.
 *///from  w  ww.j  a  va  2  s  .c om
private void doImport() {
    if (checkExistingCertificate()) {
        // prevent overwriting
        return;
    }
    final JFileChooser fc = new JFileChooser(System.getProperty("user.home"));
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setMultiSelectionEnabled(false);
    fc.setSelectedFile(new File(CONFIGURATION_FILENAME));
    fc.setFileFilter(new FileFilter() {
        @Override
        public String getDescription() {
            // config.xml or *.pem files
            return Constant.messages.getString("dynssl.filter.file");
        }

        @Override
        public boolean accept(File f) {
            return f.getName().toLowerCase().endsWith(CONFIGURATION_FILENAME)
                    || f.getName().toLowerCase().endsWith("pem") || f.isDirectory();
        }
    });
    final int result = fc.showOpenDialog(this);
    final File f = fc.getSelectedFile();
    if (result == JFileChooser.APPROVE_OPTION && f.exists()) {
        if (logger.isInfoEnabled()) {
            logger.info("Loading Root CA certificate from " + f);
        }
        KeyStore ks = null;
        if (f.getName().toLowerCase().endsWith("pem")) {
            ks = convertPemFileToKeyStore(f.toPath());
        } else {
            try {
                final ZapXmlConfiguration conf = new ZapXmlConfiguration(f);
                final String rootcastr = conf.getString(DynSSLParam.PARAM_ROOT_CA);
                ks = SslCertificateUtils.string2Keystore(rootcastr);
            } catch (final Exception e) {
                logger.error("Error importing Root CA cert from config file:", e);
                JOptionPane.showMessageDialog(this,
                        Constant.messages.getString("dynssl.message1.filecouldntloaded"),
                        Constant.messages.getString("dynssl.message1.title"), JOptionPane.ERROR_MESSAGE);
            }
        }
        if (ks != null) {
            setRootca(ks);
        }

    }
}

From source file:org.zaproxy.zap.extension.dynssl.DynamicSSLPanel.java

/**
 * Saving Root CA certificate to disk.//w ww .  java  2  s  . c  o  m
 */
private void doSave() {
    if (txt_PubCert.getDocument().getLength() < MIN_CERT_LENGTH) {
        logger.error("Illegal state! There seems to be no certificate available.");
        bt_save.setEnabled(false);
    }
    final JFileChooser fc = new JFileChooser(System.getProperty("user.home"));
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setMultiSelectionEnabled(false);
    fc.setSelectedFile(new File(OWASP_ZAP_ROOT_CA_FILENAME));
    if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        final File f = fc.getSelectedFile();
        if (logger.isInfoEnabled()) {
            logger.info("Saving Root CA certificate to " + f);
        }
        try {
            writePubCertificateToFile(f);
        } catch (final Exception e) {
            logger.error("Error while writing certificate data to file " + f, e);
        }
    }
}

From source file:os.Controller.java

public void browse() {
    FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF Files", "pdf", "PDF");
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileFilter(filter);//from  w  w  w  . ja  v a  2  s  .  co m
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.setMultiSelectionEnabled(true);
    fileChooser.showOpenDialog(null);

    File[] files = fileChooser.getSelectedFiles();
    try {
        //        if (checkSelection(files) == true) {
        //            singleThread(files);
        multiThread(files);
    } catch (Exception ex) {
        Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
    }
    selectedTxt.append("You've selected " + files.length + " PDF file(s).\n");
    //        } else {
    //            JOptionPane.showMessageDialog(fileChooser, "Please select PDF file(s) only");
    //        }
}

From source file:phex.gui.common.FileDialogHandler.java

private static File[] openDefaultMultiChooser(Component parent, JFileChooser chooser) {
    chooser.setMultiSelectionEnabled(true);
    int returnVal = chooser.showOpenDialog(parent);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        return chooser.getSelectedFiles();
    }/*from   ww  w.  j  ava2  s  .c o m*/
    return null;
}

From source file:phex.gui.common.FileDialogHandler.java

private static File openDefaultSingleChooser(Component parent, JFileChooser chooser) {
    chooser.setMultiSelectionEnabled(false);
    int returnVal = chooser.showOpenDialog(parent);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        return chooser.getSelectedFile();
    }//  ww w  .  ja v  a2 s  . c o m
    return null;
}