Search in sources :

Example 26 with JFileChooser

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

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

the class PopupMenuExportResponse method getOutputFile.

private File getOutputFile(HttpMessage msg) {
    String filename = "";
    try {
        filename = msg.getRequestHeader().getURI().getPath();
        int pos = filename.lastIndexOf("/");
        filename = filename.substring(pos);
    } catch (Exception e) {
    }
    JFileChooser chooser = new JFileChooser(extension.getModel().getOptionsParam().getUserDirectory());
    if (filename.length() > 0) {
        chooser.setSelectedFile(new File(filename));
    }
    File file = null;
    int rc = chooser.showSaveDialog(extension.getView().getMainFrame());
    if (rc == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
        if (file == null) {
            return file;
        }
        extension.getModel().getOptionsParam().setUserDirectory(chooser.getCurrentDirectory());
        return file;
    }
    return file;
}
Also used : JFileChooser(javax.swing.JFileChooser) File(java.io.File)

Example 28 with JFileChooser

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

the class BrowserDialog method capture.

private void capture() {
    try {
        //	        this.setAlwaysOnTop(true);
        BufferedImage screencapture = new Robot().createScreenCapture(new Rectangle(this.getX(), this.getY(), this.getWidth(), this.getHeight() - this.jPanelBottom.getHeight()));
        // Save as JPEG
        JFileChooser chooser = new JFileChooser();
        chooser.addChoosableFileFilter(new FileFilter() {

            @Override
            public boolean accept(File file) {
                String filename = file.getName();
                return filename.endsWith(".png");
            }

            @Override
            public String getDescription() {
                return "*.png";
            }
        });
        chooser.showSaveDialog(this);
        File file = chooser.getSelectedFile();
        if (file != null)
            ImageIO.write(screencapture, "png", file);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
//			 this.setAlwaysOnTop(false);
}
Also used : JFileChooser(javax.swing.JFileChooser) Rectangle(java.awt.Rectangle) FileFilter(javax.swing.filechooser.FileFilter) Robot(java.awt.Robot) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 29 with JFileChooser

use of javax.swing.JFileChooser in project nhin-d by DirectProject.

the class CAPanel method signCSR.

private void signCSR() {
    JFileChooser fc = new JFileChooser();
    fc.setDragEnabled(false);
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setMultiSelectionEnabled(false);
    fc.setDialogTitle("Open Signing Request PEM File");
    int result = fc.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        final File fl = fc.getSelectedFile();
        PEMReader reader = null;
        try {
            reader = new PEMReader(new InputStreamReader(FileUtils.openInputStream(fl)));
            final PKCS10CertificationRequest certReq = (PKCS10CertificationRequest) reader.readObject();
            certReq.verify();
            final X509Certificate signedCert = CertGenerator.createCertFromCSR(certReq, currentCert);
            // validate the certificate 
            signedCert.verify(currentCert.getSignerCert().getPublicKey());
            // write it to a file
            final String addressName = CryptoExtensions.getSubjectAddress(signedCert);
            final File outFile = new File(addressName + ".der");
            FileUtils.writeByteArrayToFile(outFile, signedCert.getEncoded());
            JOptionPane.showMessageDialog(this, "Signing successful.\r\nCertificate saved to " + outFile.getAbsolutePath(), "CSR Sign", JOptionPane.PLAIN_MESSAGE);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Error signging CSR: " + e.getMessage(), "CSR Sign Error", JOptionPane.ERROR_MESSAGE);
        } finally {
            IOUtils.closeQuietly(reader);
        }
    }
}
Also used : PKCS10CertificationRequest(org.bouncycastle.jce.PKCS10CertificationRequest) JFileChooser(javax.swing.JFileChooser) InputStreamReader(java.io.InputStreamReader) PEMReader(org.bouncycastle.openssl.PEMReader) File(java.io.File) X509Certificate(java.security.cert.X509Certificate)

Example 30 with JFileChooser

use of javax.swing.JFileChooser in project android_frameworks_base by DirtyUnicorns.

the class ComputeThresholdAction method run.

@Override
public void run() {
    Main.getUI().showWaitDialog();
    Map<String, Set<String>> uses = new HashMap<String, Set<String>>();
    for (DumpData d : dataTableModel.getData()) {
        Main.getUI().updateWaitDialog("Merging " + d.getPackageName());
        updateClassUse(d.getPackageName(), uses, getBootClassPathClasses(d.getDumpData()));
    }
    Main.getUI().updateWaitDialog("Computing thresholded set");
    Set<String> result = fromThreshold(uses, blacklist, threshold);
    Main.getUI().hideWaitDialog();
    boolean ret = Main.getUI().showConfirmDialog("Computed a set with " + result.size() + " classes, would you like to save to disk?", "Save?");
    if (ret) {
        JFileChooser jfc = new JFileChooser();
        int ret2 = jfc.showSaveDialog(Main.getUI());
        if (ret2 == JFileChooser.APPROVE_OPTION) {
            File f = jfc.getSelectedFile();
            saveSet(result, f);
        }
    }
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) JFileChooser(javax.swing.JFileChooser) HashMap(java.util.HashMap) DumpData(com.android.preload.DumpData) File(java.io.File)

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