List of usage examples for javax.swing JFileChooser setFileFilter
@BeanProperty(preferred = true, description = "Sets the File Filter used to filter out files of type.") public void setFileFilter(FileFilter filter)
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 {// www. 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:pl.wasko.utils.xlsxtract.MainFrame.java
private void xlsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_xlsButtonActionPerformed JFileChooser fc = new JFileChooser(System.getProperty("user.dir")); fc.setFileFilter(new FileNameExtensionFilter("Pliki *.XLS", "xls", "xlsx")); int res = fc.showOpenDialog(this); if (res == JFileChooser.APPROVE_OPTION) { xlsTextField.setText(fc.getSelectedFile().getAbsolutePath()); }// www . ja v a2 s. c o m }
From source file:playmidi.gui.Main.java
private void FileSelectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileSelectButtonActionPerformed JFileChooser filechooser = new JFileChooser(); filechooser.setFileFilter(new MidiFileFilter()); int selected = filechooser.showOpenDialog(this); if (selected == JFileChooser.APPROVE_OPTION) { File midiFile = filechooser.getSelectedFile(); FilePath.setText(""); this.openMidiFile(midiFile); }/* ww w. j av a 2 s . c o m*/ }
From source file:plugin.notes.gui.NotesView.java
/** * {@literal handle File->Open.} Will open any .gmn files, and import them into your * notes structure/*from w w w . j av a2s.c om*/ */ public void handleOpen() { // TODO fix String sFile = SettingsHandler.getGMGenOption(OPTION_NAME_LASTFILE, System.getProperty("user.dir")); File defaultFile = new File(sFile); JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(defaultFile); chooser.addChoosableFileFilter(getFileType()); chooser.setFileFilter(getFileType()); chooser.setMultiSelectionEnabled(true); Component component = GMGenSystem.inst; Cursor originalCursor = component.getCursor(); component.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); int option = chooser.showOpenDialog(GMGenSystem.inst); if (option == JFileChooser.APPROVE_OPTION) { for (File noteFile : chooser.getSelectedFiles()) { SettingsHandler.setGMGenOption(OPTION_NAME_LASTFILE, noteFile.toString()); if (noteFile.toString().endsWith(EXTENSION)) { openGMN(noteFile); } } } GMGenSystem.inst.setCursor(originalCursor); refreshTree(); }
From source file:plugin.notes.gui.NotesView.java
/** * Exports a node out to a gmn file./*w ww .j ava 2s. c om*/ * *@param node node to export to file */ private void exportFile(NotesTreeNode node) { JFileChooser fLoad = new JFileChooser(); String sFile = SettingsHandler.getGMGenOption(OPTION_NAME_LASTFILE, ""); new File(sFile); FileFilter ff = getFileType(); fLoad.addChoosableFileFilter(ff); fLoad.setFileFilter(ff); int returnVal = fLoad.showSaveDialog(this); try { if (returnVal == JFileChooser.APPROVE_OPTION) { String fileName = fLoad.getSelectedFile().getName(); String dirName = fLoad.getSelectedFile().getParent(); String extension = EXTENSION; if (fileName.indexOf(extension) < 0) { fileName += extension; } File expFile = new File(dirName + File.separator + fileName); if (expFile.exists()) { int choice = JOptionPane.showConfirmDialog(this, "File Exists, Overwrite?", "File Exists", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (choice == JOptionPane.NO_OPTION) { return; } } SettingsHandler.setGMGenOption(OPTION_NAME_LASTFILE, expFile.toString()); writeNotesFile(expFile, node); } } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error Writing File"); Logging.errorPrint("Error Writing to file: " + e.getMessage(), e); } }
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 *///ww w.j av 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 w w w . j a v a2 s . c o 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:PolyGlot.IOHandler.java
/** * Queries user for image file, and returns it * @param parent the parent window from which this is called * @return the image chosen by the user, null if canceled * @throws IOException If the image cannot be opened for some reason *//*from w w w. j a va 2 s .c o m*/ public static BufferedImage openImageFile(Component parent) throws IOException { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Open Images"); FileNameExtensionFilter filter = new FileNameExtensionFilter("Image Files", "gif", "jpg", "jpeg", "bmp", "png", "wbmp"); chooser.setFileFilter(filter); String fileName; chooser.setCurrentDirectory(new File(".")); if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { fileName = chooser.getSelectedFile().getAbsolutePath(); } else { return null; } return getImage(fileName); }
From source file:processing.app.Base.java
public void handleAddLibrary() { JFileChooser fileChooser = new JFileChooser(System.getProperty("user.home")); fileChooser.setDialogTitle(tr("Select a zip file or a folder containing the library you'd like to add")); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setFileFilter(new FileNameExtensionFilter(tr("ZIP files or folders"), "zip")); Dimension preferredSize = fileChooser.getPreferredSize(); fileChooser.setPreferredSize(new Dimension(preferredSize.width + 200, preferredSize.height + 200)); int returnVal = fileChooser.showOpenDialog(activeEditor); if (returnVal != JFileChooser.APPROVE_OPTION) { return;//from w w w .j a v a 2s .c om } File sourceFile = fileChooser.getSelectedFile(); File tmpFolder = null; try { // unpack ZIP if (!sourceFile.isDirectory()) { try { tmpFolder = FileUtils.createTempFolder(); ZipDeflater zipDeflater = new ZipDeflater(sourceFile, tmpFolder); zipDeflater.deflate(); File[] foldersInTmpFolder = tmpFolder.listFiles(new OnlyDirs()); if (foldersInTmpFolder.length != 1) { throw new IOException(tr("Zip doesn't contain a library")); } sourceFile = foldersInTmpFolder[0]; } catch (IOException e) { activeEditor.statusError(e); return; } } File libFolder = sourceFile; if (FileUtils.isSubDirectory(new File(PreferencesData.get("sketchbook.path")), libFolder)) { activeEditor.statusError(tr("A subfolder of your sketchbook is not a valid library")); return; } if (FileUtils.isSubDirectory(libFolder, new File(PreferencesData.get("sketchbook.path")))) { activeEditor.statusError(tr("You can't import a folder that contains your sketchbook")); return; } String libName = libFolder.getName(); if (!BaseNoGui.isSanitaryName(libName)) { String mess = I18n.format(tr("The library \"{0}\" cannot be used.\n" + "Library names must contain only basic letters and numbers.\n" + "(ASCII only and no spaces, and it cannot start with a number)"), libName); activeEditor.statusError(mess); return; } String[] headers; File libProp = new File(libFolder, "library.properties"); File srcFolder = new File(libFolder, "src"); if (libProp.exists() && srcFolder.isDirectory()) { headers = BaseNoGui.headerListFromIncludePath(srcFolder); } else { headers = BaseNoGui.headerListFromIncludePath(libFolder); } if (headers.length == 0) { activeEditor.statusError(tr("Specified folder/zip file does not contain a valid library")); return; } // copy folder File destinationFolder = new File(BaseNoGui.getSketchbookLibrariesFolder().folder, sourceFile.getName()); if (!destinationFolder.mkdir()) { activeEditor .statusError(I18n.format(tr("A library named {0} already exists"), sourceFile.getName())); return; } try { FileUtils.copy(sourceFile, destinationFolder); } catch (IOException e) { activeEditor.statusError(e); return; } activeEditor.statusNotice(tr("Library added to your libraries. Check \"Include library\" menu")); } catch (IOException e) { // FIXME error when importing. ignoring :( } finally { // delete zip created temp folder, if exists newLibraryImported = true; FileUtils.recursiveDelete(tmpFolder); } }
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); 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);// w w w. ja v a2 s . c om } }