Search in sources :

Example 76 with JFileChooser

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

the class SymbolicProgFrame method selectFileButtonActionPerformed.

protected void selectFileButtonActionPerformed(java.awt.event.ActionEvent e) {
    if (fci == null) {
        fci = new JFileChooser("xml" + File.separator + "decoders" + File.separator);
        fci.setFileFilter(new jmri.util.NoArchiveFileFilter());
    }
    // show dialog
    fci.rescanCurrentDirectory();
    int retVal = fci.showOpenDialog(this);
    // handle selection or cancel
    if (retVal == JFileChooser.APPROVE_OPTION) {
        File file = fci.getSelectedFile();
        if (log.isDebugEnabled()) {
            log.debug("selectFileButtonActionPerformed: located file " + file + " for XML processing");
        }
        progStatus.setText("Reading file...");
        // handle the file (later should be outside this thread?)
        readAndParseConfigFile(file);
        progStatus.setText("OK");
        if (log.isDebugEnabled()) {
            log.debug("selectFileButtonActionPerformed: parsing complete");
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) DecoderFile(jmri.jmrit.decoderdefn.DecoderFile) File(java.io.File)

Example 77 with JFileChooser

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

the class LoadVSDFileAction method actionPerformed.

/**
     * The action is performed. Let the user choose the file to load from. Read
     * XML for each VSDecoder Profile.
     *
     * @param e The event causing the action.
     */
@Override
public void actionPerformed(ActionEvent e) {
    if (fileChooser == null) {
        // Need to somehow give the user a history...
        // Must investigate JFileChooser...
        String start_dir = VSDecoderManager.instance().getVSDecoderPreferences().getDefaultVSDFilePath();
        if (last_path != null) {
            start_dir = last_path;
        }
        log.debug("Using path: " + start_dir);
        fileChooser = new JFileChooser(start_dir);
        jmri.util.FileChooserFilter filt = new jmri.util.FileChooserFilter(Bundle.getMessage("LoadVSDFileChooserFilterLabel"));
        filt.addExtension("vsd");
        filt.addExtension("zip");
        fileChooser.setFileFilter(filt);
        fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
        fileChooser.setCurrentDirectory(new File(start_dir));
    }
    int retVal = fileChooser.showOpenDialog(null);
    if (retVal != JFileChooser.APPROVE_OPTION) {
        return;
    // give up if no file selected
    }
    loadVSDFile(fileChooser.getSelectedFile());
    // Store the last used directory
    try {
        last_path = fileChooser.getCurrentDirectory().getCanonicalPath();
    } catch (java.io.IOException err) {
        log.debug("Error getting current directory: " + err);
        last_path = VSDecoderManager.instance().getVSDecoderPreferences().getDefaultVSDFilePath();
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) File(java.io.File)

Example 78 with JFileChooser

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

the class StoreXmlUserAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    JFileChooser userFileChooser = getUserFileChooser();
    userFileChooser.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
    userFileChooser.setApproveButtonText(rb.getString("StorePanelTitle"));
    userFileChooser.setDialogTitle(rb.getString("StorePanelTitle"));
    java.io.File file = getFileCustom(userFileChooser);
    if (file == null) {
        return;
    }
    // make a backup file
    ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm == null) {
        log.error("Failed to make backup due to unable to get default configure manager");
    } else {
        cm.makeBackup(file);
        // and finally store
        boolean results = cm.storeUser(file);
        log.debug(results ? "store was successful" : "store failed");
        if (!results) {
            JOptionPane.showMessageDialog(null, rb.getString("StoreHasErrors") + "\n" + rb.getString("StoreIncomplete") + "\n" + rb.getString("ConsoleWindowHasInfo"), rb.getString("StoreError"), JOptionPane.ERROR_MESSAGE);
        }
    }
}
Also used : ConfigureManager(jmri.ConfigureManager) JFileChooser(javax.swing.JFileChooser)

Example 79 with JFileChooser

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

the class LoadXmlUserAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    JFileChooser userFileChooser = getUserFileChooser();
    userFileChooser.setDialogType(javax.swing.JFileChooser.OPEN_DIALOG);
    userFileChooser.setApproveButtonText(rb.getString("LoadPanelTitle"));
    userFileChooser.setDialogTitle(rb.getString("LoadPanelTitle"));
    boolean results = loadFile(userFileChooser);
    if (results) {
        log.debug("load was successful");
        setCurrentFile(userFileChooser.getSelectedFile());
    } else {
        log.debug("load failed");
        JOptionPane.showMessageDialog(null, rb.getString("PanelHasErrors") + "\n" + rb.getString("CheckPreferences") + "\n" + rb.getString("ConsoleWindowHasInfo"), rb.getString("PanelLoadError"), JOptionPane.ERROR_MESSAGE);
        setCurrentFile(null);
    }
}
Also used : JFileChooser(javax.swing.JFileChooser)

Example 80 with JFileChooser

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

the class JythonAutomatonAction 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 JythonAutomaton(file.toString())).start();
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) 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