Example usage for javax.swing JFileChooser setDialogType

List of usage examples for javax.swing JFileChooser setDialogType

Introduction

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

Prototype


@BeanProperty(preferred = true, enumerationValues = { "JFileChooser.OPEN_DIALOG", "JFileChooser.SAVE_DIALOG",
        "JFileChooser.CUSTOM_DIALOG" }, description = "The type (open, save, custom) of the JFileChooser.")
public void setDialogType(int dialogType) 

Source Link

Document

Sets the type of this dialog.

Usage

From source file:org.piraso.ui.base.ImportDialog.java

private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseActionPerformed
    File home = new File(System.getProperty("user.home"));
    File pirasoDir = new File(home, "piraso");
    if (!pirasoDir.isDirectory()) {
        pirasoDir.mkdirs();/*  www.  j  a v a2 s  .  com*/
    }

    JFileChooser browserFileChooser = new FileChooserBuilder("piraso-dir")
            .setTitle(NbBundle.getMessage(ImportDialog.class, "ImportDialog.browser.title"))
            .setDefaultWorkingDirectory(pirasoDir).setFileFilter(new PirasoSettingsFileFilter())
            .createFileChooser();

    browserFileChooser.setDialogType(JFileChooser.OPEN_DIALOG);

    int result = browserFileChooser.showDialog(this,
            NbBundle.getMessage(ImportDialog.class, "ImportDialog.browser.approveText"));

    if (JFileChooser.APPROVE_OPTION == result) {
        selectedFile = browserFileChooser.getSelectedFile();
        txtSourceFile.setText(browserFileChooser.getSelectedFile().getAbsolutePath());

        try {
            settings = JacksonUtils.MAPPER.readValue(selectedFile, ObjectEntrySettings.class);
        } catch (IOException e) {
            ErrorManager.getDefault().notify(e);
            return;
        }

        refresh();
    }
}

From source file:org.piraso.ui.base.OpenMonitorInstanceDialog.java

private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseActionPerformed
    File home = new File(System.getProperty("user.home"));
    File pirasoDir = new File(home, "piraso");
    File pirasoSaveDir = new File(pirasoDir, "saved");
    if (!pirasoSaveDir.isDirectory()) {
        pirasoSaveDir.mkdirs();/*from   ww  w  .j  a  v a 2s.  c o  m*/
    }

    JFileChooser browserFileChooser = new FileChooserBuilder("piraso-saved-dir")
            .setTitle(NbBundle.getMessage(OpenMonitorInstanceDialog.class,
                    "OpenMonitorInstanceDialog.browser.title"))
            .setFileFilter(new PirasoFileFilter()).setDefaultWorkingDirectory(pirasoSaveDir)
            .createFileChooser();

    browserFileChooser.setDialogType(JFileChooser.OPEN_DIALOG);

    int result = browserFileChooser.showDialog(this, NbBundle.getMessage(OpenMonitorInstanceDialog.class,
            "OpenMonitorInstanceDialog.browser.approveText"));

    if (JFileChooser.APPROVE_OPTION == result) {
        selectedFile = browserFileChooser.getSelectedFile();
        txtSourceFile.setText(browserFileChooser.getSelectedFile().getAbsolutePath());
        refreshButtons();
    }
}

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  w w w  .j  a va  2 s.  c  o  m

    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:pcgen.gui2.converter.panel.WriteDirectoryPanel.java

@Override
public void setupDisplay(JPanel panel, final CDOMObject pc) {
    panel.setLayout(layout);//from w w w  .j  av a 2  s  .  c  om
    Component label = new JLabel("Please select the Directory where Converted files should be written: ");
    AbstractButton button = new JButton("Browse...");
    button.setMnemonic('r');
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setDialogType(JFileChooser.OPEN_DIALOG);
            chooser.setCurrentDirectory(path.getParentFile());
            chooser.setSelectedFile(path);
            while (true) {
                int open = chooser.showOpenDialog(null);
                if (open == JFileChooser.APPROVE_OPTION) {
                    File fileToOpen = chooser.getSelectedFile();
                    if (fileToOpen.isDirectory() && fileToOpen.canRead() && fileToOpen.canWrite()) {
                        path = fileToOpen;
                        pc.put(ObjectKey.WRITE_DIRECTORY, path);
                        fileLabel.setText(path.getAbsolutePath());
                        PCGenSettings context = PCGenSettings.getInstance();
                        context.setProperty(PCGenSettings.CONVERT_OUTPUT_SAVE_PATH, path.getAbsolutePath());
                        showWarning();
                        break;
                    }
                    JOptionPane.showMessageDialog(null,
                            "Selection must be a valid " + "(readable & writeable) Directory");
                    chooser.setCurrentDirectory(path.getParentFile());
                } else if (open == JFileChooser.CANCEL_OPTION) {
                    break;
                }
            }
        }
    });
    panel.add(label);
    panel.add(fileLabel);
    panel.add(button);
    panel.add(warningLabel);
    showWarning();
    layout.putConstraint(SpringLayout.NORTH, label, 50, SpringLayout.NORTH, panel);
    layout.putConstraint(SpringLayout.NORTH, fileLabel, 75 + label.getPreferredSize().height,
            SpringLayout.NORTH, panel);
    layout.putConstraint(SpringLayout.NORTH, button, 75 + label.getPreferredSize().height, SpringLayout.NORTH,
            panel);
    layout.putConstraint(SpringLayout.WEST, label, 25, SpringLayout.WEST, panel);
    layout.putConstraint(SpringLayout.WEST, fileLabel, 25, SpringLayout.WEST, panel);
    layout.putConstraint(SpringLayout.EAST, button, -50, SpringLayout.EAST, panel);
    layout.putConstraint(SpringLayout.NORTH, warningLabel, 20, SpringLayout.SOUTH, fileLabel);
    layout.putConstraint(SpringLayout.WEST, warningLabel, 25, SpringLayout.WEST, panel);

    fileLabel.setText(path.getAbsolutePath());
}

From source file:plugin.notes.gui.NotesView.java

/**
 *  obtains an Image for input using a custom JFileChooser dialog
 *
 *@param  startDir  Directory to open JFielChooser to
 *@param  exts      Extensions to search for
 *@param  desc      Description for files
 *@return           File pointing to the selected image
 *///w w  w  . j  a  va  2  s.  c  o m
private File getImageFromChooser(String startDir, String[] exts, String desc) {
    JFileChooser jImageDialog = new JFileChooser();
    jImageDialog.setCurrentDirectory(new File(startDir));
    jImageDialog.setAccessory(new ImageFileChooserPreview(jImageDialog));
    jImageDialog.setDialogType(JFileChooser.CUSTOM_DIALOG);
    jImageDialog.setFileFilter(new FileNameExtensionFilter(desc, exts));
    jImageDialog.setDialogTitle("Select an Image to Insert");

    int optionSelected = jImageDialog.showDialog(this, "Insert");

    if (optionSelected == JFileChooser.APPROVE_OPTION) {
        return jImageDialog.getSelectedFile();
    }

    return null;
}

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 {/*w ww .  ja v  a2  s.c  o m*/
            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;/*w  ww. jav a 2  s  .co m*/
        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;//from  ww  w .  j a  va 2s.  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);

                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;//  ww w  .  j  av  a 2s .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;/*from  w  w  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());
        }
    }
}