Java 类javax.swing.filechooser.FileFilter 实例源码

项目:openjdk-jdk10    文件:FileChooserDemo.java   
private void resetFileFilters(boolean enableFilters,
        boolean showExtensionInDescription) {
    chooser.resetChoosableFileFilters();
    if (enableFilters) {
        FileFilter jpgFilter = createFileFilter(
                "JPEG Compressed Image Files",
                showExtensionInDescription, "jpg");
        FileFilter gifFilter = createFileFilter("GIF Image Files",
                showExtensionInDescription, "gif");
        FileFilter bothFilter = createFileFilter("JPEG and GIF Image Files",
                showExtensionInDescription, "jpg",
                "gif");
        chooser.addChoosableFileFilter(bothFilter);
        chooser.addChoosableFileFilter(jpgFilter);
        chooser.addChoosableFileFilter(gifFilter);
    }
}
项目:PPRCarTrade    文件:TelaEditarImagensVeiculo.java   
private void btn_AdicionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_AdicionarActionPerformed
    // TODO add your handling code here:
    JFileChooser fc = new JFileChooser();
    FileFilter imageFilter = new FileNameExtensionFilter("Image files", ImageIO.getReaderFileSuffixes());
    fc.setFileFilter(imageFilter);
    int result = fc.showOpenDialog(null);
    if(result == JFileChooser.APPROVE_OPTION){
        try {
            String path = fc.getSelectedFile().getAbsolutePath();
            imagens.add(new ImageIcon(path));
            if(!auxImagens.contains(imagens.get(imagens.size() - 1))){
                auxImagens.add(imagens.get(imagens.size() - 1));
            }
            JOptionPane.showMessageDialog(this, "Imagem carregada com sucesso!");
        } catch(Exception e){
            JOptionPane.showMessageDialog(null, "Ocorreu um erro ao carregar a imagem!", "Erro", JOptionPane.ERROR_MESSAGE);
        }            
    }
    jsl_Slider.setMaximum(Math.max(0, imagens.size() - 1));
}
项目:PPRCarTrade    文件:TelaVenda.java   
private void btn_CarregarImagemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_CarregarImagemActionPerformed
    // TODO add your handling code here:
    JFileChooser fc = new JFileChooser();
    FileFilter imageFilter = new FileNameExtensionFilter("Image files", ImageIO.getReaderFileSuffixes());
    fc.setFileFilter(imageFilter);
    int result = fc.showOpenDialog(null);
    if(result == JFileChooser.APPROVE_OPTION){
        try {
            String path = fc.getSelectedFile().getAbsolutePath();
            imagens.add(new ImageIcon(path));
            JOptionPane.showMessageDialog(this, "Imagem carregada com sucesso!");
        } catch(Exception e){
            JOptionPane.showMessageDialog(null, "Ocorreu um erro ao carregar a imagem!", "Erro", JOptionPane.ERROR_MESSAGE);
        }            
    }
}
项目:pdfjumbler    文件:PdfJumbler.java   
@Override
public void actionPerformed(ActionEvent e) {
    JFileChooser chooser = new JFileChooser(DocOpenAction.lastOpenedFileLocation);
    chooser.setMultiSelectionEnabled(true);
    chooser.setFileFilter(new FileFilter() {
        @Override
        public boolean accept(File file) {
            DocOpenAction.lastOpenedFileLocation = file.getParent();
            return
                file.isDirectory() ||
                (file.exists() && file.isFile() && file.canRead() && file.getName().toLowerCase().endsWith(".pdf"));
        }

        @Override
        public String getDescription() {
            return resources.getString("FILE_FILTER_PDF");
        }

    });

    if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
        PdfJumbler.openFiles(list, -1, Arrays.asList(chooser.getSelectedFiles()));
    }
}
项目:jaer    文件:RNNfilter.java   
synchronized public void loadFromXML() {
    this.setProcessingEnabled(false);
    JFileChooser c = new JFileChooser(this.getLastRNNXMLFile());
    FileFilter filter = new FileNameExtensionFilter("XML File", "xml");
    c.addChoosableFileFilter(filter);
    c.setFileFilter(filter);
    c.setSelectedFile(new File(this.getLastRNNXMLFile()));
    int ret = c.showOpenDialog(chip.getAeViewer());
    if (ret != JFileChooser.APPROVE_OPTION) {
        return;
    }
    File f = c.getSelectedFile();
    try {
        this.rnnetwork.loadFromXML(f);
        this.setLastRNNXMLFile(f.toString());
        putString("lastRNNXMLFile", this.getLastRNNXMLFile());
        // this.testNumpyData.rnnetwork.loadFromXML(c.getSelectedFile()); //debug
    } catch (Exception e) {
        log.log(Level.WARNING, "Couldn't upload the xml file, please check. Caught exception {0}", e);
    }
    this.resetFilter();
}
项目:FreeCol    文件:SaveDialog.java   
/**
 * Creates a dialog to choose a file to load.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 * @param directory The directory to display when choosing the file.
 * @param fileFilters The available file filters in the dialog.
 * @param defaultName Name of the default save game file.
 */
public SaveDialog(FreeColClient freeColClient, JFrame frame,
        File directory, FileFilter[] fileFilters, String defaultName) {
    super(freeColClient, frame);

    final JFileChooser fileChooser = new JFileChooser(directory);
    if (fileFilters.length > 0) {
        for (FileFilter fileFilter : fileFilters) {
            fileChooser.addChoosableFileFilter(fileFilter);
        }
        fileChooser.setFileFilter(fileFilters[0]);
        fileChooser.setAcceptAllFileFilterUsed(false);
    }
    fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setFileHidingEnabled(false);
    fileChooser.setSelectedFile(new File(defaultName));
    fileChooser.addActionListener((ActionEvent ae) ->
            setValue((JFileChooser.APPROVE_SELECTION
                    .equals(ae.getActionCommand()))
                ? fileChooser.getSelectedFile() : cancelFile));

    List<ChoiceItem<File>> c = choices();
    initializeDialog(frame, DialogType.QUESTION, true, fileChooser, null, c);
}
项目:incubator-netbeans    文件:EditMediator.java   
public static void register(Project project,
                            AntProjectHelper helper,
                            ReferenceHelper refHelper,
                            ListComponent list,
                            ButtonModel addJar,
                            ButtonModel addLibrary,
                            ButtonModel addAntArtifact,
                            ButtonModel remove,
                            ButtonModel moveUp,
                            ButtonModel moveDown,
                            ButtonModel edit,
                            Document libPath,
                            ClassPathUiSupport.Callback callback,
                            String[] antArtifactTypes,
                            FileFilter filter,
                            int fileSelectionMode) {
    register(project, helper, refHelper, list, addJar, addLibrary, addAntArtifact, remove, moveUp, moveDown, edit, false, libPath, callback, antArtifactTypes, filter, fileSelectionMode);
}
项目:incubator-netbeans    文件:ComparePanel.java   
private void btnRefFileBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefFileBrowseActionPerformed

        JFileChooser fc = new JFileChooser(wd);
        FileFilter filter = new FileFilter() {
            public boolean accept(File f) {
                return f.getName().endsWith(".xml");
            }

            public String getDescription() {
                return "XML files";
            }

        };
        fc.setFileFilter(filter);
        int result = fc.showOpenDialog(this);
        if(result == JFileChooser.APPROVE_OPTION) {
            txtRefFile.setText (fc.getSelectedFile().getPath());
            wd = fc.getCurrentDirectory();
        }
    }
项目:incubator-netbeans    文件:ExportSnapshotAction.java   
private static JFileChooser createFileChooser() {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setDialogTitle(Bundle.ExportSnapshotAction_FileChooserCaption());
    fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    fileChooser.setApproveButtonText(Bundle.ExportSnapshotAction_ExportButtonText());
    fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
    fileChooser.addChoosableFileFilter(new FileFilter() {
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().toLowerCase().endsWith(NPSS_EXT);
        }
        public String getDescription() {
            return Bundle.ExportSnapshotAction_NpssFileFilter(NPSS_EXT);
        }
    });
    return fileChooser;
}
项目:incubator-netbeans    文件:FileFilterSupportTest.java   
/**
 * This test, although it is quite short, tests a lot of ascpects of default
 * file filters. The resolver definition XML file contains several
 * duplicities, which are detected and ignored. If this detection fails,
 * filter description and {@code accept} method is changed, and it is cought
 * by this test.
 */
public void testRegisteredFilters() {
    List<FileFilter> list = FileFilterSupport.findRegisteredFileFilters();
    assertNotNull(list);
    assertFalse(list.isEmpty());

    boolean found = false;
    for (FileFilter filter : list) {

        if (filter.getDescription().startsWith("BNM Files")) {
            found = true;
            checkBnmFilesFilter(filter);
        }
    }
    assertTrue("Registered File Filter was not found.", found);
}
项目:incubator-netbeans    文件:FileChooserBuilderTest.java   
/**
 * Test of setFileFilter method, of class FileChooserBuilder.
 */
public void testSetFileFilter() {
    FileFilter filter = new FileFilter() {

        @Override
        public boolean accept(File f) {
            return true;
        }

        @Override
        public String getDescription() {
            return "X";
        }
    };
    FileChooserBuilder instance = new FileChooserBuilder("c");
    instance.setFileFilter(filter);
    assertEquals(filter, instance.createFileChooser().getFileFilter());
}
项目:jaer    文件:AbstractDavisCNNProcessor.java   
private File openFileDialogAndGetFile(String tip, String key, String type, String... ext) {
    File file = null;
    JFileChooser c = new JFileChooser(lastNetworkFilename);
    File f = new File(lastNetworkFilename);
    c.setCurrentDirectory(new File(getString("lastNetworkPathname", "")));
    c.setToolTipText(tip);
    FileFilter filt = new FileNameExtensionFilter(type, ext);
    c.addChoosableFileFilter(filt);
    c.setFileFilter(filt);
    c.setSelectedFile(new File(lastNetworkFilename));
    int ret = c.showOpenDialog(chip.getAeViewer());
    if (ret != JFileChooser.APPROVE_OPTION) {
        return null;
    }
    lastNetworkFilename = c.getSelectedFile().toString();
    putString(key, lastNetworkFilename);
    lastNetworkPathname = f.getPath();
    putString("lastNetworkPathname", lastNetworkPathname);
    file = c.getSelectedFile();
    return file;
}
项目:OpenJSharp    文件:SynthFileChooserUIImpl.java   
public Component getListCellRendererComponent(JList<? extends FileFilter> list, FileFilter value, int index,
                                              boolean isSelected, boolean cellHasFocus) {
    Component c = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

    String text = null;
    if (value != null) {
        text = value.getDescription();
    }

    //this should always be true, since SynthComboBoxUI's SynthComboBoxRenderer
    //extends JLabel
    assert c instanceof JLabel;
    if (text != null) {
        ((JLabel)c).setText(text);
    }
    return c;
}
项目:incubator-netbeans    文件:CompareSnapshotsAction.java   
private static JFileChooser getSnapshotFileChooser() {
    if (snapshotFileChooser == null) {
        snapshotFileChooser = new JFileChooser();
        snapshotFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        snapshotFileChooser.setMultiSelectionEnabled(false);
        snapshotFileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
        snapshotFileChooser.setDialogTitle(Bundle.CompareSnapshotsAction_OpenChooserCaption());
        snapshotFileChooser.setFileFilter(new FileFilter() {
                public boolean accept(File f) {
                    return f.isDirectory() || f.getName().endsWith(".nps"); // NOI18N
                }

                public String getDescription() {
                    return Bundle.CompareSnapshotsAction_OpenChooserFilter("nps"); // NOI18N
                }
            });
        snapshotFileChooser.setAcceptAllFileFilterUsed(false);
    }

    return snapshotFileChooser;
}
项目:incubator-netbeans    文件:MercurialOptionsPanelController.java   
private void onExportFilenameBrowseClick() {
    File oldFile = getExecutableFile();
    JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(MercurialOptionsPanelController.class, "ACSD_ExportBrowseFolder"), oldFile);   // NOI18N
    fileChooser.setDialogTitle(NbBundle.getMessage(MercurialOptionsPanelController.class, "ExportBrowse_title"));                                            // NOI18N
    fileChooser.setMultiSelectionEnabled(false);
    FileFilter[] old = fileChooser.getChoosableFileFilters();
    for (int i = 0; i < old.length; i++) {
        FileFilter fileFilter = old[i];
        fileChooser.removeChoosableFileFilter(fileFilter);
    }
    fileChooser.showDialog(panel, NbBundle.getMessage(MercurialOptionsPanelController.class, "OK_Button"));                                            // NOI18N
    File f = fileChooser.getSelectedFile();
    if (f != null) {
        panel.exportFilenameTextField.setText(f.getAbsolutePath());
    }
}
项目:rapidminer    文件:CSVFileSelectionWizardStep.java   
/**
 * There must be a configuration given, but might be empty.
 */
public CSVFileSelectionWizardStep(AbstractWizard parent, CSVResultSetConfiguration configuration) {
    super(parent, configuration.getCsvFileAsFile(), new FileFilter() {

        @Override
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().endsWith("csv");
        }

        @Override
        public String getDescription() {
            return "Delimiter separated files (.csv, .tsv)";
        }
    });
    this.fileChooser.setAcceptAllFileFilterUsed(true);
    this.configuration = configuration;
}
项目:jaer    文件:SpikingCNN.java   
public void doLoadNetworkFromXML() throws IOException {
    JFileChooser c = new JFileChooser(lastXMLFilename);
    FileFilter filt = new FileNameExtensionFilter("XML File", "xml");
    c.addChoosableFileFilter(filt);
    c.setSelectedFile(new File(lastXMLFilename));
    int ret = c.showOpenDialog(chip.getAeViewer());
    if (ret != JFileChooser.APPROVE_OPTION) {
        return;
    }
    lastXMLFilename = c.getSelectedFile().toString();
    putString("lastXMLFilename", lastXMLFilename);
    if (spike!=batch) {
        loadFromXMLFile(c.getSelectedFile());
    }else{
        log.info("Please select exact one way of processing input.");
    }
}
项目:ramus    文件:GUIFramework.java   
public File showOpenDialog(String name, final String extension) {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileFilter(new FileFilter() {

        @Override
        public String getDescription() {
            return "*" + extension;
        }

        @Override
        public boolean accept(File f) {
            return (f.isDirectory()) || (f.getName().endsWith(extension));
        }
    });
    String fn = Options.getString(name);
    if (fn != null)
        chooser.setSelectedFile(new File(fn));
    if (chooser.showOpenDialog(getMainFrame()) == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        Options.setString(name, file.getAbsolutePath());
        return file;
    }
    return null;
}
项目:jdk8u-jdk    文件:FileChooserDemo.java   
private void resetFileFilters(boolean enableFilters,
        boolean showExtensionInDescription) {
    chooser.resetChoosableFileFilters();
    if (enableFilters) {
        FileFilter jpgFilter = createFileFilter(
                "JPEG Compressed Image Files",
                showExtensionInDescription, "jpg");
        FileFilter gifFilter = createFileFilter("GIF Image Files",
                showExtensionInDescription, "gif");
        FileFilter bothFilter = createFileFilter("JPEG and GIF Image Files",
                showExtensionInDescription, "jpg",
                "gif");
        chooser.addChoosableFileFilter(bothFilter);
        chooser.addChoosableFileFilter(jpgFilter);
        chooser.addChoosableFileFilter(gifFilter);
    }
}
项目:LP_Proyecto    文件:Principal.java   
private void jl_Imagen_ContactsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jl_Imagen_ContactsMouseClicked
    // TODO add your handling code here:
    jl_Imagen_Contacts.setText("");

    JFileChooser fc = new JFileChooser();
    FileFilter filtro = new FileNameExtensionFilter("Imagenes", "png", "jpg", "jpeg", "gif");
    fc.setFileFilter(filtro);

    File Archivo;
    int op = fc.showOpenDialog(this);

    if (op == JFileChooser.APPROVE_OPTION) {
        Archivo = fc.getSelectedFile();
        RutaImagen = Archivo.getPath();
        System.out.println(Archivo.getPath());
        Image Img = Toolkit.getDefaultToolkit().createImage(Archivo.getPath()).getScaledInstance(180, 229, 0);
        this.jl_Imagen_Contacts.setIcon(new ImageIcon(Img));
    }
}
项目:schneckenrennen    文件:RaceFrame.java   
private void loadConfigMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadConfigMenuItemActionPerformed
final JFileChooser fc = new JFileChooser(".");
fc.setMultiSelectionEnabled(false);
fc.setFileFilter(new FileFilter() {
    @Override
    public boolean accept(File f) {
    return f.getName().endsWith(".json");
    }

    @Override
    public String getDescription() {
    return Translations.get("Config.configFileType");
    }

});

int result = fc.showOpenDialog(this);
if (result == JFileChooser.APPROVE_OPTION) {
    String loadResult = Configs.loadSpecificConfigFile(fc.getSelectedFile().getAbsolutePath());
    if (!loadResult.isEmpty()) {
    JOptionPane.showMessageDialog(this, loadResult);
    }
    resetRace();
}
   }
项目:OpenDA    文件:FileBrowser.java   
public FileBrowser(String title, File currentSelection, String extension, boolean directoriesOnly){
    super(title);
       selectedFile = currentSelection;
       setSize(800,600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       JFileChooser chooser = new JFileChooser(currentSelection);
       if (directoriesOnly) {
           chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
       }
       if (extension != null && extension.length() > 0) {
           FileFilter filter = new FileExtensionFilter(extension.toUpperCase(), extension);
           chooser.setFileFilter(filter);
       }
       if (chooser.showOpenDialog(this) ==JFileChooser.APPROVE_OPTION) {
           selectedFile = chooser.getSelectedFile();
       }
}
项目:openjdk-jdk10    文件:JFileChooserOperator.java   
/**
 * Maps {@code JFileChooser.setFileFilter(FileFilter)} through queue
 */
public void setFileFilter(final FileFilter fileFilter) {
    runMapping(new MapVoidAction("setFileFilter") {
        @Override
        public void map() {
            ((JFileChooser) getSource()).setFileFilter(fileFilter);
        }
    });
}
项目:freecol    文件:Canvas.java   
/**
 * Displays a dialog where the user may choose a file.
 *
 * @param directory The directory containing the files.
 * @param filters The file filters which the user can select in the dialog.
 * @return The selected {@code File}.
 */
public File showLoadDialog(File directory, String extension) {
    FileFilter[] filters = new FileFilter[] {
        FreeColDataFile.getFileFilter(extension)
    };
    File file = null;
    for (;;) {
        file = showFreeColDialog(new LoadDialog(freeColClient, frame,
                                                directory, filters), null);
        if (file == null || file.isFile()) break;
        showErrorMessage(Messages.message(FreeCol.badFile("error.noSuchFile", file)), null);
    }
    return file;
}
项目:Reer    文件:SwingImportInteraction.java   
/**
 * This is called when you should ask the user for a source file to read.
 *
 * @return a file to read or null to cancel.
 */
public File promptForFile(FileFilter fileFilter) {
    JFileChooser chooser = new JFileChooser();
    chooser.addChoosableFileFilter(fileFilter);

    if (chooser.showOpenDialog(parent) != JFileChooser.APPROVE_OPTION) {
        return null;
    }

    return chooser.getSelectedFile();
}
项目:Equella    文件:DialogUtils.java   
private static DialogResult doDialog(Component parent, boolean isOpenDialog, String title, FileFilter filter,
    boolean acceptAllFilter, File defaultFile)
{
    JFileChooser chooser = new JFileChooser(getDirectory());
    if( title != null )
    {
        chooser.setDialogTitle(title);
    }
    if( filter != null )
    {
        chooser.setFileFilter(filter);
    }
    if( defaultFile != null )
    {
        chooser.setSelectedFile(defaultFile);
    }
    if( !acceptAllFilter )
    {
        chooser.setAcceptAllFileFilterUsed(false);
    }

    int result = 0;
    if( isOpenDialog )
    {
        result = chooser.showOpenDialog(parent);
    }
    else
    {
        result = chooser.showSaveDialog(parent);
    }
    return new DialogResult(result, chooser.getSelectedFile(), chooser.getCurrentDirectory());
}
项目:alevin-svn2    文件:LocatableFileChooser.java   
@Override
public boolean accept(File pathname) {
    // Accept all supported file formats.
    for (FileFilter ff : getChoosableFileFilters())
        if (!ff.equals(allSupported) && ff.accept(pathname))
            return true;

    return false;
}
项目:FreeCol    文件:Canvas.java   
/**
 * Displays a dialog where the user may choose a file.
 *
 * @param directory The directory containing the files.
 * @param filters The file filters which the user can select in the dialog.
 * @return The selected {@code File}.
 */
public File showLoadDialog(File directory, String extension) {
    FileFilter[] filters = new FileFilter[] {
        FreeColDataFile.getFileFilter(extension)
    };
    File file = null;
    for (;;) {
        file = showFreeColDialog(new LoadDialog(freeColClient, frame,
                                                directory, filters), null);
        if (file == null || file.isFile()) break;
        showErrorMessage(Messages.message(FreeCol.badFile("error.noSuchFile", file)), null);
    }
    return file;
}
项目:FApkSigner    文件:Controller.java   
@FXML
protected void openKsPath() {
    JFileChooser jfc=new JFileChooser();
    jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    jfc.setFileFilter(new FileFilter() {
        @Override
        public boolean accept(File f) {
            String name = f.getName();
            if(name.endsWith(".jks") || name.endsWith(".keystore")) {
                return true;
            }
            if(f.isDirectory()) return true;
            return false;
        }

        @Override
        public String getDescription() {
            return "android keystore(*.jks, *.keystore)";
        }
    });
    jfc.showOpenDialog(new JLabel());
    File file=jfc.getSelectedFile();
    // TODO try to parse ks
    if(file.exists() && file.isFile()) {
        key_store_path.setText(file.getAbsolutePath());
    } else {
        status.setText("Input key store file is not valid");
    }
}
项目:VISNode    文件:FileChooserFactory.java   
/**
 * Adds the extension to the file if required
 *
 * @param file
 * @param fileFilter
 * @return File
 */
private File addExtensionIfRequired(File file, FileFilter fileFilter) {
    String name = file.getName();
    // If there is an extension
    if (name.indexOf('.', name.length() - 4) >= 0) {
        return file;
    }
    if (fileFilter instanceof FileNameExtensionFilter) {
        FileNameExtensionFilter extensions = (FileNameExtensionFilter) fileFilter;
        return new File(file.getAbsolutePath() + '.' + extensions.getExtensions()[0]);
    }
    return file;
}
项目:Equella    文件:DialogUtils.java   
/**
 * Does standard 'ok' clicked checking, and confirms overwrite before
 * executing saver if applicable
 * 
 * @param parent
 * @param title
 * @param filter
 * @param defaultFileName
 * @param saver
 */
public static void doSaveDialog(Component parent, String title, FileFilter filter, String defaultFileName,
    FileWorker saver)
{
    final DialogResult result = doDialog(parent, false, title, filter, true, new File(defaultFileName));
    if( result.isOkayed() )
    {
        boolean writeFile = true;
        final File file = result.getFile();
        if( file.exists() )
        {
            final int result2 = JOptionPane.showConfirmDialog(parent,
                CurrentLocale.get("com.tle.common.gui.confirmoverwrite"), //$NON-NLS-1$
                CurrentLocale.get("com.tle.common.gui.overwrite"), //$NON-NLS-1$
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

            if( result2 != JOptionPane.YES_OPTION )
            {
                writeFile = false;
            }
        }

        if( writeFile )
        {
            saver.setFile(file);
            saver.setComponent(parent);
            saver.start();
        }
    }
}
项目:MaxSim    文件:ImportAction.java   
public static FileFilter getFileFilter() {
    return new FileFilter() {

        @Override
        public boolean accept(File f) {
            return f.getName().toLowerCase().endsWith(".xml") || f.isDirectory();
        }

        @Override
        public String getDescription() {
            return "XML files (*.xml)";
        }
    };
}
项目:jdk8u-jdk    文件:MultiFileChooserUI.java   
/**
 * Invokes the <code>getAcceptAllFileFilter</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public FileFilter getAcceptAllFileFilter(JFileChooser a) {
    FileFilter returnValue =
        ((FileChooserUI) (uis.elementAt(0))).getAcceptAllFileFilter(a);
    for (int i = 1; i < uis.size(); i++) {
        ((FileChooserUI) (uis.elementAt(i))).getAcceptAllFileFilter(a);
    }
    return returnValue;
}
项目:incubator-netbeans    文件:InstallDocSourcePanel.java   
private void btnFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFileActionPerformed
    JFileChooser chooser = new JFileChooser(lastFolder);
    chooser.setDialogTitle(isJavadoc() ? NbBundle.getMessage(InstallDocSourcePanel.class, "TIT_Select_javadoc_zip")
                                       : NbBundle.getMessage(InstallDocSourcePanel.class, "TIT_Select_source_zip"));
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setFileFilter(new FileFilter() {
        @Override
        public boolean accept(File f) {
            return (f.isDirectory() || f.getName().toLowerCase().endsWith(".jar") || f.getName().toLowerCase().endsWith(".zip")); //NOI18N
        }
        @Override
        public String getDescription() {

            return isJavadoc() ? NbBundle.getMessage(InstallDocSourcePanel.class, "LBL_Select_javadoc_zip")
                               : NbBundle.getMessage(InstallDocSourcePanel.class, "LBL_Select_source_zip");
        }
    });
    chooser.setMultiSelectionEnabled(false);
    if (txtFile.getText().trim().length() > 0) {
        File fil = new File(txtFile.getText().trim());
        if (fil.exists()) {
            chooser.setSelectedFile(fil);
        }
    }
    int ret = chooser.showDialog(SwingUtilities.getWindowAncestor(this), BTN_Select());
    if (ret == JFileChooser.APPROVE_OPTION) {
        txtFile.setText(chooser.getSelectedFile().getAbsolutePath());
        txtFile.requestFocusInWindow();
    }

}
项目:incubator-netbeans    文件:ClasspathPanel.java   
private void addClasspathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addClasspathActionPerformed
    FileChooser chooser;
    chooser = new FileChooser(model.getBaseFolder(), null);

    FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
    chooser.setFileSelectionMode (JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setMultiSelectionEnabled(true);
    chooser.setDialogTitle(NbBundle.getMessage(ClasspathPanel.class, "LBL_Browse_Classpath"));
    if (lastChosenFile != null) {
        chooser.setCurrentDirectory(lastChosenFile);
    } else {
        chooser.setCurrentDirectory(model.getBaseFolder());
    }
    //#65354: prevent adding a non-folder element on the classpath:
    FileFilter fileFilter = new SimpleFileFilter (
        NbBundle.getMessage( ClasspathPanel.class, "LBL_ZipJarFolderFilter" ),   // NOI18N
        new String[] {"ZIP","JAR"} );   // NOI18N
    //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
    chooser.setAcceptAllFileFilterUsed( false );
    chooser.setFileFilter(fileFilter);

    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        String[] filePaths = null;
        try {
            filePaths = chooser.getSelectedPaths();
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
        for (String filePath : filePaths) {
            listModel.addElement(filePath);
            lastChosenFile = chooser.getCurrentDirectory();
        }
        applyChanges();
        updateButtons();
    }
}
项目:incubator-netbeans    文件:EditMediator.java   
private EditMediator( Project project,
                     AntProjectHelper helper,
                     ReferenceHelper refHelper,
                     ListComponent list,
                     ButtonModel addJar,
                     ButtonModel addLibrary, 
                     ButtonModel addAntArtifact,
                     ButtonModel remove, 
                     ButtonModel moveUp,
                     ButtonModel moveDown, 
                     ButtonModel edit,
                     boolean allowRemoveClassPath,
                     Document libPath,
                     ClassPathUiSupport.Callback callback,
                     String[] antArtifactTypes,
                     FileFilter filter,
                     int fileSelectionMode) {

    // Remember all buttons

    this.list = list;
    this.listModel = list.getModel();
    this.selectionModel = list.getSelectionModel();
    this.addJar = addJar;
    this.addLibrary = addLibrary;
    this.addAntArtifact = addAntArtifact;
    this.remove = remove;
    this.moveUp = moveUp;
    this.moveDown = moveDown;
    this.edit = edit;
    this.libraryPath = libPath;
    this.callback = callback;
    this.helper = helper;
    this.refHelper = refHelper;
    this.project = project;
    this.filter = filter;
    this.fileSelectionMode = fileSelectionMode;
    this.antArtifactTypes = antArtifactTypes;
    this.allowRemoveClassPath = allowRemoveClassPath;
}
项目:jaer    文件:AbstractAviWriter.java   
synchronized public void doStartRecordingAndSaveAVIAs() {
    if (aviOutputStream != null) {
        JOptionPane.showMessageDialog(null, "AVI output stream is already opened");
        return;
    }
    JFileChooser c = new JFileChooser(lastFileName);
    c.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().toLowerCase().endsWith(".avi");
        }

        @Override
        public String getDescription() {
            return "AVI (Audio Video Interleave) Microsoft video file";
        }
    });
    c.setSelectedFile(new File(lastFileName));
    int ret = c.showSaveDialog(null);
    if (ret != JFileChooser.APPROVE_OPTION) {
        return;
    }
    if (!c.getSelectedFile().getName().toLowerCase().endsWith(".avi")) {
        String newName = c.getSelectedFile().toString() + ".avi";
        c.setSelectedFile(new File(newName));
    }
    lastFileName = c.getSelectedFile().toString();

    if (c.getSelectedFile().exists()) {
        int r = JOptionPane.showConfirmDialog(null, "File " + c.getSelectedFile().toString() + " already exists, overwrite it?");
        if (r != JOptionPane.OK_OPTION) {
            return;
        }
    }
    openAVIOutputStream(c.getSelectedFile(), additionalComments);
}
项目:OpenJSharp    文件:BasicFileChooserUI.java   
private void resetGlobFilter() {
    if (actualFileFilter != null) {
        JFileChooser chooser = getFileChooser();
        FileFilter currentFilter = chooser.getFileFilter();
        if (currentFilter != null && currentFilter.equals(globFilter)) {
            chooser.setFileFilter(actualFileFilter);
            chooser.removeChoosableFileFilter(globFilter);
        }
        actualFileFilter = null;
    }
}
项目:openjdk-jdk10    文件:BasicFileChooserUI.java   
private void resetGlobFilter() {
    if (actualFileFilter != null) {
        JFileChooser chooser = getFileChooser();
        FileFilter currentFilter = chooser.getFileFilter();
        if (currentFilter != null && currentFilter.equals(globFilter)) {
            chooser.setFileFilter(actualFileFilter);
            chooser.removeChoosableFileFilter(globFilter);
        }
        actualFileFilter = null;
    }
}
项目:incubator-netbeans    文件:FileFilterSupport.java   
private static FileFilter createFilter(final String name,
        final Set<FileObject> resolvers) {
    ArrayList<FilterElement> elems = new ArrayList<FilterElement>(3);
    String lastAtt;
    for (FileObject fo : resolvers) {
        int i = 0;
        while ((lastAtt = (String) fo.getAttribute(
                "ext." + i)) != null) { //NOI18N
            addExtensionToList(elems, lastAtt);
            i++;
        }
        int n = 0;
        while ((lastAtt = (String) fo.getAttribute("fileName." //NOI18N
                + (n++))) != null) {
            addNameToList(elems, lastAtt);
        }
        String type;
        if ((type = (String) fo.getAttribute("mimeType")) != null) {//NOI18N
            addMimeTypeExts(elems, type);
        }
        int t = 0;
        while ((type = (String) fo.getAttribute(
                "mimeType." + (t++))) != null) {     //NOI18N
            addMimeTypeExts(elems, type);
        }
    }
    sortFilterElements(elems);
    return new FileFilterImpl(name, elems);
}