Search in sources :

Example 1 with JFileChooser

use of javax.swing.JFileChooser in project hackpad by dropbox.

the class JSConsole method createFileChooser.

public void createFileChooser() {
    dlg = new JFileChooser();
    javax.swing.filechooser.FileFilter filter = new javax.swing.filechooser.FileFilter() {

        @Override
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return true;
            }
            String name = f.getName();
            int i = name.lastIndexOf('.');
            if (i > 0 && i < name.length() - 1) {
                String ext = name.substring(i + 1).toLowerCase();
                if (ext.equals("js")) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public String getDescription() {
            return "JavaScript Files (*.js)";
        }
    };
    dlg.addChoosableFileFilter(filter);
}
Also used : JFileChooser(javax.swing.JFileChooser) File(java.io.File)

Example 2 with JFileChooser

use of javax.swing.JFileChooser in project pcgen by PCGen.

the class SpellSupportFacadeImpl method exportSpells.

@Override
public void exportSpells() {
    final String template = PCGenSettings.getInstance().getProperty(PCGenSettings.SELECTED_SPELL_SHEET_PATH);
    if (StringUtils.isEmpty(template)) {
        delegate.showErrorMessage(Constants.APPLICATION_NAME, //$NON-NLS-1$
        LanguageBundle.getString("in_spellNoSheet"));
        return;
    }
    String ext = template.substring(template.lastIndexOf('.'));
    // Get the name of the file to output to.
    JFileChooser fcExport = new JFileChooser();
    fcExport.setCurrentDirectory(new File(PCGenSettings.getPcgDir()));
    fcExport.setDialogTitle(LanguageBundle.getString("InfoSpells.export.spells.for") + //$NON-NLS-1$
    charDisplay.getDisplayName());
    if (fcExport.showSaveDialog(null) != JFileChooser.APPROVE_OPTION) {
        return;
    }
    final String aFileName = fcExport.getSelectedFile().getAbsolutePath();
    if (aFileName.length() < 1) {
        delegate.showErrorMessage(Constants.APPLICATION_NAME, //$NON-NLS-1$ 
        LanguageBundle.getString("InfoSpells.must.set.filename"));
        return;
    }
    try {
        final File outFile = new File(aFileName);
        if (outFile.isDirectory()) {
            delegate.showErrorMessage(Constants.APPLICATION_NAME, //$NON-NLS-1$ 
            LanguageBundle.getString("InfoSpells.can.not.overwrite.directory"));
            return;
        }
        if (outFile.exists()) {
            int reallyClose = JOptionPane.showConfirmDialog(null, LanguageBundle.getFormattedString("InfoSpells.confirm.overwrite", //$NON-NLS-1$
            outFile.getName()), LanguageBundle.getFormattedString("InfoSpells.overwriting", outFile.getName()), //$NON-NLS-1$
            JOptionPane.YES_NO_OPTION);
            if (reallyClose != JOptionPane.YES_OPTION) {
                return;
            }
        }
        // Output the file
        File templateFile = new File(template);
        boolean success;
        if (ExportUtilities.isPdfTemplate(templateFile)) {
            success = BatchExporter.exportCharacterToPDF(pcFacade, outFile, templateFile);
        } else {
            success = BatchExporter.exportCharacterToNonPDF(pcFacade, outFile, templateFile);
        }
        if (!success) {
            delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getFormattedString("InfoSpells.export.failed", //$NON-NLS-1$ 
            charDisplay.getDisplayName()));
        }
    } catch (Exception ex) {
        Logging.errorPrint(LanguageBundle.getFormattedString("InfoSpells.export.failed", charDisplay.getDisplayName()), //$NON-NLS-1$
        ex);
        delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getFormattedString("InfoSpells.export.failed.retry", //$NON-NLS-1$ 
        charDisplay.getDisplayName()));
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) File(java.io.File) IOException(java.io.IOException)

Example 3 with JFileChooser

use of javax.swing.JFileChooser in project pcgen by PCGen.

the class SourceSelectionPanel method setupDisplay.

@Override
public void setupDisplay(JPanel panel, final CDOMObject pc) {
    panel.setLayout(new GridBagLayout());
    JLabel label = new JLabel("Please select the Source Directory to Convert: ");
    GridBagConstraints gbc = new GridBagConstraints();
    Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST);
    gbc.insets = new Insets(50, 25, 10, 25);
    panel.add(label, gbc);
    JButton button = new JButton("Browse...");
    button.setMnemonic('r');
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            JFileChooser chooser = new JFileChooser(SourceFolder.OTHER.getFile());
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setDialogType(JFileChooser.OPEN_DIALOG);
            chooser.setSelectedFile(path);
            while (true) {
                int open = chooser.showOpenDialog(null);
                if (open == JFileChooser.APPROVE_OPTION) {
                    File fileToOpen = chooser.getSelectedFile();
                    if (fileToOpen.isDirectory()) {
                        path = fileToOpen;
                        SourceFolder.OTHER.setFile(fileToOpen);
                        pc.put(ObjectKey.DIRECTORY, path);
                        PCGenSettings context = PCGenSettings.getInstance();
                        context.setProperty(PCGenSettings.CONVERT_INPUT_PATH, path.getAbsolutePath());
                        JRadioButton button = radioButtons[SourceFolder.OTHER.ordinal()];
                        button.setSelected(true);
                        button.setText(buildFolderText(SourceFolder.OTHER, fileToOpen.getAbsolutePath()));
                        break;
                    }
                    JOptionPane.showMessageDialog(null, "Selection must be a valid Directory");
                    chooser.setSelectedFile(path);
                } else if (open == JFileChooser.CANCEL_OPTION) {
                    break;
                }
            }
        }
    });
    radioButtons = new JRadioButton[SourceFolder.values().length];
    String selectedPath = null;
    File selectedFile = pc.get(ObjectKey.DIRECTORY);
    if (selectedFile != null) {
        selectedPath = selectedFile.getAbsolutePath();
    } else {
        PCGenSettings context = PCGenSettings.getInstance();
        selectedPath = context.getProperty(PCGenSettings.CONVERT_INPUT_PATH, null);
    }
    ButtonGroup group = new ButtonGroup();
    boolean haveSelected = false;
    Font font = panel.getFont();
    font = FontManipulation.plain(font);
    for (SourceFolder folder : SourceFolder.values()) {
        JRadioButton pathButton = new JRadioButton();
        final SourceFolder buttonFolder = folder;
        pathButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                PCGenSettings context = PCGenSettings.getInstance();
                context.setProperty(PCGenSettings.CONVERT_INPUT_PATH, buttonFolder.getFile().getAbsolutePath());
                pc.put(ObjectKey.DIRECTORY, buttonFolder.getFile());
            }
        });
        String path;
        if (folder.getFile() == null) {
            path = "Undefined";
            pathButton.setEnabled(false);
        } else {
            path = folder.getFile().getAbsolutePath();
            if (path.equals(selectedPath)) {
                pathButton.setSelected(true);
                haveSelected = true;
                PCGenSettings context = PCGenSettings.getInstance();
                context.setProperty(PCGenSettings.CONVERT_INPUT_PATH, path);
                selectedFile = folder.getFile();
            }
        }
        pathButton.setText(buildFolderText(folder, path));
        pathButton.setFont(font);
        radioButtons[folder.ordinal()] = pathButton;
        group.add(pathButton);
        if (folder == SourceFolder.OTHER) {
            Utility.buildRelativeConstraints(gbc, 1, GridBagConstraints.REMAINDER, 1.0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST);
        } else {
            Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST);
        }
        gbc.insets = new Insets(10, 25, 10, 25);
        panel.add(pathButton, gbc);
        if (folder == SourceFolder.OTHER) {
            Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHEAST);
            gbc.insets = new Insets(10, 25, 10, 25);
            panel.add(button, gbc);
        }
    }
    Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER, 1.0, 1.0, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST);
    panel.add(new JLabel(" "), gbc);
    if (!haveSelected) {
        if (selectedPath != null) {
            JRadioButton btn = radioButtons[SourceFolder.OTHER.ordinal()];
            btn.setSelected(true);
            selectedFile = new File(selectedPath);
            SourceFolder.OTHER.setFile(selectedFile);
            path = selectedFile;
            btn.setText(buildFolderText(SourceFolder.OTHER, selectedFile.getAbsolutePath()));
        } else if (radioButtons[SourceFolder.VENDORDATA.ordinal()].isEnabled()) {
            JRadioButton btn = radioButtons[SourceFolder.VENDORDATA.ordinal()];
            btn.setSelected(true);
            selectedFile = SourceFolder.VENDORDATA.getFile();
        } else if (radioButtons[SourceFolder.HOMEBREWDATA.ordinal()].isEnabled()) {
            JRadioButton btn = radioButtons[SourceFolder.HOMEBREWDATA.ordinal()];
            btn.setSelected(true);
            selectedFile = SourceFolder.HOMEBREWDATA.getFile();
        } else {
            JRadioButton btn = radioButtons[SourceFolder.DATA.ordinal()];
            btn.setSelected(true);
            selectedFile = SourceFolder.DATA.getFile();
        }
    }
    pc.put(ObjectKey.DIRECTORY, selectedFile);
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JRadioButton(javax.swing.JRadioButton) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Font(java.awt.Font) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) ButtonGroup(javax.swing.ButtonGroup) PCGenSettings(pcgen.system.PCGenSettings) File(java.io.File)

Example 4 with JFileChooser

use of javax.swing.JFileChooser in project OpenAM by OpenRock.

the class ListJPanel method containerDirBrowsejButtonActionPerformed.

private void containerDirBrowsejButtonActionPerformed(java.awt.event.ActionEvent evt) {
    if (containerDirChooser == null) {
        String initDir = System.getProperty("user.home");
        if (initDir != null) {
            containerDirChooser = new JFileChooser(initDir);
        } else {
            containerDirChooser = new JFileChooser();
        }
    } else {
        if (containerDirFile != null) {
            containerDirChooser.setCurrentDirectory(containerDirFile);
        }
    }
    containerDirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    containerDirChooser.setMultiSelectionEnabled(false);
    containerDirChooser.setDialogTitle(rb.getString("dlg_open_wc_base_dir_title"));
    if (containerDirChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        containerDirFile = containerDirChooser.getSelectedFile();
        if ((containerDirFile != null) && containerDirFile.exists() && containerDirFile.isDirectory()) {
            containerDirjTextField.setText(containerDirFile.getAbsolutePath());
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser)

Example 5 with JFileChooser

use of javax.swing.JFileChooser in project OpenAM by OpenRock.

the class ListJPanel method containerDomainDirBrowsejButtonActionPerformed.

private void containerDomainDirBrowsejButtonActionPerformed(java.awt.event.ActionEvent evt) {
    if (containerDomainDirChooser == null) {
        String initDir = System.getProperty("user.home");
        if (initDir != null) {
            containerDomainDirChooser = new JFileChooser(initDir);
        } else {
            containerDomainDirChooser = new JFileChooser();
        }
    } else {
        if (containerDomainDirFile != null) {
            containerDomainDirChooser.setCurrentDirectory(containerDomainDirFile);
        }
    }
    containerDomainDirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    containerDomainDirChooser.setMultiSelectionEnabled(false);
    containerDomainDirChooser.setDialogTitle(rb.getString("dlg_open_wc_domain_dir_title"));
    if (containerDomainDirChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        containerDomainDirFile = containerDomainDirChooser.getSelectedFile();
        if ((containerDomainDirFile != null) && containerDomainDirFile.exists() && containerDomainDirFile.isDirectory()) {
            containerDomainDirjTextField.setText(containerDomainDirFile.getAbsolutePath());
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser)

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