Example usage for javax.swing JFileChooser APPROVE_OPTION

List of usage examples for javax.swing JFileChooser APPROVE_OPTION

Introduction

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

Prototype

int APPROVE_OPTION

To view the source code for javax.swing JFileChooser APPROVE_OPTION.

Click Source Link

Document

Return value if approve (yes, ok) is chosen.

Usage

From source file:fsart.diffTools.gui.DiffToolsMainPanel.java

private String getFileGui() {

    int returnVal = fc.showOpenDialog(panel1);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {/*from ww  w . j ava2  s.c  om*/
            return fc.getSelectedFile().getCanonicalPath();
        } catch (Exception e) {
            log.error("Can't get file with FileChooser \n" + e.toString() + "\n" + e.getStackTrace());
            return "";
        }
    }
    return "";
}

From source file:com.reelfx.controller.AbstractController.java

public void askForAndSaveRecording() {
    JFileChooser fileSelect = new JFileChooser();
    int returnVal = fileSelect.showSaveDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fileSelect.getSelectedFile();
        saveRecording(file);//from  w  w  w.jav a 2s  . c om
    }
}

From source file:de.fhg.igd.mapviewer.server.file.FileTiler.java

/**
 * Ask the user for a certain file path//from w  w  w . j  a  va2 s .co  m
 * 
 * @param chooser the {@link JFileChooser} to use
 * @param filter the file filter
 * @param title the title of the dialog
 * 
 * @return the selected file or null
 */
private String askForPath(JFileChooser chooser, FileFilter filter, String title) {
    chooser.setDialogTitle(title);
    chooser.setFileFilter(filter);
    int returnVal = chooser.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        return chooser.getSelectedFile().getAbsolutePath();
    }

    return null;
}

From source file:pt.lsts.neptus.console.plugins.AirOSPeers.java

public AirOSPeers(ConsoleLayout console) {
    super(console);
    setLayout(new BorderLayout());
    chart = ChartFactory.createTimeSeriesChart(null, "Time of day", "Link Quality", tsc, true, true, true);
    chart.getPlot().setBackgroundPaint(Color.black);
    cpanel = new ChartPanel(chart);
    add(cpanel, BorderLayout.CENTER);
    cpanel.getPopupMenu().add(I18n.text("Load Addresses")).addActionListener(new ActionListener() {
        @Override//from   w ww . j  a v a 2  s . com
        public void actionPerformed(ActionEvent e) {
            try {
                JFileChooser chooser = new JFileChooser();
                chooser.setFileFilter(GuiUtils.getCustomFileFilter("CSV Files", "csv"));
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                int op = chooser.showOpenDialog(AirOSPeers.this);
                if (op == JFileChooser.APPROVE_OPTION)
                    WiFiMacAddresses.parseAddresses(new FileReader(chooser.getSelectedFile()));
            } catch (Exception ex) {
                GuiUtils.errorMessage(getConsole(), ex);
                ex.printStackTrace();
            }
        }
    });
    cpanel.getPopupMenu().addSeparator();
    cpanel.getPopupMenu().add(I18n.text("Clear")).addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tsc.removeAllSeries();
        }
    });
}

From source file:ch.randelshofer.cubetwister.PreferencesTemplatesPanel.java

private void chooseExternalTemplate(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseExternalTemplate
    if (importFileChooser == null) {
        importFileChooser = new JFileChooser();
        importFileChooser.setFileFilter(new ExtensionFileFilter("zip", "Zip Archive"));
        importFileChooser.setSelectedFile(
                new File(userPrefs.get("cubetwister.externalTemplate", "TinyLMS Template.zip")));
        importFileChooser.setApproveButtonText(labels.getString("filechooser.choose"));
    }/*from   w w w.  j ava2s. c  om*/
    if (JFileChooser.APPROVE_OPTION == importFileChooser.showOpenDialog(this)) {
        userPrefs.put("cubetwister.externalHTMLTemplate", importFileChooser.getSelectedFile().getPath());
        //externalTemplateField.setText(
        //      userPrefs.get("cubetwister.externalHTMLTemplate", ""));
    }
}

From source file:eu.novait.imagerenamer.gui.MainWindow.java

protected void addFilesToList() {
    if (chooser == null) {
        chooser = new JFileChooser();
    }//from w w  w .  j  a  v  a  2s.c  om
    chooser.addChoosableFileFilter(new ImageFileFilter());
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(true);
    chooser.setAcceptAllFileFilterUsed(false);
    int returnVal = chooser.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        this.setCurrentState(STATE_LOADING);
        Thread addThread = new Thread(new Runnable() {

            @Override
            public void run() {
                File[] selectedFiles = chooser.getSelectedFiles();
                loaderBar.setMaximum(selectedFiles.length);
                loaderBar.setValue(0);
                for (File f : selectedFiles) {
                    ImageFile imageFile = new ImageFile(f.getAbsolutePath());
                    imageTableModel.addImageToList(imageFile);
                    loaderBar.setValue(loaderBar.getValue() + 1);
                }
                imageTableModel.markAsChanged();
                setCurrentState(STATE_WAITING);
            }
        });
        addThread.start();
    }
}

From source file:utilities.GraphViewer.java

public void actionPerformed(ActionEvent e) {
    // Evenement button parcourir
    if (e.getSource() == this.parcourir) {

        JFileChooser fileopen = new JFileChooser();
        FiltreSimple filter = new FiltreSimple("Fichier res", "res");
        fileopen.addChoosableFileFilter(filter);
        int ret = fileopen.showDialog(null, "Open file");
        if (ret == JFileChooser.APPROVE_OPTION) {
            File file = fileopen.getSelectedFile();
            System.out.println(file.getPath());
            this.addSensor(file.getPath());

        }/*w ww. j  a  va 2  s. c  o m*/

    } else {

        JCheckBox check;
        for (int i = 0; i < this.sensors.size(); i++) {
            check = sensors.get(i);
            if (e.getSource() == check) {
                if (check.isSelected()) {
                    if (!this.isExist(check)) {
                        String s = check.getText();
                        s = s.substring(1);
                        ajouterFichier(this.db.getPath(check.getText()));
                        sensors1.addLast(check);
                        this.graphe.revalidate();
                    }

                } else {
                    this.removeSerie(check.getText());
                    sensors1.remove(check);
                    this.graphe.revalidate();

                }
                break;
            }
        }

    }

}

From source file:com.jtk.medicalrecord.view.panel.InputMedrecPemeriksaanpendukung.java

private void btnTambahActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTambahActionPerformed
    if (view) {/*from w w  w.  j a  va2 s  . c  o m*/
        download();
    } else {
        JFileChooser fileChooser = new JFileChooser();
        int result = fileChooser.showOpenDialog(null);
        if (result == JFileChooser.APPROVE_OPTION) {
            String url = fileChooser.getSelectedFile().getAbsolutePath();
            try {
                InputStream is = new FileInputStream(new File(url));
                String tipeFile = FilenameUtils.getExtension(url);
                String namaFile = FilenameUtils.getBaseName(url);

                PemeriksaanPendukung pp = new PemeriksaanPendukung();
                pp.setPemId(UUID.randomUUID().toString().replace("-", ""));
                pp.setPemNmFile(namaFile);
                pp.setPemTipeFile(tipeFile);
                pp.setPemFile(IOUtils.toByteArray(is));

                pemeriksaanPendukungs.add(pp);

                createTableValue();
            } catch (FileNotFoundException ex) {
                MessageHelper.addErrorMessage("Error add file", ex.getMessage());
                Logger.getLogger(InputMedrecPemeriksaanpendukung.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                MessageHelper.addErrorMessage("Error add file", ex.getMessage());
                Logger.getLogger(InputMedrecPemeriksaanpendukung.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

From source file:de.tntinteractive.portalsammler.gui.DocumentTable.java

private boolean exportDocument(final JFileChooser chooser, final int row) {
    try {/*from w w w  .  j  av a2  s  . co m*/
        final DocumentInfo di = this.getDocumentInRow(row);
        final byte[] content = this.store.getDocument(di);

        chooser.setSelectedFile(new File(this.makeFilenameFor(di)));
        final int result = chooser.showSaveDialog(this.table);
        if (result != JFileChooser.APPROVE_OPTION) {
            return true;
        }

        FileUtils.writeByteArrayToFile(chooser.getSelectedFile(), content);
        this.store.markAsRead(di);
        this.store.writeMetadata();
    } catch (final GeneralSecurityException e) {
        this.gui.showError(e);
    } catch (final IOException e) {
        this.gui.showError(e);
    }
    return false;
}

From source file:edu.uchc.octane.OctanePlugin.java

@Override
public void run(String cmd) {

    if (!IJ.isJava16()) {

        IJ.error("Octane requires Java version 1.6 or higher. Please upgrade the JVM.");
        return;// w  w w .j av  a  2  s .c  o  m

    }

    try {

        Class.forName("org.apache.commons.math3.util.FastMath");

    } catch (ClassNotFoundException e) {

        IJ.error("This version of Octane requires Apache Commons Math v3.0 or later. Please install.");
        return;
    }

    imp_ = WindowManager.getCurrentImage();

    if (imp_ == null || imp_.getStack().getSize() < 2) {

        IJ.error("This only works on an opened image stack.");
        return;

    }

    FileInfo fi = imp_.getOriginalFileInfo();
    String path;

    if (fi != null) {

        path = fi.directory;

    } else {

        IJ.error("Can't find image's disk location. You must save the data on disk first.");
        return;

    }

    if (dict_.containsKey(imp_)) { // window already open

        OctanePlugin plugin = dict_.get(imp_);

        if (plugin != null && cmd.equals("load")) {

            plugin.ctl_.getWindow().setVisible(true);
            return;

        } else {

            // do nothing

        }
    }

    if (cmd.startsWith("analyze")) {

        if (startImageAnalysis(cmd)) { // wasOked?

            SmNode[][] nodes = dlg_.processAllFrames();

            if (TrackingParameters.openDialog(dlg_.pixelSize_)) { //wasOKed ?

                TrajDataset data = TrajDataset.createDatasetFromNodes(nodes);
                data.setPixelSize(dlg_.pixelSize_);

                ctl_ = new OctaneWindowControl(imp_);

                String filename = ctl_.defaultSaveFilename();
                File file = new File(filename);

                if (file.exists()) {

                    int idx = 1;
                    File newFile;

                    do {

                        String backupName = filename + ".b" + idx;
                        newFile = new File(backupName);

                        idx++;

                    } while (newFile.exists());

                    if (!file.renameTo(newFile)) {

                        IJ.error("Problem renaming old dataset file");
                        return;

                    }

                }

                openWindow(data);

                ctl_.saveDataset();

                return;
            }
        }

        dict_.remove(imp_);
    }

    if (cmd.startsWith("calibration")) {

        startImageAnalysis(cmd);
        dict_.remove(imp_);

    }

    if (cmd.equals("load")) {

        assert (path != null);

        File file = new File(path + File.separator + imp_.getTitle() + ".dataset");

        if (file.exists()) {

            try {

                ctl_ = new OctaneWindowControl(imp_);

                openWindow(readDataset(file));

            } catch (IOException e) {

                IJ.error("An IO error occured reading file: " + file.getName() + "\n "
                        + e.getLocalizedMessage());

            } catch (ClassNotFoundException e) {

                IJ.error("Can't recognize the file format: " + file.getName() + "\n" + e.getLocalizedMessage());

            }
        } else {

            IJ.error("Can't find previous analysis results."
                    + " It needs to be saved in the same folder as your image data.");

        }

        return;

    }

    if (cmd.equals("import")) {

        JFileChooser fc = new JFileChooser();

        if (fc.showOpenDialog(IJ.getApplet()) == JFileChooser.APPROVE_OPTION) {
            try {

                ctl_ = new OctaneWindowControl(imp_);

                openWindow(TrajDataset.importDatasetFromText(fc.getSelectedFile()));

                ctl_.saveDataset();

            } catch (IOException e) {

                IJ.error("An IO error occured reading file: " + fc.getSelectedFile().getName());
                return;
            }
        }

        return;
    }
}