List of usage examples for javax.swing.filechooser FileFilter FileFilter
FileFilter
From source file:jeplus.INSELConfig.java
/** * Get a/*w w w .j a va 2 s. c o m*/ * <code>javax.swing.filechooser.FileFilter</code> * * @param type Predefined JEPlus file types * @return Swing FileFilter of the specific type */ public static FileFilter getFileFilter(final int type) { FileFilter ff = new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } String filename = f.getName(); String name = filename.split("\\s*[.]\\s*")[0] + "."; String extension = getFileExtension(f); if (extension != null) { extension = extension.toLowerCase(); switch (type) { case INSEL: return extension.equals(getInselExt()); default: return TRNSYSConfig.getFileFilter(type).accept(f); } } return false; } /** * Get description of a specific type */ @Override public String getDescription() { switch (type) { case INSEL: return "Insel text model file (*.insel)"; default: return TRNSYSConfig.getFileFilter(type).getDescription(); } } }; return ff; }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.LoadGenericDRDataController.java
/** * Private methods//w ww.j a v a2 s .c om */ //init view private void initDataLoadingPanel() { dataLoadingPanel = new DRDataLoadingPanel(); /** * Action Listeners. */ //Popup file selector and import and parse the file dataLoadingPanel.getChooseFileButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Open a JFile Chooser JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle( "Choose a tabular file (XLS, XLSX, CSV, TSV) for the import of the experiment"); // to select only appropriate files fileChooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } int index = f.getName().lastIndexOf("."); String extension = f.getName().substring(index + 1); return extension.equals("xls") || extension.equals("xlsx") || extension.equals("csv") || extension.equals("tsv"); } @Override public String getDescription() { return (".xls, .xlsx, .csv and .tsv files"); } }); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setAcceptAllFileFilterUsed(false); // in response to the button click, show open dialog int returnVal = fileChooser.showOpenDialog(dataLoadingPanel); if (returnVal == JFileChooser.APPROVE_OPTION) { File chosenFile = fileChooser.getSelectedFile(); // // create and execute a new swing worker with the selected file for the import // ImportExperimentSwingWorker importExperimentSwingWorker = new ImportExperimentSwingWorker(chosenFile); // importExperimentSwingWorker.execute(); parseDRFile(chosenFile); if (doseResponseController.getImportedDRDataHolder().getDoseResponseData() != null) { dataLoadingPanel.getFileLabel().setText(chosenFile.getAbsolutePath()); doseResponseController.getGenericDRParentPanel().getNextButton().setEnabled(true); } } else { JOptionPane.showMessageDialog(dataLoadingPanel, "Command cancelled by user", "", JOptionPane.INFORMATION_MESSAGE); } } }); dataLoadingPanel.getLogTransformCheckBox().addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { doseResponseController.setLogTransform(true); } else { doseResponseController.setLogTransform(false); } } }); }
From source file:jeplus.RadianceConfig.java
/** * Get a <code>javax.swing.filechooser.FileFilter</code> for predefined file * types.// w w w . j a va 2 s.c o m * @param type Predefined JEPlus file types * @return Swing FileFilter of the specific type */ public static FileFilter getFileFilter(final int type) { FileFilter ff = new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } String extension = getFileExtension(f); if (extension != null) { extension = extension.toLowerCase(); switch (type) { case RAD: return extension.equals(RadExt); case OCT: return extension.equals(OctreeExt); case RAY: return extension.equals(OctreeExt) || extension.equals(RadExt); default: return INSELConfig.getFileFilter(type).accept(f); } } return false; } /** * Get description of a specific type */ @Override public String getDescription() { switch (type) { case RAD: return "Radiance scene file (*.rad)"; case OCT: return "Radiance Octree file (*.oct)"; case RAY: return "Radiance files (*.rad *.oct)"; default: return INSELConfig.getFileFilter(type).getDescription(); } } }; return ff; }
From source file:org.pgptool.gui.ui.importkey.KeyImporterPm.java
public MultipleFilesChooserDialog getSourceFileChooser() { if (sourceFileChooser == null) { sourceFileChooser = new MultipleFilesChooserDialog(findRegisteredWindowIfAny(), appProps, BROWSE_FOLDER) {/*from w w w . j ava 2s . c om*/ @Override protected void doFileChooserPostConstruct(JFileChooser ofd) { super.doFileChooserPostConstruct(ofd); ofd.setDialogTitle(Messages.get("action.importKey")); ofd.setAcceptAllFileFilterUsed(false); ofd.addChoosableFileFilter(keyFilesFilter); ofd.addChoosableFileFilter(ofd.getAcceptAllFileFilter()); ofd.setFileFilter(ofd.getChoosableFileFilters()[0]); } private FileFilter keyFilesFilter = new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory() || !f.isFile()) { return true; } if (!isExtension(f.getName(), EXTENSIONS)) { return false; } // NOTE: Although it gives best results -- I have a // slight concern that this might be too heavy operation // to perform thorough -- check for each file // contents. My hope is that since we're checking only // key files it shouldn't be a problem. Non-key files // with same xtensions will not take a long time to fail try { Key readKey = keyFilesOperations.readKeyFromFile(f.getAbsolutePath()); Preconditions.checkState(readKey != null, "Key wasn't parsed"); Key existingKey = keyRingService.findKeyById(readKey.getKeyInfo().getKeyId()); if (existingKey == null) { return true; } if (!existingKey.getKeyData().isCanBeUsedForDecryption() && readKey.getKeyData().isCanBeUsedForDecryption()) { return true; } return false; } catch (Throwable t) { // in this case it's not an issue. So it's debug // level log.debug( "File is not accepte for file chooser becasue was not able to read it as a key", t); } return false; } private boolean isExtension(String fileName, String[] extensions) { String extension = FilenameUtils.getExtension(fileName); if (!StringUtils.hasText(extension)) { return false; } for (String ext : extensions) { if (ext.equalsIgnoreCase(extension)) { return true; } } return false; } @Override public String getDescription() { return "Key files (.asc, .bpg)"; } }; }; } return sourceFileChooser; }
From source file:com.floreantpos.bo.actions.DataExportAction.java
public static JFileChooser getFileChooser() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setMultiSelectionEnabled(false); fileChooser.setSelectedFile(new File("floreantpos-menu-items.xml")); //$NON-NLS-1$ fileChooser.setFileFilter(new FileFilter() { @Override/* w ww . j a va 2s .c o m*/ public String getDescription() { return "XML File"; //$NON-NLS-1$ } @Override public boolean accept(File f) { if (f.getName().endsWith(".xml")) { //$NON-NLS-1$ return true; } return false; } }); return fileChooser; }
From source file:com.intuit.tank.tools.debugger.ActionProducer.java
/** * /*from w w w . j a va 2 s.co m*/ * @param debuggerFrame * @param serviceUrl */ public ActionProducer(AgentDebuggerFrame debuggerFrame, String serviceUrl) { super(); this.debuggerFrame = debuggerFrame; this.scriptServiceClient = new ScriptServiceClient(serviceUrl); this.projectServiceClient = new ProjectServiceClientV1(serviceUrl); this.agentServiceClient = new AgentServiceClient(serviceUrl); this.dataFileClient = new DataFileClient(serviceUrl); jFileChooser = new JFileChooser(); jFileChooser.setFileFilter(new FileFilter() { @Override public String getDescription() { return "Agent XML Files"; } @Override public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase().endsWith("_h.xml"); } }); }
From source file:es.emergya.ui.gis.popups.ListaCapas.java
private JButton getCargarGPXButton() { JButton cargar = new JButton(i18n.getString("window.gpx.button.load"), LogicConstants.getIcon("historico_button_cargargpx")); cargar.addActionListener(new ActionListener() { @Override/*from ww w. ja v a2 s . c om*/ public void actionPerformed(ActionEvent e) { fileChooser = new JFileChooser(); fileChooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } return (f.getName().toLowerCase().endsWith(".gpx")); } @Override public String getDescription() { return i18n.getString("window.gpx.filechooser.filter"); } }); try { if (fileChooser.showOpenDialog(self) == JFileChooser.APPROVE_OPTION) { cargarGpx(fileChooser.getSelectedFile()); } } catch (Throwable t) { log.error("Error al cargar GPX " + t); JOptionPane.showMessageDialog(getBasicWindow().getFrame(), i18n.getString("window.gpx.loadError")); } } }); return cargar; }
From source file:com.intuit.tank.tools.script.ScriptFilterRunner.java
/** * @return//from w w w.j ava 2 s . com */ private Component createTopPanel() { JPanel topPanel = new JPanel(new GridBagLayout()); List<ConfiguredLanguage> configuredLanguages = ConfiguredLanguage.getConfiguredLanguages(); languageSelector = new JComboBox(configuredLanguages.toArray()); languageSelector.setSelectedIndex(0); languageSelector.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { setSyntaxStyle(); } }); currentFileLabel = new JLabel(); final JFileChooser jFileChooser = new JFileChooser(); jFileChooser.setFileFilter(new FileFilter() { @Override public String getDescription() { return "Tank XML Files"; } @Override public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase().endsWith("_ts.xml"); } }); JButton button = new JButton("Select File..."); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int showOpenDialog = jFileChooser.showOpenDialog(ScriptFilterRunner.this); if (showOpenDialog == JFileChooser.APPROVE_OPTION) { loadTSXml(jFileChooser.getSelectedFile()); } } }); xmlViewDialog = new XMlViewDialog(this); xmlViewDialog.setSize(new Dimension(800, 500)); showXmlBT = new JButton("Show XML"); showXmlBT.setEnabled(false); showXmlBT.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { displayXml(); } }); saveBT = new JButton("Save XML"); saveBT.setEnabled(false); saveBT.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveXml(); } }); JPanel xmlPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 10, 20)); xmlPanel.add(button); xmlPanel.add(showXmlBT); xmlPanel.add(saveBT); int y = 0; topPanel.add(new JLabel("Current Tank XML: "), getConstraints(0, y, GridBagConstraints.NONE)); topPanel.add(currentFileLabel, getConstraints(1, y++, GridBagConstraints.HORIZONTAL)); topPanel.add(new JLabel("Select Script Language: "), getConstraints(0, y, GridBagConstraints.NONE)); topPanel.add(languageSelector, getConstraints(1, y++, GridBagConstraints.HORIZONTAL)); topPanel.add(new JLabel("Select Tank XML: "), getConstraints(0, y, GridBagConstraints.NONE)); topPanel.add(xmlPanel, getConstraints(1, y++, GridBagConstraints.HORIZONTAL)); return topPanel; }
From source file:au.org.ala.delta.intkey.ui.UIUtils.java
/** * Prompts for a file using the file chooser dialog * /*from w w w . j a v a 2s .c o m*/ * @param fileExtensions * Accepted file extensions - must be null if filePrefixes is * non-null * @param filePrefixes * Accepted file prefixes - must be null if fileExtensions is * non-null * @param description * Description of the acceptable files * @param createFileIfNonExistant * if true, the file will be created if it does not exist. Also, * the system's "save" will be used instead of the "open" dialog. * @param startBrowseDirectory * The directory that the file chooser should start in * @param parent * parent component for the file chooser * @return the selected file, or null if no file was selected. * @throws IOException */ public static File promptForFile(List<String> fileExtensions, List<String> filePrefixes, final String description, boolean createFileIfNonExistant, File startBrowseDirectory, Component parent) throws IOException { if (fileExtensions != null && filePrefixes != null) { throw new IllegalArgumentException( "Only one of the file extensions or file prefixes should be non-null"); } JFileChooser chooser = new JFileChooser(startBrowseDirectory); FileFilter filter; if (fileExtensions != null) { String[] extensionsArray = new String[fileExtensions.size()]; fileExtensions.toArray(extensionsArray); filter = new FileNameExtensionFilter(description, extensionsArray); } else { final String[] prefixesArray = new String[filePrefixes.size()]; filePrefixes.toArray(prefixesArray); filter = new FileFilter() { @Override public String getDescription() { return description; } @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } else { return StringUtils.startsWithAny(f.getName(), prefixesArray); } } }; } chooser.setFileFilter(filter); int returnVal; if (createFileIfNonExistant) { returnVal = chooser.showSaveDialog(parent); } else { returnVal = chooser.showOpenDialog(parent); } if (returnVal == JFileChooser.APPROVE_OPTION) { if (createFileIfNonExistant) { File file = chooser.getSelectedFile(); if (!file.exists()) { // if only one file extension was supplied and the filename // does // not end with this extension, add it before // creating the file if (fileExtensions.size() == 1) { String extension = fileExtensions.get(0); String filePath = chooser.getSelectedFile().getAbsolutePath(); if (!filePath.endsWith(extension)) { file = new File(filePath + "." + extension); } } file.createNewFile(); } return file; } else { return chooser.getSelectedFile(); } } else { return null; } }
From source file:org.jfree.chart.demo.SuperDemo.java
private void exportToPDF() { java.awt.Component component = chartContainer.getComponent(0); if (component instanceof ChartPanel) { JFileChooser jfilechooser = new JFileChooser(); jfilechooser.setName("untitled.pdf"); jfilechooser.setFileFilter(new FileFilter() { public boolean accept(File file) { return file.isDirectory() || file.getName().endsWith(".pdf"); }/* w w w . jav a2s. c o m*/ public String getDescription() { return "Portable Document Format (PDF)"; } }); int i = jfilechooser.showSaveDialog(this); if (i == 0) { ChartPanel chartpanel = (ChartPanel) component; try { JFreeChart jfreechart = (JFreeChart) chartpanel.getChart().clone(); PDFExportTask pdfexporttask = new PDFExportTask(jfreechart, chartpanel.getWidth(), chartpanel.getHeight(), jfilechooser.getSelectedFile()); Thread thread = new Thread(pdfexporttask); thread.start(); } catch (CloneNotSupportedException clonenotsupportedexception) { clonenotsupportedexception.printStackTrace(); } } } else { String s = "Unable to export the selected item. There is "; s = s + "either no chart selected,\nor else the chart is not "; s = s + "at the expected location in the component hierarchy\n"; s = s + "(future versions of the demo may include code to "; s = s + "handle these special cases)."; JOptionPane.showMessageDialog(this, s, "PDF Export", 1); } }