use of javax.swing.filechooser.FileNameExtensionFilter in project aima-java by aimacode.
the class MapViewFrame method actionPerformed.
/**
* Defines what happens when a button is pressed.
*/
public void actionPerformed(ActionEvent e) {
if (e.getSource() == loadButton) {
String title = "Load OSM Data";
if ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)
title += " (Bounding Box Mode)";
if ((e.getModifiers() & KeyEvent.SHIFT_MASK) != 0)
title += " (Overview Mode)";
fileChooser.setDialogTitle(title);
int returnVal = fileChooser.showDialog(this, "Load");
if (returnVal == JFileChooser.APPROVE_OPTION) {
if ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0) {
// ctrl+load -> ask the user for a bounding box.
BoundingBox bb = askForBoundingBox();
if (bb != null)
mapReader.setFilter(bb);
else
return;
}
if ((e.getModifiers() & KeyEvent.SHIFT_MASK) != 0) {
EntityClassifier<Boolean> filter = createOverviewFilter();
mapReader.setFilter(filter);
}
readMap(fileChooser.getSelectedFile());
}
} else if (e.getSource() == saveButton) {
JFileChooser fc = new JFileChooser();
String[] exts = mapWriter.fileFormatDescriptions();
for (int i = 0; i < exts.length; i++) {
FileFilter filter = new FileNameExtensionFilter(exts[i], mapWriter.fileFormatExtensions()[i]);
fc.addChoosableFileFilter(filter);
}
fc.setFileFilter(fc.getChoosableFileFilters()[0]);
fc.setCurrentDirectory(fileChooser.getCurrentDirectory());
int returnVal = fc.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION && (!fc.getSelectedFile().exists() || JOptionPane.showConfirmDialog(this, "File exists, overwrite?", "Confirm", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)) {
mapWriter.writeMap(fc.getSelectedFile(), getMap(), view.getBoundingBox());
}
} else if (e.getSource() == statisticsButton) {
Object[][] data = getMap().getStatistics();
JTable table = new JTable(data, new String[] { "Attribute", "Value" });
JScrollPane scroller = new JScrollPane(table);
scroller.setPreferredSize(new Dimension(250, 300));
JOptionPane.showConfirmDialog(this, scroller, "Map Statistics", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
} else if (e.getSource() == sidebarCheckBox) {
showSidebar(sidebarCheckBox.isSelected());
}
}
use of javax.swing.filechooser.FileNameExtensionFilter in project aima-java by aimacode.
the class MapViewFrame method setMapReader.
public void setMapReader(MapReader mapReader) {
this.mapReader = mapReader;
for (int i = fileChooser.getChoosableFileFilters().length - 1; i > 0; i--) fileChooser.removeChoosableFileFilter(fileChooser.getChoosableFileFilters()[i]);
String[] exts = mapReader.fileFormatDescriptions();
for (int i = 0; i < exts.length; i++) {
FileFilter filter = new FileNameExtensionFilter(exts[i], mapReader.fileFormatExtensions()[i]);
fileChooser.addChoosableFileFilter(filter);
}
fileChooser.setFileFilter(fileChooser.getChoosableFileFilters()[0]);
fileChooser.setSelectedFile(new File(""));
}
use of javax.swing.filechooser.FileNameExtensionFilter in project jadx by skylot.
the class MainWindow method openFile.
public void openFile() {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setAcceptAllFileFilterUsed(true);
String[] exts = { "apk", "dex", "jar", "class", "zip", "aar" };
String description = "supported files: " + Arrays.toString(exts).replace('[', '(').replace(']', ')');
fileChooser.setFileFilter(new FileNameExtensionFilter(description, exts));
fileChooser.setToolTipText(NLS.str("file.open"));
String currentDirectory = settings.getLastOpenFilePath();
if (!currentDirectory.isEmpty()) {
fileChooser.setCurrentDirectory(new File(currentDirectory));
}
int ret = fileChooser.showDialog(mainPanel, NLS.str("file.open"));
if (ret == JFileChooser.APPROVE_OPTION) {
settings.setLastOpenFilePath(fileChooser.getCurrentDirectory().getPath());
openFile(fileChooser.getSelectedFile());
}
}
use of javax.swing.filechooser.FileNameExtensionFilter in project jgnash by ccavanaugh.
the class ExportTransactionsAction method exportTransactions.
public static void exportTransactions(final Account account, final LocalDate startDate, final LocalDate endDate) {
final ResourceBundle rb = ResourceUtils.getBundle();
final Preferences pref = Preferences.userNodeForPackage(ExportTransactionsAction.class);
JFileChooser chooser = new JFileChooser(pref.get(CURRENT_DIR, null));
FileNameExtensionFilter csvFilter = new FileNameExtensionFilter(rb.getString("Label.CsvFiles") + " (*.csv)", "csv");
FileNameExtensionFilter ofxFilter = new FileNameExtensionFilter(rb.getString("Label.OfxFiles") + " (*.ofx)", OFX);
FileNameExtensionFilter ssFilter = new FileNameExtensionFilter(rb.getString("Label.SpreadsheetFiles") + " (*.xls, *.xlsx)", "xls", "xlsx");
chooser.addChoosableFileFilter(csvFilter);
chooser.addChoosableFileFilter(ofxFilter);
chooser.addChoosableFileFilter(ssFilter);
chooser.setAcceptAllFileFilterUsed(false);
chooser.setMultiSelectionEnabled(false);
chooser.setFileFilter(csvFilter);
if (chooser.showSaveDialog(UIApplication.getFrame()) == JFileChooser.APPROVE_OPTION) {
pref.put(CURRENT_DIR, chooser.getCurrentDirectory().getAbsolutePath());
final File file = chooser.getSelectedFile();
final class Export extends SwingWorker<Void, Void> {
@Override
protected Void doInBackground() throws Exception {
UIApplication.getFrame().displayWaitMessage(rb.getString("Message.PleaseWait"));
if (OFX.equals(FileUtils.getFileExtension(file.getName()))) {
OfxExport export = new OfxExport(account, startDate, endDate, file);
export.exportAccount();
} else if (FileUtils.getFileExtension(file.getName()).contains(XLS)) {
AccountExport.exportAccount(account, RegisterFactory.getColumnNames(account), startDate, endDate, file);
} else {
CsvExport.exportAccount(account, startDate, endDate, file);
}
return null;
}
@Override
protected void done() {
UIApplication.getFrame().stopWaitMessage();
}
}
new Export().execute();
}
}
use of javax.swing.filechooser.FileNameExtensionFilter in project jgnash by ccavanaugh.
the class BudgetPanel method exportBudgetAction.
private void exportBudgetAction() {
final Preferences pref = Preferences.userNodeForPackage(BudgetPanel.class);
final ResourceBundle rb = ResourceUtils.getBundle();
JFileChooser chooser = new JFileChooser(pref.get(CURRENT_DIR, null));
chooser.setMultiSelectionEnabled(false);
chooser.setAcceptAllFileFilterUsed(false);
chooser.addChoosableFileFilter(new FileNameExtensionFilter(rb.getString("Label.SpreadsheetFiles") + " (*.xls, *.xlsx)", "xls", "xlsx"));
if (chooser.showSaveDialog(UIApplication.getFrame()) == JFileChooser.APPROVE_OPTION) {
pref.put(CURRENT_DIR, chooser.getCurrentDirectory().getAbsolutePath());
final File file = new File(chooser.getSelectedFile().getAbsolutePath());
final class Export extends SwingWorker<String, Void> {
@Override
protected String doInBackground() throws Exception {
UIApplication.getFrame().displayWaitMessage(rb.getString("Message.PleaseWait"));
return BudgetResultsExport.exportBudgetResultsModel(file.toPath(), resultsModel);
}
@Override
protected void done() {
UIApplication.getFrame().stopWaitMessage();
try {
String message = get();
// display any errors that may have occurred
if (message != null) {
StaticUIMethods.displayError(message);
}
} catch (InterruptedException | ExecutionException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
}
new Export().execute();
}
}
Aggregations