Search in sources :

Example 81 with JFileChooser

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

the class JythonSigletAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    // create a SampleAutomaton
    JFileChooser fci = jmri.jmrit.XmlFile.userFileChooser("Python script files", "py");
    fci.setDialogTitle("Find desired script file");
    int retVal = fci.showOpenDialog(_who);
    // handle selection or cancel
    if (retVal == JFileChooser.APPROVE_OPTION) {
        File file = fci.getSelectedFile();
        // create an object to handle script and run
        (new JythonSiglet(file.toString())).start();
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) File(java.io.File)

Example 82 with JFileChooser

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

the class RouteTableAction method setSoundPressed.

/**
     * Set the sound file
     */
void setSoundPressed() {
    if (soundChooser == null) {
        soundChooser = new JFileChooser(FileUtil.getUserFilesPath());
        soundChooser.setFileFilter(new jmri.util.NoArchiveFileFilter());
    }
    soundChooser.rescanCurrentDirectory();
    int retVal = soundChooser.showOpenDialog(null);
    // handle selection or cancel
    if (retVal == JFileChooser.APPROVE_OPTION) {
        try {
            soundFile.setText(soundChooser.getSelectedFile().getCanonicalPath());
        } catch (java.io.IOException e) {
            log.error("exception setting sound file: " + e);
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser)

Example 83 with JFileChooser

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

the class BackupFilesAction method backUp.

private void backUp() {
    // check to see if files are dirty
    if (OperationsXml.areFilesDirty()) {
        if (JOptionPane.showConfirmDialog(null, Bundle.getMessage("OperationsFilesModified"), Bundle.getMessage("SaveOperationFiles"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            OperationsXml.save();
        }
    }
    BackupBase backup = new DefaultBackup();
    // get directory to write to
    JFileChooser fc = new JFileChooser(backup.getBackupRoot());
    fc.addChoosableFileFilter(new fileFilter());
    File fs = new File(backup.suggestBackupSetName());
    fc.setSelectedFile(fs);
    int retVal = fc.showSaveDialog(null);
    if (retVal != JFileChooser.APPROVE_OPTION) {
        // Canceled
        return;
    }
    if (fc.getSelectedFile() == null) {
        // Canceled
        return;
    }
    File directory = fc.getSelectedFile();
    // Fix this later....... UGH!!
    try {
        backup.backupFilesToDirectory(directory);
    } catch (IOException ex) {
        log.error("backup failed");
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) IOException(java.io.IOException) File(java.io.File)

Example 84 with JFileChooser

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

the class StoreXmlVSDecoderAction method actionPerformed.

/**
     * The action is performed. Let the user choose the file to save to. Write
     * XML for each ThrottleFrame.
     *
     * @param e The event causing the action.
     */
@Override
public void actionPerformed(ActionEvent e) {
    JFileChooser fileChooser = jmri.jmrit.XmlFile.userFileChooser(Bundle.getMessage("PromptXmlFileTypes"), "xml");
    fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    fileChooser.setCurrentDirectory(new File(VSDecoderPane.getDefaultVSDecoderFolder()));
    java.io.File file = StoreXmlConfigAction.getFileName(fileChooser);
    if (file == null) {
        return;
    }
    saveVSDecoderProfile(file);
}
Also used : JFileChooser(javax.swing.JFileChooser) File(java.io.File) XmlFile(jmri.jmrit.XmlFile) File(java.io.File)

Example 85 with JFileChooser

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

the class DccSpeedProfile method openImportFile.

private void openImportFile() {
    JFileChooser fileChooser = new JFileChooser(FileUtil.getUserFilesPath());
    // get filename
    // start at current file, show dialog
    int retVal = fileChooser.showOpenDialog(null);
    // handle selection or cancel
    if (retVal == JFileChooser.APPROVE_OPTION) {
        String selectedPath = fileChooser.getSelectedFile().getPath();
        Path filePath = Paths.get(selectedPath);
        try {
            dccProfileData = Files.readAllLines(filePath);
        } catch (IOException ex) {
            log.error("Failed to read reference profile file " + ex);
        }
    }
}
Also used : Path(java.nio.file.Path) JFileChooser(javax.swing.JFileChooser) IOException(java.io.IOException)

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