Example usage for javax.swing JFileChooser getSelectedFile

List of usage examples for javax.swing JFileChooser getSelectedFile

Introduction

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

Prototype

public File getSelectedFile() 

Source Link

Document

Returns the selected file.

Usage

From source file:pl.dpbz.poid.zadanie3.GUI.java

private void savePhaseJButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_savePhaseJButton1ActionPerformed
    try {// w  w w .  jav  a  2  s  .  co m
        // TODO zapis sekwencji na fazie do pliku
        JFileChooser fc = new JFileChooser();
        fc.showSaveDialog(this);
        String path = fc.getSelectedFile().getAbsolutePath();
        path += ".wav";

        Integer[] ints = WaveToSamplesConverter.convertWaveToIntSamples(this.f);
        double samplingFrequency = WaveToSamplesConverter.getSamplingFrequency(this.f);
        System.out.println("Samples overview " + ints.length);

        int samplesPerPart = Integer.parseInt(this.samplesPerPartJTextField1.getText());
        SamplesToWaveConverter conv = new PhaseSpaceSampleConverter(samplingFrequency, samplesPerPart,
                WaveToSamplesConverter.getAudioFormat(f));

        conv.setupFrequenciesFromSamples(ints);
        System.out.println("Zapisuj");

        conv.saveGeneratedSamples(path);
    } catch (IOException ex) {
        Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnsupportedAudioFileException ex) {
        Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:pl.dpbz.poid.zadanie3.GUI.java

private void saveCombJButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveCombJButton1ActionPerformed
    try {// ww w .j  a v a 2s  . c  o  m
        // TODO zapisz sekwencje na grzebieniu
        //Test sekwencji na grzebieniu
        JFileChooser fc = new JFileChooser();
        fc.showSaveDialog(this);
        String path = fc.getSelectedFile().getAbsolutePath();
        path += ".wav";

        Integer[] ints = WaveToSamplesConverter.convertWaveToIntSamples(this.f);
        double samplingFrequency = WaveToSamplesConverter.getSamplingFrequency(this.f);
        System.out.println("Samples overview " + ints.length);

        int samplesPerPart = Integer.parseInt(this.samplesPerPartJTextField1.getText());

        SamplesToWaveConverter conv2 = new CombFilteringSampleConverter(samplingFrequency, samplesPerPart,
                WaveToSamplesConverter.getAudioFormat(f));

        conv2.setupFrequenciesFromSamples(ints);
        System.out.println("Zapisuj");
        conv2.saveGeneratedSamples(path);
    } catch (IOException ex) {
        Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnsupportedAudioFileException ex) {
        Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:gui.InboxPanel.java

private void openDecryptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openDecryptButtonActionPerformed
    // TODO add your handling code here:
    JFileChooser chooser = new JFileChooser();
    int retrieval = chooser.showOpenDialog(null);
    if (retrieval == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        Path path = Paths.get(file.getAbsolutePath());
        try {/*  w  w w  . java 2  s  .c  om*/
            key = Files.readAllBytes(path);
            keyDecryptTextField.setText(key.toString());
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java

private void saveXML() {
    JFileChooser chooser = new JFileChooser("Save evaluation result as alignment XML");
    chooser.setCurrentDirectory(frame.defaultDirectory);
    int returnVal = chooser.showSaveDialog(frame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        if (chooser.getSelectedFile().exists() && (JOptionPane.showConfirmDialog(frame,
                "File already exists. Overwrite?") != JOptionPane.YES_OPTION)) {
            return;
        }//from   w  w  w.  j a  v a 2  s .co  m
        try {
            frame.saveXML(chooser.getSelectedFile(), SaveXMLMode.SAVE_EVERYTHING);
        } catch (JDOMException | IOException e) {
            JOptionPane.showConfirmDialog(frame, e, "Error saving XML", JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:gui.QTLResultsPanel.java

void saveTXT() {
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File(Prefs.gui_dir));
    fc.setDialogTitle("Save QTL Results");

    while (fc.showSaveDialog(MsgBox.frm) == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();

        // Make sure it has an appropriate extension
        if (!file.exists()) {
            if (file.getName().indexOf(".") == -1) {
                file = new File(file.getPath() + ".csv");
            }// www . j  a  va2 s  .  c o m
        }

        // Confirm overwrite
        if (file.exists()) {
            int response = MsgBox.yesnocan(file + " already exists.\nDo " + "you want to replace it?", 1);

            if (response == JOptionPane.NO_OPTION) {
                continue;
            } else if (response == JOptionPane.CANCEL_OPTION || response == JOptionPane.CLOSED_OPTION) {
                return;
            }
        }

        // Otherwise it's ok to save...
        Prefs.gui_dir = "" + fc.getCurrentDirectory();
        saveTXTFile(file);
        return;
    }
}

From source file:jpad.MainEditor.java

public void openFile() {
    if (_isOSX || ostype == ostype.Linux || ostype == ostype.Other) {
        openFile_OSX_Nix();//from   ww  w . ja v a2  s .  c  om
    } else {
        JFileChooser fc = new JFileChooser();
        fc.setDialogTitle("Open a Text File");
        fc.setFileFilter(new FileNameExtensionFilter("Plain Text Files", "txt"));
        int returnval = fc.showOpenDialog(this);
        if (returnval == 0) {
            hasSavedToFile = true;
            hasChanges = false;
            curFile = fc.getSelectedFile().getAbsolutePath();
            try (FileInputStream stream = new FileInputStream(curFile)) {
                String file = IOUtils.toString(stream);
                mainTextArea.setText(file);
                this.setTitle(String.format("JPad - %s", curFile));
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    }
}

From source file:table.TablePanel.java

public String doSaveAs(File f) throws IOException {
    JFileChooser fileChooser = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter("PNG Image Files", "png");
    fileChooser.addChoosableFileFilter(filter);
    fileChooser.setFileFilter(filter);//from ww  w . j  a  v  a2  s . c o  m
    String filename = "";
    int option = fileChooser.showSaveDialog(this.parent);
    if (option == JFileChooser.APPROVE_OPTION) {
        filename = fileChooser.getSelectedFile().getPath();
        if (!filename.endsWith(".png")) {
            filename = filename + ".png";
        }
        saveTableAsPNG(new File(filename), this.table, parent.getWidth(), parent.getHeight());
    }
    return filename;
}

From source file:de.ist.clonto.Ontogui.java

private void loadQuery(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_loadQuery
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File(System.getProperty("user.dir") + "/sparql"));
    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        queryPath = fc.getSelectedFile().toPath();

        smellNameField.setText(fc.getSelectedFile().getName());
    } else {//w  ww  .ja  va  2s .  c  o  m
        JOptionPane.showMessageDialog(this, "Loading query failed");
    }
}

From source file:org.jax.maanova.plot.SaveChartAction.java

/**
 * {@inheritDoc}/*from w  ww  .j  ava  2s.  c om*/
 */
public void actionPerformed(ActionEvent e) {
    JFreeChart myChart = this.chart;
    Dimension mySize = this.size;

    if (myChart == null || mySize == null) {
        LOG.severe("Failed to save graph image because of a null value");
        MessageDialogUtilities.errorLater(Maanova.getInstance().getApplicationFrame(),
                "Internal error: Failed to save graph image.", "Image Save Failed");
    } else {
        // use the remembered starting dir
        MaanovaApplicationConfigurationManager configurationManager = MaanovaApplicationConfigurationManager
                .getInstance();
        JMaanovaApplicationState applicationState = configurationManager.getApplicationState();
        FileType rememberedJaxbImageDir = applicationState.getRecentImageExportDirectory();
        File rememberedImageDir = null;
        if (rememberedJaxbImageDir != null && rememberedJaxbImageDir.getFileName() != null) {
            rememberedImageDir = new File(rememberedJaxbImageDir.getFileName());
        }

        // select the image file to save
        JFileChooser fileChooser = new JFileChooser(rememberedImageDir);
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileChooser.setApproveButtonText("Save Graph");
        fileChooser.setDialogTitle("Save Graph as Image");
        fileChooser.setMultiSelectionEnabled(false);
        fileChooser.addChoosableFileFilter(PngFileFilter.getInstance());
        fileChooser.setFileFilter(PngFileFilter.getInstance());
        int response = fileChooser.showSaveDialog(Maanova.getInstance().getApplicationFrame());
        if (response == JFileChooser.APPROVE_OPTION) {
            File selectedFile = fileChooser.getSelectedFile();

            // tack on the extension if there isn't one
            // already
            if (!PngFileFilter.getInstance().accept(selectedFile)) {
                String newFileName = selectedFile.getName() + "." + PngFileFilter.PNG_EXTENSION;
                selectedFile = new File(selectedFile.getParentFile(), newFileName);
            }

            if (selectedFile.exists()) {
                // ask the user if they're sure they want to overwrite
                String message = "Exporting the graph image to " + selectedFile.getAbsolutePath()
                        + " will overwrite an " + " existing file. Would you like to continue anyway?";
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.fine(message);
                }

                boolean overwriteOk = MessageDialogUtilities
                        .confirmOverwrite(Maanova.getInstance().getApplicationFrame(), selectedFile);
                if (!overwriteOk) {
                    if (LOG.isLoggable(Level.FINE)) {
                        LOG.fine("overwrite canceled");
                    }
                    return;
                }
            }

            try {
                ChartUtilities.saveChartAsPNG(selectedFile, myChart, mySize.width, mySize.height);

                File parentDir = selectedFile.getParentFile();
                if (parentDir != null) {
                    // update the "recent image directory"
                    ObjectFactory objectFactory = new ObjectFactory();
                    FileType latestJaxbImageDir = objectFactory.createFileType();
                    latestJaxbImageDir.setFileName(parentDir.getAbsolutePath());
                    applicationState.setRecentImageExportDirectory(latestJaxbImageDir);
                }
            } catch (Exception ex) {
                LOG.log(Level.SEVERE, "failed to save graph image", ex);
            }
        }
    }
}

From source file:com.litt.core.security.license.gui.ValidatePanel.java

/**
 * Create the panel.//w  ww .ja  va2  s .  c om
 */
public ValidatePanel() {
    GridBagLayout gbl_validatePanel = new GridBagLayout();
    gbl_validatePanel.columnWidths = new int[] { 0, 0, 0 };
    gbl_validatePanel.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    gbl_validatePanel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
    gbl_validatePanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            Double.MIN_VALUE };
    this.setLayout(gbl_validatePanel);

    JLabel label_10 = new JLabel("");
    GridBagConstraints gbc_label_10 = new GridBagConstraints();
    gbc_label_10.insets = new Insets(0, 0, 5, 5);
    gbc_label_10.anchor = GridBagConstraints.EAST;
    gbc_label_10.gridx = 0;
    gbc_label_10.gridy = 0;
    this.add(label_10, gbc_label_10);

    field_pubKeyFilePath = new JTextField();
    field_pubKeyFilePath.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            //fileChooser.setVisible(true);
            LicenseFileFilter fileFilter = new LicenseFileFilter(new String[] { "key" });
            fileChooser.setFileFilter(fileFilter);
            fileChooser.addChoosableFileFilter(fileFilter);
            fileChooser.showOpenDialog(e.getComponent());
            File pubKeyFile = fileChooser.getSelectedFile();

            field_pubKeyFilePath.setText(pubKeyFile.getAbsolutePath());

        }
    });
    GridBagConstraints gbc_field_pubKeyFilePath = new GridBagConstraints();
    gbc_field_pubKeyFilePath.insets = new Insets(0, 0, 5, 0);
    gbc_field_pubKeyFilePath.fill = GridBagConstraints.HORIZONTAL;
    gbc_field_pubKeyFilePath.gridx = 1;
    gbc_field_pubKeyFilePath.gridy = 0;
    this.add(field_pubKeyFilePath, gbc_field_pubKeyFilePath);
    field_pubKeyFilePath.setColumns(10);

    JLabel label_19 = new JLabel("?");
    GridBagConstraints gbc_label_19 = new GridBagConstraints();
    gbc_label_19.anchor = GridBagConstraints.EAST;
    gbc_label_19.insets = new Insets(0, 0, 5, 5);
    gbc_label_19.gridx = 0;
    gbc_label_19.gridy = 1;
    this.add(label_19, gbc_label_19);

    field_licenseFilePath = new JTextField();
    field_licenseFilePath.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            //fileChooser.setVisible(true);
            LicenseFileFilter fileFilter = new LicenseFileFilter(new String[] { "xml" });
            fileChooser.setFileFilter(fileFilter);
            fileChooser.addChoosableFileFilter(fileFilter);
            fileChooser.showOpenDialog(e.getComponent());
            File licenseFile = fileChooser.getSelectedFile();

            field_licenseFilePath.setText(licenseFile.getAbsolutePath());
        }
    });
    GridBagConstraints gbc_textField1 = new GridBagConstraints();
    gbc_textField1.insets = new Insets(0, 0, 5, 0);
    gbc_textField1.fill = GridBagConstraints.HORIZONTAL;
    gbc_textField1.gridx = 1;
    gbc_textField1.gridy = 1;
    this.add(field_licenseFilePath, gbc_textField1);
    field_licenseFilePath.setColumns(10);

    JLabel lblid = new JLabel("?ID");
    lblid.setHorizontalAlignment(SwingConstants.CENTER);
    GridBagConstraints gbc_lblid = new GridBagConstraints();
    gbc_lblid.insets = new Insets(0, 0, 5, 5);
    gbc_lblid.gridx = 0;
    gbc_lblid.gridy = 2;
    this.add(lblid, gbc_lblid);

    label_licenseId = new JLabel("");
    label_licenseId.setHorizontalAlignment(SwingConstants.CENTER);
    GridBagConstraints gbc_label_licenseId = new GridBagConstraints();
    gbc_label_licenseId.insets = new Insets(0, 0, 5, 0);
    gbc_label_licenseId.gridx = 1;
    gbc_label_licenseId.gridy = 2;
    this.add(label_licenseId, gbc_label_licenseId);

    JLabel label_12 = new JLabel("?");
    GridBagConstraints gbc_label_12 = new GridBagConstraints();
    gbc_label_12.insets = new Insets(0, 0, 5, 5);
    gbc_label_12.gridx = 0;
    gbc_label_12.gridy = 3;
    this.add(label_12, gbc_label_12);

    label_licenseType = new JLabel("");
    GridBagConstraints gbc_label_licenseType = new GridBagConstraints();
    gbc_label_licenseType.insets = new Insets(0, 0, 5, 0);
    gbc_label_licenseType.gridx = 1;
    gbc_label_licenseType.gridy = 3;
    this.add(label_licenseType, gbc_label_licenseType);

    JLabel label_13 = new JLabel("???");
    GridBagConstraints gbc_label_13 = new GridBagConstraints();
    gbc_label_13.insets = new Insets(0, 0, 5, 5);
    gbc_label_13.gridx = 0;
    gbc_label_13.gridy = 4;
    this.add(label_13, gbc_label_13);

    label_productName = new JLabel("");
    GridBagConstraints gbc_label_productName = new GridBagConstraints();
    gbc_label_productName.insets = new Insets(0, 0, 5, 0);
    gbc_label_productName.gridx = 1;
    gbc_label_productName.gridy = 4;
    this.add(label_productName, gbc_label_productName);

    JLabel label_14 = new JLabel("???");
    GridBagConstraints gbc_label_14 = new GridBagConstraints();
    gbc_label_14.insets = new Insets(0, 0, 5, 5);
    gbc_label_14.gridx = 0;
    gbc_label_14.gridy = 5;
    this.add(label_14, gbc_label_14);

    label_companyName = new JLabel("");
    GridBagConstraints gbc_label_companyName = new GridBagConstraints();
    gbc_label_companyName.insets = new Insets(0, 0, 5, 0);
    gbc_label_companyName.gridx = 1;
    gbc_label_companyName.gridy = 5;
    this.add(label_companyName, gbc_label_companyName);

    JLabel label_15 = new JLabel("??");
    GridBagConstraints gbc_label_15 = new GridBagConstraints();
    gbc_label_15.insets = new Insets(0, 0, 5, 5);
    gbc_label_15.gridx = 0;
    gbc_label_15.gridy = 6;
    this.add(label_15, gbc_label_15);

    label_customerName = new JLabel("");
    GridBagConstraints gbc_label_customerName = new GridBagConstraints();
    gbc_label_customerName.insets = new Insets(0, 0, 5, 0);
    gbc_label_customerName.gridx = 1;
    gbc_label_customerName.gridy = 6;
    this.add(label_customerName, gbc_label_customerName);

    JLabel label_16 = new JLabel("");
    GridBagConstraints gbc_label_16 = new GridBagConstraints();
    gbc_label_16.insets = new Insets(0, 0, 5, 5);
    gbc_label_16.gridx = 0;
    gbc_label_16.gridy = 7;
    this.add(label_16, gbc_label_16);

    label_version = new JLabel("");
    GridBagConstraints gbc_label_version = new GridBagConstraints();
    gbc_label_version.insets = new Insets(0, 0, 5, 0);
    gbc_label_version.gridx = 1;
    gbc_label_version.gridy = 7;
    this.add(label_version, gbc_label_version);

    JLabel label_11 = new JLabel("");
    GridBagConstraints gbc_label_11 = new GridBagConstraints();
    gbc_label_11.insets = new Insets(0, 0, 5, 5);
    gbc_label_11.gridx = 0;
    gbc_label_11.gridy = 8;
    this.add(label_11, gbc_label_11);

    label_createDate = new JLabel("");
    GridBagConstraints gbc_label_createDate = new GridBagConstraints();
    gbc_label_createDate.insets = new Insets(0, 0, 5, 0);
    gbc_label_createDate.gridx = 1;
    gbc_label_createDate.gridy = 8;
    this.add(label_createDate, gbc_label_createDate);

    JLabel label_17 = new JLabel("");
    GridBagConstraints gbc_label_17 = new GridBagConstraints();
    gbc_label_17.insets = new Insets(0, 0, 5, 5);
    gbc_label_17.gridx = 0;
    gbc_label_17.gridy = 9;
    this.add(label_17, gbc_label_17);

    label_expiredDate = new JLabel("");
    GridBagConstraints gbc_label_expiredDate = new GridBagConstraints();
    gbc_label_expiredDate.insets = new Insets(0, 0, 5, 0);
    gbc_label_expiredDate.gridx = 1;
    gbc_label_expiredDate.gridy = 9;
    this.add(label_expiredDate, gbc_label_expiredDate);

    JButton button_2 = new JButton("");
    button_2.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {

            String licenseFilePath = Utility.trimNull(field_licenseFilePath.getText());
            String pubKeyFilePath = Utility.trimNull(field_pubKeyFilePath.getText());
            if (Utility.isEmpty(licenseFilePath)) {
                JOptionPane.showMessageDialog(e.getComponent(), "?!");
                return;
            }
            if (Utility.isEmpty(pubKeyFilePath)) {
                JOptionPane.showMessageDialog(e.getComponent(), "!");
                return;
            }
            File licenseFile = new File(licenseFilePath);
            try {
                XMLConfiguration config = new XMLConfiguration(licenseFile);
                config.setAutoSave(true);

                label_licenseId.setText(config.getString(("licenseId")));
                label_licenseType.setText(config.getString("licenseType"));
                label_productName.setText(config.getString("productName"));
                label_companyName.setText(config.getString("companyName"));
                label_customerName.setText(config.getString("customerName"));
                label_version.setText(config.getString("version"));
                label_createDate.setText(config.getString("createDate"));
                label_expiredDate.setText(config.getString("expiredDate"));

            } catch (Exception e1) {
                // TODO Auto-generated catch block
                JOptionPane.showMessageDialog(e.getComponent(), e1.getMessage());
            }

            try {
                LicenseManager.validateLicense(licenseFile.getAbsolutePath(), pubKeyFilePath);
                JOptionPane.showMessageDialog(e.getComponent(), "?");
            } catch (LicenseException e1) {
                // TODO Auto-generated catch block
                JOptionPane.showMessageDialog(e.getComponent(), e1.getMessage());
            }

        }
    });
    GridBagConstraints gbc_button_2 = new GridBagConstraints();
    gbc_button_2.gridx = 1;
    gbc_button_2.gridy = 10;
    this.add(button_2, gbc_button_2);
}