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