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:org.archiviststoolkit.importer.ImportUtils.java
public static File chooseFile(Component parent, SimpleFileFilter fileFilter) { UserPreferences userPrefs = UserPreferences.getInstance(); JFileChooser chooser; if (userPrefs.getSavePath() == null) { chooser = new JFileChooser(); } else {/*from w w w .j av a2 s . co m*/ chooser = new JFileChooser(userPrefs.getSavePath()); } if (fileFilter != null) { chooser.setFileFilter(fileFilter); } // chooser.setCurrentDirectory("."); if (chooser.showOpenDialog(parent) != JFileChooser.APPROVE_OPTION) { return null; } else { userPrefs.setSavePath(chooser.getCurrentDirectory().getPath()); return chooser.getSelectedFile(); } }
From source file:org.ayound.js.debug.ui.DebugMainFrame.java
private void initAction() { actionOpen = new AbstractAction(Messages.getString("DebugMainFrame.Open")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { JFileChooser fileDialog = new JFileChooser(); // fileDialog.setFileFilter(new FileFilter() { @Override//from w w w. j a va 2 s . c o m public boolean accept(File f) { String fileName = f.getName().toLowerCase(); if (fileName.endsWith(".htm") //$NON-NLS-1$ || fileName.endsWith(".html") //$NON-NLS-1$ || fileName.endsWith(".js") || f.isDirectory()) { //$NON-NLS-1$ return true; } else { return false; } } @Override public String getDescription() { return ".htm,.html,.js"; //$NON-NLS-1$ } }); int result = fileDialog.showOpenDialog(DebugMainFrame.this); if (result == JFileChooser.APPROVE_OPTION) { openHtmlFile(fileDialog.getSelectedFile()); } } }; actionClose = new AbstractAction(Messages.getString("DebugMainFrame.Close")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { int index = mainPane.getSelectedIndex(); if (index > -1) { mainPane.remove(index); } } }; actionExit = new AbstractAction(Messages.getString("DebugMainFrame.Exit")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { System.exit(0); } }; ImageIcon startIcon = new ImageIcon(DebugMainFrame.class.getResource("icons/launch_run.gif")); //$NON-NLS-1$ actionDebugStart = new AbstractAction(Messages.getString("DebugMainFrame.Start"), startIcon) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { startDebug(); } }; ImageIcon endIcon = new ImageIcon(DebugMainFrame.class.getResource("icons/terminate_co.gif")); //$NON-NLS-1$ actionDebugEnd = new AbstractAction(Messages.getString("DebugMainFrame.End"), endIcon) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { endDebug(); } }; actionDebugEnd.setEnabled(false); actionHelp = new AbstractAction(Messages.getString("DebugMainFrame.Content")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { String locale = DebugMainFrame.this.getLocale().toString(); String helpPath = "help/index_" + locale + ".html"; File testFile = new File(new File(getBaseDir()), helpPath); //$NON-NLS-1$ final String url = "file:///" + testFile.getAbsolutePath().replace('\\', '/'); //$NON-NLS-1$ SwingUtilities.invokeLater(new Runnable() { public void run() { try { // TODO Auto-generated method stub JFrame someWindow = new JFrame(); JEditorPane htmlPane = new JEditorPane(url); htmlPane.setEditable(false); someWindow.setSize(800, 600); someWindow.setExtendedState(JFrame.MAXIMIZED_BOTH); someWindow.setVisible(true); someWindow.add(new JScrollPane(htmlPane)); } catch (IOException ioe) { System.err.println(Messages.getString("DebugMainFrame.ErrorDisplay") + url); //$NON-NLS-1$ } } }); } }; actionAbout = new AbstractAction(Messages.getString("DebugMainFrame.About")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(DebugMainFrame.this, Messages.getString("DebugMainFrame.AboutContent"), //$NON-NLS-1$ Messages.getString("DebugMainFrame.ApplicationName"), JOptionPane.INFORMATION_MESSAGE); //$NON-NLS-1$ } }; actionLanguageChinese = new AbstractAction("Chinese") { public void actionPerformed(ActionEvent e) { DebugUIUtil.updateUI(Locale.SIMPLIFIED_CHINESE); } }; actionLanguageEnglish = new AbstractAction("English") { public void actionPerformed(ActionEvent e) { DebugUIUtil.updateUI(Locale.ENGLISH); } }; }
From source file:org.ayound.js.debug.ui.DebugMainFrame.java
private void initToolBar() { toolBar = new JToolBar(); Container debugInfoContainer = new Box(BoxLayout.LINE_AXIS); toolBar.add(debugInfoContainer);/*from w w w .j a v a 2s .com*/ JLabel urlLabel = new JLabel(Messages.getString("DebugMainFrame.UrlLabel")); //$NON-NLS-1$ debugInfoContainer.add(urlLabel); urlText = new JTextField(20); String historyUrl = ConfigUtil.getPropertie("url"); if (historyUrl == null) { File testFile = new File(new File(getBaseDir()), "test/test.htm"); //$NON-NLS-1$ urlText.setText(testFile.getAbsolutePath().replace('\\', '/')); } else { urlText.setText(historyUrl); } debugInfoContainer.add(urlText); urlButton = new JButton(Messages.getString("DebugMainFrame.Select")); //$NON-NLS-1$ urlButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub JFileChooser fileDialog = new JFileChooser(); // fileDialog.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { String fileName = f.getName().toLowerCase(); if (fileName.endsWith(".htm") //$NON-NLS-1$ || fileName.endsWith(".html") //$NON-NLS-1$ || f.isDirectory()) { return true; } else { return false; } } @Override public String getDescription() { return ".htm,.html"; //$NON-NLS-1$ } }); int result = fileDialog.showOpenDialog(DebugMainFrame.this); if (result == JFileChooser.APPROVE_OPTION) { urlText.setText(fileDialog.getSelectedFile().getAbsolutePath()); } } }); debugInfoContainer.add(urlButton); JLabel portLabel = new JLabel(Messages.getString("DebugMainFrame.PortLabel")); //$NON-NLS-1$ debugInfoContainer.add(portLabel); portText = new JTextField(2); portText.setText("8088"); //$NON-NLS-1$ debugInfoContainer.add(portText); JLabel browserLabel = new JLabel(Messages.getString("DebugMainFrame.BrowserLabel")); //$NON-NLS-1$ debugInfoContainer.add(browserLabel); browserText = new JTextField(20); debugInfoContainer.add(browserText); String historyBrowser = ConfigUtil.getPropertie("browser"); if (historyBrowser != null) { browserText.setText(historyBrowser); // .setText("C:\\Program Files\\Internet Explorer\\iexplore.exe"); // //$NON-NLS-1$ } browserButton = new JButton(Messages.getString("DebugMainFrame.Select")); //$NON-NLS-1$ browserButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub JFileChooser fileDialog = new JFileChooser(); // fileDialog.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { String fileName = f.getName().toLowerCase(); if (fileName.endsWith(".exe") || f.isDirectory()) { //$NON-NLS-1$ return true; } else { return false; } } @Override public String getDescription() { return ".exe(windows)"; //$NON-NLS-1$ } }); int result = fileDialog.showOpenDialog(DebugMainFrame.this); if (result == JFileChooser.APPROVE_OPTION) { browserText.setText(fileDialog.getSelectedFile().getAbsolutePath()); } } }); debugInfoContainer.add(browserButton); toolBar.addSeparator(); JButton startBtn = toolBar.add(actionDebugStart); startBtn.setToolTipText(Messages.getString("DebugMainFrame.StartDebug")); //$NON-NLS-1$ JButton endBtn = toolBar.add(actionDebugEnd); endBtn.setToolTipText(Messages.getString("DebugMainFrame.EndDebug")); //$NON-NLS-1$ getContentPane().add(toolBar, BorderLayout.BEFORE_FIRST_LINE); }
From source file:org.bimserver.client.Client.java
void checkout(SRevision revision) { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter("IFC File", "ifc")); int showSaveDialog = chooser.showSaveDialog(this); if (showSaveDialog == JFileChooser.APPROVE_OPTION) { File selectedFile = chooser.getSelectedFile(); FileOutputStream fileOutputStream; try {/*from w w w.j a va2 s .c om*/ fileOutputStream = new FileOutputStream(selectedFile); checkout(revision, fileOutputStream, true); } catch (FileNotFoundException e) { LOGGER.error("", e); } } }
From source file:org.bimserver.client.Client.java
public void download(SRevision revision) { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter("IFC File", "ifc")); int showSaveDialog = chooser.showSaveDialog(this); if (showSaveDialog == JFileChooser.APPROVE_OPTION) { File selectedFile = chooser.getSelectedFile(); try {/*from w w w. j a va 2 s .c o m*/ FileOutputStream fileOutputStream = new FileOutputStream(selectedFile); download(revision.getOid(), fileOutputStream, true); } catch (FileNotFoundException e) { LOGGER.error("", e); } } }
From source file:org.colombbus.tangara.net.FileReceptionDialog.java
private void setTargetFile() { File targetDir = Configuration.instance().getUserHome(); JFileChooser chooserDlg = new JFileChooser(targetDir); String filterMsg = Messages.getString("FileReceptionDialog.filter.allFiles"); SimpleFileFilter filter = new SimpleFileFilter(filterMsg); chooserDlg.setFileFilter(filter); File originalSelFile = new File(targetDir, sourceFilename); File curSelFile = originalSelFile; boolean showDialog = true; while (showDialog) { chooserDlg.setSelectedFile(curSelFile); int userAction = chooserDlg.showSaveDialog(owner); curSelFile = chooserDlg.getSelectedFile(); switch (userAction) { case JFileChooser.CANCEL_OPTION: showDialog = false;/*w w w. ja v a2s . c o m*/ break; case JFileChooser.APPROVE_OPTION: if (curSelFile.exists()) { String title = Messages.getString("FileReceptionDialog.overwrite.title"); String msgPattern = Messages.getString("FileReceptionDialog.overwrite.message"); String overwriteMsg = MessageFormat.format(msgPattern, curSelFile.getName()); Object[] options = { Messages.getString("FileReceptionDialog.yes"), Messages.getString("FileReceptionDialog.no") }; int userChoice = JOptionPane.showOptionDialog(owner, overwriteMsg, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, // do not use a // custom Icon options, // the titles of buttons options[0]); if (userChoice == JOptionPane.OK_OPTION) { if (saveFileAs(curSelFile)) { showDialog = false; } } } else if (saveFileAs(curSelFile)) { showDialog = false; } break; case JFileChooser.ERROR_OPTION: LOG.error("Error in file chooser dialog"); // TODO what to do in case of error ? Retry ? showDialog = false; break; } } }
From source file:org.docwhat.iated.ui.PreferencesDialog.java
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Please select your editor"); chooser.setCurrentDirectory(new File(getDefaultAppDirectory())); chooser.setFileFilter(new FileFilter() { public boolean accept(File f) { if (OS.isFamilyMac() && f.isDirectory() && f.getName().toLowerCase().endsWith(".app")) { return (true); }// w w w . j a va2s . c o m return f.canExecute(); } public String getDescription() { return "Applications"; } }); int result = chooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { editorField.setText(chooser.getSelectedFile().getPath()); } }
From source file:org.domainmath.gui.MainFrame.java
/** * Creates file chooser dialog box and allows the user to select files * and importData selected files in fileTab. *//* ww w. j a v a 2s.com*/ public void open() { JFileChooser fc = new JFileChooser(); // set current directory. if (fileTab.getTabCount() > 0) { File f = new File(fileTab.getToolTipTextAt(fileTab.getSelectedIndex())); fc.setCurrentDirectory(f.getParentFile()); } else { fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works")); } FileNameExtensionFilter filter = new FileNameExtensionFilter("M-Files (*.m)", "m"); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(filter); fc.setMultiSelectionEnabled(true); fc.setFileView(new ScriptFileView()); File file1[]; int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { file1 = fc.getSelectedFiles(); this.setCurrentDirFileTab(fc.getCurrentDirectory().getAbsolutePath()); for (int i = 0; i < file1.length; i++) { if (!fileNameList.contains(file1[i].getAbsolutePath())) { open(file1[i], i); } else { System.out.println(file1[i].getAbsolutePath() + " already open!"); } } } }
From source file:org.domainmath.gui.MainFrame.java
public void saveHistoryAs() { JFileChooser fc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("M-Files (*.m)", "m"); fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works")); fc.setFileFilter(filter); fc.setMultiSelectionEnabled(false);/*from w w w .j a v a 2 s . c o m*/ fc.setDialogTitle("Save As"); File file_save; int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { String path = fc.getSelectedFile().getAbsolutePath(); if (!path.endsWith(".m")) { file_save = new File(fc.getSelectedFile().getAbsolutePath() + ".m"); saveHistory(file_save); } else { file_save = new File(fc.getSelectedFile().getAbsolutePath() + ".m"); saveHistory(file_save); } } }
From source file:org.domainmath.gui.MainFrame.java
public void saveplot() { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir") + File.separator + "works")); fc.setFileFilter(DomainMathFileFilter.SAVE_PLOT_FILE_FILTER); fc.setAcceptAllFileFilterUsed(false); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(false);//from w w w . j ava 2 s.com File file_plot; String name; int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { System.err.println(fc.getFileFilter().getDescription()); file_plot = fc.getSelectedFile(); name = file_plot.getName(); evaluateWithOutput("saveas(1," + "'" + file_plot.getAbsolutePath() + "');"); } }