Search in sources :

Example 11 with FileFilter

use of javax.swing.filechooser.FileFilter in project pcgen by PCGen.

the class PCGenFrame method showSavePartyChooser.

boolean showSavePartyChooser() {
    PartyFacade party = CharacterManager.getCharacters();
    PCGenSettings context = PCGenSettings.getInstance();
    String parentPath = context.getProperty(PCGenSettings.PCP_SAVE_PATH);
    chooser.setCurrentDirectory(new File(parentPath));
    File file = party.getFileRef().get();
    chooser.setSelectedFile(file);
    chooser.resetChoosableFileFilters();
    FileFilter filter = new FileNameExtensionFilter("Pcp files only", "pcp");
    chooser.addChoosableFileFilter(filter);
    chooser.setFileFilter(filter);
    int ret = chooser.showSaveDialog(this);
    if (ret != JFileChooser.APPROVE_OPTION) {
        return false;
    }
    file = chooser.getSelectedFile();
    if (!file.getName().endsWith(Constants.EXTENSION_PARTY_FILE)) {
        file = new File(file.getParent(), file.getName() + Constants.EXTENSION_PARTY_FILE);
    }
    if (file.isDirectory()) {
        showErrorMessage(Constants.APPLICATION_NAME, //$NON-NLS-1$
        LanguageBundle.getString("in_savePcDirOverwrite"));
        return showSavePartyChooser();
    }
    if (file.exists()) {
        boolean overwrite = showWarningConfirm(LanguageBundle.getFormattedString("in_savePcConfirmOverTitle", //$NON-NLS-1$
        file.getName()), LanguageBundle.getFormattedString("in_savePcConfirmOverMsg", //$NON-NLS-1$
        file.getName()));
        if (!overwrite) {
            return showSavePartyChooser();
        }
    }
    party.setFile(file);
    context.setProperty(PCGenSettings.PCP_SAVE_PATH, file.getParent());
    if (!saveAllCharacters()) {
        showErrorMessage(//$NON-NLS-1$
        LanguageBundle.getString("in_savePartyFailTitle"), //$NON-NLS-1$
        LanguageBundle.getString("in_savePartyFailMsg"));
        return false;
    }
    if (!CharacterManager.saveCurrentParty()) {
        return showSavePartyChooser();
    }
    return true;
}
Also used : PartyFacade(pcgen.facade.core.PartyFacade) PCGenSettings(pcgen.system.PCGenSettings) FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) PCGFile(pcgen.io.PCGFile) File(java.io.File)

Example 12 with FileFilter

use of javax.swing.filechooser.FileFilter in project zaproxy by zaproxy.

the class DriversView method browseButtonActionPerformed.

private void browseButtonActionPerformed(ActionEvent evt) {
    final JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new FileFilter() {

        @Override
        public String getDescription() {
            return "DLL/dylib";
        }

        //FIXME: Support so and dynlib files as well
        @Override
        public boolean accept(java.io.File f) {
            return f.isDirectory() || f.getName().toLowerCase().endsWith(".dll") || f.getName().toLowerCase().endsWith(".dylib");
        }
    });
    final int state = fc.showOpenDialog(null);
    if (state == JFileChooser.APPROVE_OPTION) {
        fileTextField.setText(fc.getSelectedFile().toString());
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter)

Example 13 with FileFilter

use of javax.swing.filechooser.FileFilter in project zaproxy by zaproxy.

the class PolicyManagerDialog method getExportButton.

private JButton getExportButton() {
    if (this.exportButton == null) {
        this.exportButton = new JButton(Constant.messages.getString("ascan.policymgr.button.export"));
        this.exportButton.setEnabled(false);
        this.exportButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                String name = (String) getParamsModel().getValueAt(getParamsTable().getSelectedRow(), 0);
                if (name != null) {
                    JFileChooser chooser = new JFileChooser(Constant.getPoliciesDir());
                    File file = new File(Constant.getZapHome(), name + PolicyManager.POLICY_EXTENSION);
                    chooser.setSelectedFile(file);
                    chooser.setFileFilter(new FileFilter() {

                        @Override
                        public boolean accept(File file) {
                            if (file.isDirectory()) {
                                return true;
                            } else if (file.isFile() && file.getName().endsWith(".policy")) {
                                return true;
                            }
                            return false;
                        }

                        @Override
                        public String getDescription() {
                            return Constant.messages.getString("file.format.zap.policy");
                        }
                    });
                    int rc = chooser.showSaveDialog(View.getSingleton().getMainFrame());
                    if (rc == JFileChooser.APPROVE_OPTION) {
                        file = chooser.getSelectedFile();
                        if (file == null) {
                            return;
                        }
                        try {
                            ScanPolicy policy = extension.getPolicyManager().getPolicy(name);
                            if (policy != null) {
                                extension.getPolicyManager().exportPolicy(policy, file);
                            }
                        } catch (ConfigurationException e1) {
                            logger.error(e1.getMessage(), e1);
                            View.getSingleton().showWarningDialog(Constant.messages.getString("ascan.policy.load.error"));
                        }
                    }
                }
            }
        });
    }
    return this.exportButton;
}
Also used : ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Example 14 with FileFilter

use of javax.swing.filechooser.FileFilter in project pcgen by PCGen.

the class ExportDialog method export.

private void export(boolean pdf) {
    UIPropertyContext context = UIPropertyContext.createContext("ExportDialog");
    final JFileChooser fcExport = new JFileChooser();
    fcExport.setFileSelectionMode(JFileChooser.FILES_ONLY);
    File baseDir = null;
    {
        String path;
        if (pdf) {
            path = context.getProperty(PDF_EXPORT_DIR_PROP);
        } else {
            path = context.getProperty(HTML_EXPORT_DIR_PROP);
        }
        if (path != null) {
            baseDir = new File(path);
        }
    }
    if (baseDir == null || !baseDir.isDirectory()) {
        baseDir = SystemUtils.getUserHome();
    }
    fcExport.setCurrentDirectory(baseDir);
    URI uri = (URI) fileList.getSelectedValue();
    String extension = ExportUtilities.getOutputExtension(uri.toString(), pdf);
    if (pdf) {
        FileFilter fileFilter = new FileNameExtensionFilter("PDF Documents (*.pdf)", "pdf");
        fcExport.addChoosableFileFilter(fileFilter);
        fcExport.setFileFilter(fileFilter);
    } else if ("htm".equalsIgnoreCase(extension) || "html".equalsIgnoreCase(extension)) {
        FileFilter fileFilter = new FileNameExtensionFilter("HTML Documents (*.htm, *.html)", "htm", "html");
        fcExport.addChoosableFileFilter(fileFilter);
        fcExport.setFileFilter(fileFilter);
    } else if ("xml".equalsIgnoreCase(extension)) {
        FileFilter fileFilter = new FileNameExtensionFilter("XML Documents (*.xml)", "xml");
        fcExport.addChoosableFileFilter(fileFilter);
        fcExport.setFileFilter(fileFilter);
    } else {
        String desc = extension + " Files (*." + extension + ")";
        fcExport.addChoosableFileFilter(new FileNameExtensionFilter(desc, extension));
    }
    String name;
    File path;
    if (!partyBox.isSelected()) {
        CharacterFacade character = (CharacterFacade) characterBox.getSelectedItem();
        path = character.getFileRef().get();
        if (path != null) {
            path = path.getParentFile();
        } else {
            path = new File(PCGenSettings.getPcgDir());
        }
        name = character.getTabNameRef().get();
        if (StringUtils.isEmpty(name)) {
            name = character.getNameRef().get();
        }
    } else {
        path = new File(PCGenSettings.getPcgDir());
        name = "Entire Party";
    }
    if (pdf) {
        fcExport.setSelectedFile(new File(path, name + ".pdf"));
    } else {
        fcExport.setSelectedFile(new File(path, name + "." + extension));
    }
    fcExport.setDialogTitle("Export " + name);
    if (fcExport.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
        return;
    }
    final File outFile = fcExport.getSelectedFile();
    if (pdf) {
        context.setProperty(PDF_EXPORT_DIR_PROP, outFile.getParent());
    } else {
        context.setProperty(HTML_EXPORT_DIR_PROP, outFile.getParent());
    }
    if (StringUtils.isEmpty(outFile.getName())) {
        pcgenFrame.showErrorMessage("PCGen", "You must set a filename.");
        return;
    }
    if (outFile.isDirectory()) {
        pcgenFrame.showErrorMessage("PCGen", "You cannot overwrite a directory with a file.");
        return;
    }
    if (outFile.exists() && SettingsHandler.getAlwaysOverwrite() == false) {
        int reallyClose = JOptionPane.showConfirmDialog(this, "The file " + outFile.getName() + " already exists, are you sure you want to overwrite it?", "Confirm overwriting " + outFile.getName(), JOptionPane.YES_NO_OPTION);
        if (reallyClose != JOptionPane.YES_OPTION) {
            return;
        }
    }
    try {
        if (pdf) {
            new PDFExporter(outFile, extension, name).execute();
        } else {
            if (!printToFile(outFile)) {
                String message = "The character export failed. Please see the log for details.";
                pcgenFrame.showErrorMessage(Constants.APPLICATION_NAME, message);
                return;
            }
            maybeOpenFile(outFile);
            Globals.executePostExportCommandStandard(outFile.getAbsolutePath());
        }
    } catch (IOException ex) {
        pcgenFrame.showErrorMessage("PCGen", "Could not export " + name + ". Try another filename.");
        Logging.errorPrint("Could not export " + name, ex);
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) IOException(java.io.IOException) IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) TrueFileFilter(org.apache.commons.io.filefilter.TrueFileFilter) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter) FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) UIPropertyContext(pcgen.gui2.UIPropertyContext) File(java.io.File) URI(java.net.URI) CharacterFacade(pcgen.facade.core.CharacterFacade)

Example 15 with FileFilter

use of javax.swing.filechooser.FileFilter in project yyl_example by Relucent.

the class ExcelBuilderUI method registerListener.

private void registerListener() {
    btnExcel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            chooser.setFileFilter(new FileFilter() {

                public boolean accept(File f) {
                    return (f.isDirectory() || f.getName().endsWith(".xls"));
                }

                public String getDescription() {
                    return null;
                }
            });
            int returnVal = chooser.showOpenDialog(btnExcel);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                txtExcel.setText(chooser.getSelectedFile().getAbsolutePath());
            }
            validate();
        }
    });
    btnOutFolder.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = chooser.showOpenDialog(btnOutFolder);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                txtOutFolder.setText(chooser.getSelectedFile().getAbsolutePath());
            }
            validate();
        }
    });
    btnTemplet.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int returnVal = chooser.showOpenDialog(btnTemplet);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                txtTemplet.setText(chooser.getSelectedFile().getAbsolutePath());
            }
            validate();
        }
    });
    btnConfirm.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            Thread thread = new Thread(new Runnable() {

                public void run() {
                    btnConfirm.setEnabled(false);
                    ExcelBuilderMethod.outExcel(txtExcel.getText(), txtOutFolder.getText(), txtTemplet.getText(), txtDebug);
                    btnConfirm.setEnabled(true);
                }
            });
            thread.setDaemon(true);
            thread.start();
        }
    });
    btnCancel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            txtDebug.setText("");
        }
    });
}
Also used : ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) ActionEvent(java.awt.event.ActionEvent) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Aggregations

FileFilter (javax.swing.filechooser.FileFilter)59 File (java.io.File)48 JFileChooser (javax.swing.JFileChooser)39 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)15 IOException (java.io.IOException)10 ActionEvent (java.awt.event.ActionEvent)7 ActionListener (java.awt.event.ActionListener)5 DatabaseException (org.parosproxy.paros.db.DatabaseException)5 PCGFile (pcgen.io.PCGFile)5 IllegalContextNameException (org.zaproxy.zap.model.IllegalContextNameException)4 TopLevelWindowManager (cbit.vcell.client.TopLevelWindowManager)3 UserPreferences (cbit.vcell.client.server.UserPreferences)3 ArrayList (java.util.ArrayList)3 Preferences (java.util.prefs.Preferences)3 JButton (javax.swing.JButton)3 Session (org.parosproxy.paros.model.Session)3 Component (java.awt.Component)2 Cursor (java.awt.Cursor)2 Dimension (java.awt.Dimension)2 FileDialog (java.awt.FileDialog)2