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:pi.bestdeal.gui.InterfacePrincipale.java

private void ButtonRapportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonRapportActionPerformed
    int idd = (int) jTable3.getModel().getValueAt(jTable3.getSelectedRow(), 0);
    String pattern = null;/*w ww .java 2  s  .  co  m*/
    String path;
    FileNameExtensionFilter filter = new FileNameExtensionFilter("JASPER files", "jasper");
    JFileChooser chooser = new JFileChooser();
    chooser.setFileFilter(filter);
    int returnVal = chooser.showOpenDialog(this);
    chooser.setMultiSelectionEnabled(false);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        pattern = chooser.getSelectedFile().getPath();
    }
    FileNameExtensionFilter filterpath = new FileNameExtensionFilter("PDF files", "pdf");
    JFileChooser chooserpath = new JFileChooser();
    chooserpath.setFileFilter(filterpath);
    int returnSave = chooserpath.showSaveDialog(this);
    if (returnSave == JFileChooser.APPROVE_OPTION) {
        path = chooserpath.getSelectedFile().getPath();

        if (!path.contains("pdf")) {
            path = path + ".pdf";
            String a = "\\";
        }
        pattern = pattern.replace("\\", "\\" + "\\");
        path = path.replace("\\", "\\" + "\\");

        ReportCreator creator = new ReportCreator();
        int a = creator.CreateReportDeal(pattern, idd, path);
        if (a == 1) {
            File file = new File(path.toString());
            try {
                Desktop.getDesktop().open(file);
            } catch (IOException ex) {
                Logger.getLogger(InterfacePrincipale.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

From source file:com.tiempometa.muestradatos.JMuestraDatos.java

private void exportTagsMenuItemActionPerformed(ActionEvent e) {
    JFileChooser fc = new JFileChooser();
    int response = fc.showSaveDialog(this);
    if (response == JFileChooser.APPROVE_OPTION) {
        TagExcelExporter exporter = new TagExcelExporter();
        try {/* w  w w .  java  2s . c o  m*/
            exporter.open(fc.getSelectedFile());
            List<Rfid> rfidList = rfidDao.findAll();
            exporter.export(rfidList);
            JOptionPane.showMessageDialog(this, "Se exportaron los tags con xito", "Exportar Tags",
                    JOptionPane.PLAIN_MESSAGE);
        } catch (IOException e1) {
            JOptionPane.showMessageDialog(this, "Error exportando " + e1.getMessage(), "Exportar Tags",
                    JOptionPane.ERROR_MESSAGE);
        } catch (SQLException e1) {
            JOptionPane.showMessageDialog(this, "Error exportando " + e1.getMessage(), "Exportar Tags",
                    JOptionPane.ERROR_MESSAGE);
        } catch (RowsExceededException e1) {
            JOptionPane.showMessageDialog(this, "Error exportando " + e1.getMessage(), "Exportar Tags",
                    JOptionPane.ERROR_MESSAGE);
        } catch (WriteException e1) {
            JOptionPane.showMessageDialog(this, "Error exportando " + e1.getMessage(), "Exportar Tags",
                    JOptionPane.ERROR_MESSAGE);
        }

    }
}

From source file:io.heming.accountbook.ui.MainFrame.java

private void exportRecords() {
    final JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.addChoosableFileFilter(new AbbFileFilter());
    chooser.setAcceptAllFileFilterUsed(false);
    int value = chooser.showSaveDialog(this);
    if (value == JFileChooser.APPROVE_OPTION) {
        final File file = chooser.getSelectedFile();
        disableAllControls();/*from w ww  . j ava 2 s.c o  m*/
        new Thread() {
            @Override
            public void run() {
                try {
                    statusLabel.setIcon(new ImageIcon(getClass().getResource("loader.gif")));
                    setStatusText("?...");
                    FacadeUtil.shutdown();
                    // .abb?
                    setStatusText("?...");
                    List<String> exclusion = Arrays.asList();
                    if (!file.getName().endsWith(".abb")) {
                        ZIPUtil.compress(new File(Constants.DATA_DIR),
                                new File(file.getAbsolutePath() + ".abb"), exclusion);
                    } else {
                        ZIPUtil.compress(new File(Constants.DATA_DIR), file, exclusion);
                    }
                    setStatusText("??...");
                    FacadeUtil.restart();
                    enableAllControls();
                    setStatusText("");
                    statusLabel.setIcon(new ImageIcon(getClass().getResource("stopped-loader.png")));
                    JOptionPane.showMessageDialog(MainFrame.this, String.format("?"), "?",
                            JOptionPane.INFORMATION_MESSAGE);
                } catch (IOException e) {
                    JOptionPane.showMessageDialog(MainFrame.this, String.format(""), "",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        }.start();
    }
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.AngleDirectController.java

/**
 *
 * @throws IOException//from  www . j  a  v a  2 s  .co m
 */
private void createPdf(JFreeChart chart) 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);
    chooseDirectory.setSelectedFile(new File("chart rose plot" + ".pdf"));
    // in response to the button click, show open dialog
    int returnVal = chooseDirectory.showSaveDialog(angleDirectPanel);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File directory = chooseDirectory.getCurrentDirectory();
        PdfSwingWorker pdfSwingWorker = new PdfSwingWorker(directory,
                chooseDirectory.getSelectedFile().getName(), chart);
        pdfSwingWorker.execute();
    } else {
        singleCellPreProcessingController.showMessage("Open command cancelled by user", "",
                JOptionPane.INFORMATION_MESSAGE);
    }
}

From source file:SciTK.Plot.java

/** 
* Save displayed chart as vector graphics 
*///from w  w w .ja  v a 2 s  .  co m
public void saveVectorGraphics() {
    Rectangle r = chart_panel.getBounds(); // get size of chart

    // file selection:
    JFileChooser fc = new JFileChooser();
    fc.addChoosableFileFilter(new ExtensionFileFilter("SVG", new String[] { "svg,SVG" }));
    fc.addChoosableFileFilter(new ExtensionFileFilter("PS", new String[] { "ps,PS" }));
    fc.addChoosableFileFilter(new ExtensionFileFilter("EPS", new String[] { "eps,EPS" }));
    // remove default option:
    fc.setAcceptAllFileFilterUsed(false);

    // Select a file using the JFileChooser dialog:
    int fc_return = fc.showSaveDialog(Plot.this);

    // if the user actually wants to save:
    if (fc_return == JFileChooser.APPROVE_OPTION) {
        //get the file:
        File save_file = fc.getSelectedFile();
        // and the type of extension (from file chooser)
        String extension = fc.getFileFilter().getDescription();
        try // try/catch for IO errors
        {
            // For each type of extension, check to see if the name includes the
            // correct extension and then save the image to file.
            // Default extension is EPS
            if (extension == "SVG") {
                // sanity check extension:
                if (!save_file.getName().endsWith(".svg") && !save_file.getName().endsWith(".SVG"))
                    save_file = new File(save_file.getAbsolutePath() + ".svg");
                exportChartAsSVG(chart, r, save_file);
            } else if (extension == "PS") {
                // sanity check extension:
                if (!save_file.getName().endsWith(".ps") && !save_file.getName().endsWith(".PS"))
                    save_file = new File(save_file.getAbsolutePath() + ".ps");
                exportChartAsPS(chart, r, save_file, "ps");
            } else {
                // sanity check extension:
                if (!save_file.getName().endsWith(".eps") && !save_file.getName().endsWith(".EPS"))
                    save_file = new File(save_file.getAbsolutePath() + ".eps");
                exportChartAsPS(chart, r, save_file, "eps");
            }
        } catch (IOException e) {
            DialogError emsg = new DialogError(this, " There was an error saving the file."
                    + System.getProperty("line.separator") + e.getMessage());
        }
    }
}

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

@Nullable
@Override/*from   www  .  ja va  2  s  . 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";
                }/*  w  w w .  java 2  s .  c om*/
                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:au.org.ala.delta.editor.DeltaEditor.java

public File selectFile(boolean open) {
    File selectedFile = null;//w w w. j  a  v a2s.c  om
    JFileChooser chooser = new JFileChooser();

    if (_lastDirectory != null) {
        chooser.setCurrentDirectory(_lastDirectory);
    }

    chooser.setFileFilter(new FileNameExtensionFilter("Delta Editor files *.dlt", DELTA_FILE_EXTENSION));
    int dialogResult;
    if (open) {
        dialogResult = chooser.showOpenDialog(getMainFrame());
    } else {
        dialogResult = chooser.showSaveDialog(getMainFrame());
    }
    if (dialogResult == JFileChooser.APPROVE_OPTION) {
        selectedFile = chooser.getSelectedFile();
        _lastDirectory = chooser.getCurrentDirectory();
    }
    return selectedFile;
}

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   w  w  w  .ja v  a  2s  . 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:ca.osmcanada.osvuploadr.JPMain.java

private void jbAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAddActionPerformed
    try {/*ww w . j a  va  2 s  .c  om*/
        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) {
    }
}