Java Code Examples for javax.swing.JFileChooser#setAcceptAllFileFilterUsed()

The following examples show how to use javax.swing.JFileChooser#setAcceptAllFileFilterUsed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FrmTextEditor.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void doOpen_Jython() {
    // TODO add your handling code here:          
    JFileChooser aDlg = new JFileChooser();
    aDlg.setMultiSelectionEnabled(true);
    aDlg.setAcceptAllFileFilterUsed(false);
    //File dir = new File(this._parent.getCurrentDataFolder());
    File dir = new File(System.getProperty("user.dir"));
    if (dir.isDirectory()) {
        aDlg.setCurrentDirectory(dir);
    }
    String[] fileExts = new String[]{"py"};
    GenericFileFilter mapFileFilter = new GenericFileFilter(fileExts, "Jython File (*.py)");
    aDlg.setFileFilter(mapFileFilter);
    if (JFileChooser.APPROVE_OPTION == aDlg.showOpenDialog(this)) {
        File[] files = aDlg.getSelectedFiles();
        //this._parent.setCurrentDataFolder(files[0].getParent());
        System.setProperty("user.dir", files[0].getParent());
        this.openFiles(files);
    }
}
 
Example 2
Source File: LanguageDescriptionPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Messages("DESC_IconFilter=Icons (.png, .jpg, .gif)")
private void browseIconActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseIconActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setFileFilter(new FileFilter() {
        @Override
        public boolean accept(File f) {
            return f.isDirectory() ||
                   f.getName().toLowerCase(Locale.ENGLISH).endsWith(".png") ||
                   f.getName().toLowerCase(Locale.ENGLISH).endsWith(".jpg") ||
                   f.getName().toLowerCase(Locale.ENGLISH).endsWith(".gif");
        }

        @Override
        public String getDescription() {
            return Bundle.DESC_IconFilter();
        }
    });
    chooser.setAcceptAllFileFilterUsed(true);
    chooser.setSelectedFile(new File(icon.getText()));
    if (chooser.showDialog(null, Bundle.BTN_Select()) == JFileChooser.APPROVE_OPTION) {
        icon.setText(chooser.getSelectedFile().getAbsolutePath());
    }
}
 
Example 3
Source File: MainForm.java    From zxpoly with GNU General Public License v3.0 6 votes vote down vote up
private File chooseFileForOpen(final String title, final File initial,
                               final AtomicReference<FileFilter> selectedFilter,
                               final FileFilter... filter) {
  final JFileChooser chooser = new JFileChooser(initial);
  for (final FileFilter f : filter) {
    chooser.addChoosableFileFilter(f);
  }
  chooser.setAcceptAllFileFilterUsed(false);
  chooser.setMultiSelectionEnabled(false);
  chooser.setDialogTitle(title);
  chooser.setFileFilter(filter[0]);
  chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

  final File result;
  if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
    result = chooser.getSelectedFile();
    if (selectedFilter != null) {
      selectedFilter.set(chooser.getFileFilter());
    }
  } else {
    result = null;
  }
  return result;
}
 
Example 4
Source File: AddServerLocationVisualPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private JFileChooser getJFileChooser() {
    JFileChooser chooser = new JFileChooser();
    String t = NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName");
    chooser.setDialogTitle(t); //NOI18N
    chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); //NOI18N
    chooser.setMultiSelectionEnabled(false);
    chooser.addChoosableFileFilter(new DirFilter());
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setApproveButtonToolTipText(t); //NOI18N
    chooser.getAccessibleContext().setAccessibleName(t); //NOI18N
    chooser.getAccessibleContext().setAccessibleDescription(t); //NOI18N

    // set the current directory
    File currentLocation = new File(hk2HomeTextField.getText());
    File currentLocationParent = currentLocation.getParentFile();
    if(currentLocationParent != null && currentLocationParent.exists()) {
        chooser.setCurrentDirectory(currentLocationParent);
    }
    if (currentLocation.exists() && currentLocation.isDirectory()) {
        chooser.setSelectedFile(currentLocation);
    } 
    
    return chooser;
}
 
Example 5
Source File: FrmMeteoData.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void onAWXDataClick(ActionEvent e) {
    String path = this.getStartupPath();
    File pathDir = new File(path);

    JFileChooser aDlg = new JFileChooser();
    aDlg.setCurrentDirectory(pathDir);
    aDlg.setAcceptAllFileFilterUsed(false);
    String[] fileExts = new String[]{"awx"};
    GenericFileFilter mapFileFilter = new GenericFileFilter(fileExts, "AWX Data (*.awx)");
    aDlg.setFileFilter(mapFileFilter);
    aDlg.setMultiSelectionEnabled(true);
    if (JFileChooser.APPROVE_OPTION == aDlg.showOpenDialog(this)) {
        File[] files = aDlg.getSelectedFiles();
        System.setProperty("user.dir", files[0].getParent());
        for (File file : files) {
            MeteoDataInfo aDataInfo = new MeteoDataInfo();
            aDataInfo.openAWXData(file.getAbsolutePath());
            addMeteoData(aDataInfo);
        }
    }
}
 
Example 6
Source File: SaveDialog.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 7
Source File: SaveFrame.java    From GIFKR with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void initializeComponents() {
	widthSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 99999, 100));
	heightSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 99999, 100));
	frameDelayLabel = new JLabel("Frame delay (ms):");
	frameDelaySpinner = new JSpinner(new SpinnerNumberModel(0, 0, 99999, 1));

	chooser	= new JFileChooser();
	chooser.setDialogType(JFileChooser.SAVE_DIALOG);
	chooser.setAcceptAllFileFilterUsed(false);
	//setAnimationMode(true);
	//		chooser.setSelectedFile(StringUtil.resolveConflictName(chooser.getSelectedFile(), "glitch", true));
}
 
Example 8
Source File: PnlMain.java    From ISO8583 with GNU General Public License v3.0 5 votes vote down vote up
private void openFile() {
	JFileChooser file = new JFileChooser();
	file.setAcceptAllFileFilterUsed(false);
	file.setFileFilter(new FileNameExtensionFilter("xml files (*.xml)", "xml"));
	
	if (lastCurrentDirectory != null) 
		file.setCurrentDirectory(lastCurrentDirectory);
	
	if (file.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
		txtFilePath.setText(file.getSelectedFile().getAbsolutePath());
		lastCurrentDirectory = file.getSelectedFile();			

		openXML();
	}
}
 
Example 9
Source File: DocSetupPanelVisual.java    From jeddict with Apache License 2.0 5 votes vote down vote up
private void jBtnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnBrowseActionPerformed
    JFileChooser chooser = new JFileChooser(previousDirectory);
    chooser.setMultiSelectionEnabled(false);
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.addChoosableFileFilter(FILE_FILTER);
    chooser.setFileFilter(FILE_FILTER);

    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File wsdlFile = chooser.getSelectedFile();
        jsonFileTextField.setText(wsdlFile.getAbsolutePath());
        previousDirectory = wsdlFile.getPath();
    }
}
 
Example 10
Source File: ExistingFileChooserDialog.java    From pgptool with GNU General Public License v3.0 5 votes vote down vote up
private JFileChooser buildFileChooserDialog() {
	JFileChooser ofd = new JFileChooser();
	ofd.setFileSelectionMode(JFileChooser.FILES_ONLY);
	ofd.setAcceptAllFileFilterUsed(true);
	ofd.setMultiSelectionEnabled(false);
	ofd.setDialogTitle(Messages.get("action.chooseExistingFile"));
	ofd.setApproveButtonText(Messages.get("action.choose"));
	suggestInitialDirectory(ofd);
	doFileChooserPostConstruct(ofd);
	return ofd;
}
 
Example 11
Source File: OpenAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public static JFileChooser createFileChooser(ScriptEngineFactory scriptEngineFactory) {
    JFileChooser fs = new JFileChooser();
    fs.setAcceptAllFileFilterUsed(false);
    FileNameExtensionFilter filter = createFileFilter(scriptEngineFactory);
    fs.addChoosableFileFilter(filter);
    return fs;
}
 
Example 12
Source File: MainWindowDialogs.java    From amidst with GNU General Public License v3.0 5 votes vote down vote up
@CalledOnlyBy(AmidstThread.EDT)
private JFileChooser createSaveGameFileChooser() {
	JFileChooser result = new JFileChooser(runningLauncherProfile.getLauncherProfile().getSaves().toFile());
	result.setFileFilter(new LevelFileFilter());
	result.setAcceptAllFileFilterUsed(false);
	result.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
	result.setFileHidingEnabled(false);
	return result;
}
 
Example 13
Source File: MainPanel.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
public void importScript(final SWF swf) {
    As3ScriptReplacerInterface as3ScriptReplacer = getAs3ScriptReplacer();
    if (as3ScriptReplacer == null) {
        return;
    }
    String flexLocation = Configuration.flexSdkLocation.get();
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File(Configuration.lastExportDir.get()));
    chooser.setDialogTitle(translate("import.select.directory"));
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        String selFile = Helper.fixDialogFile(chooser.getSelectedFile()).getAbsolutePath();
        String scriptsFolder = Path.combine(selFile, ScriptExportSettings.EXPORT_FOLDER_NAME);

        int countAs2 = new AS2ScriptImporter().importScripts(scriptsFolder, swf.getASMs(true));
        int countAs3 = new AS3ScriptImporter().importScripts(as3ScriptReplacer, scriptsFolder, swf.getAS3Packs());

        if (countAs3 > 0) {
            updateClassesList();
        }

        View.showMessageDialog(this, translate("import.script.result").replace("%count%", Integer.toString(countAs2 + countAs3)));
        if (countAs2 != 0 || countAs3 != 0) {
            reload(true);
        }
    }
}
 
Example 14
Source File: OpenAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public static JFileChooser createFileChooser(ScriptEngineFactory[] scriptEngineFactories) {
    JFileChooser fs = new JFileChooser();
    fs.setAcceptAllFileFilterUsed(false);
    for (ScriptEngineFactory scriptEngineFactory : scriptEngineFactories) {
        FileNameExtensionFilter filter = createFileFilter(scriptEngineFactory);
        fs.addChoosableFileFilter(filter);
    }
    return fs;
}
 
Example 15
Source File: RasterLayer.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Save layer as a shape file
 */
@Override
public void saveFile() {
    File aFile = new File(this.getFileName());
    if (aFile.exists()) {
        saveFile(aFile.getAbsolutePath());
    } else {
        JFileChooser aDlg = new JFileChooser();
        String curDir = System.getProperty("user.dir");
        aDlg.setCurrentDirectory(new File(curDir));
        String[] fileExts = {"bil"};
        GenericFileFilter pFileFilter = new GenericFileFilter(fileExts, "BIL File (*.bil)");
        aDlg.addChoosableFileFilter(pFileFilter);
        aDlg.setFileFilter(pFileFilter);
        fileExts = new String[]{"grd"};
        pFileFilter = new GenericFileFilter(fileExts, "Surfer ASCII Grid File (*.grd)");
        aDlg.addChoosableFileFilter(pFileFilter);
        fileExts = new String[]{"asc"};
        pFileFilter = new GenericFileFilter(fileExts, "ESRI ASCII Grid File (*.asc)");
        aDlg.addChoosableFileFilter(pFileFilter);
        aDlg.setAcceptAllFileFilterUsed(false);
        if (JFileChooser.APPROVE_OPTION == aDlg.showSaveDialog(null)) {
            aFile = aDlg.getSelectedFile();
            System.setProperty("user.dir", aFile.getParent());
            String extent = ((GenericFileFilter) aDlg.getFileFilter()).getFileExtent();
            String fileName = aFile.getAbsolutePath();
            if (!fileName.substring(fileName.length() - extent.length()).equals(extent)) {
                fileName = fileName + "." + extent;
            }
            saveFile(fileName);
        }
    }
}
 
Example 16
Source File: CoreDumpConfigurator.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void chooseCoreDump() {
    JFileChooser chooser = new JFileChooser(new File(getCoreDumpFile()));
    chooser.setDialogTitle(NbBundle.getMessage(CoreDumpConfigurator.class, "LBL_Select_VM_Coredump"));    // NOI18N
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileFilter(CoreDumpSupport.getCategory().getFileFilter());
    int returnVal = chooser.showOpenDialog(WindowManager.getDefault().getMainWindow());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        coreDumpFileField.setText(chooser.getSelectedFile().getAbsolutePath());
    }
}
 
Example 17
Source File: ImportAltsFileChooser.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args)
{
	SwingUtils.setLookAndFeel();
	JFileChooser fileChooser = new ImportAltsFileChooser(new File(args[0]));
	
	fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
	fileChooser.setAcceptAllFileFilterUsed(false);
	fileChooser.addChoosableFileFilter(
		new FileNameExtensionFilter("TXT file (username:password)", "txt"));
	
	if(fileChooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION)
		return;
	
	File file = fileChooser.getSelectedFile();
	try
	{
		for(String line : Files.readAllLines(file.toPath()))
			System.out.println(line);
		
	}catch(IOException e)
	{
		e.printStackTrace();
		StringWriter writer = new StringWriter();
		e.printStackTrace(new PrintWriter(writer));
		String message = writer.toString();
		JOptionPane.showMessageDialog(fileChooser, message, "Error",
			JOptionPane.ERROR_MESSAGE);
	}
}
 
Example 18
Source File: J2SEPlatformCustomizer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static boolean select(
    final PathModel model,
    final File[] currentDir,
    final Component parentComponent) {
    final JFileChooser chooser = new JFileChooser ();
    chooser.setMultiSelectionEnabled (true);
    String title = null;
    String message = null;
    String approveButtonName = null;
    String approveButtonNameMne = null;
    if (model.type == SOURCES) {
        title = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenSources");
        message = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_Sources");
        approveButtonName = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenSources");
        approveButtonNameMne = NbBundle.getMessage (J2SEPlatformCustomizer.class,"MNE_OpenSources");
    } else if (model.type == JAVADOC) {
        title = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenJavadoc");
        message = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_Javadoc");
        approveButtonName = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenJavadoc");
        approveButtonNameMne = NbBundle.getMessage (J2SEPlatformCustomizer.class,"MNE_OpenJavadoc");
    }
    chooser.setDialogTitle(title);
    chooser.setApproveButtonText(approveButtonName);
    chooser.setApproveButtonMnemonic (approveButtonNameMne.charAt(0));
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    if (Utilities.isMac()) {
        //New JDKs and JREs are bundled into package, allow JFileChooser to navigate in
        chooser.putClientProperty("JFileChooser.packageIsTraversable", "always");   //NOI18N
    }
    //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
    chooser.setAcceptAllFileFilterUsed( false );
    chooser.setFileFilter (new ArchiveFileFilter(message,new String[] {"ZIP","JAR"}));   //NOI18N
    if (currentDir[0] != null) {
        chooser.setCurrentDirectory(currentDir[0]);
    }
    if (chooser.showOpenDialog(parentComponent) == JFileChooser.APPROVE_OPTION) {
        File[] fs = chooser.getSelectedFiles();
        boolean addingFailed = false;
        for (File f : fs) {
            //XXX: JFileChooser workaround (JDK bug #5075580), double click on folder returns wrong file
            // E.g. for /foo/src it returns /foo/src/src
            // Try to convert it back by removing last invalid name component
            if (!f.exists()) {
                File parent = f.getParentFile();
                if (parent != null && f.getName().equals(parent.getName()) && parent.exists()) {
                    f = parent;
                }
            }
            if (f.exists()) {
                addingFailed|=!model.addPath (f);
            }
        }
        if (addingFailed) {
            new NotifyDescriptor.Message (NbBundle.getMessage(J2SEPlatformCustomizer.class,"TXT_CanNotAddResolve"),
                    NotifyDescriptor.ERROR_MESSAGE);
        }
        currentDir[0] = FileUtil.normalizeFile(chooser.getCurrentDirectory());
        return true;
    }
    return false;
}
 
Example 19
Source File: SikulixFileChooser.java    From SikuliX1 with MIT License 4 votes vote down vote up
private void processDialog(int selectionMode, String last_dir, String title, int mode, Object[] filters,
                           Object[] result) {
  JFileChooser fchooser = new JFileChooser();
  File fileChoosen = null;
  FileFilter filterChoosen = null;
  if (!last_dir.isEmpty()) {
    fchooser.setCurrentDirectory(new File(last_dir));
  }
  fchooser.setSelectedFile(null);
  fchooser.setDialogTitle(title);
  String btnApprove = "Select";
  if (fromPopFile) {
    fchooser.setFileSelectionMode(DIRSANDFILES);
    fchooser.setAcceptAllFileFilterUsed(true);
  } else {
    fchooser.setFileSelectionMode(selectionMode);
    if (mode == FileDialog.SAVE) {
      fchooser.setDialogType(JFileChooser.SAVE_DIALOG);
      btnApprove = "Save";
    }
    if (filters.length == 0) {
      fchooser.setAcceptAllFileFilterUsed(true);
    } else {
      fchooser.setAcceptAllFileFilterUsed(false);
      for (Object filter : filters) {
        fchooser.setFileFilter((FileFilter) filter);
      }
    }
  }
  if (Settings.isMac()) {
    fchooser.putClientProperty("JFileChooser.packageIsTraversable", "always");
  }
  int dialogResponse = fchooser.showDialog(parentFrame, btnApprove);
  if (dialogResponse != JFileChooser.APPROVE_OPTION) {
    fileChoosen = null;
  } else {
    fileChoosen = fchooser.getSelectedFile();
  }
  result[0] = fileChoosen;
  if (filters.length > 0) {
    result[1] = fchooser.getFileFilter();
  }
}
 
Example 20
Source File: MarvinFileChooser.java    From marvinproject with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static void init(){
	chooser = new JFileChooser("./img");
	chooser.setAcceptAllFileFilterUsed(false);
}