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:org.tinymediamanager.ui.TmmUIHelper.java
public static Path saveFile(String title, String filename, FileNameExtensionFilter filter) { // try to open AWT dialog on OSX if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) { try {// ww w.ja v a 2 s. co m // open file chooser return openFileDialog(title, FileDialog.SAVE, filename); } catch (Exception e) { LOGGER.warn("cannot open AWT filechooser" + e.getMessage()); } catch (Error e) { LOGGER.warn("cannot open AWT filechooser" + e.getMessage()); } } return openJFileChooser(JFileChooser.FILES_ONLY, title, false, filename, filter); }
From source file:org.tmpotter.ui.ActionHandler.java
/** * Save project as specified filename.//from w w w . j a v a 2 s . c o m */ private void saveProjectAs() { File outFile = new File(modelMediator.getProjectName().concat(".tmpx")); try { boolean save = false; boolean cancel = false; while (!save && !cancel) { final JFileChooser fc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("TMX File", "tmpx"); fc.setFileFilter(filter); boolean nameOfUser = false; while (!nameOfUser) { fc.setLocation(230, 300); fc.setCurrentDirectory(RuntimePreferences.getUserHome()); fc.setDialogTitle(getString("DLG.SAVEAS")); fc.setMultiSelectionEnabled(false); fc.setSelectedFile(outFile); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); RuntimePreferences.setUserHome(fc.getCurrentDirectory()); int returnVal; returnVal = fc.showSaveDialog(parent); if (returnVal == JFileChooser.APPROVE_OPTION) { outFile = fc.getSelectedFile(); if (!outFile.getName().endsWith(".tmpx")) { outFile = new File(outFile.getName().concat(".tmpx")); } nameOfUser = true; } else { nameOfUser = true; cancel = true; } } int selected; if (nameOfUser && !cancel) { if (outFile.exists()) { final Object[] options = { getString("BTN.SAVE"), getString("BTN.CANCEL") }; selected = JOptionPane.showOptionDialog(parent, getString("MSG.FILE_EXISTS"), getString("MSG.WARNING"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (selected == 0) { save = true; } } else { save = true; } } } if (save) { cleanTmData(); ProjectProperties prop = modelMediator.getProjectProperties(); prop.setFilePathProject(outFile); TmxpWriter.writeTmxp(prop, tmData.getDocumentOriginal(), tmData.getDocumentTranslation()); } } catch (Exception ex) { JOptionPane.showMessageDialog(parent, JOptionPane.ERROR_MESSAGE); } }
From source file:org.zaproxy.zap.extension.beanshell.BeanShellConsoleFrame.java
private JButton getBtnLoad() { if (btnLoad == null) { btnLoad = new JButton(); btnLoad.setText(Constant.messages.getString("beanshell.button.load")); btnLoad.addActionListener(new ActionListener() { @Override/*w w w . ja va 2 s .c om*/ public void actionPerformed(ActionEvent e) { if (getBeanShellPanel().isSaved() == false) { int confirm = view .showConfirmDialog(Constant.messages.getString("beanshell.dialog.unsaved")); if (confirm == JOptionPane.CANCEL_OPTION) return; } JFileChooser fc = new JFileChooser(scriptsDir); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int result = fc.showOpenDialog(getBeanShellPanel()); if (result == JFileChooser.APPROVE_OPTION) { try { String temp = loadScript(fc.getSelectedFile()); getBeanShellPanel().getTxtEditor().setText(temp); getBeanShellPanel().getTxtEditor().discardAllEdits(); getBeanShellPanel().setSaved(true); currentScriptFile = fc.getSelectedFile(); } catch (IOException ex) { log.error(ex.getMessage(), ex); View.getSingleton().showWarningDialog( Constant.messages.getString("beanshell.error.message.loading.script")); } } } }); } return btnLoad; }
From source file:org.zaproxy.zap.extension.beanshell.BeanShellConsoleFrame.java
private JButton getBtnSave() { if (btnSave == null) { btnSave = new JButton(); btnSave.setText(Constant.messages.getString("beanshell.button.save")); btnSave.addActionListener(new ActionListener() { @Override/*from www .ja v a 2 s . c om*/ public void actionPerformed(ActionEvent e) { if (currentScriptFile != null) { try { saveScript(getBeanShellPanel().getTxtEditor().getText(), currentScriptFile); getBeanShellPanel().setSaved(true); } catch (IOException ex) { log.error(ex.getMessage(), ex); View.getSingleton().showWarningDialog( Constant.messages.getString("beanshell.error.message.saving.script")); } } else { JFileChooser fc = new JFileChooser(scriptsDir); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int result = fc.showSaveDialog(getBeanShellPanel()); if (result == JFileChooser.APPROVE_OPTION) { try { saveScript(getBeanShellPanel().getTxtEditor().getText(), fc.getSelectedFile()); getBeanShellPanel().setSaved(true); currentScriptFile = fc.getSelectedFile(); } catch (IOException ex) { log.error(ex.getMessage(), ex); View.getSingleton().showWarningDialog( Constant.messages.getString("beanshell.error.message.saving.script")); } } } } }); } return btnSave; }
From source file:org.zaproxy.zap.extension.beanshell.BeanShellConsoleFrame.java
private JButton getBtnSaveAs() { if (btnSaveAs == null) { btnSaveAs = new JButton(); btnSaveAs.setText(Constant.messages.getString("beanshell.button.saveas")); btnSaveAs.addActionListener(new ActionListener() { @Override/*from w w w. j a va2 s. co m*/ public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(scriptsDir); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int result = fc.showSaveDialog(getBeanShellPanel()); if (result == JFileChooser.APPROVE_OPTION) { try { saveScript(getBeanShellPanel().getTxtEditor().getText(), fc.getSelectedFile()); getBeanShellPanel().setSaved(true); currentScriptFile = fc.getSelectedFile(); } catch (IOException ex) { log.error(ex.getMessage(), ex); View.getSingleton().showWarningDialog( Constant.messages.getString("beanshell.error.message.saving.script")); } } } }); } return btnSaveAs; }
From source file:org.zaproxy.zap.extension.dynssl.DynamicSSLPanel.java
/** * Import Root CA certificate from other ZAP configuration files. *//*w w w . j a v a 2 s. c o m*/ private void doImport() { if (checkExistingCertificate()) { // prevent overwriting return; } final JFileChooser fc = new JFileChooser(System.getProperty("user.home")); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(false); fc.setSelectedFile(new File(CONFIGURATION_FILENAME)); fc.setFileFilter(new FileFilter() { @Override public String getDescription() { // config.xml or *.pem files return Constant.messages.getString("dynssl.filter.file"); } @Override public boolean accept(File f) { return f.getName().toLowerCase().endsWith(CONFIGURATION_FILENAME) || f.getName().toLowerCase().endsWith("pem") || f.isDirectory(); } }); final int result = fc.showOpenDialog(this); final File f = fc.getSelectedFile(); if (result == JFileChooser.APPROVE_OPTION && f.exists()) { if (logger.isInfoEnabled()) { logger.info("Loading Root CA certificate from " + f); } KeyStore ks = null; if (f.getName().toLowerCase().endsWith("pem")) { ks = convertPemFileToKeyStore(f.toPath()); } else { try { final ZapXmlConfiguration conf = new ZapXmlConfiguration(f); final String rootcastr = conf.getString(DynSSLParam.PARAM_ROOT_CA); ks = SslCertificateUtils.string2Keystore(rootcastr); } catch (final Exception e) { logger.error("Error importing Root CA cert from config file:", e); JOptionPane.showMessageDialog(this, Constant.messages.getString("dynssl.message1.filecouldntloaded"), Constant.messages.getString("dynssl.message1.title"), JOptionPane.ERROR_MESSAGE); } } if (ks != null) { setRootca(ks); } } }
From source file:org.zaproxy.zap.extension.dynssl.DynamicSSLPanel.java
/** * Saving Root CA certificate to disk./*from www .ja v a 2s . c o m*/ */ private void doSave() { if (txt_PubCert.getDocument().getLength() < MIN_CERT_LENGTH) { logger.error("Illegal state! There seems to be no certificate available."); bt_save.setEnabled(false); } final JFileChooser fc = new JFileChooser(System.getProperty("user.home")); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(false); fc.setSelectedFile(new File(OWASP_ZAP_ROOT_CA_FILENAME)); if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { final File f = fc.getSelectedFile(); if (logger.isInfoEnabled()) { logger.info("Saving Root CA certificate to " + f); } try { writePubCertificateToFile(f); } catch (final Exception e) { logger.error("Error while writing certificate data to file " + f, e); } } }
From source file:pcgen.gui2.dialog.ExportDialog.java
private void export(boolean pdf) { UIPropertyContext context = UIPropertyContext.createContext("ExportDialog"); final JFileChooser fcExport = new JFileChooser(); fcExport.setFileSelectionMode(JFileChooser.FILES_ONLY); File baseDir = null;//from www. j a v a2s . co m { String path; if (pdf) { path = context.getProperty(PDF_EXPORT_DIR_PROP); } else { path = context.getProperty(HTML_EXPORT_DIR_PROP); } if (path != null) { baseDir = new File(path); } } if (baseDir == null || !baseDir.isDirectory()) { baseDir = SystemUtils.getUserHome(); } fcExport.setCurrentDirectory(baseDir); URI uri = fileList.getSelectedValue(); String extension = ExportUtilities.getOutputExtension(uri.toString(), pdf); if (pdf) { FileFilter fileFilter = new FileNameExtensionFilter("PDF Documents (*.pdf)", "pdf"); fcExport.addChoosableFileFilter(fileFilter); fcExport.setFileFilter(fileFilter); } else if ("htm".equalsIgnoreCase(extension) || "html".equalsIgnoreCase(extension)) { FileFilter fileFilter = new FileNameExtensionFilter("HTML Documents (*.htm, *.html)", "htm", "html"); fcExport.addChoosableFileFilter(fileFilter); fcExport.setFileFilter(fileFilter); } else if ("xml".equalsIgnoreCase(extension)) { FileFilter fileFilter = new FileNameExtensionFilter("XML Documents (*.xml)", "xml"); fcExport.addChoosableFileFilter(fileFilter); fcExport.setFileFilter(fileFilter); } else { String desc = extension + " Files (*." + extension + ")"; fcExport.addChoosableFileFilter(new FileNameExtensionFilter(desc, extension)); } String name; File path; if (!partyBox.isSelected()) { CharacterFacade character = (CharacterFacade) characterBox.getSelectedItem(); path = character.getFileRef().get(); if (path != null) { path = path.getParentFile(); } else { path = new File(PCGenSettings.getPcgDir()); } name = character.getTabNameRef().get(); if (StringUtils.isEmpty(name)) { name = character.getNameRef().get(); } } else { path = new File(PCGenSettings.getPcgDir()); name = "Entire Party"; } if (pdf) { fcExport.setSelectedFile(new File(path, name + ".pdf")); } else { fcExport.setSelectedFile(new File(path, name + "." + extension)); } fcExport.setDialogTitle("Export " + name); if (fcExport.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) { return; } final File outFile = fcExport.getSelectedFile(); if (pdf) { context.setProperty(PDF_EXPORT_DIR_PROP, outFile.getParent()); } else { context.setProperty(HTML_EXPORT_DIR_PROP, outFile.getParent()); } if (StringUtils.isEmpty(outFile.getName())) { pcgenFrame.showErrorMessage("PCGen", "You must set a filename."); return; } if (outFile.isDirectory()) { pcgenFrame.showErrorMessage("PCGen", "You cannot overwrite a directory with a file."); return; } if (outFile.exists() && !SettingsHandler.getAlwaysOverwrite()) { int reallyClose = JOptionPane.showConfirmDialog(this, "The file " + outFile.getName() + " already exists, are you sure you want to overwrite it?", "Confirm overwriting " + outFile.getName(), JOptionPane.YES_NO_OPTION); if (reallyClose != JOptionPane.YES_OPTION) { return; } } if (pdf) { new PDFExporter(outFile, extension, name).execute(); } else { if (!printToFile(outFile)) { String message = "The character export failed. Please see the log for details."; pcgenFrame.showErrorMessage(Constants.APPLICATION_NAME, message); return; } maybeOpenFile(outFile); Globals.executePostExportCommandStandard(outFile.getAbsolutePath()); } }
From source file:pdfreader.PDFReader.java
public void convertToStandardHtml() { JFileChooser jfc = new JFileChooser("F:\\rajmeen\\All files together\\PDF to HTML"); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setSelectedFile(newFile(nameOfFile.substring(0, nameOfFile.length() - 4) + ".html")); jfc.showSaveDialog(PDFReader.this); File saveFile = jfc.getSelectedFile(); String outputFileName = saveFile.toString(); // String typee = JOptionPane.showInputDialog("Type","3"); // int type = Integer.parseInt(typee); // String zooom = JOptionPane.showInputDialog("Zoom","2"); // int zoom = new Float(zooom); // System.out.println(type+"<---type and zoom--->"+zoom); try {/*w w w .jav a 2 s . co m*/ // HtmFile htmlFile = new HtmFile(outputFileName, type, zoom); // StandardHtml shtml = new StandardHtml(outputFileName, 3, 2); // shtml.convertPdfToHtml(name); // shtml.closeFile(); HtmlFile htmlFile; htmlFile = new HtmlFile(outputFileName, 3, 2); htmlFile.convertPdfToHtml(name); htmlFile.endTable();//used for spanning htmlFile.getAllCell();//used for spanning htmlFile.closeFile(); } catch (Exception e) { System.err.println("Filed to convert Pdf to Html."); e.printStackTrace(); } }
From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java
private void dcm2JPEG(int thumbnailSize) { /**/*w w w. ja va 2 s .co m*/ * Why couldn't? It works! if (System.getProperty("os.name").toUpperCase().indexOf("MAC OS") != -1) { JOptionPane.showMessageDialog(this, "Operation Not Available to MAC OS.", "Missing JAI Tool", JOptionPane.WARNING_MESSAGE); return; } */ String pathDir = "."; JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(pathDir)); chooser.setDialogTitle("Dicoogle Dcm2JPG - Select DICOM File"); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); //chooser.setFileFilter(arg0) chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File filePath = new File(chooser.getSelectedFile().toString()); if (filePath.exists() && filePath.isFile() && filePath.canRead()) { File jpgFile = new File(filePath.getAbsolutePath() + ".jpg"); Dicom2JPEG.convertDicom2Jpeg(filePath, jpgFile, thumbnailSize); } } }