Search in sources :

Example 11 with JFileChooser

use of javax.swing.JFileChooser 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 12 with JFileChooser

use of javax.swing.JFileChooser in project jadx by skylot.

the class MainWindow method saveAll.

private void saveAll(boolean export) {
    settings.setExportAsGradleProject(export);
    if (export) {
        settings.setSkipSources(false);
        settings.setSkipResources(false);
    }
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.setToolTipText(NLS.str("file.save_all_msg"));
    String currentDirectory = settings.getLastSaveFilePath();
    if (!currentDirectory.isEmpty()) {
        fileChooser.setCurrentDirectory(new File(currentDirectory));
    }
    int ret = fileChooser.showDialog(mainPanel, NLS.str("file.select"));
    if (ret == JFileChooser.APPROVE_OPTION) {
        settings.setLastSaveFilePath(fileChooser.getCurrentDirectory().getPath());
        ProgressMonitor progressMonitor = new ProgressMonitor(mainPanel, NLS.str("msg.saving_sources"), "", 0, 100);
        progressMonitor.setMillisToPopup(0);
        wrapper.saveAll(fileChooser.getSelectedFile(), progressMonitor);
    }
}
Also used : ProgressMonitor(javax.swing.ProgressMonitor) JFileChooser(javax.swing.JFileChooser) ResourceFile(jadx.api.ResourceFile) File(java.io.File)

Example 13 with JFileChooser

use of javax.swing.JFileChooser in project languagetool by languagetool-org.

the class Tools method openFileDialog.

private static File openFileDialog(Frame frame, FileFilter fileFilter, File initialDir, int mode) {
    JFileChooser jfc = new JFileChooser();
    jfc.setFileSelectionMode(mode);
    jfc.setCurrentDirectory(initialDir);
    jfc.setFileFilter(fileFilter);
    jfc.showOpenDialog(frame);
    return jfc.getSelectedFile();
}
Also used : JFileChooser(javax.swing.JFileChooser)

Example 14 with JFileChooser

use of javax.swing.JFileChooser in project smile by haifengl.

the class PlotCanvas method save.

/**
     * Shows a file chooser and exports the plot to the selected image file.
     * @throws IOException if an error occurs during writing.
     */
public void save() throws IOException {
    FileChooser.SimpleFileFilter filter = FileChooser.SimpleFileFilter.getWritableImageFIlter();
    JFileChooser chooser = FileChooser.getInstance();
    chooser.setFileFilter(filter);
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setSelectedFiles(new File[0]);
    int returnVal = chooser.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        if (!filter.accept(file)) {
            file = new File(file.getParentFile(), file.getName() + ".png");
        }
        save(file);
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) JFileChooser(javax.swing.JFileChooser) FileChooser(smile.swing.FileChooser) File(java.io.File)

Example 15 with JFileChooser

use of javax.swing.JFileChooser in project smile by haifengl.

the class PlotPanel method save.

/**
     * Shows a file chooser and exports the plot to the selected image file.
     * @throws IOException if an error occurs during writing.
     */
public void save() throws IOException {
    JFileChooser fc = FileChooser.getInstance();
    fc.setFileFilter(FileChooser.SimpleFileFilter.getWritableImageFIlter());
    fc.setAcceptAllFileFilterUsed(false);
    fc.setSelectedFiles(new File[0]);
    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        save(file);
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) File(java.io.File)

Aggregations

JFileChooser (javax.swing.JFileChooser)273 File (java.io.File)157 IOException (java.io.IOException)55 FileFilter (javax.swing.filechooser.FileFilter)40 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)29 ActionEvent (java.awt.event.ActionEvent)25 ActionListener (java.awt.event.ActionListener)20 JButton (javax.swing.JButton)18 FileOutputStream (java.io.FileOutputStream)17 JPanel (javax.swing.JPanel)15 Preferences (java.util.prefs.Preferences)12 Component (java.awt.Component)11 Point (java.awt.Point)11 JMenuItem (javax.swing.JMenuItem)11 FileNotFoundException (java.io.FileNotFoundException)10 JLabel (javax.swing.JLabel)10 JFrame (javax.swing.JFrame)9 ResourceBundle (java.util.ResourceBundle)8 BorderLayout (java.awt.BorderLayout)7 FileDialog (java.awt.FileDialog)7