Search in sources :

Example 71 with JFileChooser

use of javax.swing.JFileChooser in project CFLint by cflint.

the class CFLintMain method ui.

private void ui() {
    final JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Select target directory");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    final int returnVal = chooser.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        folder.add(chooser.getSelectedFile().getAbsolutePath());
    } else {
        return;
    }
    final String[] slist = new String[] { "xml", "html", "text", "txt", "json" };
    final JList<String> list = new JList<String>(slist);
    JOptionPane.showMessageDialog(null, list, "Output Type", JOptionPane.PLAIN_MESSAGE);
    final int[] indxs = list.getSelectedIndices();
    // If selected set htmlOutput to false
    for (final int indx : indxs) {
        if (indx == 0) {
            xmlOutput = true;
        }
        if (indx == 1) {
            htmlOutput = true;
        }
        if (indx == 2 || indx == 3) {
            textOutput = true;
        }
        if (indx == 4) {
            jsonOutput = true;
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) CFLint(com.cflint.CFLint) JList(javax.swing.JList)

Example 72 with JFileChooser

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

the class ProfileManagerDialog method btnUseExistingActionPerformed.

//GEN-LAST:event_btnCreateActionPerformed
private void btnUseExistingActionPerformed(ActionEvent evt) {
    //GEN-FIRST:event_btnUseExistingActionPerformed
    timer.stop();
    countDownLbl.setVisible(false);
    JFileChooser chooser = new JFileChooser(FileUtil.getHomePath());
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setFileFilter(new ProfileFileFilter());
    chooser.setFileView(new ProfileFileView());
    // TODO: Use NetBeans OpenDialog if its availble
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {
            Profile p = new Profile(chooser.getSelectedFile());
            ProfileManager.getDefault().addProfile(p);
            profiles.setSelectedValue(p, true);
        } catch (IOException ex) {
            log.warn("{} is not a profile directory", chooser.getSelectedFile());
        // TODO: Display error dialog - selected file is not a profile directory
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) IOException(java.io.IOException)

Example 73 with JFileChooser

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

the class ProfilePreferencesPanel method btnOpenExistingProfileActionPerformed.

//GEN-LAST:event_btnDeleteProfileActionPerformed
private void btnOpenExistingProfileActionPerformed(ActionEvent evt) {
    //GEN-FIRST:event_btnOpenExistingProfileActionPerformed
    JFileChooser chooser = new JFileChooser(FileUtil.getHomePath());
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setFileFilter(new ProfileFileFilter());
    chooser.setFileView(new ProfileFileView());
    // TODO: Use NetBeans OpenDialog if its availble
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {
            Profile p = new Profile(chooser.getSelectedFile());
            ProfileManager.getDefault().addProfile(p);
            int index = ProfileManager.getDefault().getAllProfiles().indexOf(p);
            profilesTbl.setRowSelectionInterval(index, index);
        } catch (IOException ex) {
            log.warn("{} is not a profile directory", chooser.getSelectedFile());
            JOptionPane.showMessageDialog(this, Bundle.getMessage("ProfilePreferencesPanel.btnOpenExistingProfile.errorMessage", chooser.getSelectedFile().getPath()), Bundle.getMessage("ProfilePreferencesPanel.btnOpenExistingProfile.errorMessage"), JOptionPane.ERROR_MESSAGE);
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) IOException(java.io.IOException)

Example 74 with JFileChooser

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

the class SetupExcelProgramFrame method selectFile.

/**
     * Opens a dialog window in either the csvManifest or csvSwitchLists
     * directory
     * @param directoryName The string name of the directory
     * @return The File selected.
     *
     */
protected File selectFile(String directoryName) {
    // NOI18N
    JFileChooser fc = jmri.jmrit.XmlFile.userFileChooser(Bundle.getMessage("ExcelProgramFiles"), "xls", "xlsm");
    fc.setCurrentDirectory(OperationsManager.getInstance().getFile(directoryName));
    fc.setDialogTitle(Bundle.getMessage("FindDesiredExcelFile"));
    // when reusing the chooser, make sure new files are included
    fc.rescanCurrentDirectory();
    int retVal = fc.showOpenDialog(null);
    // handle selection or cancel
    if (retVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // Run the script from it's filename
        return file;
    }
    return null;
}
Also used : JFileChooser(javax.swing.JFileChooser) File(java.io.File)

Example 75 with JFileChooser

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

the class FullBackupExportAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    Roster roster = Roster.getDefault();
    ZipOutputStream zipper = null;
    try {
        String roster_filename_extension = "roster";
        JFileChooser chooser = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("JMRI full roster files", roster_filename_extension);
        chooser.setFileFilter(filter);
        int returnVal = chooser.showSaveDialog(_parent);
        if (returnVal != JFileChooser.APPROVE_OPTION) {
            return;
        }
        String filename = chooser.getSelectedFile().getAbsolutePath();
        if (!filename.endsWith(roster_filename_extension)) {
            filename = filename.concat(roster_filename_extension);
        }
        zipper = new ZipOutputStream(new FileOutputStream(filename));
        // create a zip file roster entry for each entry in the main roster
        for (RosterEntry entry : roster.getAllEntries()) {
            copyFileToStream(entry.getPathName(), "roster", zipper, entry.getId());
        }
        // Now the full roster entry
        copyFileToStream(Roster.getDefault().getRosterIndexPath(), null, zipper, null);
        zipper.setComment("Roster file saved from DecoderPro " + jmri.Version.name());
        zipper.close();
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (zipper != null) {
            try {
                zipper.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter)

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