Search in sources :

Example 46 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 47 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 48 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 49 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)

Example 50 with JFileChooser

use of javax.swing.JFileChooser in project gephi by gephi.

the class GraphFileExporterUI method action.

@Override
public void action() {
    final String LAST_PATH = "GraphFileExporterUI_Last_Path";
    final String LAST_PATH_DEFAULT = "GraphFileExporterUI_Last_Path_Default";
    final ExportControllerUI exportController = Lookup.getDefault().lookup(ExportControllerUI.class);
    if (exportController == null) {
        return;
    }
    //Get last directory
    String lastPathDefault = NbPreferences.forModule(GraphFileExporterUI.class).get(LAST_PATH_DEFAULT, null);
    String lastPath = NbPreferences.forModule(GraphFileExporterUI.class).get(LAST_PATH, lastPathDefault);
    //Options panel
    FlowLayout layout = new FlowLayout(FlowLayout.RIGHT);
    JPanel optionsPanel = new JPanel(layout);
    final JButton optionsButton = new JButton(NbBundle.getMessage(GraphFileExporterUI.class, "GraphFileExporterUI_optionsButton_name"));
    optionsPanel.add(optionsButton);
    optionsButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ExporterUI exporterUI = exportController.getExportController().getUI(selectedExporter);
            if (exporterUI != null) {
                JPanel panel = exporterUI.getPanel();
                exporterUI.setup(selectedExporter);
                DialogDescriptor dd = new DialogDescriptor(panel, NbBundle.getMessage(GraphFileExporterUI.class, "GraphFileExporterUI_optionsDialog_title", selectedBuilder.getName()));
                TopDialog topDialog = new TopDialog(dialog, dd.getTitle(), dd.isModal(), dd, dd.getClosingOptions(), dd.getButtonListener());
                topDialog.setVisible(true);
                Object result = (dd.getValue() != null) ? dd.getValue() : NotifyDescriptor.CLOSED_OPTION;
                //                    Object result = DialogDisplayer.getDefault().notify(dd);
                exporterUI.unsetup(result == NotifyDescriptor.OK_OPTION);
            }
        }
    });
    //Graph Settings Panel
    final JPanel southPanel = new JPanel(new BorderLayout());
    southPanel.add(optionsPanel, BorderLayout.NORTH);
    GraphFileExporterUIPanel graphSettings = new GraphFileExporterUIPanel();
    graphSettings.setVisibleOnlyGraph(visibleOnlyGraph);
    southPanel.add(graphSettings, BorderLayout.CENTER);
    //Optionable file chooser
    final JFileChooser chooser = new JFileChooser(lastPath) {

        @Override
        protected JDialog createDialog(Component parent) throws HeadlessException {
            dialog = super.createDialog(parent);
            dialog.setSize(640, 480);
            dialog.setResizable(true);
            Component c = dialog.getContentPane().getComponent(0);
            if (c != null && c instanceof JComponent) {
                Insets insets = ((JComponent) c).getInsets();
                southPanel.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
            }
            dialog.getContentPane().add(southPanel, BorderLayout.SOUTH);
            return dialog;
        }

        @Override
        public void approveSelection() {
            if (canExport(this)) {
                super.approveSelection();
            }
        }
    };
    chooser.setDialogTitle(NbBundle.getMessage(GraphFileExporterUI.class, "GraphFileExporterUI_filechooser_title"));
    chooser.addPropertyChangeListener(JFileChooser.FILE_FILTER_CHANGED_PROPERTY, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            DialogFileFilter fileFilter = (DialogFileFilter) evt.getNewValue();
            //Options panel enabling
            selectedBuilder = getExporter(fileFilter);
            if (selectedBuilder != null) {
                selectedExporter = selectedBuilder.buildExporter();
            }
            if (selectedBuilder != null && exportController.getExportController().getUI(selectedExporter) != null) {
                optionsButton.setEnabled(true);
            } else {
                optionsButton.setEnabled(false);
            }
            //Selected file extension change
            if (selectedFile != null && fileFilter != null) {
                String fileName = selectedFile.getName();
                String directoryPath = chooser.getCurrentDirectory().getAbsolutePath();
                if (fileName.lastIndexOf(".") != -1) {
                    fileName = fileName.substring(0, fileName.lastIndexOf("."));
                    fileName = fileName.concat(fileFilter.getExtensions().get(0));
                    selectedFile = new File(directoryPath, fileName);
                    chooser.setSelectedFile(selectedFile);
                }
            }
        }
    });
    chooser.addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getNewValue() != null) {
                selectedFile = (File) evt.getNewValue();
            }
        }
    });
    //File filters
    DialogFileFilter defaultFilter = null;
    for (GraphFileExporterBuilder graphFileExporter : Lookup.getDefault().lookupAll(GraphFileExporterBuilder.class)) {
        for (FileType fileType : graphFileExporter.getFileTypes()) {
            DialogFileFilter dialogFileFilter = new DialogFileFilter(fileType.getName());
            dialogFileFilter.addExtensions(fileType.getExtensions());
            if (defaultFilter == null) {
                defaultFilter = dialogFileFilter;
            }
            chooser.addChoosableFileFilter(dialogFileFilter);
        }
    }
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileFilter(defaultFilter);
    selectedFile = new File(chooser.getCurrentDirectory(), "Untitled" + defaultFilter.getExtensions().get(0));
    chooser.setSelectedFile(selectedFile);
    //Show
    int returnFile = chooser.showSaveDialog(null);
    if (returnFile == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        file = FileUtil.normalizeFile(file);
        FileObject fileObject = FileUtil.toFileObject(file);
        //Save last path
        NbPreferences.forModule(GraphFileExporterUI.class).put(LAST_PATH, file.getAbsolutePath());
        //Save variable
        visibleOnlyGraph = graphSettings.isVisibleOnlyGraph();
        //Do
        selectedExporter.setExportVisible(visibleOnlyGraph);
        exportController.exportFile(fileObject, selectedExporter);
    }
    dialog = null;
}
Also used : JPanel(javax.swing.JPanel) GraphFileExporterBuilder(org.gephi.io.exporter.spi.GraphFileExporterBuilder) FlowLayout(java.awt.FlowLayout) Insets(java.awt.Insets) ExporterUI(org.gephi.io.exporter.spi.ExporterUI) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) GraphFileExporterUIPanel(org.gephi.desktop.io.export.GraphFileExporterUIPanel) BorderLayout(java.awt.BorderLayout) FileObject(org.openide.filesystems.FileObject) JComponent(javax.swing.JComponent) Component(java.awt.Component) DialogFileFilter(org.gephi.ui.utils.DialogFileFilter) PropertyChangeEvent(java.beans.PropertyChangeEvent) JComponent(javax.swing.JComponent) ExportControllerUI(org.gephi.desktop.io.export.ExportControllerUI) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) FileType(org.gephi.io.exporter.api.FileType) DialogDescriptor(org.openide.DialogDescriptor) FileObject(org.openide.filesystems.FileObject) File(java.io.File)

Aggregations

JFileChooser (javax.swing.JFileChooser)797 File (java.io.File)571 IOException (java.io.IOException)185 FileFilter (javax.swing.filechooser.FileFilter)109 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)96 ActionEvent (java.awt.event.ActionEvent)59 ActionListener (java.awt.event.ActionListener)48 JButton (javax.swing.JButton)44 JPanel (javax.swing.JPanel)40 Component (java.awt.Component)39 FileOutputStream (java.io.FileOutputStream)39 FileNotFoundException (java.io.FileNotFoundException)30 JMenuItem (javax.swing.JMenuItem)29 Point (java.awt.Point)28 ArrayList (java.util.ArrayList)28 FileWriter (java.io.FileWriter)25 Dimension (java.awt.Dimension)24 PrintWriter (java.io.PrintWriter)24 JLabel (javax.swing.JLabel)22 JFrame (javax.swing.JFrame)21