Search in sources :

Example 1 with FileNameExtensionFilter

use of javax.swing.filechooser.FileNameExtensionFilter in project javatari by ppeccin.

the class FileROMChooser method chooseFileToSavestate.

public static File chooseFileToSavestate() throws AccessControlException {
    if (chooser != null && chooser.isShowing())
        return null;
    if (lastSaveFileChosen == null)
        lastSaveFileChosen = new File(Parameters.LAST_ROM_SAVE_FILE_CHOSEN);
    if (chooser == null)
        createChooser();
    chooser.setFileFilter(new FileNameExtensionFilter(ROMLoader.VALID_STATE_FILE_DESC, ROMLoader.VALID_STATE_FILE_EXTENSION));
    chooser.setSelectedFile(lastSaveFileChosen);
    int res = chooser.showSaveDialog(null);
    if (res != 0)
        return null;
    lastSaveFileChosen = chooser.getSelectedFile();
    if (!lastSaveFileChosen.toString().toUpperCase().endsWith(ROMLoader.VALID_STATE_FILE_EXTENSION.toUpperCase()))
        lastSaveFileChosen = new File(lastSaveFileChosen + "." + ROMLoader.VALID_STATE_FILE_EXTENSION);
    Parameters.LAST_ROM_SAVE_FILE_CHOSEN = lastSaveFileChosen.toString();
    Parameters.savePreferences();
    return lastSaveFileChosen;
}
Also used : FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

Example 2 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 3 with FileNameExtensionFilter

use of javax.swing.filechooser.FileNameExtensionFilter in project CoreNLP by stanfordnlp.

the class DisplayMatchesPanel method doExportTree.

private void doExportTree() {
    JFileChooser chooser = new JFileChooser();
    chooser.setSelectedFile(new File("./tree.png"));
    FileNameExtensionFilter filter = new FileNameExtensionFilter("PNG images", "png");
    chooser.setFileFilter(filter);
    int status = chooser.showSaveDialog(this);
    if (status != JFileChooser.APPROVE_OPTION)
        return;
    Dimension size = tjp.getPreferredSize();
    BufferedImage im = new BufferedImage((int) size.getWidth(), (int) size.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = im.createGraphics();
    tjp.paint(g);
    try {
        ImageIO.write(im, "png", chooser.getSelectedFile());
    } catch (IOException e) {
        JOptionPane.showMessageDialog(this, "Failed to save the tree image file.\n" + e.getLocalizedMessage(), "Export Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : Dimension(java.awt.Dimension) IOException(java.io.IOException) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 4 with FileNameExtensionFilter

use of javax.swing.filechooser.FileNameExtensionFilter in project DistributedFractalNetwork by Budder21.

the class Display method menus.

private JMenuBar menus() {
    ToolTipManager.sharedInstance().setInitialDelay(0);
    JMenuBar bar = new JMenuBar();
    JMenu view = new JMenu("View");
    JMenuItem serverLog = new JMenuItem("Server Log");
    serverLog.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JFrame f = new JFrame("Server Log");
            JTextArea textArea = new JTextArea(35, 55);
            JScrollPane scroll = new JScrollPane(textArea);
            textArea.setText(log.getLog());
            scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
            scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
            f.setLayout(new BorderLayout());
            f.add(scroll, BorderLayout.CENTER);
            JButton b = new JButton("Save");
            b.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    JFileChooser fileChooser = new JFileChooser();
                    FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "text");
                    fileChooser.setFileFilter(filter);
                    fileChooser.setCurrentDirectory(new File("fractals/logs"));
                    fileChooser.showSaveDialog(null);
                    String dir = fileChooser.getSelectedFile().getPath();
                    if (!dir.substring(dir.lastIndexOf(".") + 1).equals("txt"))
                        dir = dir.substring(0, dir.lastIndexOf(".")) + ".txt";
                    System.out.println("\n\n" + dir + "\n\n");
                    try {
                        PrintWriter out = new PrintWriter(dir);
                        Scanner s = new Scanner(textArea.getText());
                        while (s.hasNextLine()) out.println(s.nextLine());
                        out.flush();
                        out.close();
                    } catch (FileNotFoundException e1) {
                        log.addError(e1);
                    }
                }
            });
            JPanel tempPanel = new JPanel();
            tempPanel.add(b);
            f.add(tempPanel, BorderLayout.SOUTH);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setResizable(true);
            f.setVisible(true);
        }
    });
    serverLog.setToolTipText("Displays the log of the current server.");
    view.add(serverLog);
    bar.add(view);
    return bar;
}
Also used : JScrollPane(javax.swing.JScrollPane) Scanner(java.util.Scanner) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) FileNotFoundException(java.io.FileNotFoundException) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout) JFileChooser(javax.swing.JFileChooser) JFrame(javax.swing.JFrame) JMenuItem(javax.swing.JMenuItem) File(java.io.File) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu) PrintWriter(java.io.PrintWriter)

Example 5 with FileNameExtensionFilter

use of javax.swing.filechooser.FileNameExtensionFilter in project pcgen by PCGen.

the class ExportDialog method export.

private void export(boolean pdf) {
    UIPropertyContext context = UIPropertyContext.createContext("ExportDialog");
    final JFileChooser fcExport = new JFileChooser();
    fcExport.setFileSelectionMode(JFileChooser.FILES_ONLY);
    File baseDir = null;
    {
        String path;
        if (pdf) {
            path = context.getProperty(PDF_EXPORT_DIR_PROP);
        } else {
            path = context.getProperty(HTML_EXPORT_DIR_PROP);
        }
        if (path != null) {
            baseDir = new File(path);
        }
    }
    if (baseDir == null || !baseDir.isDirectory()) {
        baseDir = SystemUtils.getUserHome();
    }
    fcExport.setCurrentDirectory(baseDir);
    URI uri = (URI) fileList.getSelectedValue();
    String extension = ExportUtilities.getOutputExtension(uri.toString(), pdf);
    if (pdf) {
        FileFilter fileFilter = new FileNameExtensionFilter("PDF Documents (*.pdf)", "pdf");
        fcExport.addChoosableFileFilter(fileFilter);
        fcExport.setFileFilter(fileFilter);
    } else if ("htm".equalsIgnoreCase(extension) || "html".equalsIgnoreCase(extension)) {
        FileFilter fileFilter = new FileNameExtensionFilter("HTML Documents (*.htm, *.html)", "htm", "html");
        fcExport.addChoosableFileFilter(fileFilter);
        fcExport.setFileFilter(fileFilter);
    } else if ("xml".equalsIgnoreCase(extension)) {
        FileFilter fileFilter = new FileNameExtensionFilter("XML Documents (*.xml)", "xml");
        fcExport.addChoosableFileFilter(fileFilter);
        fcExport.setFileFilter(fileFilter);
    } else {
        String desc = extension + " Files (*." + extension + ")";
        fcExport.addChoosableFileFilter(new FileNameExtensionFilter(desc, extension));
    }
    String name;
    File path;
    if (!partyBox.isSelected()) {
        CharacterFacade character = (CharacterFacade) characterBox.getSelectedItem();
        path = character.getFileRef().get();
        if (path != null) {
            path = path.getParentFile();
        } else {
            path = new File(PCGenSettings.getPcgDir());
        }
        name = character.getTabNameRef().get();
        if (StringUtils.isEmpty(name)) {
            name = character.getNameRef().get();
        }
    } else {
        path = new File(PCGenSettings.getPcgDir());
        name = "Entire Party";
    }
    if (pdf) {
        fcExport.setSelectedFile(new File(path, name + ".pdf"));
    } else {
        fcExport.setSelectedFile(new File(path, name + "." + extension));
    }
    fcExport.setDialogTitle("Export " + name);
    if (fcExport.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
        return;
    }
    final File outFile = fcExport.getSelectedFile();
    if (pdf) {
        context.setProperty(PDF_EXPORT_DIR_PROP, outFile.getParent());
    } else {
        context.setProperty(HTML_EXPORT_DIR_PROP, outFile.getParent());
    }
    if (StringUtils.isEmpty(outFile.getName())) {
        pcgenFrame.showErrorMessage("PCGen", "You must set a filename.");
        return;
    }
    if (outFile.isDirectory()) {
        pcgenFrame.showErrorMessage("PCGen", "You cannot overwrite a directory with a file.");
        return;
    }
    if (outFile.exists() && SettingsHandler.getAlwaysOverwrite() == false) {
        int reallyClose = JOptionPane.showConfirmDialog(this, "The file " + outFile.getName() + " already exists, are you sure you want to overwrite it?", "Confirm overwriting " + outFile.getName(), JOptionPane.YES_NO_OPTION);
        if (reallyClose != JOptionPane.YES_OPTION) {
            return;
        }
    }
    try {
        if (pdf) {
            new PDFExporter(outFile, extension, name).execute();
        } else {
            if (!printToFile(outFile)) {
                String message = "The character export failed. Please see the log for details.";
                pcgenFrame.showErrorMessage(Constants.APPLICATION_NAME, message);
                return;
            }
            maybeOpenFile(outFile);
            Globals.executePostExportCommandStandard(outFile.getAbsolutePath());
        }
    } catch (IOException ex) {
        pcgenFrame.showErrorMessage("PCGen", "Could not export " + name + ". Try another filename.");
        Logging.errorPrint("Could not export " + name, ex);
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) IOException(java.io.IOException) IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) TrueFileFilter(org.apache.commons.io.filefilter.TrueFileFilter) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter) FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) UIPropertyContext(pcgen.gui2.UIPropertyContext) File(java.io.File) URI(java.net.URI) CharacterFacade(pcgen.facade.core.CharacterFacade)

Aggregations

FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)51 File (java.io.File)31 JFileChooser (javax.swing.JFileChooser)29 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