List of usage examples for javax.swing JFileChooser addChoosableFileFilter
@BeanProperty(preferred = true, description = "Adds a filter to the list of user choosable file filters.") public void addChoosableFileFilter(FileFilter filter)
From source file:analysers.ExportValidated.java
@Override public void analyze(Cell currentCell) { JFileChooser fc = new JFileChooser(); fc.addChoosableFileFilter(new FileNameExtensionFilter("Comma Separated Values", "csv")); fc.addChoosableFileFilter(new FileNameExtensionFilter("JSON file", "json")); int rv = fc.showSaveDialog(null); if (rv == JFileChooser.APPROVE_OPTION) { int b = Prefs.getInt(".TrackApp.FilterValidatedDialog.exportMean", 1); if (b != 0) { IJ.log("Exporting mean intensity values."); } else {//from ww w .jav a 2 s . co m IJ.log("Exporting sum of intensity values."); } File ff = fc.getSelectedFile(); String fn = fc.getSelectedFile().getAbsolutePath(); if (fc.getFileFilter().getDescription().contains("JSON")) { if (!fn.toLowerCase().endsWith(".json")) { fn = fn + ".json"; ff = new File(ff + ".json"); } IJ.log("Writing a JSON file."); } else { if (!fn.toLowerCase().endsWith(".csv")) { fn = fn + ".csv"; ff = new File(ff + ".csv"); } IJ.log("Writing a CSV file."); } IJ.log("Writing to " + fn); if (fn.endsWith(".csv")) { writeCSV(ff); } else if (fn.endsWith(".json")) { writeJSON(ff); } else { IJ.log("Unknown output format for file name " + fn); } } }
From source file:com.litt.core.security.license.gui.ValidatePanel.java
/** * Create the panel.//from w w w.jav a 2s . c om */ public ValidatePanel() { GridBagLayout gbl_validatePanel = new GridBagLayout(); gbl_validatePanel.columnWidths = new int[] { 0, 0, 0 }; gbl_validatePanel.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; gbl_validatePanel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE }; gbl_validatePanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; this.setLayout(gbl_validatePanel); JLabel label_10 = new JLabel(""); GridBagConstraints gbc_label_10 = new GridBagConstraints(); gbc_label_10.insets = new Insets(0, 0, 5, 5); gbc_label_10.anchor = GridBagConstraints.EAST; gbc_label_10.gridx = 0; gbc_label_10.gridy = 0; this.add(label_10, gbc_label_10); field_pubKeyFilePath = new JTextField(); field_pubKeyFilePath.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { JFileChooser fileChooser = new JFileChooser(); //fileChooser.setVisible(true); LicenseFileFilter fileFilter = new LicenseFileFilter(new String[] { "key" }); fileChooser.setFileFilter(fileFilter); fileChooser.addChoosableFileFilter(fileFilter); fileChooser.showOpenDialog(e.getComponent()); File pubKeyFile = fileChooser.getSelectedFile(); field_pubKeyFilePath.setText(pubKeyFile.getAbsolutePath()); } }); GridBagConstraints gbc_field_pubKeyFilePath = new GridBagConstraints(); gbc_field_pubKeyFilePath.insets = new Insets(0, 0, 5, 0); gbc_field_pubKeyFilePath.fill = GridBagConstraints.HORIZONTAL; gbc_field_pubKeyFilePath.gridx = 1; gbc_field_pubKeyFilePath.gridy = 0; this.add(field_pubKeyFilePath, gbc_field_pubKeyFilePath); field_pubKeyFilePath.setColumns(10); JLabel label_19 = new JLabel("?"); GridBagConstraints gbc_label_19 = new GridBagConstraints(); gbc_label_19.anchor = GridBagConstraints.EAST; gbc_label_19.insets = new Insets(0, 0, 5, 5); gbc_label_19.gridx = 0; gbc_label_19.gridy = 1; this.add(label_19, gbc_label_19); field_licenseFilePath = new JTextField(); field_licenseFilePath.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { JFileChooser fileChooser = new JFileChooser(); //fileChooser.setVisible(true); LicenseFileFilter fileFilter = new LicenseFileFilter(new String[] { "xml" }); fileChooser.setFileFilter(fileFilter); fileChooser.addChoosableFileFilter(fileFilter); fileChooser.showOpenDialog(e.getComponent()); File licenseFile = fileChooser.getSelectedFile(); field_licenseFilePath.setText(licenseFile.getAbsolutePath()); } }); GridBagConstraints gbc_textField1 = new GridBagConstraints(); gbc_textField1.insets = new Insets(0, 0, 5, 0); gbc_textField1.fill = GridBagConstraints.HORIZONTAL; gbc_textField1.gridx = 1; gbc_textField1.gridy = 1; this.add(field_licenseFilePath, gbc_textField1); field_licenseFilePath.setColumns(10); JLabel lblid = new JLabel("?ID"); lblid.setHorizontalAlignment(SwingConstants.CENTER); GridBagConstraints gbc_lblid = new GridBagConstraints(); gbc_lblid.insets = new Insets(0, 0, 5, 5); gbc_lblid.gridx = 0; gbc_lblid.gridy = 2; this.add(lblid, gbc_lblid); label_licenseId = new JLabel(""); label_licenseId.setHorizontalAlignment(SwingConstants.CENTER); GridBagConstraints gbc_label_licenseId = new GridBagConstraints(); gbc_label_licenseId.insets = new Insets(0, 0, 5, 0); gbc_label_licenseId.gridx = 1; gbc_label_licenseId.gridy = 2; this.add(label_licenseId, gbc_label_licenseId); JLabel label_12 = new JLabel("?"); GridBagConstraints gbc_label_12 = new GridBagConstraints(); gbc_label_12.insets = new Insets(0, 0, 5, 5); gbc_label_12.gridx = 0; gbc_label_12.gridy = 3; this.add(label_12, gbc_label_12); label_licenseType = new JLabel(""); GridBagConstraints gbc_label_licenseType = new GridBagConstraints(); gbc_label_licenseType.insets = new Insets(0, 0, 5, 0); gbc_label_licenseType.gridx = 1; gbc_label_licenseType.gridy = 3; this.add(label_licenseType, gbc_label_licenseType); JLabel label_13 = new JLabel("???"); GridBagConstraints gbc_label_13 = new GridBagConstraints(); gbc_label_13.insets = new Insets(0, 0, 5, 5); gbc_label_13.gridx = 0; gbc_label_13.gridy = 4; this.add(label_13, gbc_label_13); label_productName = new JLabel(""); GridBagConstraints gbc_label_productName = new GridBagConstraints(); gbc_label_productName.insets = new Insets(0, 0, 5, 0); gbc_label_productName.gridx = 1; gbc_label_productName.gridy = 4; this.add(label_productName, gbc_label_productName); JLabel label_14 = new JLabel("???"); GridBagConstraints gbc_label_14 = new GridBagConstraints(); gbc_label_14.insets = new Insets(0, 0, 5, 5); gbc_label_14.gridx = 0; gbc_label_14.gridy = 5; this.add(label_14, gbc_label_14); label_companyName = new JLabel(""); GridBagConstraints gbc_label_companyName = new GridBagConstraints(); gbc_label_companyName.insets = new Insets(0, 0, 5, 0); gbc_label_companyName.gridx = 1; gbc_label_companyName.gridy = 5; this.add(label_companyName, gbc_label_companyName); JLabel label_15 = new JLabel("??"); GridBagConstraints gbc_label_15 = new GridBagConstraints(); gbc_label_15.insets = new Insets(0, 0, 5, 5); gbc_label_15.gridx = 0; gbc_label_15.gridy = 6; this.add(label_15, gbc_label_15); label_customerName = new JLabel(""); GridBagConstraints gbc_label_customerName = new GridBagConstraints(); gbc_label_customerName.insets = new Insets(0, 0, 5, 0); gbc_label_customerName.gridx = 1; gbc_label_customerName.gridy = 6; this.add(label_customerName, gbc_label_customerName); JLabel label_16 = new JLabel(""); GridBagConstraints gbc_label_16 = new GridBagConstraints(); gbc_label_16.insets = new Insets(0, 0, 5, 5); gbc_label_16.gridx = 0; gbc_label_16.gridy = 7; this.add(label_16, gbc_label_16); label_version = new JLabel(""); GridBagConstraints gbc_label_version = new GridBagConstraints(); gbc_label_version.insets = new Insets(0, 0, 5, 0); gbc_label_version.gridx = 1; gbc_label_version.gridy = 7; this.add(label_version, gbc_label_version); JLabel label_11 = new JLabel(""); GridBagConstraints gbc_label_11 = new GridBagConstraints(); gbc_label_11.insets = new Insets(0, 0, 5, 5); gbc_label_11.gridx = 0; gbc_label_11.gridy = 8; this.add(label_11, gbc_label_11); label_createDate = new JLabel(""); GridBagConstraints gbc_label_createDate = new GridBagConstraints(); gbc_label_createDate.insets = new Insets(0, 0, 5, 0); gbc_label_createDate.gridx = 1; gbc_label_createDate.gridy = 8; this.add(label_createDate, gbc_label_createDate); JLabel label_17 = new JLabel(""); GridBagConstraints gbc_label_17 = new GridBagConstraints(); gbc_label_17.insets = new Insets(0, 0, 5, 5); gbc_label_17.gridx = 0; gbc_label_17.gridy = 9; this.add(label_17, gbc_label_17); label_expiredDate = new JLabel(""); GridBagConstraints gbc_label_expiredDate = new GridBagConstraints(); gbc_label_expiredDate.insets = new Insets(0, 0, 5, 0); gbc_label_expiredDate.gridx = 1; gbc_label_expiredDate.gridy = 9; this.add(label_expiredDate, gbc_label_expiredDate); JButton button_2 = new JButton(""); button_2.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { String licenseFilePath = Utility.trimNull(field_licenseFilePath.getText()); String pubKeyFilePath = Utility.trimNull(field_pubKeyFilePath.getText()); if (Utility.isEmpty(licenseFilePath)) { JOptionPane.showMessageDialog(e.getComponent(), "?!"); return; } if (Utility.isEmpty(pubKeyFilePath)) { JOptionPane.showMessageDialog(e.getComponent(), "!"); return; } File licenseFile = new File(licenseFilePath); try { XMLConfiguration config = new XMLConfiguration(licenseFile); config.setAutoSave(true); label_licenseId.setText(config.getString(("licenseId"))); label_licenseType.setText(config.getString("licenseType")); label_productName.setText(config.getString("productName")); label_companyName.setText(config.getString("companyName")); label_customerName.setText(config.getString("customerName")); label_version.setText(config.getString("version")); label_createDate.setText(config.getString("createDate")); label_expiredDate.setText(config.getString("expiredDate")); } catch (Exception e1) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(e.getComponent(), e1.getMessage()); } try { LicenseManager.validateLicense(licenseFile.getAbsolutePath(), pubKeyFilePath); JOptionPane.showMessageDialog(e.getComponent(), "?"); } catch (LicenseException e1) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(e.getComponent(), e1.getMessage()); } } }); GridBagConstraints gbc_button_2 = new GridBagConstraints(); gbc_button_2.gridx = 1; gbc_button_2.gridy = 10; this.add(button_2, gbc_button_2); }
From source file:org.martus.client.swingui.FxInSwingMainWindow.java
private JFileChooser createFileChooser(String title, File directory, Vector<FormatFilter> filters) { JFileChooser fileChooser = new JFileChooser(directory); fileChooser.setDialogTitle(title);//from w ww. j a va2s .c o m filters.forEach(filter -> fileChooser.addChoosableFileFilter(filter)); // NOTE: Apparently the all file filter has a Mac bug, so this is a workaround fileChooser.setAcceptAllFileFilterUsed(false); return fileChooser; }
From source file:com.att.aro.ui.model.diagnostic.GraphPanelHelper.java
public void SaveImageAs(JViewport pane, String graphPanelSaveDirectory) { JFileChooser fc = new JFileChooser(graphPanelSaveDirectory); // Set up file types String[] fileTypesJPG = new String[2]; String fileDisplayTypeJPG = ResourceBundleHelper.getMessageString("fileChooser.contentDisplayType.jpeg"); fileTypesJPG[0] = ResourceBundleHelper.getMessageString("fileChooser.contentType.jpeg"); fileTypesJPG[1] = ResourceBundleHelper.getMessageString("fileChooser.contentType.jpg"); FileFilter filterJPG = new ExtensionFileFilter(fileDisplayTypeJPG, fileTypesJPG); fc.addChoosableFileFilter(fc.getAcceptAllFileFilter()); String[] fileTypesPng = new String[1]; String fileDisplayTypePng = ResourceBundleHelper.getMessageString("fileChooser.contentDisplayType.png"); fileTypesPng[0] = ResourceBundleHelper.getMessageString("fileChooser.contentType.png"); FileFilter filterPng = new ExtensionFileFilter(fileDisplayTypePng, fileTypesPng); fc.addChoosableFileFilter(filterPng); fc.setFileFilter(filterJPG);//from w w w . ja v a2s . c o m File plotImageFile = null; boolean bSavedOrCancelled = false; while (!bSavedOrCancelled) { if (fc.showSaveDialog(pane) == JFileChooser.APPROVE_OPTION) { String strFile = fc.getSelectedFile().toString(); String strFileLowerCase = strFile.toLowerCase(); String fileDesc = fc.getFileFilter().getDescription(); String fileType = ResourceBundleHelper.getMessageString("fileChooser.contentType.jpg"); if ((fileDesc.equalsIgnoreCase( ResourceBundleHelper.getMessageString("fileChooser.contentDisplayType.png")) || strFileLowerCase.endsWith(ResourceBundleHelper.getMessageString("fileType.filters.dot") + fileTypesPng[0].toLowerCase()))) { fileType = fileTypesPng[0]; } if (strFile.length() > 0) { // Save current directory graphPanelSaveDirectory = fc.getCurrentDirectory().getPath(); if ((fileType != null) && (fileType.length() > 0)) { String fileTypeLowerCaseWithDot = ResourceBundleHelper .getMessageString("fileType.filters.dot") + fileType.toLowerCase(); if (!strFileLowerCase.endsWith(fileTypeLowerCaseWithDot)) { strFile += ResourceBundleHelper.getMessageString("fileType.filters.dot") + fileType; } } plotImageFile = new File(strFile); boolean bAttemptToWriteToFile = true; if (plotImageFile.exists()) { if (MessageDialogFactory.showConfirmDialog(pane, MessageFormat.format( ResourceBundleHelper.getMessageString("fileChooser.fileExists"), plotImageFile.getAbsolutePath()), ResourceBundleHelper.getMessageString("fileChooser.confirm"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) { bAttemptToWriteToFile = false; } } if (bAttemptToWriteToFile) { try { if (fileType != null && fileType.equalsIgnoreCase(fileTypesPng[0])) { BufferedImage bufImage = ImageHelper.createImage(pane.getBounds().width, pane.getBounds().height); Graphics2D g = bufImage.createGraphics(); pane.paint(g); ImageIO.write(bufImage, "png", plotImageFile); } else { BufferedImage bufImage = ImageHelper.createImage(pane.getBounds().width, pane.getBounds().height); Graphics2D g = bufImage.createGraphics(); pane.paint(g); ImageIO.write(bufImage, "jpg", plotImageFile); } bSavedOrCancelled = true; } catch (IOException e) { MessageDialogFactory.showMessageDialog(pane, ResourceBundleHelper .getMessageString("fileChooser.errorWritingToFile" + plotImageFile.toString())); } } } } else { bSavedOrCancelled = true; } } }
From source file:frames.MainGUI.java
private File getSelectedFile() { // get file path FileFilter filter = new FileNameExtensionFilter("soccer data files", "csv"); JFileChooser chooser = new JFileChooser(System.getProperty("user.dir")); chooser.addChoosableFileFilter(filter); int returnVal = chooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile(); } else//from ww w . j av a2s . c o m return null; }
From source file:SciTK.Plot.java
/** * Save data for generic plot to file /*from w ww . jav a 2s. c om*/ */ public void saveData() { JFileChooser fc = new JFileChooser(); fc.addChoosableFileFilter(new ExtensionFileFilter("CSV", new String[] { "csv,CSV" })); // remove default option: fc.setAcceptAllFileFilterUsed(false); // Select a file using the JFileChooser dialog: int fc_return = fc.showSaveDialog(this); if (fc_return == JFileChooser.APPROVE_OPTION) // user wants to save { //get the file name from the filter: File save_file = fc.getSelectedFile(); // check to see if the user entered an extension: if (!save_file.getName().endsWith(".csv") && !save_file.getName().endsWith(".CSV")) { save_file = new File(save_file.getAbsolutePath() + ".csv"); } // create a string to save String s = toString(); // IO inside a try/catch try { // Create a File Writer FileWriter fw = new FileWriter(save_file); fw.write(s); fw.close(); } // If there was an error, launch an error dialog box: catch (IOException e) { DialogError emsg = new DialogError(this, " There was an error saving the file." + System.getProperty("line.separator") + e.getMessage()); } } }
From source file:org.pgptool.gui.ui.encryptone.EncryptOnePm.java
public ExistingFileChooserDialog getSourceFileChooser() { if (sourceFileChooser == null) { sourceFileChooser = new ExistingFileChooserDialog(findRegisteredWindowIfAny(), appProps, SOURCE_FOLDER) {/*w ww .j av a2s. c o m*/ @Override protected void doFileChooserPostConstruct(JFileChooser ofd) { super.doFileChooserPostConstruct(ofd); ofd.setDialogTitle(Messages.get("phrase.selectFileToEncrypt")); ofd.setAcceptAllFileFilterUsed(false); ofd.addChoosableFileFilter(notEncryptedFiles); ofd.addChoosableFileFilter(ofd.getAcceptAllFileFilter()); ofd.setFileFilter(ofd.getChoosableFileFilters()[0]); } private FileFilter notEncryptedFiles = new FileFilter() { @Override public boolean accept(File f) { return !DecryptOnePm.isItLooksLikeYourSourceFile(f.getAbsolutePath()); } @Override public String getDescription() { return text("phrase.allExceptEncrypted"); } }; }; } return sourceFileChooser; }
From source file:SciTK.Plot.java
/** * Save displayed chart as vector graphics *///from w w w. j a v a2 s. com public void saveVectorGraphics() { Rectangle r = chart_panel.getBounds(); // get size of chart // file selection: JFileChooser fc = new JFileChooser(); fc.addChoosableFileFilter(new ExtensionFileFilter("SVG", new String[] { "svg,SVG" })); fc.addChoosableFileFilter(new ExtensionFileFilter("PS", new String[] { "ps,PS" })); fc.addChoosableFileFilter(new ExtensionFileFilter("EPS", new String[] { "eps,EPS" })); // remove default option: fc.setAcceptAllFileFilterUsed(false); // Select a file using the JFileChooser dialog: int fc_return = fc.showSaveDialog(Plot.this); // if the user actually wants to save: if (fc_return == JFileChooser.APPROVE_OPTION) { //get the file: File save_file = fc.getSelectedFile(); // and the type of extension (from file chooser) String extension = fc.getFileFilter().getDescription(); try // try/catch for IO errors { // For each type of extension, check to see if the name includes the // correct extension and then save the image to file. // Default extension is EPS if (extension == "SVG") { // sanity check extension: if (!save_file.getName().endsWith(".svg") && !save_file.getName().endsWith(".SVG")) save_file = new File(save_file.getAbsolutePath() + ".svg"); exportChartAsSVG(chart, r, save_file); } else if (extension == "PS") { // sanity check extension: if (!save_file.getName().endsWith(".ps") && !save_file.getName().endsWith(".PS")) save_file = new File(save_file.getAbsolutePath() + ".ps"); exportChartAsPS(chart, r, save_file, "ps"); } else { // sanity check extension: if (!save_file.getName().endsWith(".eps") && !save_file.getName().endsWith(".EPS")) save_file = new File(save_file.getAbsolutePath() + ".eps"); exportChartAsPS(chart, r, save_file, "eps"); } } catch (IOException e) { DialogError emsg = new DialogError(this, " There was an error saving the file." + System.getProperty("line.separator") + e.getMessage()); } } }
From source file:pl.dpbz.poid.zadanie3.GUI.java
private String readSoundFile() { final JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(false); FileNameExtensionFilter filter = new FileNameExtensionFilter("WAV sounds", "wav"); fc.addChoosableFileFilter(filter); int returnVal = fc.showOpenDialog(this); String path = fc.getSelectedFile().getAbsolutePath(); System.out.println("path: " + path); return path;// w ww .j a va 2s .c o m }
From source file:org.pgptool.gui.ui.decryptone.DecryptOnePm.java
public ExistingFileChooserDialog getSourceFileChooser() { if (sourceFileChooser == null) { sourceFileChooser = new ExistingFileChooserDialog(findRegisteredWindowIfAny(), appProps, SOURCE_FOLDER) {//from w w w.java 2 s .c om @Override protected void doFileChooserPostConstruct(JFileChooser ofd) { super.doFileChooserPostConstruct(ofd); ofd.setAcceptAllFileFilterUsed(false); ofd.addChoosableFileFilter( new FileNameExtensionFilter("Encrypted files (.gpg, .pgp, .asc)", EXTENSIONS)); ofd.addChoosableFileFilter(ofd.getAcceptAllFileFilter()); ofd.setFileFilter(ofd.getChoosableFileFilters()[0]); ofd.setDialogTitle(text("phrase.selectFileToDecrypt")); } @Override protected String handleFileWasChosen(String filePathName) { if (filePathName == null) { return null; } sourceFile.setValueByOwner(filePathName); return filePathName; } }; } return sourceFileChooser; }