Example usage for javax.swing JFileChooser showSaveDialog

List of usage examples for javax.swing JFileChooser showSaveDialog

Introduction

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

Prototype

public int showSaveDialog(Component parent) throws HeadlessException 

Source Link

Document

Pops up a "Save File" file chooser dialog.

Usage

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

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

        @Override//ww  w  .j  a v a  2s .c  o m
        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:org.owasp.webscarab.plugin.sessionid.swing.SessionIDPanel.java

private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed
    if (_key == null) {
        JOptionPane.showMessageDialog(null, "Please select the Session ID to export, using the drop down list",
                "Error", JOptionPane.ERROR_MESSAGE);
        return;/*from   ww w .ja  v a  2 s.c  om*/
    }
    JFileChooser jfc = new JFileChooser(Preferences.getPreference("WebScarab.DefaultDirectory"));
    jfc.setDialogTitle("Select a directory to write the sessionids into");
    int returnVal = jfc.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        final File file = jfc.getSelectedFile();
        try {
            _sa.exportIDSToCSV(_key, file);
        } catch (IOException ioe) {
            JOptionPane.showMessageDialog(null,
                    new String[] { "Error exporting session identifiers", ioe.getMessage() }, "Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
    File dir = jfc.getCurrentDirectory();
    if (dir != null)
        Preferences.setPreference("WebScarab.DefaultDirectory", dir.getAbsolutePath());
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.GenericDoseResponseController.java

/**
 * Ask user to choose for a directory and invoke swing worker for creating
 * PDF report/*from  w  w w .  j a  v a2s .c om*/
 *
 * @throws IOException
 */
protected void createPdfReport() throws IOException {
    // choose directory to save pdf file
    JFileChooser chooseDirectory = new JFileChooser();
    chooseDirectory.setDialogTitle("Choose a directory to save the report");
    chooseDirectory.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    //        needs more information
    chooseDirectory.setSelectedFile(
            new File("Dose Response Report " + importedDRDataHolder.getExperimentNumber() + ".pdf"));
    // in response to the button click, show open dialog
    //        TEST WHETHER THIS PARENT PANEL/FRAME IS OKAY
    int returnVal = chooseDirectory.showSaveDialog(cellMissyController.getCellMissyFrame());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File directory = chooseDirectory.getCurrentDirectory();
        DoseResponseReportSwingWorker doseResponseReportSwingWorker = new DoseResponseReportSwingWorker(
                directory, chooseDirectory.getSelectedFile().getName());
        doseResponseReportSwingWorker.execute();
    } else {
        cellMissyController.showMessage("Open command cancelled by user", "", JOptionPane.INFORMATION_MESSAGE);
    }
}

From source file:de.bfs.radon.omsimulation.gui.OMPanelData.java

/**
 * Initialises the interface of the data panel.
 *///w  ww .j  a v a2 s.  c o m
protected void initialize() {
    setLayout(null);

    lblExportChartTo = new JLabel("Export chart to ...");
    lblExportChartTo.setBounds(436, 479, 144, 14);
    lblExportChartTo.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    lblExportChartTo.setVisible(false);
    add(lblExportChartTo);

    btnCsv = new JButton("CSV");
    btnCsv.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.csv", "csv"));
            fileDialog.showSaveDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String csv;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("csv")) {
                    csv = "";
                } else {
                    csv = ".csv";
                }
                String csvPath = file.getAbsolutePath() + csv;
                OMRoom selectedRoom = (OMRoom) comboBoxRooms.getSelectedItem();
                double[] selectedValues = selectedRoom.getValues();
                File csvFile = new File(csvPath);
                try {
                    FileWriter logWriter = new FileWriter(csvFile);
                    BufferedWriter csvOutput = new BufferedWriter(logWriter);
                    csvOutput.write("\"ID\";\"" + selectedRoom.getId() + "\"");
                    csvOutput.newLine();
                    for (int i = 0; i < selectedValues.length; i++) {
                        csvOutput.write("\"" + i + "\";\"" + (int) selectedValues[i] + "\"");
                        csvOutput.newLine();
                    }
                    JOptionPane.showMessageDialog(null, "CSV saved successfully!\n" + csvPath, "Success",
                            JOptionPane.INFORMATION_MESSAGE);
                    csvOutput.close();
                } catch (IOException ioe) {
                    JOptionPane.showMessageDialog(null,
                            "Failed to write CSV. Please check permissions!\n" + ioe.getMessage(), "Failed",
                            JOptionPane.ERROR_MESSAGE);
                    ioe.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check the file path!",
                        "Failed", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    btnCsv.setBounds(590, 475, 70, 23);
    btnCsv.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnCsv.setVisible(false);
    add(btnCsv);

    btnPdf = new JButton("PDF");
    btnPdf.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.pdf", "pdf"));
            fileDialog.showSaveDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String pdf;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("pdf")) {
                    pdf = "";
                } else {
                    pdf = ".pdf";
                }
                String pdfPath = file.getAbsolutePath() + pdf;
                OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem();
                String title = building.getName();
                OMRoom selectedRoom = (OMRoom) comboBoxRooms.getSelectedItem();
                JFreeChart chart = OMCharts.createRoomChart(title, selectedRoom, false);
                int height = (int) PageSize.A4.getWidth();
                int width = (int) PageSize.A4.getHeight();
                try {
                    OMExports.exportPdf(pdfPath, chart, width, height, new DefaultFontMapper(), title);
                    JOptionPane.showMessageDialog(null, "PDF saved successfully!\n" + pdfPath, "Success",
                            JOptionPane.INFORMATION_MESSAGE);
                } catch (IOException ioe) {
                    JOptionPane.showMessageDialog(null,
                            "Failed to write PDF. Please check permissions!\n" + ioe.getMessage(), "Failed",
                            JOptionPane.ERROR_MESSAGE);
                    ioe.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check the file path!",
                        "Failed", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    btnPdf.setBounds(670, 475, 70, 23);
    btnPdf.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnPdf.setVisible(false);
    add(btnPdf);

    lblSelectProject = new JLabel("Select Project");
    lblSelectProject.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    lblSelectProject.setBounds(10, 65, 132, 14);
    add(lblSelectProject);

    lblSelectRoom = new JLabel("Select Room");
    lblSelectRoom.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    lblSelectRoom.setBounds(10, 94, 132, 14);
    add(lblSelectRoom);

    panelData = new JPanel();
    panelData.setBounds(10, 118, 730, 347);
    add(panelData);

    btnRefresh = new JButton("Load");
    btnRefresh.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnRefresh.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (txtOmbFile.getText() != null && !txtOmbFile.getText().equals("")
                    && !txtOmbFile.getText().equals(" ")) {
                txtOmbFile.setBackground(Color.WHITE);
                String ombPath = txtOmbFile.getText();
                String omb;
                String[] tmpFileName = ombPath.split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("omb")) {
                    omb = "";
                } else {
                    omb = ".omb";
                }
                txtOmbFile.setText(ombPath + omb);
                setOmbFile(ombPath + omb);
                File ombFile = new File(ombPath + omb);
                if (ombFile.exists()) {
                    txtOmbFile.setBackground(Color.WHITE);
                    btnRefresh.setEnabled(false);
                    comboBoxProjects.setEnabled(false);
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    btnPdf.setVisible(false);
                    btnCsv.setVisible(false);
                    lblExportChartTo.setVisible(false);
                    progressBar.setVisible(true);
                    progressBar.setStringPainted(true);
                    progressBar.setIndeterminate(true);
                    refreshProjectsTask = new RefreshProjects();
                    refreshProjectsTask.execute();
                } else {
                    txtOmbFile.setBackground(new Color(255, 222, 222, 128));
                    JOptionPane.showMessageDialog(null, "OMB-file not found, please check the file path!",
                            "Error", JOptionPane.ERROR_MESSAGE);
                }
            } else {
                txtOmbFile.setBackground(new Color(255, 222, 222, 128));
                JOptionPane.showMessageDialog(null, "Please select an OMB-file!", "Warning",
                        JOptionPane.WARNING_MESSAGE);
            }
        }
    });
    btnRefresh.setBounds(616, 61, 124, 23);
    add(btnRefresh);

    btnMaximize = new JButton("Fullscreen");
    btnMaximize.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnMaximize.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (comboBoxRooms.isEnabled()) {
                if (comboBoxRooms.getSelectedItem() != null) {
                    OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem();
                    String title = building.getName();
                    OMRoom room = (OMRoom) comboBoxRooms.getSelectedItem();
                    panelRoom = createRoomPanel(title, room, false, false);
                    JFrame chartFrame = new JFrame();
                    JPanel chartPanel = createRoomPanel(title, room, false, true);
                    chartFrame.getContentPane().add(chartPanel);
                    chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                    chartFrame.setBounds(0, 0, (int) dim.getWidth(), (int) dim.getHeight());
                    chartFrame.setTitle("OM Simulation Tool: " + title + ", Room " + room.getId());
                    chartFrame.setResizable(true);
                    chartFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
                    chartFrame.setVisible(true);
                }
            }
        }
    });
    btnMaximize.setBounds(10, 475, 124, 23);
    btnMaximize.setVisible(false);
    add(btnMaximize);

    comboBoxProjects = new JComboBox<OMBuilding>();
    comboBoxProjects.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    comboBoxProjects.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            boolean b = false;
            Color c = null;
            if (comboBoxProjects.isEnabled()) {
                if (comboBoxProjects.getSelectedItem() != null) {
                    b = true;
                    c = Color.WHITE;
                    OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem();
                    comboBoxRooms.removeAllItems();
                    for (int i = 0; i < building.getRooms().length; i++) {
                        comboBoxRooms.addItem(building.getRooms()[i]);
                    }
                    for (int i = 0; i < building.getCellars().length; i++) {
                        comboBoxRooms.addItem(building.getCellars()[i]);
                    }
                    for (int i = 0; i < building.getMiscs().length; i++) {
                        comboBoxRooms.addItem(building.getMiscs()[i]);
                    }
                } else {
                    b = false;
                    c = null;
                }
            } else {
                b = false;
                c = null;
            }
            lblSelectRoom.setEnabled(b);
            panelData.setEnabled(b);
            btnMaximize.setVisible(b);
            comboBoxRooms.setEnabled(b);
            panelData.setBackground(c);
        }
    });
    comboBoxProjects.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            boolean b = false;
            Color c = null;
            if (comboBoxProjects.isEnabled()) {
                if (comboBoxProjects.getSelectedItem() != null) {
                    b = true;
                    c = Color.WHITE;
                    OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem();
                    comboBoxRooms.removeAllItems();
                    for (int i = 0; i < building.getRooms().length; i++) {
                        comboBoxRooms.addItem(building.getRooms()[i]);
                    }
                    for (int i = 0; i < building.getCellars().length; i++) {
                        comboBoxRooms.addItem(building.getCellars()[i]);
                    }
                    for (int i = 0; i < building.getMiscs().length; i++) {
                        comboBoxRooms.addItem(building.getMiscs()[i]);
                    }
                } else {
                    b = false;
                    c = null;
                }
            } else {
                b = false;
                c = null;
            }
            lblSelectRoom.setEnabled(b);
            panelData.setEnabled(b);
            btnMaximize.setVisible(b);
            comboBoxRooms.setEnabled(b);
            panelData.setBackground(c);
        }
    });
    comboBoxProjects.setBounds(152, 61, 454, 22);
    add(comboBoxProjects);

    comboBoxRooms = new JComboBox<OMRoom>();
    comboBoxRooms.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    comboBoxRooms.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (comboBoxRooms.isEnabled()) {
                if (comboBoxRooms.getSelectedItem() != null) {
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    remove(panelData);
                    comboBoxRooms.setEnabled(false);
                    refreshChartsTask = new RefreshCharts();
                    refreshChartsTask.execute();
                }
            }
        }
    });
    comboBoxRooms.setBounds(152, 90, 454, 22);
    add(comboBoxRooms);

    progressBar = new JProgressBar();
    progressBar.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    progressBar.setBounds(10, 475, 730, 23);
    progressBar.setVisible(false);
    add(progressBar);

    lblSelectRoom.setEnabled(false);
    panelData.setEnabled(false);
    comboBoxRooms.setEnabled(false);

    lblHelp = new JLabel(
            "Select an OMB-Object file to analyse its data. You can inspect radon concentration for each room.");
    lblHelp.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    lblHelp.setForeground(Color.GRAY);
    lblHelp.setBounds(10, 10, 730, 14);
    add(lblHelp);

    txtOmbFile = new JTextField();
    txtOmbFile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    txtOmbFile.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent arg0) {
            setOmbFile(txtOmbFile.getText());
        }
    });
    txtOmbFile.setBounds(152, 33, 454, 20);
    add(txtOmbFile);
    txtOmbFile.setColumns(10);

    btnBrowse = new JButton("Browse");
    btnBrowse.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.omb", "omb"));
            fileDialog.showOpenDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String omb;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("omb")) {
                    omb = "";
                } else {
                    omb = ".omb";
                }
                txtOmbFile.setText(file.getAbsolutePath() + omb);
                setOmbFile(file.getAbsolutePath() + omb);
            }
        }
    });
    btnBrowse.setBounds(616, 32, 124, 23);
    add(btnBrowse);

    lblSelectOmbfile = new JLabel("Select OMB-File");
    lblSelectOmbfile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    lblSelectOmbfile.setBounds(10, 36, 132, 14);
    add(lblSelectOmbfile);
}

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

private void saveReference(boolean mustSupportEvaluation, boolean includeEvaluation)
        throws FileNotFoundException {
    Set<ReferenceFormat> formats = mustSupportEvaluation
            ? ReferenceFormats.REFERENCE_FORMATS.evaluationIncludingFormats
            : ReferenceFormats.REFERENCE_FORMATS.formats;
    formats.retainAll(ReferenceFormats.REFERENCE_FORMATS.writeableFormats);

    ReferenceFormat format = formatChooser(formats);
    if (format == null) {
        return;/*from  ww  w .j a va 2 s .  com*/
    }

    JFileChooser chooser = new JFileChooser("Save reference. Please choose a file.");
    chooser.setCurrentDirectory(frame.defaultDirectory);
    chooser.setFileSelectionMode(
            format.readsDirectory() ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY);
    if (format.getFileExtension() != null) {
        chooser.addChoosableFileFilter(
                new FilesystemFilter(format.getFileExtension(), format.getDescription()));
    } else {
        chooser.setAcceptAllFileFilterUsed(true);
    }

    int returnVal = chooser.showSaveDialog(frame);
    if (returnVal != JFileChooser.APPROVE_OPTION)
        return;
    System.out.print("Saving...");
    format.writeReference(frame.reference, chooser.getSelectedFile(), includeEvaluation);
    //frame.loadPositiveNegativeNT(chooser.getSelectedFile());
    System.out.println("saving finished.");
}

From source file:com.sshtools.common.ui.SshToolsApplicationClientPanel.java

/**
 *
 *
 * @param saveAs//from  w  ww . j  a  va2s . com
 * @param file
 * @param profile
 *
 * @return
 */
public File saveConnection(boolean saveAs, File file, SshToolsConnectionProfile profile) {
    if (profile != null) {
        if ((file == null) || saveAs) {
            String prefsDir = super.getApplication().getApplicationPreferencesDirectory().getAbsolutePath();
            JFileChooser fileDialog = new JFileChooser(prefsDir);

            fileDialog.setFileFilter(connectionFileFilter);

            int ret = fileDialog.showSaveDialog(this);

            if (ret == fileDialog.CANCEL_OPTION) {
                return null;
            }

            file = fileDialog.getSelectedFile();

            if (!file.getName().toLowerCase().endsWith(".xml")) {
                file = new File(file.getAbsolutePath() + ".xml");
            }
        }

        try {
            if (saveAs && file.exists()) {
                if (JOptionPane.showConfirmDialog(this, "File already exists. Are you sure?", "File exists",
                        JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.NO_OPTION) {
                    return null;
                }
            }

            // Check to make sure its valid
            if (file != null) {
                // Save the connection details to file
                log.debug("Saving connection to " + file.getAbsolutePath());
                profile.save(file.getAbsolutePath());

                if (profile == getCurrentConnectionProfile()) {
                    log.debug("Current connection saved, disabling save action.");
                    setNeedSave(false);
                }

                return file;
            } else {
                showExceptionMessage("The file specified is invalid!", "Save Connection");
            }
        } catch (InvalidProfileFileException e) {
            showExceptionMessage(e.getMessage(), "Save Connection");
        }
    }

    return null;
}

From source file:com.peterbochs.sourceleveldebugger.SourceLevelDebugger3.java

private void jButton12ActionPerformed(ActionEvent evt) {
    JFileChooser fc = new JFileChooser();
    int returnVal = fc.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        PeterBochsCommonLib.exportTableModelToExcel(file, this.instructionTable.getModel(),
                "instruction 0x" + this.jInstructionComboBox.getSelectedItem().toString());
    }/*from  ww w. ja  v a  2s.c o  m*/
}

From source file:uk.ac.lkl.cram.ui.ModuleFrame.java

private void exportReport() {
    JFileChooser jfc = new JFileChooser();
    jfc.setAcceptAllFileFilterUsed(false);
    jfc.setDialogTitle("Export CRAM Module");
    FileFilter filter = new FileNameExtensionFilter("Word Document", "docx");
    jfc.setFileFilter(filter);/*from  w  w  w. j  a v a 2  s.co  m*/
    jfc.setSelectedFile(new File(module.getModuleName() + ".docx"));
    //Open the dialog and wait for the user to provide a name for the file
    int returnVal = jfc.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = jfc.getSelectedFile();
        //Add the file extension
        if (!jfc.getSelectedFile().getAbsolutePath().endsWith(".docx")) {
            file = new File(jfc.getSelectedFile() + ".docx");
        }
        try {
            this.setCursor(WAIT);
            Report report = new Report(module);
            report.save(file);
        } catch (Docx4JException ex) {
            LOGGER.log(Level.SEVERE, "Failed to export report", ex);
            JOptionPane.showMessageDialog(this, ex.getLocalizedMessage(), "Failed to export report",
                    JOptionPane.ERROR_MESSAGE);
        } finally {
            this.setCursor(Cursor.getDefaultCursor());
        }
    }
}

From source file:org.nekorp.workflow.desktop.view.ServicioView.java

private void ordenServicioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ordenServicioActionPerformed
    try {//from  w w w. java  2  s .  com
        if (servicioMetaData.isEditado()) {
            this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
            this.aplication.guardaServicio();
            this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
        }
        ParametrosReporteOS param = new ParametrosReporteOS();
        Object[] options = { "Evaluacin", "Presupuesto" };
        int n = javax.swing.JOptionPane.showOptionDialog(mainFrame, "Qu tipo de reporte desea generar?",
                "Tipo de reporte", javax.swing.JOptionPane.YES_NO_OPTION,
                javax.swing.JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
        if (n == javax.swing.JOptionPane.CLOSED_OPTION) {
            return;
        }
        param.setConCosto(!(n == javax.swing.JOptionPane.YES_OPTION));
        JFileChooser chooser = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivo PDF", "pdf");
        chooser.setFileFilter(filter);
        String homePath = System.getProperty("user.home");
        String prefijo;
        if (param.isConCosto()) {
            prefijo = "/Orden-Servicio-presupuesto-";
        } else {
            prefijo = "/Orden-Servicio-evaluacion-";
        }
        File f = new File(
                new File(homePath + prefijo + this.viewServicioModel.getId() + ".pdf").getCanonicalPath());
        chooser.setSelectedFile(f);
        int returnVal = chooser.showSaveDialog(this.mainFrame);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
            param.setDestination(chooser.getSelectedFile());
            this.aplication.generaOrdenServicio(param);
        }
    } catch (IllegalArgumentException e) {
        //no lo guardo por que tenia horribles errores... tambien especializar la excepcion
    } catch (IOException ex) {
        ServicioView.LOGGER.error("error al exportar orden de servicio", ex);
    } finally {
        this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
    }
}

From source file:com._17od.upm.gui.DatabaseActions.java

/**
 * This method prompts the user for the name of a file.
 * If the file exists then it will ask if they want to overwrite (the file isn't overwritten though,
 * that would be done by the calling method)
 * @param title The string title to put on the dialog
 * @return The file to save to or null/*from  w  w  w .ja  v  a 2s  .  c o  m*/
 */
private File getSaveAsFile(String title) {
    File selectedFile;

    boolean gotValidFile = false;
    do {
        JFileChooser fc = new JFileChooser();
        fc.setDialogTitle(title);
        int returnVal = fc.showSaveDialog(mainWindow);

        if (returnVal != JFileChooser.APPROVE_OPTION) {
            return null;
        }

        selectedFile = fc.getSelectedFile();

        //Warn the user if the database file already exists
        if (selectedFile.exists()) {
            Object[] options = { "Yes", "No" };
            int i = JOptionPane.showOptionDialog(mainWindow,
                    Translator.translate("fileAlreadyExistsWithFileName", selectedFile.getAbsolutePath()) + '\n'
                            + Translator.translate("overwrite"),
                    Translator.translate("fileAlreadyExists"), JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
            if (i == JOptionPane.YES_OPTION) {
                gotValidFile = true;
            }
        } else {
            gotValidFile = true;
        }

    } while (!gotValidFile);

    return selectedFile;
}