Example usage for javax.swing JFileChooser SAVE_DIALOG

List of usage examples for javax.swing JFileChooser SAVE_DIALOG

Introduction

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

Prototype

int SAVE_DIALOG

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

Click Source Link

Document

Type value indicating that the JFileChooser supports a "Save" file operation.

Usage

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);//from   www .  j  a  v a  2  s. c  om

    int result = fc.showDialog(null, null);
    if (result == JFileChooser.CANCEL_OPTION || result == JFileChooser.ERROR_OPTION) {
        return;
    }

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

From source file:org.wandora.application.gui.topicpanels.ProcessingTopicPanel.java

public void saveSketchToFile() {
    File scriptFile = null;//from  w  w w .  j a  v a 2s  . com
    try {
        fc.setDialogTitle("Save Processing sketch");
        fc.setDialogType(JFileChooser.SAVE_DIALOG);
        int answer = fc.showDialog(Wandora.getWandora(), "Save");
        if (answer == SimpleFileChooser.APPROVE_OPTION) {
            scriptFile = fc.getSelectedFile();
            String scriptCode = processingEditor.getText();
            FileUtils.writeStringToFile(scriptFile, scriptCode, null);
            currentSketchSource = FILE_SOURCE;
        }
    } catch (Exception e) {
        WandoraOptionPane.showMessageDialog(Wandora.getWandora(),
                "Exception '" + e.getMessage() + "' occurred while storing Processing sketch to file '"
                        + scriptFile.getName() + "'.",
                "Can't save R script", WandoraOptionPane.INFORMATION_MESSAGE);
    }
}

From source file:org.wandora.application.gui.topicpanels.RTopicPanel.java

private void saveScriptToFile() {
    File scriptFile = null;/*from w  w  w  . j ava2s .  co m*/
    try {
        fc.setDialogTitle("Save R script");
        fc.setDialogType(JFileChooser.SAVE_DIALOG);
        int answer = fc.showDialog(Wandora.getWandora(), "Save");
        if (answer == SimpleFileChooser.APPROVE_OPTION) {
            scriptFile = fc.getSelectedFile();
            String scriptCode = rEditor.getText();
            FileUtils.writeStringToFile(scriptFile, scriptCode, null);
            currentScriptSource = FILE_SOURCE;
        }
    } catch (Exception e) {
        WandoraOptionPane.showMessageDialog(Wandora.getWandora(),
                "Exception '" + e.getMessage() + "' occurred while storing R script to file '"
                        + scriptFile.getName() + "'.",
                "Can't save R script", WandoraOptionPane.INFORMATION_MESSAGE);
    }
}

From source file:tax.MainForm.java

private void printMonthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printMonthActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(" ");
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        String folderName = chooser.getSelectedFile().getAbsolutePath();
        //            System.out.println(folderName);

        try {// ww w  .  j a va2  s  .  c  om
            FileUtils.forceMkdir(new File(folderName + "/" + curYear + "/pdf"));
            Printer.createPdf(
                    folderName + "/" + curYear + "/pdf/" + curMonth + ". " + Util.months[curMonth - 1] + ".pdf",
                    curTable);
        } catch (IOException ex) {
            Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (DocumentException ex) {
            Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
        }

        new Completed("<html> ? ?<br> .</html>")
                .setVisible(true);
    }
}

From source file:tax.MainForm.java

private void excelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_excelActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(" ");
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        String folderName = chooser.getSelectedFile().getAbsolutePath();

        String data[][] = null;//www  . jav a  2  s .  c om
        data = Util.arrayFromTablename(curTable);
        List month = new ArrayList();
        List receipts = new ArrayList();

        month.add(Util.tablenameToDate(curTable));
        Map beans = new HashMap();
        beans.put("month", month);

        for (int i = 0; i < data.length; i++) {
            receipts.add(new Receipt(data[i][0], Float.parseFloat(data[i][1]), data[i][2], data[i][3]));
        }

        beans.put("receipts", receipts);

        XLSTransformer transformer = new XLSTransformer();
        transformer.markAsFixedSizeCollection("month");
        transformer.markAsFixedSizeCollection("receipts");

        try {
            FileUtils.forceMkdir(new File(folderName + "/" + curYear + "/excel"));
            transformer.transformXLS("etc/excel.xls", beans, folderName + "/" + curYear + "/excel/" + curMonth
                    + ". " + Util.months[curMonth - 1] + ".xls");
        } catch (IOException ex) {
            Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParsePropertyException ex) {
            Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidFormatException ex) {
            Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
        }

        new Completed("<html>  ?<br> .</html>")
                .setVisible(true);
    }
}

From source file:tax.MainForm.java

public void printYear(int inYear) {
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(" ");
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        String folderName = chooser.getSelectedFile().getAbsolutePath();
        String output = "\u0009\u0009\u0009\n"
                + "-----------------------------------\n";
        float totalSum = 0;

        Connection c = null;/*  w  w  w.  j  a v  a2s  .  co  m*/
        Statement stmt = null;
        try {
            Class.forName("org.sqlite.JDBC");
            c = DriverManager.getConnection("jdbc:sqlite:etc/tax.sqlite");
            c.setAutoCommit(false);

            stmt = c.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT * FROM main.sqlite_master WHERE type='table';");
            while (rs.next()) {
                String name = rs.getString("name");
                if (!name.startsWith("t"))
                    continue;

                int monthYear[] = new int[2];
                monthYear = Util.tablenameToMonthAndYear(name);
                int month = monthYear[0];
                int year = monthYear[1];

                float monthlySum = 0;

                if (inYear != year)
                    continue;

                String data[][] = null;
                data = Util.arrayFromTablename(name);

                for (int i = 0; i < data.length; i++) {
                    Float price = Float.parseFloat(data[i][1]);
                    monthlySum += price;
                }

                totalSum += monthlySum;
                String sumS = Util.formatSum(monthlySum);

                String tabSpace;
                if (Util.months[month - 1].length() >= 8)
                    tabSpace = "\u0009\u0009";
                else
                    tabSpace = "\u0009\u0009\u0009";

                output += Util.months[month - 1] + tabSpace + sumS + "\n";

                try {
                    FileUtils.forceMkdir(new File(folderName + "/" + year + "/pdf"));
                    Printer.createPdf(
                            folderName + "/" + year + "/pdf/" + month + ". " + Util.months[month - 1] + ".pdf",
                            name);
                } catch (IOException ex) {
                    Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
                } catch (DocumentException ex) {
                    Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

            output += "-----------------------------------\n" + "?\u0009\u0009\u0009"
                    + Util.formatSum(totalSum) + "\n";

            FileUtils.write(new File(folderName + "/" + inYear + "/?.txt"), output, "UTF-8");

            rs.close();
            stmt.close();
            c.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(0);
        }

        new Completed("<html> ? ?<br> .</html>")
                .setVisible(true);
    }
}

From source file:tax.MainForm.java

public void exportExcelYear(int inYear) {
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(" ");
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        String folderName = chooser.getSelectedFile().getAbsolutePath();
        String output = "\u0009\u0009\u0009\n"
                + "-----------------------------------\n";
        float totalSum = 0;

        Connection c = null;/*from  w  w w. ja va  2 s.  c  om*/
        Statement stmt = null;
        try {
            Class.forName("org.sqlite.JDBC");
            c = DriverManager.getConnection("jdbc:sqlite:etc/tax.sqlite");
            c.setAutoCommit(false);

            stmt = c.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT * FROM main.sqlite_master WHERE type='table';");

            while (rs.next()) {
                String name = rs.getString("name");
                if (!name.startsWith("t"))
                    continue;

                int monthYear[] = new int[2];
                monthYear = Util.tablenameToMonthAndYear(name);
                int month = monthYear[0];
                int year = monthYear[1];

                float monthlySum = 0;

                if (inYear != year)
                    continue;

                String data[][] = null;
                data = Util.arrayFromTablename(name);
                List monthL = new ArrayList();
                List receipts = new ArrayList();

                monthL.add(Util.tablenameToDate(name));
                Map beans = new HashMap();
                beans.put("month", monthL);

                for (int i = 0; i < data.length; i++) {
                    Float price = Float.parseFloat(data[i][1]);
                    receipts.add(new Receipt(data[i][0], price, data[i][2], data[i][3]));
                    monthlySum += price;
                }

                totalSum += monthlySum;
                String sumS = Util.formatSum(monthlySum);

                String tabSpace;
                if (Util.months[month - 1].length() >= 8)
                    tabSpace = "\u0009\u0009";
                else
                    tabSpace = "\u0009\u0009\u0009";

                output += Util.months[month - 1] + tabSpace + sumS + "\n";

                beans.put("receipts", receipts);

                XLSTransformer transformer = new XLSTransformer();
                transformer.markAsFixedSizeCollection("month");
                transformer.markAsFixedSizeCollection("receipts");

                try {
                    FileUtils.forceMkdir(new File(folderName + "/" + year + "/excel"));
                    transformer.transformXLS("etc/excel.xls", beans, folderName + "/" + year + "/excel/" + month
                            + ". " + Util.months[month - 1] + ".xls");
                } catch (IOException ex) {
                    Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ParsePropertyException ex) {
                    Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
                } catch (InvalidFormatException ex) {
                    Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

            output += "-----------------------------------\n" + "?\u0009\u0009\u0009"
                    + Util.formatSum(totalSum) + "\n";

            FileUtils.write(new File(folderName + "/" + inYear + "/?.txt"), output, "UTF-8");

            rs.close();
            stmt.close();
            c.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(0);
        }

        new Completed("<html>  ?<br> .</html>")
                .setVisible(true);
    }
}

From source file:terminotpad.MainFrame.java

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
    // TODO add your handling code here:
    String content;// ww  w  . j  a  v  a 2 s .  c  o m
    String destFile;
    int ext = 0;
    content = rSyntax.getText();
    //    destFile = "src/doc/test.txt";
    while (ext == 0) {
        JFileChooser dlg = new JFileChooser();
        dlg.addChoosableFileFilter(new MessageFilter());
        dlg.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
        dlg.setDialogTitle("Enregistrer sous ...");
        int ret = dlg.showOpenDialog(this);
        File fileReturn;
        // Traite le contenu du fichier
        if (ret == JFileChooser.APPROVE_OPTION) {
            fileReturn = dlg.getSelectedFile();
            destFile = fileReturn.toString();
            System.out.println(destFile);
            Fichier file = new Fichier(destFile, content);
            file.fileWrite();

            String reg = "[.][a-zA-Z0-9]{3}$";
            if (file.getExtend().matches(reg)) {
                ext = 1;
            }
            localFile.setFile(file.getFile());
        }
    }
}

From source file:weka.knowledgeflow.steps.TimeSeriesForecasting.java

/**
 * Set the name of the file to save the forecasting model out to if the user
 * has opted to rebuild the forecaster using the incoming data.
 *
 * @param fileName the file name to save to.
 *//*from w ww  .  ja v a  2s.  com*/
@FilePropertyMetadata(fileChooserDialogType = JFileChooser.SAVE_DIALOG, directoriesOnly = false)
@OptionMetadata(displayName = "File to save forecaster to", description = "File to save forecaster to (only applies when rebuilding forecaster)", displayOrder = 4)
public void setSaveFilename(File fileName) {
    m_saveFileName = fileName;
}

From source file:wsattacker.sso.openid.attacker.gui.MainGui.java

/**
 * This method is called from within the constructor to
 * initialize the form.//w  ww  . ja  v  a2s.c  om
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
    bindingGroup = new BindingGroup();

    saveFileChooser = new JFileChooser();
    loadFileChooser = new JFileChooser();
    xmlFileFilter = new XmlFileFilter();
    controller = new ServerController();
    serverStatusToIconConverter = new ServerStatusToIconConverter();
    splitPane = new JSplitPane();
    jXTaskPaneContainer1 = new JXTaskPaneContainer();
    attackerIdpTaskPane = new JXTaskPane();
    analyzerIdpTaskPane = new JXTaskPane();
    evaluationTaskPane = new JXTaskPane();
    logTaskPane = new JXTaskPane();
    menuBar = new JMenuBar();
    fileMenu = new JMenu();
    saveItem = new JMenuItem();
    loadItem = new JMenuItem();
    jSeparator2 = new JPopupMenu.Separator();
    clearLogMenuItem = new JMenuItem();
    jSeparator1 = new JPopupMenu.Separator();
    exitNoConfigSave = new JMenuItem();
    exitAndSaveConfig = new JMenuItem();

    saveFileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    saveFileChooser.setFileFilter(xmlFileFilter);

    loadFileChooser.setFileFilter(xmlFileFilter);
    loadFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent evt) {
            formWindowOpened(evt);
        }

        public void windowClosing(WindowEvent evt) {
            formWindowClosing(evt);
        }
    });

    splitPane.setBorder(null);
    splitPane.setDividerLocation(200);
    splitPane.setDividerSize(0);

    jXTaskPaneContainer1.setMinimumSize(new Dimension(200, 259));
    jXTaskPaneContainer1.setPreferredSize(new Dimension(200, 10));
    VerticalLayout verticalLayout1 = new VerticalLayout();
    verticalLayout1.setGap(14);
    jXTaskPaneContainer1.setLayout(verticalLayout1);

    attackerIdpTaskPane.setFocusable(false);
    attackerIdpTaskPane.setTitle("Attacker IdP");

    Binding binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, controller,
            ELProperty.create("${attackerServer.status}"), attackerIdpTaskPane, BeanProperty.create("icon"));
    binding.setConverter(serverStatusToIconConverter);
    bindingGroup.addBinding(binding);

    jXTaskPaneContainer1.add(attackerIdpTaskPane);

    analyzerIdpTaskPane.setFocusable(false);
    analyzerIdpTaskPane.setTitle("Analyzer IdP");

    binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, controller,
            ELProperty.create("${analyzerServer.status}"), analyzerIdpTaskPane, BeanProperty.create("icon"));
    binding.setConverter(serverStatusToIconConverter);
    bindingGroup.addBinding(binding);

    jXTaskPaneContainer1.add(analyzerIdpTaskPane);

    evaluationTaskPane.setFocusable(false);
    evaluationTaskPane.setTitle("Evaluation");
    jXTaskPaneContainer1.add(evaluationTaskPane);

    logTaskPane.setFocusable(false);
    logTaskPane.setTitle("Other");
    jXTaskPaneContainer1.add(logTaskPane);

    splitPane.setLeftComponent(jXTaskPaneContainer1);

    fileMenu.setMnemonic('F');
    fileMenu.setText("File");

    saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_MASK));
    saveItem.setText("Save Config");
    saveItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            saveItemActionPerformed(evt);
        }
    });
    fileMenu.add(saveItem);

    loadItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.ALT_MASK));
    loadItem.setText("Load Config");
    loadItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            loadItemActionPerformed(evt);
        }
    });
    fileMenu.add(loadItem);
    fileMenu.add(jSeparator2);

    clearLogMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));
    clearLogMenuItem.setText("Clear Log");
    clearLogMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            clearLogMenuItemActionPerformed(evt);
        }
    });
    fileMenu.add(clearLogMenuItem);
    fileMenu.add(jSeparator1);

    exitNoConfigSave.setText("Exit (without saving config)");
    exitNoConfigSave.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            exitNoConfigSaveActionPerformed(evt);
        }
    });
    fileMenu.add(exitNoConfigSave);

    exitAndSaveConfig.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.META_MASK));
    exitAndSaveConfig.setText("Exit");
    exitAndSaveConfig.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            exitAndSaveConfigActionPerformed(evt);
        }
    });
    fileMenu.add(exitAndSaveConfig);

    menuBar.add(fileMenu);

    setJMenuBar(menuBar);

    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(splitPane,
            GroupLayout.DEFAULT_SIZE, 960, Short.MAX_VALUE));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(splitPane,
            GroupLayout.DEFAULT_SIZE, 528, Short.MAX_VALUE));

    bindingGroup.bind();

    pack();
}