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:pl.edu.pw.appt.GUI.java

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("Zapisz plik jako...");

    FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Pliki UMLDump (*.umldump)", "umldump");
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.setFileFilter(xmlfilter);

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd_hh-mm-ss");
    fileChooser.setSelectedFile(new File(df.format(new Date())));

    int userSelection = fileChooser.showSaveDialog(this);
    if (userSelection == JFileChooser.APPROVE_OPTION) {
        File fileToSave = fileChooser.getSelectedFile();
        if (!FilenameUtils.getExtension(fileToSave.getName()).equalsIgnoreCase("umldump")) {
            fileToSave = new File(fileToSave.getParentFile(),
                    FilenameUtils.getBaseName(fileToSave.getName()) + ".umldump");
        }/* w  ww .  ja v  a 2 s .  co  m*/
        try {
            FileHandler.saveFile(Paths.get(fileToSave.getAbsolutePath()),
                    server.messages.toString(selectSystem.getSelectedItem().toString()));
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, "Nie udao si zapisa pliku.", "Wystpi bd",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:pl.edu.pw.appt.GUI.java

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Pliki UMLDump (*.umldump)", "umldump");
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.setFileFilter(xmlfilter);
    int returnValue = fileChooser.showOpenDialog(this);
    String data = null;/*w  w w . j  a v a 2s.c o m*/
    if (returnValue == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        try {
            data = FileHandler.getFile(Paths.get(selectedFile.getAbsolutePath()));
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, "Nie udao si otworzy pliku.", "Wystpi bd",
                    JOptionPane.ERROR_MESSAGE);
        }

        server.messages.clear(selectedFile.getName());
        String[] lines = data.split("[\\r?\\n]+");
        for (String line : lines) {
            String[] parts = line.split("-");
            if (parts.length < 8) {
                break;
            }
            Message message = new Message(parts[0], parts[1], parts[2], parts[3], parts[5], parts[4], parts[6],
                    parts[7]);
            server.messages.add(selectedFile.getName(), message);
        }

        if (((DefaultComboBoxModel) selectSystem.getModel()).getIndexOf(selectedFile.getName()) == -1) {
            selectSystem.addItem(selectedFile.getName());
            selectSystem.setSelectedItem(selectedFile.getName());
        } else {
            selectSystem.setSelectedItem(selectedFile.getName());
        }

        updateUml(server.messages.toUml(selectedFile.getName(), startMsg.getText(), stopMsg.getText()));
    }
}

From source file:pl.edu.pw.appt.GUI.java

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("Zapisz obraz jako...");

    FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Pliki BMP (*.bmp)", "bmp");
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.setFileFilter(xmlfilter);

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd_hh-mm-ss");
    fileChooser.setSelectedFile(new File(df.format(new Date())));

    int userSelection = fileChooser.showSaveDialog(this);
    if (userSelection == JFileChooser.APPROVE_OPTION) {
        File fileToSave = fileChooser.getSelectedFile();
        if (!FilenameUtils.getExtension(fileToSave.getName()).equalsIgnoreCase("bmp")) {
            fileToSave = new File(fileToSave.getParentFile(),
                    FilenameUtils.getBaseName(fileToSave.getName()) + ".bmp");
        }/*from w w  w. j a  v  a 2  s.c o  m*/
        try {
            ImageIO.write((RenderedImage) image, "bmp", fileToSave);
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, "Nie udao si zapisa obrazu.", "Wystpi bd",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:pl.wasko.utils.xlsxtract.MainFrame.java

private void mainCfgButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mainCfgButtonActionPerformed
    JFileChooser fc = new JFileChooser(System.getProperty("user.dir"));
    fc.setFileFilter(new FileNameExtensionFilter("Pliki *.cfg", "cfg"));
    int res = fc.showOpenDialog(this);
    if (res == JFileChooser.APPROVE_OPTION) {
        mainCfgTextField.setText(fc.getSelectedFile().getAbsolutePath());
        try {/*ww w . j  a v a 2 s  . c  o  m*/
            confComboModel = new DefaultComboBoxModel<>(readMainCfgFile(fc.getSelectedFile()));
            confComboBox.setModel(confComboModel);
        } catch (IOException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this,
                    "Blad podczas wczytywania pliku konfiguracyjnego: " + ex.getMessage(), "Bd",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:plugin.notes.gui.NotesView.java

private static FileFilter getFileType() {
    return new FileNameExtensionFilter(LanguageBundle.getString("in_plugin_notes_file"),
            NotesPlugin.EXTENSION_NOTES);

}

From source file:plugin.notes.gui.NotesView.java

/**
 *  obtains an Image for input using a custom JFileChooser dialog
 *
 *@param  startDir  Directory to open JFielChooser to
 *@param  exts      Extensions to search for
 *@param  desc      Description for files
 *@return           File pointing to the selected image
 *///www.  ja v a  2 s .  c  o  m
private File getImageFromChooser(String startDir, String[] exts, String desc) {
    JFileChooser jImageDialog = new JFileChooser();
    jImageDialog.setCurrentDirectory(new File(startDir));
    jImageDialog.setAccessory(new ImageFileChooserPreview(jImageDialog));
    jImageDialog.setDialogType(JFileChooser.CUSTOM_DIALOG);
    jImageDialog.setFileFilter(new FileNameExtensionFilter(desc, exts));
    jImageDialog.setDialogTitle("Select an Image to Insert");

    int optionSelected = jImageDialog.showDialog(this, "Insert");

    if (optionSelected == JFileChooser.APPROVE_OPTION) {
        return jImageDialog.getSelectedFile();
    }

    return null;
}

From source file:plugins.tprovoost.Microscopy.MicroManagerForIcy.MMMainFrame.java

/**
 * Used to load XML Files/*from   ww  w  . java2s .  co m*/
 * 
 * @return Returns null if Dialog exited.
 */
private String xmlFileChooser() {
    String filename = null;
    JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new FileNameExtensionFilter("Sate Files (.xml)", "xml"));
    int returnVal = fc.showDialog(Icy.getMainInterface().getMainFrame(), "Save File");
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        filename = fc.getSelectedFile().getAbsolutePath();
        if (!filename.endsWith(".xml"))
            filename += ".xml";
    } else {
        filename = null;
    }
    return filename;

}

From source file:Proiect.uploadFTP.java

public void propFTP() {
    uploadFTP.setBackground(Encrypter.color_light);
    pan1.setBackground(Encrypter.color_light);
    pan1.setBorder(BorderFactory.createEmptyBorder(6, 5, 10, 5));
    pan2.setBackground(Encrypter.color_light);
    inpan1.setBackground(Encrypter.color_light);
    inpan2.setBackground(Encrypter.color_light);
    pan3.setBackground(Encrypter.color_light);
    pan4.setBackground(Encrypter.color_light);

    adress.setForeground(Encrypter.color_blue);
    user.setForeground(Encrypter.color_blue);
    pass.setForeground(Encrypter.color_blue);
    folder.setForeground(Encrypter.color_blue);
    filen.setForeground(Encrypter.color_blue);

    adressf.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, Encrypter.color_dark));
    adressf.setSelectionColor(Encrypter.color_black);
    adressf.setSelectedTextColor(Encrypter.color_white);
    adressf.setBackground(Encrypter.color_light);

    userf.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, Encrypter.color_dark));
    userf.setSelectionColor(Encrypter.color_black);
    userf.setSelectedTextColor(Encrypter.color_white);
    userf.setBackground(Encrypter.color_light);

    passf.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, Encrypter.color_dark));
    passf.setSelectionColor(Encrypter.color_black);
    passf.setSelectedTextColor(Encrypter.color_white);
    passf.setBackground(Encrypter.color_light);

    folderf.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, Encrypter.color_dark));
    folderf.setSelectionColor(Encrypter.color_black);
    folderf.setSelectedTextColor(Encrypter.color_white);
    folderf.setBackground(Encrypter.color_light);

    status.setHorizontalAlignment(SwingConstants.RIGHT);

    ImageIcon title_icon = getImageIcon("assets/icons/upload.png");
    titleFTP.setForeground(Encrypter.color_blue);
    titleFTP.setFont(Encrypter.font16);//from w w w.j a  va2 s . co  m
    titleFTP.setIcon(title_icon);

    connect.setBackground(Encrypter.color_light);
    connect.setBorder(BorderFactory.createEmptyBorder());
    connect.setForeground(Encrypter.color_black);
    connect.setFont(Encrypter.font16);
    connect.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    connect.setToolTipText("Transfer File");

    browsef.setBackground(Encrypter.color_light);
    browsef.setBorder(BorderFactory.createEmptyBorder());
    browsef.setForeground(Encrypter.color_black);
    browsef.setFont(Encrypter.font16);
    browsef.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    browsef.setToolTipText("Add file");

    ImageIcon exit_icon = getImageIcon("assets/icons/exit.png");
    exit.setBackground(Encrypter.color_light);
    exit.setBorder(BorderFactory.createLineBorder(Encrypter.color_dark, 0));
    exit.setForeground(Encrypter.color_black);
    exit.setFont(Encrypter.font16);
    exit.setIcon(exit_icon);
    exit.setToolTipText("Exit");

    ImageIcon adv_icon = getImageIcon("assets/icons/adv_ftp.png");
    adv.setIcon(adv_icon);
    adv.setBackground(Encrypter.color_light);
    adv.setBorder(BorderFactory.createLineBorder(Encrypter.color_light, 0));
    adv.setFont(Encrypter.font16);
    adv.setToolTipText("Display server files");
    adv.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

    chooserf.addChoosableFileFilter(new FileNameExtensionFilter("Text", "txt"));
    chooserf.addChoosableFileFilter(new FileNameExtensionFilter("HTM", "htm"));
    chooserf.addChoosableFileFilter(new FileNameExtensionFilter("XHTML", "xhtml"));
    chooserf.addChoosableFileFilter(new FileNameExtensionFilter("HTML", "html"));
    chooserf.setAcceptAllFileFilterUsed(false);
}

From source file:quake3mapfixer.Pk3Fixer.java

private void fileChooserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileChooserActionPerformed
    Boolean old = UIManager.getBoolean("FileChooser.readOnly");
    UIManager.put("FileChooser.readOnly", Boolean.TRUE);
    JFileChooser chooser = new JFileChooser();
    UIManager.put("FileChooser.readOnly", old);
    FileNameExtensionFilter pk3filter = new FileNameExtensionFilter("pk3 files (*.pk3)", "pk3");
    chooser.setFileFilter(pk3filter);/*from   ww  w.j av a 2  s.  co m*/
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setDialogTitle("Open pk3 file");
    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        currentDirectory = chooser.getCurrentDirectory().toString();
        selectedFile = chooser.getSelectedFile().toString();
        absolutePath = chooser.getSelectedFile().getName();
        areaFileName.setText(selectedFile);
        fileFixer.setEnabled(true);
    }

}

From source file:richtercloud.document.scanner.gui.DocumentScanner.java

private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF files", "pdf");
    chooser.setFileFilter(filter);/* w w w.  j  ava2 s .  co m*/
    int returnVal = chooser.showOpenDialog(this);
    final File selectedFile = chooser.getSelectedFile();
    if (returnVal != JFileChooser.APPROVE_OPTION) {
        return;
    }
    OCREngine oCREngine = DocumentScanner.this.retrieveOCREngine();
    if (oCREngine == null) {
        //a warning in form of a dialog has been given
        return;
    }
    try {
        List<BufferedImage> images = this.mainPanel.retrieveImages(selectedFile);
        if (images == null) {
            LOGGER.debug("image retrieval has been canceled, discontinuing adding document");
            return;
        }
        this.mainPanel.addDocument(images, selectedFile);
    } catch (DocumentAddException | InterruptedException | ExecutionException ex) {
        handleException(ex, "Exception during adding new document");
    }
}