Search in sources :

Example 11 with FileNameExtensionFilter

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());
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JFileChooser(javax.swing.JFileChooser) BoundingBox(aimax.osm.data.BoundingBox) JTable(javax.swing.JTable) Dimension(java.awt.Dimension) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) FileFilter(javax.swing.filechooser.FileFilter)

Example 12 with FileNameExtensionFilter

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(""));
}
Also used : FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

Example 13 with FileNameExtensionFilter

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());
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) ResourceFile(jadx.api.ResourceFile) File(java.io.File)

Example 14 with FileNameExtensionFilter

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();
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) SwingWorker(javax.swing.SwingWorker) CsvExport(jgnash.convert.exports.csv.CsvExport) AccountExport(jgnash.convert.exports.ssf.AccountExport) OfxExport(jgnash.convert.exports.ofx.OfxExport) ResourceBundle(java.util.ResourceBundle) OfxExport(jgnash.convert.exports.ofx.OfxExport) Preferences(java.util.prefs.Preferences) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

Example 15 with FileNameExtensionFilter

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();
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) SwingWorker(javax.swing.SwingWorker) BudgetResultsExport(jgnash.engine.budget.BudgetResultsExport) ResourceBundle(java.util.ResourceBundle) Preferences(java.util.prefs.Preferences) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File)

Aggregations

FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)52 File (java.io.File)32 JFileChooser (javax.swing.JFileChooser)30 FileFilter (javax.swing.filechooser.FileFilter)15 IOException (java.io.IOException)11 Preferences (java.util.prefs.Preferences)7 FileNotFoundException (java.io.FileNotFoundException)6 PCGFile (pcgen.io.PCGFile)6 ResourceBundle (java.util.ResourceBundle)5 SwingWorker (javax.swing.SwingWorker)5 FileOutputStream (java.io.FileOutputStream)3 PCGenSettings (pcgen.system.PCGenSettings)3 ImportException (dr.evolution.io.Importer.ImportException)2 MissingBlockException (dr.evolution.io.NexusImporter.MissingBlockException)2 java.awt (java.awt)2 BorderLayout (java.awt.BorderLayout)2 Cursor (java.awt.Cursor)2 Dimension (java.awt.Dimension)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2