List of usage examples for javax.swing JFileChooser setDialogTitle
@BeanProperty(preferred = true, description = "The title of the JFileChooser dialog window.") public void setDialogTitle(String dialogTitle)
JFileChooser
window's title bar. From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Setup the environment to save the current SPARQL results to a file. * /*w w w. j a va2 s.c o m*/ * @see #writeSparqlResults(File) */ private void setupToWriteSparqlResults() { JFileChooser fileChooser; File destinationFile; int choice; if (lastDirectoryUsed == null) { lastDirectoryUsed = new File("."); } fileChooser = new JFileChooser(); if (sparqlResultsExportFile != null) { fileChooser.setSelectedFile(sparqlResultsExportFile); } else { fileChooser.setSelectedFile(lastDirectoryUsed); } fileChooser.setDialogTitle("Save SPARQL Results to File (Format:" + (setupExportSparqlResultsAsCsv.isSelected() ? "CSV" : "TSV") + ")"); choice = fileChooser.showSaveDialog(this); destinationFile = fileChooser.getSelectedFile(); // Did not click save, did not select a file or chose a directory // So do not write anything if (choice != JFileChooser.APPROVE_OPTION || destinationFile == null || (destinationFile.exists() && !destinationFile.isFile())) { return; // EARLY EXIT! } if (okToOverwriteFile(destinationFile)) { sparqlResultsExportFile = destinationFile; runSparqlResultsExport(); } }
From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Setup the environment to save the current model to a file. * //from w w w . ja v a 2s.com * @see #writeOntologyModel(File) */ private void setupToWriteOntologyModel() { JFileChooser fileChooser; File destinationFile; int choice; if (lastDirectoryUsed == null) { lastDirectoryUsed = new File("."); } fileChooser = new JFileChooser(); if (rdfFileSource != null && rdfFileSource.isFile()) { fileChooser.setSelectedFile(rdfFileSource.getBackingFile()); } else { fileChooser.setSelectedFile(lastDirectoryUsed); } fileChooser.setDialogTitle("Save Ontology Model to File (" + getSelectedOutputLanguage() + ")"); choice = fileChooser.showSaveDialog(this); destinationFile = fileChooser.getSelectedFile(); // Did not click save, did not select a file or chose a directory // So do not write anything if (choice != JFileChooser.APPROVE_OPTION || destinationFile == null || (destinationFile.exists() && !destinationFile.isFile())) { return; // EARLY EXIT! } if (okToOverwriteFile(destinationFile)) { modelExportFile = destinationFile; runModelExport(); } }
From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Save the text from the assertions text area to a file Note that this is * not the model and it may not be in an legal syntax for RDF triples. It is * simply storing what the user has placed in the text area. * //w w w . ja v a 2 s.c om * @see writeOntologyModel */ private void saveAssertionsToFile() { FileWriter out; JFileChooser fileChooser; File destinationFile; int choice; out = null; if (lastDirectoryUsed == null) { lastDirectoryUsed = new File("."); } fileChooser = new JFileChooser(); if (rdfFileSource != null && rdfFileSource.isFile()) { fileChooser.setSelectedFile(rdfFileSource.getBackingFile()); } else { fileChooser.setSelectedFile(lastDirectoryUsed); } fileChooser.setDialogTitle("Save Assertions to File"); choice = fileChooser.showSaveDialog(this); destinationFile = fileChooser.getSelectedFile(); // Did not click save, did not select a file or chose a directory // So do not write anything if (choice != JFileChooser.APPROVE_OPTION || destinationFile == null || (destinationFile.exists() && !destinationFile.isFile())) { return; // EARLY EXIT! } if (okToOverwriteFile(destinationFile)) { LOGGER.info("Write assertions to file, " + destinationFile); try { out = new FileWriter(destinationFile, false); out.write(assertionsInput.getText()); setRdfFileSource(new FileSource(destinationFile)); addRecentAssertedTriplesFile(new FileSource(destinationFile)); } catch (IOException ioExc) { final String errorMessage = "Unable to write to file: " + destinationFile; LOGGER.error(errorMessage, ioExc); throw new RuntimeException(errorMessage, ioExc); } finally { if (out != null) { try { out.close(); } catch (Throwable throwable) { final String errorMessage = "Failed to close output file: " + destinationFile; LOGGER.error(errorMessage, throwable); throw new RuntimeException(errorMessage, throwable); } } } } }
From source file:base.BasePlayer.Main.java
public void actionPerformed(ActionEvent e) { //Logo.frame.setVisible(false); if (e.getSource() == pleiadesButton) { gotoURL("http://kaptah.local.lab.helsinki.fi/pleiades/"); } else if (e.getSource() == manage) { if (VariantHandler.frame == null) { VariantHandler.main(argsit); }/*from ww w. j av a 2 s . co m*/ VariantHandler.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantHandler.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); VariantHandler.frame.setState(JFrame.NORMAL); VariantHandler.frame.setVisible(true); Draw.calculateVars = true; Draw.updatevars = true; drawCanvas.repaint(); } else if (e.getSource() == tbrowser) { tablebrowser.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantCaller.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); tablebrowser.frame.setState(JFrame.NORMAL); tablebrowser.frame.setVisible(true); } else if (e.getSource() == bconvert) { bedconverter.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantCaller.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); bedconverter.frame.setState(JFrame.NORMAL); bedconverter.frame.setVisible(true); } else if (e.getSource() == peakCaller) { if (PeakCaller.frame == null) { PeakCaller.main(argsit); } PeakCaller.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantCaller.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); PeakCaller.frame.setState(JFrame.NORMAL); PeakCaller.frame.setVisible(true); } else if (e.getSource() == variantCaller) { //FileRead.checkSamples(); if (VariantCaller.frame == null) { VariantCaller.main(argsit); } VariantCaller.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantCaller.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); VariantCaller.frame.setState(JFrame.NORMAL); VariantCaller.frame.setVisible(true); } else if (e.getSource() == average) { if (Average.frame == null) { Average.createAndShowGUI(); } Average.setSamples(); Average.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - Average.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); Average.frame.setState(JFrame.NORMAL); Average.frame.setVisible(true); } else if (e.getSource() == errorlog) { ErrorLog.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - ErrorLog.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); // VariantHandler.frame.setAlwaysOnTop(true); ErrorLog.frame.setState(JFrame.NORMAL); ErrorLog.frame.setVisible(true); } /* else if(e.getSource() == help) { JOptionPane.showMessageDialog(Main.chromDraw, "This is pre-release version of BasePlayer\nContact: help@baseplayer.fi\nUniversity of Helsinki", "Help", JOptionPane.INFORMATION_MESSAGE); }*/ else if (e.getSource() == settings) { Settings.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - Settings.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); Settings.frame.setState(JFrame.NORMAL); Settings.frame.setVisible(true); } else if (e.getSource() == update) { try { Updater update = new Updater(); update.execute(); } catch (Exception ex) { ex.printStackTrace(); } } else if (e.getSource() == clearMemory) { FileRead.nullifyVarNodes(); //FileRead.removeNonListVariants();f System.gc(); chromDraw.repaint(); } else if (e.getSource() == zoomout) { zoomout(); } else if (e.getSource() == dosomething) { BedNode currentbed = bedCanvas.bedTrack.get(0).getHead().getNext(); VarNode currentvar = FileRead.head.getNext(); while (currentbed != null) { while (currentvar != null && currentvar.getPosition() < currentbed.getPosition()) { currentvar = currentvar.getNext(); } while (currentbed != null && currentvar.getPosition() > currentbed.getPosition() + currentbed.getLength()) { currentbed = currentbed.getNext(); } if (currentvar != null && currentvar.getPosition() >= currentbed.getPosition() && currentvar.getPosition() < currentbed.getPosition() + currentbed.getLength()) { currentvar.setBedhit(true); currentvar = currentvar.getNext(); } if (currentvar == null) { break; } currentbed = currentbed.getNext(); } } else if (e.getSource() == clear) { clearData(); } else if (e.getSource() == exit) { System.exit(0); } else if (e.getSource() == openbams) { try { if (!checkGenome()) return; if (VariantHandler.frame != null) { VariantHandler.frame.setState(Frame.ICONIFIED); } FileDialog fc = new FileDialog(frame, "Choose BAM file(s)", FileDialog.LOAD); fc.setDirectory(path); fc.setFile("*.bam;*.cram;*.link"); fc.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".bam") || name.toLowerCase().endsWith(".cram") || name.toLowerCase().endsWith(".link"); } }); fc.setMultipleMode(true); fc.setVisible(true); File[] openfiles = fc.getFiles(); if (openfiles != null && openfiles.length > 0) { path = openfiles[0].getParent(); writeToConfig("DefaultDir=" + path); FileRead filereader = new FileRead(openfiles); filereader.start = (int) drawCanvas.selectedSplit.start; filereader.end = (int) drawCanvas.selectedSplit.end; filereader.readBAM = true; filereader.execute(); } else { //Main.showError("File(s) does not exist.", "Error"); } } catch (Exception ex) { Main.showError(ex.getMessage(), "Error"); } } else if (e.getSource() == openvcfs) { try { if (!checkGenome()) return; if (VariantHandler.frame != null) { VariantHandler.frame.setState(Frame.ICONIFIED); } FileDialog fc = new FileDialog(frame, "Choose VCF file(s)", FileDialog.LOAD); fc.setDirectory(path); fc.setFile("*.vcf"); fc.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".vcf") || name.toLowerCase().endsWith(".vcf.gz"); } }); fc.setMultipleMode(true); fc.setVisible(true); File[] openfiles = fc.getFiles(); if (openfiles != null && openfiles.length > 0) { path = openfiles[0].getParent(); writeToConfig("DefaultDir=" + path); FileRead filereader = new FileRead(openfiles); filereader.start = (int) drawCanvas.selectedSplit.start; filereader.end = (int) drawCanvas.selectedSplit.end; filereader.readVCF = true; filereader.execute(); } else { //Main.showError("File(s) does not exist.", "Error"); } if (1 == 1) { return; } JFileChooser chooser = new JFileChooser(path); getText(chooser.getComponents()); chooser.setMultiSelectionEnabled(true); //chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setAcceptAllFileFilterUsed(false); chooser.addChoosableFileFilter(vcfFilter); chooser.addChoosableFileFilter(bamFilter); chooser.addChoosableFileFilter(linkFilter); if (defaultSelectType == "vcf") { chooser.setFileFilter(vcfFilter); } else if (defaultSelectType == "bam") { chooser.setFileFilter(bamFilter); } else { chooser.setFileFilter(linkFilter); } chooser.setDialogTitle("Add samples"); chooser.setPreferredSize( new Dimension((int) screenSize.getWidth() / 3, (int) screenSize.getHeight() / 3)); int returnVal = chooser.showOpenDialog((Component) this.getParent()); if (returnVal == JFileChooser.APPROVE_OPTION) { File vcffiles[] = chooser.getSelectedFiles(); if (vcffiles.length == 1 && !vcffiles[0].exists() && pleiades) { if (Main.chooserText.contains("`")) { Main.chooserText.replace("`", "?"); } if (Main.chooserText.contains(" ")) { Main.chooserText.replace(" ", "%20"); } if (Main.chooserText.contains("pleiades")) { try { URL url = new URL(Main.chooserText); //System.out.println(Main.chooserText); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); httpConn.connect(); int responseCode = httpConn.getResponseCode(); if (responseCode == HttpsURLConnection.HTTP_OK) { String loading = drawCanvas.loadingtext; InputStream inputStream = httpConn.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); Main.drawCanvas.loadingtext = loading + " 0MB"; String line; StringBuffer buffer = new StringBuffer(""); while ((line = reader.readLine()) != null) { buffer.append(line); } inputStream.close(); reader.close(); String split2; String[] split = buffer.toString().split("dataUnit"); String location; ArrayList<File> array = new ArrayList<File>(); File[] paths; FileSystemView fsv = FileSystemView.getFileSystemView(); paths = File.listRoots(); String loc = "/mnt"; boolean missingfiles = false; for (File path : paths) { if (fsv.getSystemDisplayName(path).contains("merit")) { loc = path.getCanonicalPath(); } } for (int i = 0; i < split.length; i++) { if (!split[i].contains("lastLocation")) { continue; } split2 = split[i].split("\"lastLocation\":\"")[1]; location = split2.substring(0, split2.indexOf("\"}")); String filename = ""; String testloc = location.replace("/mnt", loc) + "/wgspipeline/"; File testDir = new File(testloc); if (testDir.exists() && testDir.isDirectory()) { if (chooser.getFileFilter() .equals(chooser.getChoosableFileFilters()[1])) { File[] addDir = testDir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".bam") || name.toLowerCase().endsWith(".cram"); } }); if (addDir.length > 0) { filename = addDir[0].getName(); } } else { File[] addDir = testDir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".vcf.gz"); } }); if (addDir.length > 0) { filename = addDir[0].getName(); } } } location = testloc + "/" + filename; if (!new File(location).exists()) { if (!new File(location).exists()) { missingfiles = true; ErrorLog.addError("No sample files found in " + testloc); } else { array.add(new File(location)); } } else { array.add(new File(location)); } } File[] files = new File[array.size()]; for (int i = 0; i < files.length; i++) { files[i] = array.get(i); } FileRead filereader = new FileRead(files); filereader.start = (int) drawCanvas.selectedSplit.start; filereader.end = (int) drawCanvas.selectedSplit.end; if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[1])) { filereader.readBAM = true; } else { filereader.readVCF = true; } filereader.execute(); if (missingfiles) { JOptionPane.showMessageDialog(Main.drawScroll, "Missing files. Check Tools->View log", "Note", JOptionPane.INFORMATION_MESSAGE); } } } catch (Exception ex) { ex.printStackTrace(); } } return; } if (vcffiles.length > 0) { path = vcffiles[0].getParent(); writeToConfig("DefaultDir=" + path); FileRead filereader = new FileRead(vcffiles); if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[0])) { defaultSelectType = "vcf"; filereader.start = (int) drawCanvas.selectedSplit.start; filereader.end = (int) drawCanvas.selectedSplit.end; filereader.readVCF = true; filereader.execute(); } else if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[1])) { defaultSelectType = "bam"; filereader.readBAM = true; filereader.execute(); } else if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[2])) { defaultSelectType = "link"; filereader.readBAM = true; filereader.execute(); } } else { JOptionPane.showMessageDialog(Main.drawScroll, "The file does not exist. The file link may be broken.\nThe problem may also be the Java run time version in Linux.", "Note", JOptionPane.INFORMATION_MESSAGE); } } } catch (Exception ex) { ex.printStackTrace(); } } else if (e.getSource() == addcontrols) { if (!checkGenome()) return; if (VariantHandler.frame != null) { VariantHandler.frame.setState(Frame.ICONIFIED); } FileDialog fc = new FileDialog(frame, "Choose control file(s)", FileDialog.LOAD); fc.setDirectory(Main.controlDir); fc.setFile("*.vcf.gz"); fc.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".vcf.gz"); } }); fc.setMultipleMode(true); fc.setVisible(true); File[] openfiles = fc.getFiles(); if (openfiles != null && openfiles.length > 0) { controlDir = openfiles[0].getParent(); writeToConfig("DefaultControlDir=" + controlDir); Control.addFiles(openfiles); } if (1 == 1) { return; } JFileChooser chooser = new JFileChooser(controlDir); // JFileChooser chooser = new JFileChooser(path); chooser.setMultiSelectionEnabled(true); chooser.setAcceptAllFileFilterUsed(false); Control.MyFilter vcfFilter = new Control.MyFilter(); chooser.addChoosableFileFilter(vcfFilter); chooser.setDialogTitle("Add controls"); chooser.setPreferredSize( new Dimension((int) screenSize.getWidth() / 3, (int) screenSize.getHeight() / 3)); int returnVal = chooser.showOpenDialog((Component) this.getParent()); if (returnVal == JFileChooser.APPROVE_OPTION) { File vcffiles[] = chooser.getSelectedFiles(); controlDir = vcffiles[0].getParent(); writeToConfig("DefaultControlDir=" + controlDir); if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[0])) { Control.addFiles(vcffiles); } } } else if (e.getSource() == addtracks) { if (!checkGenome()) return; try { if (!checkGenome()) return; if (VariantHandler.frame != null) { VariantHandler.frame.setState(Frame.ICONIFIED); } FileDialog fc = new FileDialog(frame, "Choose track file(s)", FileDialog.LOAD); fc.setDirectory(Main.trackDir); fc.setFile( "*.bed;*.bedgraph.gz;*.gff.gz;*.gff3.gz;*.bigwig;*.bw;*.bigbed;*.bb;*.tsv.gz;*.tsv.bgz;*.txt"); fc.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".bed") || name.toLowerCase().endsWith(".bed.gz") || name.toLowerCase().endsWith(".bedgraph.gz") || name.toLowerCase().endsWith(".bedgraph.gz") || name.toLowerCase().endsWith(".bedgraph.gz") || name.toLowerCase().endsWith(".gff.gz") || name.toLowerCase().endsWith(".gff3.gz") || name.toLowerCase().endsWith(".bigwig") || name.toLowerCase().endsWith(".bw") || name.toLowerCase().endsWith(".bigbed") || name.toLowerCase().endsWith(".bb") || name.toLowerCase().endsWith(".tsv.gz") || name.toLowerCase().endsWith(".tsv.bgz") || name.toLowerCase().endsWith(".txt"); } }); fc.setMultipleMode(true); fc.setVisible(true); File[] openfiles = fc.getFiles(); if (openfiles != null && openfiles.length > 0) { trackDir = openfiles[0].getParent(); writeToConfig("DefaultTrackDir=" + trackDir); FileRead filereader = new FileRead(openfiles); filereader.readBED = true; filereader.execute(); } else { //Main.showError("File(s) does not exist.", "Error"); } } catch (Exception ex) { Main.showError(ex.getMessage(), "Error"); } if (1 == 1) { return; } if (VariantHandler.frame != null) { VariantHandler.frame.setState(Frame.ICONIFIED); } JFileChooser chooser = new JFileChooser(Main.trackDir); getText(chooser.getComponents()); chooser.setMultiSelectionEnabled(true); chooser.setAcceptAllFileFilterUsed(false); MyFilterBED bedFilter = new MyFilterBED(); MyFilterTXT txtFilter = new MyFilterTXT(); chooser.addChoosableFileFilter(bedFilter); chooser.addChoosableFileFilter(txtFilter); chooser.setDialogTitle("Add tracks"); chooser.setPreferredSize( new Dimension((int) screenSize.getWidth() / 3, (int) screenSize.getHeight() / 3)); int returnVal = chooser.showOpenDialog((Component) this.getParent()); try { if (returnVal == JFileChooser.APPROVE_OPTION) { File bedfiles[] = chooser.getSelectedFiles(); if (bedfiles[0].exists()) { trackDir = bedfiles[0].getParent(); writeToConfig("DefaultTrackDir=" + trackDir); FileRead filereader = new FileRead(bedfiles); filereader.readBED(bedfiles); } else { if (Main.chooserText.length() > 5 && Main.chooserText.endsWith(".bed.gz") || Main.chooserText.endsWith(".gff.gz") || Main.chooserText.endsWith(".gff3.gz") || Main.chooserText.endsWith(".bedgraph.gz")) { if (Main.chooserText.startsWith("http://") || Main.chooserText.startsWith("ftp://")) { URL url = new URL(Main.chooserText); SeekableStream stream = SeekableStreamFactory.getInstance().getStreamFor(url); TabixReader tabixReader = null; String index = null; try { tabixReader = new TabixReader(Main.chooserText, Main.chooserText + ".tbi", stream); index = Main.chooserText + ".tbi"; } catch (Exception ex) { try { tabixReader = new TabixReader(Main.chooserText, Main.chooserText.substring(0, Main.chooserText.indexOf(".gz")) + ".tbi", stream); index = Main.chooserText.substring(0, Main.chooserText.indexOf(".gz")) + ".tbi"; } catch (Exception exc) { exc.printStackTrace(); } } if (tabixReader != null && index != null) { FileRead filereader = new FileRead(bedfiles); filereader.readBED(Main.chooserText, index, false); tabixReader.close(); } } } else { if (Main.chooserText.contains("://")) { try { // bbreader = new BBFileReader(Main.chooserText, stream); } catch (Exception ex) { ex.printStackTrace(); } // if(bbreader != null) { FileRead filereader = new FileRead(bedfiles); filereader.readBED(Main.chooserText, "nan", false); // } // stream.close(); } } } } } catch (Exception ex) { ex.printStackTrace(); } } else if (e.getSource() == openProject) { if (!checkGenome()) return; if (VariantHandler.frame != null) { VariantHandler.frame.setState(Frame.ICONIFIED); } openProject(); } else if (e.getSource() == saveProjectAs) { if (VariantHandler.frame != null) { VariantHandler.frame.setState(Frame.ICONIFIED); } try { File savefile = null; FileDialog fs = new FileDialog(frame, "Save project as...", FileDialog.SAVE); fs.setDirectory(projectDir); fs.setFile("*.ses"); fs.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".ses"); } }); fs.setVisible(true); while (true) { String filename = fs.getFile(); if (filename != null) { savefile = new File(fs.getDirectory() + "/" + filename); projectDir = fs.getDirectory(); writeToConfig("DefaultProjectDir=" + projectDir); /* if(!Files.isWritable(Paths.get(savefile.getParent()))) { Main.showError("No permission to write.", "Error"); continue; }*/ if (!savefile.getAbsolutePath().endsWith(".ses")) { savefile = new File(savefile.getAbsolutePath() + ".ses"); } Serializer ser = new Serializer(); ser.serialize(savefile); break; } else { break; } } if (1 == 1) { return; } JFileChooser chooser = new JFileChooser(); chooser.setAcceptAllFileFilterUsed(false); MyFilterSES sesFilter = new MyFilterSES(); chooser.addChoosableFileFilter(sesFilter); chooser.setDialogTitle("Save project as..."); int returnVal = chooser.showSaveDialog((Component) this.getParent()); if (returnVal == JFileChooser.APPROVE_OPTION) { File outfile = chooser.getSelectedFile(); if (!outfile.getAbsolutePath().endsWith(".ses")) { outfile = new File(outfile.getAbsolutePath() + ".ses"); } Serializer ser = new Serializer(); ser.serialize(outfile); } } catch (Exception ex) { ex.printStackTrace(); } } else if (e.getSource() == saveProject) { if (drawCanvas.drawVariables.projectName.equals("Untitled")) { saveProjectAs.doClick(); } else { Serializer ser = new Serializer(); ser.serialize(drawCanvas.drawVariables.projectFile); } } /* else if(e.getSource() == welcome) { WelcomeScreen.main(args); WelcomeScreen.frame.setVisible(true); WelcomeScreen.frame.setLocation(frame.getLocationOnScreen().x+frame.getWidth()/2 - WelcomeScreen.frame.getWidth()/2, frame.getLocationOnScreen().y+frame.getHeight()/6); }*/ }
From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Allow the user to select a file, which is expected to be an ontology, and * then load the file./*from w w w . j av a2 s. c o m*/ */ private void openOntologyFile() { JFileChooser fileChooser; FileFilter defaultFileFilter = null; FileFilter preferredFileFilter = null; File chosenFile; if (lastDirectoryUsed == null) { lastDirectoryUsed = new File("."); } fileChooser = new JFileChooser(lastDirectoryUsed); for (FileFilterDefinition filterDefinition : FileFilterDefinition.values()) { if (filterDefinition.name().startsWith("ONTOLOGY")) { final FileFilter fileFilter = new SuffixFileFilter(filterDefinition.description(), filterDefinition.acceptedSuffixes()); if (filterDefinition.isPreferredOption()) { preferredFileFilter = fileFilter; } fileChooser.addChoosableFileFilter(fileFilter); if (filterDefinition.description().equals(latestChosenRdfFileFilterDescription)) { defaultFileFilter = fileFilter; } } } if (defaultFileFilter != null) { fileChooser.setFileFilter(defaultFileFilter); } else if (latestChosenRdfFileFilterDescription != null && latestChosenRdfFileFilterDescription.startsWith("All")) { fileChooser.setFileFilter(fileChooser.getAcceptAllFileFilter()); } else if (preferredFileFilter != null) { fileChooser.setFileFilter(preferredFileFilter); } fileChooser.setDialogTitle("Open Assertions File"); fileChooser.showOpenDialog(this); try { latestChosenRdfFileFilterDescription = fileChooser.getFileFilter().getDescription(); } catch (Throwable throwable) { LOGGER.warn("Unable to determine which ontology file filter was chosen", throwable); } chosenFile = fileChooser.getSelectedFile(); if (chosenFile != null) { setupToLoadOntologyFile(new FileSource(chosenFile)); } }
From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Allow the user to select a file, which is expected to be an ontology, and * then load the file./*from w w w .j a va2 s . c om*/ */ private void openSparqlQueryFile() { JFileChooser fileChooser; FileFilter defaultFileFilter = null; FileFilter preferredFileFilter = null; File chosenFile; if (lastDirectoryUsed == null) { lastDirectoryUsed = new File("."); } fileChooser = new JFileChooser(lastDirectoryUsed); for (FileFilterDefinition filterDefinition : FileFilterDefinition.values()) { if (filterDefinition.name().startsWith("SPARQL")) { final FileFilter fileFilter = new SuffixFileFilter(filterDefinition.description(), filterDefinition.acceptedSuffixes()); if (filterDefinition.isPreferredOption()) { preferredFileFilter = fileFilter; } fileChooser.addChoosableFileFilter(fileFilter); if (filterDefinition.description().equals(latestChosenSparqlFileFilterDescription)) { defaultFileFilter = fileFilter; } } } if (defaultFileFilter != null) { fileChooser.setFileFilter(defaultFileFilter); } else if (latestChosenSparqlFileFilterDescription != null && latestChosenSparqlFileFilterDescription.startsWith("All")) { fileChooser.setFileFilter(fileChooser.getAcceptAllFileFilter()); } else if (preferredFileFilter != null) { fileChooser.setFileFilter(preferredFileFilter); } fileChooser.setDialogTitle("Open SPARQL Query File"); fileChooser.showOpenDialog(this); try { latestChosenSparqlFileFilterDescription = fileChooser.getFileFilter().getDescription(); } catch (Throwable throwable) { LOGGER.warn("Unable to determine which SPARQL file filter was chosen", throwable); } chosenFile = fileChooser.getSelectedFile(); if (chosenFile != null) { loadSparqlQueryFile(chosenFile); } }
From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Save the text from the SPARQL query text area to a file. * //from w w w .ja va 2 s . co m */ private void saveSparqlQueryToFile() { FileWriter out; JFileChooser fileChooser; FileFilter defaultFileFilter = null; FileFilter preferredFileFilter = null; File destinationFile; int choice; out = null; if (lastDirectoryUsed == null) { lastDirectoryUsed = new File("."); } fileChooser = new JFileChooser(); for (FileFilterDefinition filterDefinition : FileFilterDefinition.values()) { if (filterDefinition.name().startsWith("SPARQL")) { final FileFilter fileFilter = new SuffixFileFilter(filterDefinition.description(), filterDefinition.acceptedSuffixes()); if (filterDefinition.isPreferredOption()) { preferredFileFilter = fileFilter; } fileChooser.addChoosableFileFilter(fileFilter); if (filterDefinition.description().equals(latestChosenSparqlFileFilterDescription)) { defaultFileFilter = fileFilter; } } } if (defaultFileFilter != null) { fileChooser.setFileFilter(defaultFileFilter); } else if (latestChosenSparqlFileFilterDescription != null && latestChosenSparqlFileFilterDescription.startsWith("All")) { fileChooser.setFileFilter(fileChooser.getAcceptAllFileFilter()); } else if (preferredFileFilter != null) { fileChooser.setFileFilter(preferredFileFilter); } if (sparqlQueryFile != null) { fileChooser.setSelectedFile(sparqlQueryFile); } else { fileChooser.setSelectedFile(lastDirectoryUsed); } fileChooser.setDialogTitle("Save SPARQL Query to File"); choice = fileChooser.showSaveDialog(this); try { latestChosenSparqlFileFilterDescription = fileChooser.getFileFilter().getDescription(); } catch (Throwable throwable) { LOGGER.warn("Unable to determine which SPARQL file filter was chosen", throwable); } destinationFile = fileChooser.getSelectedFile(); // Did not click save, did not select a file or chose a directory // So do not write anything if (choice != JFileChooser.APPROVE_OPTION || destinationFile == null || (destinationFile.exists() && !destinationFile.isFile())) { return; // EARLY EXIT! } // Adjust file suffix if necessary final FileFilter fileFilter = fileChooser.getFileFilter(); if (fileFilter != null && fileFilter instanceof SuffixFileFilter && !fileChooser.getFileFilter().accept(destinationFile)) { destinationFile = ((SuffixFileFilter) fileFilter).makeWithPrimarySuffix(destinationFile); } if (okToOverwriteFile(destinationFile)) { LOGGER.info("Write SPARQL query to file, " + destinationFile); try { out = new FileWriter(destinationFile, false); if (sparqlServiceUrl.getSelectedIndex() != 0) { out.write( "# " + SPARQL_QUERY_SAVE_SERVICE_URL_PARAM + sparqlServiceUrl.getSelectedItem() + "\n"); } else { out.write("# " + SPARQL_QUERY_SAVE_SERVICE_URL_PARAM + SPARQL_QUERY_SAVE_SERVICE_URL_VALUE_FOR_NO_SERVICE_URL + "\n"); } if (defaultGraphUri.getText().trim().length() > 0) { out.write("# " + SPARQL_QUERY_SAVE_SERVICE_DEFAULT_GRAPH_PARAM + defaultGraphUri.getText().trim() + "\n"); } out.write(sparqlInput.getText()); setSparqlQueryFile(destinationFile); } catch (IOException ioExc) { final String errorMessage = "Unable to write to file: " + destinationFile; LOGGER.error(errorMessage, ioExc); throw new RuntimeException(errorMessage, ioExc); } finally { if (out != null) { try { out.close(); } catch (Throwable throwable) { final String errorMessage = "Failed to close output file: " + destinationFile; LOGGER.error(errorMessage, throwable); throw new RuntimeException(errorMessage, throwable); } } setTitle(); } } }
From source file:src.gui.ItSIMPLE.java
/** * @return Returns the planAnalysisFramePanel. *///from w w w.j a v a2s. co m private ItFramePanel getPlanAnalysisFramePanel() { if (planAnalysisFramePanel == null) { planAnalysisFramePanel = new ItFramePanel(":: Plan Analysis", ItFramePanel.NO_MINIMIZE_MAXIMIZE); // tool bar JToolBar chartsToolBar = new JToolBar(); chartsToolBar.add(new JButton(drawChartAction)); // charts panel chartsPanel = new JPanel(); chartsPanel.setLayout(new BoxLayout(chartsPanel, BoxLayout.Y_AXIS)); ItFramePanel variableSelectionPanel = new ItFramePanel(".: Select variables to be tracked", ItFramePanel.NO_MINIMIZE_MAXIMIZE); //variableSelectionPanel.setBackground(new Color(151,151,157)); JSplitPane split = new JSplitPane(); split.setContinuousLayout(true); split.setOrientation(JSplitPane.HORIZONTAL_SPLIT); split.setDividerLocation(2 * screenSize.height / 3); split.setDividerSize(8); //split.setPreferredSize(new Dimension(screenSize.width/4-20, screenSize.height/2 - 50)); //split.setPreferredSize(new Dimension(screenSize.width/4-20, 120)); split.setLeftComponent(new JScrollPane(variablesPlanTree)); split.setRightComponent(new JScrollPane(selectedVariablesPlanTree)); variableSelectionPanel.setContent(split, false); //variableSelectionPanel.setParentSplitPane() //JPanel variableSelectionPanel = new JPanel(new BorderLayout()); //variableSelectionPanel.add(new JScrollPane(variablesPlanTree), BorderLayout.CENTER); //variableSelectionPanel.add(new JScrollPane(selectedVariablesPlanTree), BorderLayout.EAST); ItFramePanel variableGraphPanel = new ItFramePanel(".: Chart", ItFramePanel.NO_MINIMIZE_MAXIMIZE); variableGraphPanel.setContent(chartsPanel, true); JSplitPane mainvariablesplit = new JSplitPane(); mainvariablesplit.setContinuousLayout(true); mainvariablesplit.setOrientation(JSplitPane.VERTICAL_SPLIT); mainvariablesplit.setDividerLocation(150); mainvariablesplit.setDividerSize(8); //mainvariablesplit.setPreferredSize(new Dimension(screenSize.width/4-20, screenSize.height/2 - 50)); mainvariablesplit.setTopComponent(variableSelectionPanel); mainvariablesplit.setBottomComponent(variableGraphPanel); // main charts panel - used to locate the tool bar above the charts panel JPanel mainChartsPanel = new JPanel(new BorderLayout()); mainChartsPanel.add(chartsToolBar, BorderLayout.NORTH); //mainChartsPanel.add(new JScrollPane(chartsPanel), BorderLayout.CENTER); mainChartsPanel.add(mainvariablesplit, BorderLayout.CENTER); //Results planInfoEditorPane = new JEditorPane(); planInfoEditorPane.setContentType("text/html"); planInfoEditorPane.setEditable(false); planInfoEditorPane.setCursor(new Cursor(Cursor.TEXT_CURSOR)); planInfoEditorPane.setBackground(Color.WHITE); JPanel resultsPanel = new JPanel(new BorderLayout()); JToolBar resultsToolBar = new JToolBar(); resultsToolBar.setRollover(true); JButton planReportButton = new JButton("View Full Report", new ImageIcon("resources/images/viewreport.png")); planReportButton.setToolTipText("<html>View full plan report.<br> For multiple plans you will need " + "access to the Internet.<br> The components used in the report require such access (no data is " + "sent through the Internet).</html>"); planReportButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { //Opens html with defaut browser String path = "resources/report/Report.html"; File report = new File(path); path = report.getAbsolutePath(); try { BrowserLauncher launcher = new BrowserLauncher(); launcher.openURLinBrowser("file://" + path); } catch (BrowserLaunchingInitializingException ex) { Logger.getLogger(ItSIMPLE.class.getName()).log(Level.SEVERE, null, ex); appendOutputPanelText("ERROR. Problem while trying to open the default browser. \n"); } catch (UnsupportedOperatingSystemException ex) { Logger.getLogger(ItSIMPLE.class.getName()).log(Level.SEVERE, null, ex); appendOutputPanelText("ERROR. Problem while trying to open the default browser. \n"); } } }); resultsToolBar.add(planReportButton); resultsToolBar.addSeparator(); JButton planReportDataButton = new JButton("Save Report Data", new ImageIcon("resources/images/savePDDL.png")); planReportDataButton.setToolTipText("<html>Save report data to file</html>"); planReportDataButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { //Save report data if (solveResult != null) { Element lastOpenFolderElement = itSettings.getChild("generalSettings") .getChild("lastOpenFolder"); JFileChooser fc = new JFileChooser(lastOpenFolderElement.getText()); fc.setDialogTitle("Save Report Data"); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setFileFilter(new XMLFileFilter()); int returnVal = fc.showSaveDialog(ItSIMPLE.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = fc.getSelectedFile(); String path = selectedFile.getPath(); if (!path.toLowerCase().endsWith(".xml")) { path += ".xml"; } //save file (xml) try { FileWriter file = new FileWriter(path); file.write(XMLUtilities.toString(solveResult)); file.close(); } catch (IOException e1) { e1.printStackTrace(); } //Save as a last open folder String folder = selectedFile.getParent(); //Element lastOpenFolderElement = itSettings.getChild("generalSettings").getChild("lastOpenFolder"); lastOpenFolderElement.setText(folder); XMLUtilities.writeToFile("resources/settings/itSettings.xml", itSettings.getDocument()); //Ask if the user wants to save plans individually too. boolean needToSavePlans = false; int option = JOptionPane.showOptionDialog(instance, "<html><center>Do you also want to save the plans" + "<br>in individual files?</center></html>", "Save plans", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); switch (option) { case JOptionPane.YES_OPTION: { needToSavePlans = true; } break; case JOptionPane.NO_OPTION: { needToSavePlans = false; } break; } if (needToSavePlans) { //Close Open tabs List<?> problems = null; try { XPath ppath = new JDOMXPath("project/domains/domain/problems/problem"); problems = ppath.selectNodes(solveResult); } catch (JaxenException e2) { e2.printStackTrace(); } for (int i = 0; i < problems.size(); i++) { Element problem = (Element) problems.get(i); //create a folder for each problem and put all plans inside as xml files String folderName = problem.getChildText("name"); String folderPath = selectedFile.getAbsolutePath() .replace(selectedFile.getName(), folderName); //System.out.println(folderPath); File planfolder = new File(folderPath); boolean canSavePlan = false; try { if (planfolder.mkdir()) { System.out.println("Directory '" + folderPath + "' created."); canSavePlan = true; } else { System.out.println("Directory '" + folderPath + "' was not created."); } } catch (Exception ep) { ep.printStackTrace(); } if (canSavePlan) { Element plans = problem.getChild("plans"); for (Iterator<Element> it = plans.getChildren("xmlPlan").iterator(); it .hasNext();) { Element eaplan = it.next(); Element theplanner = eaplan.getChild("planner"); //save file (xml) String planFileName = "solution" + theplanner.getChildText("name") + "-" + theplanner.getChildText("version") + "-" + Integer.toString(plans.getChildren().indexOf(eaplan)) + ".xml"; String planPath = folderPath + File.separator + planFileName; /* try { FileWriter planfile = new FileWriter(planPath); planfile.write(XMLUtilities.toString(eaplan)); planfile.close(); System.out.println("File '" + planPath + "' created."); } catch (IOException e1) { e1.printStackTrace(); } * */ if (eaplan.getChild("plan").getChildren().size() > 0) { //TODO: save the plan in PDDL too. It should be done through the XPDDL/PDDL classes String pddlplan = ToXPDDL.XMLtoXPDDLPlan(eaplan); String planFileNamePDDL = "solution" + theplanner.getChildText("name") + "-" + theplanner.getChildText("version") + "-" + Integer.toString(plans.getChildren().indexOf(eaplan)) + ".pddl"; String planPathPDDL = folderPath + File.separator + planFileNamePDDL; //String cfolderPath = selectedFile.getAbsolutePath().replace(selectedFile.getName(), ""); //String planFileNamePDDL = theplanner.getChildText("name")+"-"+theplanner.getChildText("version") + "-" + folderName+"-solution.pddl"; //String planPathPDDL = cfolderPath + File.separator + planFileNamePDDL; //if (!theplanner.getChildText("name").contains("MIPS")){ try { FileWriter planfile = new FileWriter(planPathPDDL); planfile.write(pddlplan); planfile.close(); System.out.println("File '" + planPathPDDL + "' created."); } catch (IOException e1) { e1.printStackTrace(); } } //} } } } } } } else { appendOutputPanelText(">> No report data available to save! \n"); } } }); resultsToolBar.add(planReportDataButton); JButton openPlanReportDataButton = new JButton("Open Report Data", new ImageIcon("resources/images/openreport.png")); openPlanReportDataButton.setToolTipText("<html>Open report data to file</html>"); openPlanReportDataButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { planSimStatusBar.setText("Status: Opening File..."); appendOutputPanelText(">> Opening File... \n"); //Open report data Element lastOpenFolderElement = itSettings.getChild("generalSettings") .getChild("lastOpenFolder"); JFileChooser fc = new JFileChooser(lastOpenFolderElement.getText()); fc.setDialogTitle("Open Report Data"); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setFileFilter(new XMLFileFilter()); int returnVal = fc.showOpenDialog(ItSIMPLE.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // Get itSIMPLE itSettings from itSettings.xml org.jdom.Document resultsDoc = null; try { resultsDoc = XMLUtilities.readFromFile(file.getPath()); solveResult = resultsDoc.getRootElement(); //XMLUtilities.printXML(solveResult); if (solveResult.getName().equals("projects")) { String report = PlanAnalyzer.generatePlannersComparisonReport(solveResult); String comparisonReport = PlanAnalyzer .generateFullPlannersComparisonReport(solveResult); //Save Comparison Report file saveFile("resources/report/Report.html", comparisonReport); setPlanInfoPanelText(report); setPlanEvaluationInfoPanelText(""); appendOutputPanelText(">> Report data read! \n"); //My experiments PlanAnalyzer.myAnalysis(itPlanners.getChild("planners"), solveResult); } } catch (Exception e1) { e1.printStackTrace(); } //Save as a last open folder String folder = fc.getSelectedFile().getParent(); lastOpenFolderElement.setText(folder); XMLUtilities.writeToFile("resources/settings/itSettings.xml", itSettings.getDocument()); } else { planSimStatusBar.setText("Status:"); appendOutputPanelText(">> Canceled \n"); } } }); resultsToolBar.add(openPlanReportDataButton); JButton compareProjectReportDataButton = new JButton("Compare Project Data", new ImageIcon("resources/images/compare.png")); compareProjectReportDataButton.setToolTipText( "<html>Compare different project report data <br> This is commonly use to compare diferent domain models with different adjustments.<br>" + "One project data must be chosen as a reference; others will be compared to this referencial one.</html>"); compareProjectReportDataButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { final ProjectComparisonDialog dialog = new ProjectComparisonDialog(); dialog.setVisible(true); final List<String> files = dialog.getFiles(); if (files.size() > 1) { new Thread() { public void run() { appendOutputPanelText(">> Project comparison report requested. Processing... \n"); planSimStatusBar.setText("Status: Reading files ..."); appendOutputPanelText(">> Reading files ... \n"); //base project file String baseFileName = files.get(0); appendOutputPanelText(">> Reading file '" + baseFileName + "' \n"); org.jdom.Document baseProjectDoc = null; try { baseProjectDoc = XMLUtilities.readFromFile(baseFileName); } catch (Exception ec) { ec.printStackTrace(); } Element baseProject = null; if (baseProjectDoc != null) { baseProject = baseProjectDoc.getRootElement().getChild("project"); } //The comparible projects List<Element> comparableProjects = new ArrayList<Element>(); for (int i = 1; i < files.size(); i++) { String eafile = files.get(i); appendOutputPanelText(">> Reading file '" + eafile + "' \n"); org.jdom.Document eaProjectDoc = null; try { eaProjectDoc = XMLUtilities.readFromFile(eafile); } catch (Exception ec) { ec.printStackTrace(); } if (eaProjectDoc != null) { comparableProjects.add(eaProjectDoc.getRootElement().getChild("project")); } } appendOutputPanelText(">> Files read. Building report... \n"); String comparisonReport = PlanAnalyzer.generateProjectComparisonReport(baseProject, comparableProjects); saveFile("resources/report/Report.html", comparisonReport); appendOutputPanelText( ">> Project comparison report generated. Press 'View Full Report'\n"); appendOutputPanelText(" \n"); } }.start(); } } }); resultsToolBar.add(compareProjectReportDataButton); resultsPanel.add(resultsToolBar, BorderLayout.NORTH); resultsPanel.add(new JScrollPane(planInfoEditorPane), BorderLayout.CENTER); JTabbedPane planAnalysisTabbedPane = new JTabbedPane(); planAnalysisTabbedPane.addTab("Results", resultsPanel); planAnalysisTabbedPane.addTab("Variable Tracking", mainChartsPanel); planAnalysisTabbedPane.addTab("Movie Maker", getMovieMakerPanel()); planAnalysisTabbedPane.addTab("Plan Evaluation", getPlanEvaluationPanel()); planAnalysisTabbedPane.addTab("Plan Database", getPlanDatabasePanel()); planAnalysisTabbedPane.addTab("Rationale Database", getRationaleDatabasePanel()); JPanel planAnalysisPanel = new JPanel(new BorderLayout()); //planAnalysisPanel.add(chartsToolBar, BorderLayout.NORTH); planAnalysisPanel.add(planAnalysisTabbedPane, BorderLayout.CENTER); planAnalysisFramePanel.setContent(planAnalysisPanel, false); } return planAnalysisFramePanel; }
From source file:nick.gaImageRecognitionGui.panel.JPanelTestSavedConfiguration.java
private void jButtonSelectImagesFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectImagesFolderActionPerformed JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new java.io.File(".")); fc.setDialogTitle(StringConstants.SELECT_TEST_IMAGES_FOLDER); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setAcceptAllFileFilterUsed(false); if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String path = fc.getSelectedFile().getPath(); RuntimeConfiguration.getInstance().setTestImagesFolderLocation(path); testImagesFolderLocation.setText(path); } else {//from www . j a v a 2s.c o m String path = RuntimeConfiguration.getInstance().getTestImagesFolderLocation(); if (StringUtils.isNotBlank(path)) { testImagesFolderLocation.setText(path); } } }
From source file:nick.gaImageRecognitionGui.panel.JPanelTestSavedConfiguration.java
private void jButtonSelectConfigurationFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectConfigurationFolderActionPerformed JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new java.io.File(".")); fc.setDialogTitle(StringConstants.SELECT_TEST_IMAGES_FOLDER); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setAcceptAllFileFilterUsed(false); if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String path = fc.getSelectedFile().getPath(); RuntimeConfiguration.getInstance().setTestConfigurationsFolderLocation(path); configurationsFolderLocation.setText(path); } else {/*from ww w . ja v a 2 s . co m*/ String path = RuntimeConfiguration.getInstance().getTestConfigurationsFolderLocation(); if (StringUtils.isNotBlank(path)) { configurationsFolderLocation.setText(path); } } }