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:oct.analysis.application.OCTAnalysisUI.java
private void saveAnalysisMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAnalysisMenuItemActionPerformed //allow the user to choose where to save the analysis file fc.resetChoosableFileFilters();//from w w w.j a va2 s.c o m fc.setFileFilter(new FileNameExtensionFilter("ORA analysis file", "ora")); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setSelectedFile(new File("analysis.ora")); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File saveFile = fc.getSelectedFile(); AnalysisSaver.saveAnalysis(saveFile); } }
From source file:oct.analysis.application.OCTAnalysisUI.java
private void openAnalysisMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openAnalysisMenuItemActionPerformed //allow the user to choose where the saved analysis file is fc.resetChoosableFileFilters();/*from w ww .j a v a 2 s. co m*/ fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setFileFilter(new FileNameExtensionFilter("ORA analysis file", "ora")); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File saveFile = fc.getSelectedFile(); try { AnalysisSaveState readAnalysis = AnalysisSaver.readAnalysis(saveFile); Util.openSavedAnalysis(this, readAnalysis); //enable save saveAnalysisMenuItem.setEnabled(true); exportAnalysisResultsMenuItem.setEnabled(true); } catch (IOException ex) { Logger.getLogger(OCTAnalysisUI.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:mondrian.gui.Workbench.java
private void openMenuItemActionPerformed(ActionEvent evt) { JFileChooser jfc = new JFileChooser(); try {//from w ww. j ava2 s . c o m jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setFileFilter(new javax.swing.filechooser.FileFilter() { public boolean accept(File pathname) { return pathname.getName().toLowerCase().endsWith(".xml") || pathname.isDirectory(); } public String getDescription() { return getResourceConverter().getString("workbench.open.schema.file.type", "Mondrian Schema files (*.xml)"); } }); String lastUsed = getWorkbenchProperty(LAST_USED1_URL); if (lastUsed != null) { jfc.setCurrentDirectory(new File(new URI(lastUsed))); } } catch (Exception ex) { LOGGER.error("Could not set file chooser", ex); } MondrianProperties.instance(); if (jfc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { try { setLastUsed(jfc.getSelectedFile().getName(), jfc.getSelectedFile().toURI().toURL().toString()); } catch (MalformedURLException e) { LOGGER.error(e); } openSchemaFrame(jfc.getSelectedFile(), false); } }
From source file:com.pianobakery.complsa.MainGui.java
public void importSearchFile() { searchDocValue.setText("loading..."); try {/* w ww . j av a 2 s . c o m*/ File selected; searchFileString = ""; JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(System.getProperty("user.home"))); chooser.setDialogTitle("Choose Search File"); chooser.setFileHidingEnabled(Boolean.TRUE); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setAcceptAllFileFilterUsed(false); int whatChoose = chooser.showOpenDialog(null); if (whatChoose == JFileChooser.APPROVE_OPTION) { selected = chooser.getSelectedFile(); logger.debug("AddCorpDir is: " + selected.toString()); logger.debug("getCurrentDirectory(): " + chooser.getCurrentDirectory()); logger.debug("getSelectedFile() : " + chooser.getSelectedFile()); enableUIElements(true); if (selected.exists()) { Parser parser = new Parser(selected); try { parser.parseDocToPlainText(); searchFileString = Utilities.removeQuoteFromString(parser.getPlainText()); logger.debug("The Search File: " + searchFileString); searchDocValue .setText(selected.getParentFile().getName() + File.separator + selected.getName()); } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (TikaException e) { e.printStackTrace(); } } } } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Falsche Eingabe"); } }
From source file:edu.ku.brc.specify.tasks.WorkbenchTask.java
/** * Creates a new WorkBench from the Column Headers and the Data in a file. * @return the new Workbench// w ww .ja v a 2s. com */ protected Workbench createNewWorkbenchFromFile() { // For ease of testing File file = null; // FileDialog fileDialog = new FileDialog(/*(Frame)UIRegistry.get(UIRegistry.FRAME),*/ // (Frame )UIRegistry.getTopWindow(), // getResourceString("CHOOSE_WORKBENCH_IMPORT_FILE"), // FileDialog.LOAD); // fileDialog.setDirectory(getDefaultDirPath(IMPORT_FILE_PATH)); // fileDialog.setFilenameFilter(new java.io.FilenameFilter() // { // public boolean accept(File dir, String filename) // { // for (ExportFileConfigurationFactory.ExportableType exportType : ExportFileConfigurationFactory.getExportList()) // { // String ext = FilenameUtils.getExtension(filename); // if (StringUtils.isNotEmpty(ext) && exportType.getExtension().toLowerCase().equals(ext)) // { // return true; // } // } // return false; // } // // }); // UIHelper.centerAndShow(fileDialog); // fileDialog.dispose(); JFileChooser chooser = new JFileChooser(getDefaultDirPath(IMPORT_FILE_PATH)); chooser.setDialogTitle(getResourceString("CHOOSE_WORKBENCH_IMPORT_FILE")); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); String[] exts = { "xls", "csv" }; chooser.setFileFilter(new UIFileFilter(exts, getResourceString("WB_EXCELANDCSVFILES"))); String currDirPath = AppPreferences.getLocalPrefs().get(IMPORT_FILE_PATH, null); if (currDirPath != null) { File currDir = new File(currDirPath); if (currDir.isDirectory() && currDir.exists()) { chooser.setCurrentDirectory(currDir); } } if (chooser.showOpenDialog(UIRegistry.get(UIRegistry.FRAME)) != JFileChooser.APPROVE_OPTION) { UIRegistry.getStatusBar().setText(""); return null; } // String fileName = fileDialog.getFile(); // String path = fileDialog.getDirectory(); // if (StringUtils.isNotEmpty(path)) // { // AppPreferences localPrefs = AppPreferences.getLocalPrefs(); // localPrefs.put(IMPORT_FILE_PATH, path); // } // // if (StringUtils.isNotEmpty(fileName) && StringUtils.isNotEmpty(path)) // { // file = new File(path + File.separator + fileName); // } else // { // return null; // } file = chooser.getSelectedFile(); if (file.exists()) { if (StringUtils.isNotEmpty(file.getPath())) { AppPreferences localPrefs = AppPreferences.getLocalPrefs(); localPrefs.put(IMPORT_FILE_PATH, file.getParent()); } ImportDataFileInfo dataFileInfo = new ImportDataFileInfo(); if (dataFileInfo.load(file)) { Workbench workbench = createNewWorkbench(dataFileInfo, file); // This means correct usage count for ImportXLS will actually be getUsageCount(ImportXLS) - getUsageCount(ImportCSV)... //if (dataFileInfo.getConfig().getProperties().getProperty("mimetype","").equals(ExportFileConfigurationFactory.CSV_MIME_TYPE)) //{ // UsageTracker.incrUsageCount("WB.ImportCSV"); //} return workbench; } else if (dataFileInfo.getConfig() == null || dataFileInfo.getConfig().getStatus() != ConfigureExternalDataIFace.Status.Cancel) { JStatusBar statusBar = UIRegistry.getStatusBar(); statusBar.setErrorMessage( String.format(getResourceString("WB_PARSE_FILE_ERROR"), new Object[] { file.getName() })); } } return null; }
From source file:org.jets3t.apps.uploader.Uploader.java
/** * Handles GUI actions.//w w w . jav a 2 s . co m */ public void actionPerformed(ActionEvent actionEvent) { if ("Next".equals(actionEvent.getActionCommand())) { wizardStepForward(); } else if ("Back".equals(actionEvent.getActionCommand())) { wizardStepBackward(); } else if ("ChooseFile".equals(actionEvent.getActionCommand())) { JFileChooser fileChooser = new JFileChooser(); if (validFileExtensions.size() > 0) { UploaderFileExtensionFilter filter = new UploaderFileExtensionFilter("Allowed files", validFileExtensions); fileChooser.setFileFilter(filter); } fileChooser.setMultiSelectionEnabled(fileMaxCount > 1); fileChooser.setDialogTitle("Choose file" + (fileMaxCount > 1 ? "s" : "") + " to upload"); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setApproveButtonText("Choose file" + (fileMaxCount > 1 ? "s" : "")); int returnVal = fileChooser.showOpenDialog(ownerFrame); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } List fileList = new ArrayList(); if (fileChooser.getSelectedFiles().length > 0) { fileList.addAll(Arrays.asList(fileChooser.getSelectedFiles())); } else { fileList.add(fileChooser.getSelectedFile()); } if (checkProposedUploadFiles(fileList)) { wizardStepForward(); } } else if ("CancelUpload".equals(actionEvent.getActionCommand())) { if (uploadCancelEventTrigger != null) { uploadCancelEventTrigger.cancelTask(this); progressBar.setValue(0); } else { log.warn("Ignoring attempt to cancel file upload when cancel trigger is not available"); } } else { log.warn("Unrecognised action command, ignoring: " + actionEvent.getActionCommand()); } }
From source file:neembuu.uploader.NeembuuUploader.java
private void selectFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectFileButtonActionPerformed f.setMultiSelectionEnabled(true);//from w w w. j av a2 s . c om f.setFileSelectionMode(JFileChooser.FILES_ONLY); f.setAcceptAllFileFilterUsed(true); //Open up the Open File dialog //If the user clicks cancel or close, do not continue. if (f.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) { return; } //getSelectedFiles() returns as File array. //We need ArrayList for efficiency. So convert array to ArrayList this.files = new ArrayList<File>(Arrays.asList(f.getSelectedFiles())); //Same stuff as in FileDrop code in constructor if (files.size() == 1) { inputFileTextField.setText(files.get(0) + ""); } else { inputFileTextField.setText(files.size() + " " + Translation.T().nfilesselected()); } NULogger.getLogger().info("Files selected"); }
From source file:Creator.WidgetPanel.java
private void _Button_LoadXlsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__Button_LoadXlsActionPerformed _FileChooser_IoFile.setDialogTitle("Load XLS File"); _FileChooser_IoFile.setFileSelectionMode(JFileChooser.FILES_ONLY); _FileChooser_IoFile.setDialogType(JFileChooser.OPEN_DIALOG); _FileChooser_IoFile.setApproveButtonText("Open XLS File"); int returnVal = _FileChooser_IoFile.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = _FileChooser_IoFile.getSelectedFile(); String filePath = file.getAbsolutePath(); readXFile(filePath);/*from w w w .j av a 2 s . c o m*/ _Button_CreateImports.setEnabled(true); _Label_Loaded.setText("Loaded File!"); } else { System.out.println("File access cancelled by user."); } }
From source file:com.nikonhacker.gui.EmulatorUI.java
private void loadState() { if (framework.isEmulatorPlaying(Constants.CHIP_TX) || framework.isEmulatorPlaying(Constants.CHIP_FR)) { JOptionPane.showMessageDialog(this, "Could not load while playing", "Error", JOptionPane.ERROR_MESSAGE); return;/*from ww w. ja v a 2 s.c om*/ } final JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Select source file"); fc.setCurrentDirectory(new java.io.File(".")); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); /* TODO add chip name to triggers extension */ fc.setFileFilter(Format.createFilter(STATE_EXTENSION, "Emulator state (*" + STATE_EXTENSION + ")")); if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File sourceFile = fc.getSelectedFile(); if (!sourceFile.exists()) { JOptionPane.showMessageDialog(this, "Could not find file '" + sourceFile.getAbsolutePath() + "'.", "Error", JOptionPane.ERROR_MESSAGE); } else { // Problem: some UI components install listeners and links will be lost closeAllFrames(); try { final String source = sourceFile.getAbsolutePath(); setTitle(ApplicationInfo.getNameVersion() + " - Loading..."); framework = EmulationFramework.load(source, prefs); framework.setupCallbacks(getCallbackHandler(0), getCallbackHandler(1)); framework.getMasterClock().setSyncPlay(prefs.isSyncPlay()); setTitle(ApplicationInfo.getNameVersion() + " - Loaded " + source); } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, e.getMessage() + "\nSee console for more info", "Error", JOptionPane.ERROR_MESSAGE); } // some menu items may get disabled updateStates(); } } }
From source file:base.BasePlayer.AddGenome.java
public void actionPerformed(ActionEvent event) { if (event.getSource() == download) { if (!downloading) { downloading = true;/* ww w . j ava2 s .c o m*/ downloadGenome(genometable.getValueAt(genometable.getSelectedRow(), 0).toString()); downloading = false; } } else if (event.getSource() == getLinks) { URL[] urls = AddGenome.genomeHash .get(genometable.getValueAt(genometable.getSelectedRow(), 0).toString()); JPopupMenu menu = new JPopupMenu(); JTextArea area = new JTextArea(); JScrollPane menuscroll = new JScrollPane(); area.setFont(Main.menuFont); menu.add(menuscroll); menu.setPreferredSize(new Dimension( menu.getFontMetrics(Main.menuFont).stringWidth(urls[0].toString()) + Main.defaultFontSize * 10, (int) menu.getFontMetrics(Main.menuFont).getHeight() * 4)); //area.setMaximumSize(new Dimension(300, 600)); area.setLineWrap(true); area.setWrapStyleWord(true); for (int i = 0; i < urls.length; i++) { area.append(urls[i].toString() + "\n"); } area.setCaretPosition(0); area.revalidate(); menuscroll.getViewport().add(area); menu.pack(); menu.show(this, 0, 0); } else if (event.getSource() == checkEnsembl) { if (ensemblfetch) { menu.show(AddGenome.treescroll, 0, 0); } else { EnsemblFetch fetcher = new EnsemblFetch(); fetcher.execute(); } } else if (event.getSource() == checkUpdates) { URL testfile = null; try { // kattoo onko paivityksia annotaatioon String ref = selectedNode.toString(); if (AddGenome.genomeHash.get(ref) != null) { ArrayList<String> testfiles = new ArrayList<String>(); if (Main.drawCanvas != null) { for (int i = 0; i < Main.genomehash.get(ref).size(); i++) { testfiles.add(Main.genomehash.get(ref).get(i).getName().replace(".bed.gz", "")); } } testfile = AddGenome.genomeHash.get(ref)[1]; String result = Main.checkFile(testfile, testfiles); if (result.length() == 0) { Main.showError("You have newest annotation file.", "Note"); } else { int n = JOptionPane.showConfirmDialog(Main.drawCanvas, "New annotation file found: " + result + "\nDownload it now?", "Note", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { URL fileurl = new URL(testfile.getProtocol() + "://" + testfile.getHost() + testfile.getPath().substring(0, testfile.getPath().lastIndexOf("/") + 1) + result); OutputRunner runner = new OutputRunner(fileurl, ref); runner.downloadAnnotation = true; runner.execute(); } } } else { Main.showError("This genome is not from Ensembl list, could not check for updates.", "Note", AddGenome.genometable); } } catch (Exception e) { Main.showError("Cannot connect to " + testfile.getHost() + ".\nTry again later.", "Error"); e.printStackTrace(); } } else if (event.getSource() == remove) { if (!selectedNode.isLeaf()) { String removeref = selectedNode.toString(); // Boolean same = false; try { if (Main.drawCanvas != null) { if (removeref.equals(Main.refDropdown.getSelectedItem().toString())) { Main.referenceFile.close(); // same = true; if (ChromDraw.exonReader != null) { ChromDraw.exonReader.close(); } } } if (Main.genomehash.containsKey(removeref)) { for (int i = Main.genomehash.get(removeref).size() - 1; i >= 0; i--) { Main.genomehash.get(removeref).remove(i); } Main.genomehash.remove(removeref); } if (Main.drawCanvas != null) { Main.refModel.removeElement(removeref); Main.refDropdown.removeItem(removeref); Main.refDropdown.revalidate(); } for (int i = 0; i < Main.genome.getItemCount(); i++) { if (Main.genome.getItem(i).getName() != null) { if (Main.genome.getItem(i).getName().equals(removeref)) { Main.genome.remove(Main.genome.getItem(i)); break; } } } FileUtils.deleteDirectory(new File(Main.genomeDir.getCanonicalPath() + "/" + removeref)); checkGenomes(); Main.setAnnotationDrop(""); if (Main.genomehash.size() == 0) { Main.refDropdown.setSelectedIndex(0); Main.setChromDrop("-1"); } } catch (Exception e) { e.printStackTrace(); try { Main.showError("Could not delete genome folder.\nYou can do it manually by deleting folder " + Main.genomeDir.getCanonicalPath() + "/" + removeref, "Note"); } catch (IOException e1) { e1.printStackTrace(); } } } else { try { if (Main.drawCanvas != null) { if (ChromDraw.exonReader != null) { ChromDraw.exonReader.close(); } } Main.removeAnnotationFile(selectedNode.getParent().toString(), selectedNode.toString()); FileUtils.deleteDirectory(new File(Main.genomeDir.getCanonicalPath() + "/" + selectedNode.getParent().toString() + "/annotation/" + selectedNode.toString())); // root.remove(selectedNode.getParent().getIndex(selectedNode)); // root.remove // checkGenomes(); } catch (Exception e) { e.printStackTrace(); try { Main.showError("Could not delete genome folder.\nYou can do it manually by deleting folder " + Main.genomeDir.getCanonicalPath() + "/" + selectedNode.getParent().toString() + "/annotation/" + selectedNode.toString(), "Note"); } catch (IOException e1) { e1.printStackTrace(); } } treemodel.removeNodeFromParent(selectedNode); } } else if (event.getSource() == add) { if (genomeFile == null) { if (new File(genomeFileText.getText()).exists()) { genomeFile = new File(genomeFileText.getText()); } else { genomeFileText.setText("Select reference genome fasta-file."); genomeFileText.setForeground(Color.red); return; } } /*if(genomeName.getText().contains("Give name") || genomeName.getText().length() == 0) { genomeName.setText("Give name of the genome"); genomeName.setForeground(Color.red); genomeName.revalidate(); } else if(!annotation && new File(Main.userDir +"/genomes/"+genomeName.getText().trim().replace("\\s+", "_")).exists()) { genomeName.setText("This genome exists already."); genomeName.setForeground(Color.red); genomeName.revalidate(); } else */ if ((genomeFileText.getText().length() == 0 || genomeFileText.getText().startsWith("Select reference"))) { genomeFileText.setText("Select reference genome fasta-file."); genomeFileText.setForeground(Color.red); genomeFileText.revalidate(); } else { OutputRunner runner = new OutputRunner( genomeFile.getName().replace(".fasta", "").replace(".gz", ""), genomeFile, annotationFile); runner.execute(); } } else if (event.getSource() == openRef) { try { JFileChooser chooser = new JFileChooser(Main.downloadDir); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setAcceptAllFileFilterUsed(false); MyFilterFasta fastaFilter = new MyFilterFasta(); chooser.addChoosableFileFilter(fastaFilter); chooser.setDialogTitle("Select reference fasta-file"); if (Main.screenSize != null) { chooser.setPreferredSize(new Dimension((int) Main.screenSize.getWidth() / 3, (int) Main.screenSize.getHeight() / 3)); } int returnVal = chooser.showOpenDialog((Component) this.getParent()); if (returnVal == JFileChooser.APPROVE_OPTION) { genomeFile = chooser.getSelectedFile(); Main.downloadDir = genomeFile.getParent(); Main.writeToConfig("DownloadDir=" + genomeFile.getParent()); genomeFileText.setText(genomeFile.getName()); genomeFileText.revalidate(); frame.pack(); } } catch (Exception ex) { ex.printStackTrace(); } } else if (event.getSource() == openAnno) { try { JFileChooser chooser = new JFileChooser(Main.downloadDir); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setAcceptAllFileFilterUsed(false); MyFilterGFF gffFilter = new MyFilterGFF(); chooser.addChoosableFileFilter(gffFilter); chooser.setDialogTitle("Select annotation gff3-file"); if (Main.screenSize != null) { chooser.setPreferredSize(new Dimension((int) Main.screenSize.getWidth() / 3, (int) Main.screenSize.getHeight() / 3)); } int returnVal = chooser.showOpenDialog((Component) this.getParent()); if (returnVal == JFileChooser.APPROVE_OPTION) { if (genomeFile == null) { genomeFile = Main.fastahash.get(Main.hoverGenome); } annotationFile = chooser.getSelectedFile(); Main.downloadDir = annotationFile.getParent(); Main.writeToConfig("DownloadDir=" + annotationFile.getParent()); OutputRunner runner = new OutputRunner( genomeFile.getName().replace(".fasta", "").replace(".gz", ""), genomeFile, annotationFile); runner.execute(); } } catch (Exception ex) { ex.printStackTrace(); } } }