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.");
}
}
}
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;
}
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);
}
}
}
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;
}
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());
}
}
Aggregations