Example usage for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter

List of usage examples for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter

Introduction

In this page you can find the example usage for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter.

Prototype

public FileNameExtensionFilter(String description, String... extensions) 

Source Link

Document

Creates a FileNameExtensionFilter with the specified description and file name extensions.

Usage

From source file:uk.ac.lkl.cram.ui.ModuleFrame.java

private void exportReport() {
    JFileChooser jfc = new JFileChooser();
    jfc.setAcceptAllFileFilterUsed(false);
    jfc.setDialogTitle("Export CRAM Module");
    FileFilter filter = new FileNameExtensionFilter("Word Document", "docx");
    jfc.setFileFilter(filter);/*from   w w w  . j a  v  a2 s.  co  m*/
    jfc.setSelectedFile(new File(module.getModuleName() + ".docx"));
    //Open the dialog and wait for the user to provide a name for the file
    int returnVal = jfc.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = jfc.getSelectedFile();
        //Add the file extension
        if (!jfc.getSelectedFile().getAbsolutePath().endsWith(".docx")) {
            file = new File(jfc.getSelectedFile() + ".docx");
        }
        try {
            this.setCursor(WAIT);
            Report report = new Report(module);
            report.save(file);
        } catch (Docx4JException ex) {
            LOGGER.log(Level.SEVERE, "Failed to export report", ex);
            JOptionPane.showMessageDialog(this, ex.getLocalizedMessage(), "Failed to export report",
                    JOptionPane.ERROR_MESSAGE);
        } finally {
            this.setCursor(Cursor.getDefaultCursor());
        }
    }
}

From source file:com.marginallyclever.makelangelo.MainGUI.java

private void SaveFileDialog() {
    // Note: source for ExampleFileFilter can be found in FileChooserDemo,
    // under the demo/jfc directory in the Java 2 SDK, Standard Edition.
    String s = recentFiles.get(0);
    String filename = (s.length() > 0) ? filename = s : "";

    FileFilter filterGCODE = new FileNameExtensionFilter(translator.get("FileTypeGCode"), "ngc");

    JFileChooser fc = new JFileChooser(new File(filename));
    fc.addChoosableFileFilter(filterGCODE);
    if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        String selectedFile = fc.getSelectedFile().getAbsolutePath();

        if (!selectedFile.toLowerCase().endsWith(".ngc")) {
            selectedFile += ".ngc";
        }/*from  w w  w.ja  v a 2s. co  m*/

        try {
            gcode.Save(selectedFile);
        } catch (IOException e) {
            Log("<span style='color:red'>" + translator.get("Failed") + e.getMessage() + "</span>\n");
            return;
        }
    }
}

From source file:au.com.jwatmuff.eventmanager.gui.main.LoadCompetitionWindow.java

private void saveBackupButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBackupButtonActionPerformed
    DatabaseInfo info = (DatabaseInfo) competitionList.getSelectedValue();
    if (info == null || !info.local)
        return;/*from  w  ww .j  ava  2  s  . c om*/
    JFileChooser chooser = new JFileChooser();
    chooser.setFileFilter(new FileNameExtensionFilter("Event Manager Files", "evm"));
    if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        if (!file.getName().toLowerCase().endsWith(".evm"))
            file = new File(file.getAbsolutePath() + ".evm");
        if (file.exists()) {
            int result = JOptionPane.showConfirmDialog(rootPane,
                    file.getName() + " already exists. Overwrite file?", "Save Backup",
                    JOptionPane.YES_NO_OPTION);
            if (result != JOptionPane.YES_OPTION)
                return;
        }
        try {
            File tempDir = Files.createTempDirectory("event-manager").toFile();
            FileUtils.copyDirectory(info.localDirectory, tempDir);

            File lockFile = new File(tempDir, "update.dat.lock");
            lockFile.delete();

            /* change id */
            Properties props = new Properties();
            FileReader fr = new FileReader(new File(tempDir, "info.dat"));
            props.load(fr);
            fr.close();
            props.setProperty("old-UUID", props.getProperty("UUID", "none"));
            props.setProperty("UUID", UUID.randomUUID().toString());
            FileWriter fw = new FileWriter(new File(tempDir, "info.dat"));
            props.store(fw, "");
            fw.close();

            ZipUtils.zipFolder(tempDir, file, false);
        } catch (Exception e) {
            GUIUtils.displayError(this, "Failed to save file: " + e.getMessage());
        }
    }
}

From source file:frames.MainGUI.java

private File getSelectedFile() {
    // get file path
    FileFilter filter = new FileNameExtensionFilter("soccer data files", "csv");

    JFileChooser chooser = new JFileChooser(System.getProperty("user.dir"));

    chooser.addChoosableFileFilter(filter);
    int returnVal = chooser.showOpenDialog(null);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        return chooser.getSelectedFile();
    } else//from  ww w .ja  v  a2 s .co  m
        return null;
}

From source file:techtonic.Techtonic.java

private void jmiLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiLoadActionPerformed
    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter fnef = new FileNameExtensionFilter("xml file only", ".xml");
    chooser.setFileFilter(fnef);/* ww  w.  jav  a  2s. com*/
    int input = chooser.showOpenDialog(this);
    if (input == 0) {

    }
}

From source file:at.nhmwien.schema_mapping_tool.ProcessMappingWindow.java

/**
 * Save all settings to a given file/*from   www  .  ja  v  a  2s. c o  m*/
 * @param evt
 */
private void saveSettingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveSettingsButtonActionPerformed
    // Save all configuration properties
    this.settings.setProperty("config.input-file-processor", this.inputFileFormatComboBox.getSelectedItem());
    this.settings.setProperty("config.output-file-processor", this.outputFileFormatComboBox.getSelectedItem());
    this.settings.setProperty("config.input-file-encoding",
            this.ifEncodingComboBox.getSelectedItem().toString());
    this.settings.setProperty("config.output-file-encoding",
            this.ofEncodingComboBox.getSelectedItem().toString());
    this.settings.setProperty("config.input-id-prefix", this.inputIDPrefixTextField.getText());
    this.settings.setProperty("config.count-threshold", this.countThresholdTextField.getText());
    this.settings.setProperty("config.input-field-order", MappingsHandler.Self().getInputOrder());
    this.settings.setProperty("config.output-field-order", MappingsHandler.Self().getOutputOrder());
    // Save File-Processor specific options
    FileProcessor fp = this.inputOptionsPanel.getProcessor();
    String fpOptions[] = fp.getAvailableOptions();
    for (String fpOption : fpOptions) {
        this.settings.setProperty("config.inputProcessor.options." + fpOption, fp.getOption(fpOption));
    }
    fp = this.outputOptionsPanel.getProcessor();
    fpOptions = fp.getAvailableOptions();
    for (String fpOption : fpOptions) {
        this.settings.setProperty("config.outputProcessor.options." + fpOption, fp.getOption(fpOption));
    }

    JFileChooser fc = new JFileChooser();
    fc.setAcceptAllFileFilterUsed(false);
    FileNameExtensionFilter fnef = new FileNameExtensionFilter("SMT Processing Settings (*.sps)", "sps");
    fc.addChoosableFileFilter(fnef);

    // Let the user chose a settings file
    if (fc.showDialog(this, "Save Processing Settings") == JFileChooser.APPROVE_OPTION) {
        try {
            this.settings.save(fc.getSelectedFile());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:au.com.jwatmuff.eventmanager.gui.main.LoadCompetitionWindow.java

private void loadBackupButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadBackupButtonActionPerformed
    File databaseStore = new File(Main.getWorkingDirectory(), "comps");
    JFileChooser chooser = new JFileChooser();
    chooser.setFileFilter(new FileNameExtensionFilter("Event Manager Files", "evm"));

    JPanel optionsPanel = new JPanel();

    optionsPanel.setBorder(/* w  ww.ja  va 2 s . c om*/
            new CompoundBorder(new EmptyBorder(0, 10, 0, 10), new TitledBorder("Load backup options")));
    JCheckBox preserveIDCheckbox = new JCheckBox("Preserve competition ID");
    optionsPanel.add(preserveIDCheckbox);

    chooser.setAccessory(optionsPanel);

    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        /* input zip file */
        File file = chooser.getSelectedFile();
        /* construct output directory */
        File dir = new File(databaseStore, file.getName());
        int suffix = 0;
        while (dir.exists()) {
            suffix++;
            dir = new File(databaseStore, file.getName() + "_" + suffix);
        }
        /* unzip */
        try {
            ZipUtils.unzipFile(dir, file);

            /* change id */
            Properties props = new Properties();
            FileReader fr = new FileReader(new File(dir, "info.dat"));
            props.load(fr);
            fr.close();
            if (!preserveIDCheckbox.isSelected()) {
                props.setProperty("UUID", UUID.randomUUID().toString());
            }
            props.setProperty("name", props.getProperty("name") + " - " + dateFormat.format(new Date()));
            FileWriter fw = new FileWriter(new File(dir, "info.dat"));
            props.store(fw, "");
            fw.close();

            /* update gui */
            checkDatabasesExecutor.schedule(checkDatabasesTask, 0, TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            GUIUtils.displayError(null, "Error while opening file: " + e.getMessage());
        }
    }
}

From source file:pl.dpbz.poid.zadanie3.GUI.java

private String readSoundFile() {
    final JFileChooser fc = new JFileChooser();
    fc.setAcceptAllFileFilterUsed(false);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("WAV sounds", "wav");
    fc.addChoosableFileFilter(filter);//from www. j  a  v  a  2 s .  c  o m
    int returnVal = fc.showOpenDialog(this);
    String path = fc.getSelectedFile().getAbsolutePath();
    System.out.println("path: " + path);

    return path;
}

From source file:ca.uviccscu.lp.server.main.MainFrame.java

public static void setupOther() {
    jFileChooser1.setFileFilter(new FileNameExtensionFilter("uTorrent executable(.exe)", "exe"));
}

From source file:canreg.client.gui.management.CanReg4MigrationInternalFrame.java

@Action
//public Task browseDefAction() {
public void browseDefAction() {
    String defname = null;//from   w  w  w  .j  a  va2s  . c  o m
    chooser = new JFileChooser();
    // Filter only the DEF-files.
    FileNameExtensionFilter filter = new FileNameExtensionFilter(java.util.ResourceBundle
            .getBundle("canreg/client/gui/management/resources/CanReg4SystemConverterInternalFrame")
            .getString("CANREG4 SYSTEM DEFINITION FILE"), DEF_FILE_EXTENSION);
    chooser.addChoosableFileFilter(filter);
    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
            //set the file name
            sysDefTextField.setText(chooser.getSelectedFile().getCanonicalPath());
            defname = sysDefTextField.getText();
        } catch (IOException ex) {
            Logger.getLogger(CanReg4SystemConverterInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    BrowseDefActionTask bTask = new BrowseDefActionTask(
            org.jdesktop.application.Application.getInstance(canreg.client.CanRegClientApp.class), defname);
    bTask.execute();
    //return new BrowseDefActionTask(org.jdesktop.application.Application.getInstance(canreg.client.CanRegClientApp.class), defname);
}