List of usage examples for javax.swing JFileChooser FILES_ONLY
int FILES_ONLY
To view the source code for javax.swing JFileChooser FILES_ONLY.
Click Source Link
From source file:AudioFilter.java
public static void main(String[] args) { AudioFilter audioFilter = new AudioFilter(); JFileChooser jfc = new JFileChooser(); jfc.setDialogTitle("Open File"); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setCurrentDirectory(new File(".")); jfc.setFileFilter(audioFilter);//from w ww . ja v a 2s.c o m int result = jfc.showOpenDialog(null); if (result == JFileChooser.CANCEL_OPTION) { System.out.println("cancel"); } else if (result == JFileChooser.APPROVE_OPTION) { File fFile = jfc.getSelectedFile(); String filestr = fFile.getAbsolutePath(); System.out.println(filestr); } }
From source file:de.dakror.jagui.parser.NGuiParser.java
public static void main(String[] args) { try {// w ww . j a va 2s. co m DIR.mkdirs(); if (!new File(DIR, "convert.exe").exists()) Helper.copyInputStream(NGuiParser.class.getResourceAsStream("/res/convert.exe"), new FileOutputStream(new File(DIR, "convert.exe"))); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); JFileChooser jfc = new JFileChooser( new File(NGuiParser.class.getProtectionDomain().getCodeSource().getLocation().toURI())); jfc.setMultiSelectionEnabled(false); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setFileFilter(new FileNameExtensionFilter("Unity ngui Gui-Skin (*.guiskin)", "guiskin")); if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { p("Collecting GUIDs, Converting Resources"); HashMap<String, File> guids = collectGUIDs(jfc.getCurrentDirectory()); p("Parsing Guiskin file"); String s = Helper.getFileContent(jfc.getSelectedFile()); String[] lines = s.split("\n"); ArrayList<String> l = new ArrayList<>(Arrays.asList(lines)); String string = ""; for (int i = 0; i < l.size(); i++) if (!l.get(i).startsWith("%") && !l.get(i).startsWith("---")) string += l.get(i) + "\n"; Yaml yaml = new Yaml(); for (Iterator<Object> iter = yaml.loadAll(string).iterator(); iter.hasNext();) { JSONObject o = new JSONObject((Map<?, ?>) iter.next()); p("Cconverting Guiskin"); replaceGuidDeep(o, guids, jfc.getSelectedFile()); p("Writing converted file"); Helper.setFileContent(new File(jfc.getSelectedFile().getParentFile(), jfc.getSelectedFile().getName() + ".json"), o.toString(4)); p("DONE"); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.acmutv.ontoqa.GrammalexMain.java
/** * The app main method, executed when the program is launched. * @param args The command line arguments. * @throws IllegalAccessException // ww w . j a v a 2 s . com * @throws InstantiationException */ public static void main(String[] args) throws InstantiationException, IllegalAccessException { //CliService.handleArguments(args); RuntimeManager.registerShutdownHooks(new ShutdownHook()); try { Path path = FileSystems.getDefault().getPath("data/lexicon").toAbsolutePath(); String currentDirectory = path.toString(); final JFileChooser fc = new JFileChooser(currentDirectory); int returnVal = fc.showOpenDialog(null); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); if (returnVal == JFileChooser.OPEN_DIALOG) { File file = fc.getSelectedFile(); System.out.println("File Select: " + file.getName() + "\n\n"); List<LexicalEntry> lEntries = LexiconUsage.getLexicalEntries(file.getAbsolutePath(), "", LexiconFormat.RDFXML); Grammar grammar = SerializeSltag.getAllElementarySltag(lEntries); SerializeSltag.writeGrammarOnFile(grammar, fileJson); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.exit(0); }
From source file:Main.java
public static File chooseFile(Component parentComponent, String title) { JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.showDialog(parentComponent, title); return jfc.getSelectedFile(); }
From source file:Main.java
public static JFileChooser generateFileChooser(String description, String... ext) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setFileFilter(new FileFilter() { @Override/*from w w w. j a v a2 s. co m*/ public boolean accept(File f) { boolean res = f.isDirectory(); for (String s : ext) { res = res || f.getName().endsWith("." + s); } return res; } @Override public String getDescription() { return description; } }); return fileChooser; }
From source file:Main.java
/** * Creates a new JFileChooser and returns the selected path's location. * @param title/* w ww . j a v a 2s. c o m*/ * @param openTo * @param chooseDirectory * @param filter * @return */ public static String getFilePath(String title, String openTo, boolean chooseDirectory, FileFilter filter) { String location = null; JFileChooser chooser = new JFileChooser(title); chooser.setCurrentDirectory(new File(openTo)); chooser.setFileFilter(filter); chooser.setDialogTitle("Open Cache"); if (chooseDirectory) { chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } else { chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); } chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(chooser) == JFileChooser.APPROVE_OPTION) { location = chooser.getSelectedFile().getAbsolutePath(); } return location; }
From source file:Main.java
/** * Displays a {@link JFileChooser} to select a file. * * @param title The title of the dialog. * @param startDirectory The directory where the dialog is initialed opened. * @param fileExtension File extension to filter each content of the opened * directories. Example ".xml"./*from w ww . j av a 2 s.co m*/ * @param startFile The preselected file where the dialog is initialed opened. * @return The {@link File} object selected, returns null if no file was selected. */ public static File chooseFile(String title, String startDirectory, final String fileExtension, String startFile) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle(title); if (fileExtension != null && !fileExtension.trim().equals("")) { FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() || pathname.getName().endsWith(fileExtension); } @Override public String getDescription() { return "(" + fileExtension + ")"; } }; chooser.setFileFilter(filter); } if (startDirectory != null && !startDirectory.trim().equals("")) { chooser.setCurrentDirectory(new File(startDirectory)); } if (startFile != null && !startFile.trim().equals("")) { chooser.setSelectedFile(new File(startFile)); } int status = chooser.showOpenDialog(null); if (status == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile(); } return null; }
From source file:com.willwinder.universalgcodesender.uielements.components.FirmwareSettingsFileTypeFilter.java
public static JFileChooser getSettingsFileChooser() { FirmwareSettingsFileTypeFilter filter = new FirmwareSettingsFileTypeFilter(); // Setup file browser with the last path used. JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setFileHidingEnabled(true); fileChooser.addChoosableFileFilter(filter); fileChooser.setAcceptAllFileFilterUsed(true); fileChooser.setFileFilter(filter);/*w w w . j av a 2s . c om*/ return fileChooser; }
From source file:net.rptools.maptool.util.AssetExtractor.java
public static void extract() throws Exception { new Thread() { @Override/* www. j av a 2s . c om*/ public void run() { JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) { return; } File file = chooser.getSelectedFile(); File newDir = new File(file.getParentFile(), file.getName().substring(0, file.getName().lastIndexOf('.')) + "_images"); JLabel label = new JLabel("", JLabel.CENTER); JFrame frame = new JFrame(); frame.setTitle("Campaign Image Extractor"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setSize(400, 75); frame.add(label); SwingUtil.centerOnScreen(frame); frame.setVisible(true); Reader r = null; OutputStream out = null; PackedFile pakfile = null; try { newDir.mkdirs(); label.setText("Loading campaign ..."); pakfile = new PackedFile(file); Set<String> files = pakfile.getPaths(); XStream xstream = new XStream(); int count = 0; for (String filename : files) { count++; if (filename.indexOf("assets") < 0) { continue; } r = pakfile.getFileAsReader(filename); Asset asset = (Asset) xstream.fromXML(r); IOUtils.closeQuietly(r); File newFile = new File(newDir, asset.getName() + ".jpg"); label.setText("Extracting image " + count + " of " + files.size() + ": " + newFile); if (newFile.exists()) { newFile.delete(); } newFile.createNewFile(); out = new FileOutputStream(newFile); FileUtil.copyWithClose(new ByteArrayInputStream(asset.getImage()), out); } label.setText("Done."); } catch (Exception ioe) { MapTool.showInformation("AssetExtractor failure", ioe); } finally { if (pakfile != null) pakfile.close(); IOUtils.closeQuietly(r); IOUtils.closeQuietly(out); } } }.start(); }
From source file:com.googlecode.bpmn_simulator.gui.dialogs.ImageExportChooser.java
public ImageExportChooser() { super();/*from w w w. j a v a2 s . c om*/ setFileSelectionMode(JFileChooser.FILES_ONLY); setMultiSelectionEnabled(false); setAcceptAllFileFilterUsed(false); for (final String suffix : ImageIO.getWriterFileSuffixes()) { addChoosableFileFilter(new FileNameExtensionFilter(suffix, suffix)); } }