Search in sources :

Example 21 with JFileChooser

use of javax.swing.JFileChooser in project binnavi by google.

the class CLogFilePanel method showLogfileDialog.

/**
   * Shows the log file dialog.
   */
private void showLogfileDialog() {
    final JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File(ConfigHelper.getConfigurationDirectory(Constants.COMPANY_NAME, Constants.PROJECT_NAME)));
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {
            CLogFileDialog.show(SwingUtilities.getWindowAncestor(this), FileUtils.readTextfile(chooser.getSelectedFile().getAbsolutePath()));
        } catch (final IOException e) {
            CMessageBox.showInformation(SwingUtilities.getWindowAncestor(this), "The log file could not be read.");
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) IOException(java.io.IOException) File(java.io.File)

Example 22 with JFileChooser

use of javax.swing.JFileChooser in project zaproxy by zaproxy.

the class ExtensionCompare method getOutputFile.

private File getOutputFile() {
    JFileChooser chooser = new JFileChooser(getModel().getOptionsParam().getUserDirectory());
    chooser.setFileFilter(new FileFilter() {

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

        @Override
        public String getDescription() {
            return Constant.messages.getString("file.format.html");
        }
    });
    File file = null;
    int rc = chooser.showSaveDialog(getView().getMainFrame());
    if (rc == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
        if (file == null) {
            return file;
        }
        getModel().getOptionsParam().setUserDirectory(chooser.getCurrentDirectory());
        String fileNameLc = file.getAbsolutePath().toLowerCase();
        if (!fileNameLc.endsWith(".htm") && !fileNameLc.endsWith(".html")) {
            file = new File(file.getAbsolutePath() + ".html");
        }
        return file;
    }
    return file;
}
Also used : JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Example 23 with JFileChooser

use of javax.swing.JFileChooser in project zaproxy by zaproxy.

the class DynamicSSLPanel method doImport.

/**
	 * Import Root CA certificate from other ZAP configuration files.
	 */
private void doImport() {
    if (checkExistingCertificate()) {
        // prevent overwriting
        return;
    }
    final JFileChooser fc = new JFileChooser(System.getProperty("user.home"));
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setMultiSelectionEnabled(false);
    fc.setSelectedFile(new File(CONFIGURATION_FILENAME));
    fc.setFileFilter(new FileFilter() {

        @Override
        public String getDescription() {
            // config.xml or *.pem files
            return Constant.messages.getString("dynssl.filter.file");
        }

        @Override
        public boolean accept(File f) {
            return f.getName().toLowerCase().endsWith(CONFIGURATION_FILENAME) || f.getName().toLowerCase().endsWith("pem") || f.isDirectory();
        }
    });
    final int result = fc.showOpenDialog(this);
    final File f = fc.getSelectedFile();
    if (result == JFileChooser.APPROVE_OPTION && f.exists()) {
        if (logger.isInfoEnabled()) {
            logger.info("Loading Root CA certificate from " + f);
        }
        KeyStore ks = null;
        if (f.getName().toLowerCase().endsWith("pem")) {
            ks = convertPemFileToKeyStore(f.toPath());
        } else {
            try {
                final ZapXmlConfiguration conf = new ZapXmlConfiguration(f);
                final String rootcastr = conf.getString(DynSSLParam.PARAM_ROOT_CA);
                ks = SslCertificateUtils.string2Keystore(rootcastr);
            } catch (final Exception e) {
                logger.error("Error importing Root CA cert from config file:", e);
                JOptionPane.showMessageDialog(this, Constant.messages.getString("dynssl.message1.filecouldntloaded"), Constant.messages.getString("dynssl.message1.title"), JOptionPane.ERROR_MESSAGE);
            }
        }
        if (ks != null) {
            setRootca(ks);
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) KeyStore(java.security.KeyStore) IOException(java.io.IOException)

Example 24 with JFileChooser

use of javax.swing.JFileChooser in project zaproxy by zaproxy.

the class ExtensionAutoUpdate method getMenuItemLoadAddOn.

private ZapMenuItem getMenuItemLoadAddOn() {
    if (menuItemLoadAddOn == null) {
        menuItemLoadAddOn = new ZapMenuItem("cfu.file.menu.loadaddon", KeyStroke.getKeyStroke(KeyEvent.VK_L, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));
        menuItemLoadAddOn.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent e) {
                try {
                    JFileChooser chooser = new JFileChooser(Model.getSingleton().getOptionsParam().getUserDirectory());
                    File file = null;
                    chooser.setFileFilter(new FileFilter() {

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

                        @Override
                        public String getDescription() {
                            return Constant.messages.getString("file.format.zap.addon");
                        }
                    });
                    int rc = chooser.showOpenDialog(View.getSingleton().getMainFrame());
                    if (rc == JFileChooser.APPROVE_OPTION) {
                        file = chooser.getSelectedFile();
                        if (file == null) {
                            return;
                        }
                        installLocalAddOn(file.toPath());
                    }
                } catch (Exception e1) {
                    logger.error(e1.getMessage(), e1);
                }
            }
        });
    }
    return menuItemLoadAddOn;
}
Also used : ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) ZapMenuItem(org.zaproxy.zap.view.ZapMenuItem) FileFilter(javax.swing.filechooser.FileFilter) ActionEvent(java.awt.event.ActionEvent) File(java.io.File) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException)

Example 25 with JFileChooser

use of javax.swing.JFileChooser 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)

Aggregations

JFileChooser (javax.swing.JFileChooser)273 File (java.io.File)157 IOException (java.io.IOException)55 FileFilter (javax.swing.filechooser.FileFilter)40 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)29 ActionEvent (java.awt.event.ActionEvent)25 ActionListener (java.awt.event.ActionListener)20 JButton (javax.swing.JButton)18 FileOutputStream (java.io.FileOutputStream)17 JPanel (javax.swing.JPanel)15 Preferences (java.util.prefs.Preferences)12 Component (java.awt.Component)11 Point (java.awt.Point)11 JMenuItem (javax.swing.JMenuItem)11 FileNotFoundException (java.io.FileNotFoundException)10 JLabel (javax.swing.JLabel)10 JFrame (javax.swing.JFrame)9 ResourceBundle (java.util.ResourceBundle)8 BorderLayout (java.awt.BorderLayout)7 FileDialog (java.awt.FileDialog)7