use of javax.swing.filechooser.FileNameExtensionFilter in project jgnash by ccavanaugh.
the class ImportOfxAction method importOfx.
private static void importOfx() {
final ResourceBundle rb = ResourceUtils.getBundle();
final Preferences pref = Preferences.userNodeForPackage(ImportOfxAction.class);
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
if (engine == null || engine.getRootAccount().getChildCount() == 0) {
StaticUIMethods.displayError(rb.getString("Message.Error.CreateBasicAccounts"));
return;
}
final JFileChooser chooser = new JFileChooser(pref.get(OFX_DIR, null));
chooser.setMultiSelectionEnabled(false);
chooser.addChoosableFileFilter(new FileNameExtensionFilter("Ofx Files (*.ofx,*.qfx)", "ofx", "qfx"));
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
pref.put(OFX_DIR, chooser.getCurrentDirectory().getAbsolutePath());
File file = chooser.getSelectedFile();
if (file.exists()) {
new Import(file).execute();
}
}
}
use of javax.swing.filechooser.FileNameExtensionFilter in project jgnash by ccavanaugh.
the class AttachmentPanel method attachmentAction.
private void attachmentAction() {
final Preferences pref = Preferences.userNodeForPackage(AbstractBankTransactionPanel.class);
final String baseFile = EngineFactory.getActiveDatabase();
final String[] fileSuffixes = ImageIO.getReaderFileSuffixes();
StringBuilder description = new StringBuilder(rb.getString("Title.ImageFiles")).append(" (");
for (int i = 0; i < fileSuffixes.length; i++) {
description.append("*.");
description.append(fileSuffixes[i]);
if (i < fileSuffixes.length - 1) {
description.append(", ");
}
}
description.append(")");
FileFilter fileFilter = new FileNameExtensionFilter(description.toString(), fileSuffixes);
final JFileChooser chooser = new JFileChooser(pref.get(LAST_DIR, null));
chooser.addChoosableFileFilter(fileFilter);
chooser.setFileFilter(fileFilter);
chooser.setMultiSelectionEnabled(false);
chooser.setAcceptAllFileFilterUsed(false);
if (attachment != null) {
chooser.setSelectedFile(attachment.toFile());
}
if (chooser.showOpenDialog(UIApplication.getFrame()) == JFileChooser.APPROVE_OPTION) {
pref.put(LAST_DIR, chooser.getCurrentDirectory().getAbsolutePath());
File selectedFile = chooser.getSelectedFile();
if (selectedFile != null) {
boolean result = true;
final Path attachmentDirectory = AttachmentUtils.getAttachmentDirectory(Paths.get(baseFile));
if (baseFile.startsWith(EngineFactory.REMOTE_PREFIX)) {
// working remotely
moveAttachment = true;
} else if (attachmentDirectory != null && !attachmentDirectory.toString().equals(selectedFile.getParent())) {
String message = ResourceUtils.getString("Message.Warn.MoveFile", selectedFile.toString(), attachmentDirectory.toString());
result = YesNoDialog.showYesNoDialog(UIApplication.getFrame(), new JLabel(message), rb.getString("Title.MoveFile"));
if (result) {
moveAttachment = true;
Path newPath = Paths.get(AttachmentUtils.getAttachmentDirectory(Paths.get(baseFile)) + FileUtils.separator + selectedFile.getName());
if (newPath.toFile().exists()) {
message = ResourceUtils.getString("Message.Warn.SameFile", selectedFile.toString(), attachmentDirectory.toString());
StaticUIMethods.displayWarning(message);
moveAttachment = false;
result = false;
}
}
}
if (result) {
attachment = selectedFile.toPath();
}
}
}
}
use of javax.swing.filechooser.FileNameExtensionFilter in project jgnash by ccavanaugh.
the class MonthBalanceCSV method getFileName.
private String getFileName() {
final JFileChooser chooser = new JFileChooser();
chooser.setMultiSelectionEnabled(false);
chooser.addChoosableFileFilter(new FileNameExtensionFilter(rb.getString("Message.CSVFile"), "csv"));
if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
String fileName = chooser.getSelectedFile().getAbsolutePath();
if (!fileName.endsWith(".csv")) {
fileName = fileName + ".csv";
}
return fileName;
}
return null;
}
use of javax.swing.filechooser.FileNameExtensionFilter in project jgnash by ccavanaugh.
the class ProfitLossTXT method getFileName.
private String getFileName() {
final JFileChooser chooser = new JFileChooser();
chooser.setMultiSelectionEnabled(false);
chooser.addChoosableFileFilter(new FileNameExtensionFilter(rb.getString("Message.TXTFile"), "txt"));
if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
String fileName = chooser.getSelectedFile().getAbsolutePath();
if (!fileName.endsWith(".txt")) {
fileName = fileName + ".txt";
}
return fileName;
}
return null;
}
use of javax.swing.filechooser.FileNameExtensionFilter in project jgnash by ccavanaugh.
the class PrintCheckDialog method createFileChooser.
/**
* Creates a {@code JFileChooser}
* directory can be null, The JFileChooser will sort it out
* @param dir directory to start in
* @return the JFileChooser
*/
private JFileChooser createFileChooser(final String dir) {
JFileChooser chooser = new JFileChooser(dir);
chooser.addChoosableFileFilter(new FileNameExtensionFilter(rb.getString("Label.jGnashFiles") + " (*.xml)", "xml"));
return chooser;
}
Aggregations