List of usage examples for javax.swing JFileChooser getSelectedFile
public File getSelectedFile()
From source file:com.wet.wired.jsr.player.JPlayer.java
public void actionPerformed(ActionEvent ev) { if (ev.getActionCommand().equals("open")) { UIManager.put("FileChooser.readOnly", true); JFileChooser fileChooser = new JFileChooser(); FileExtensionFilter filter = new FileExtensionFilter(); filter = new FileExtensionFilter(); filter.addExtension("owl"); filter.setDescription("TestingOwl File"); if (target != null) { fileChooser.setSelectedFile(new File(target + ".owl")); }/*from w ww .ja v a 2s.co m*/ fileChooser.setFileFilter(filter); fileChooser.setCurrentDirectory(new File(".")); fileChooser.showOpenDialog(this); if (fileChooser.getSelectedFile() != null) { // target = fileChooser.getSelectedFile().getAbsolutePath(); String targetCapOwl = fileChooser.getSelectedFile().getAbsolutePath(); target = targetCapOwl.substring(0, targetCapOwl.lastIndexOf(".owl")); open(); } } else if (ev.getActionCommand().equals("play")) { play(); } else if (ev.getActionCommand().equals("reset")) { reset(); } else if (ev.getActionCommand().equals("fastForward")) { fastForward(); } else if (ev.getActionCommand().equals("pause")) { pause(); } else if (ev.getActionCommand().equals("close")) { close(); } else if (ev.getActionCommand().equals("recorder")) { closePlayer(); Main.getRecorder().init(new String[0]); } }
From source file:org.nekorp.workflow.desktop.view.CostoServicioView.java
private void generarReporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generarReporteActionPerformed try {/*from w w w. java 2s .co m*/ if (servicioMetaData.isEditado()) { this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); this.aplication.guardaServicio(); this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); } JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Hojas de clculo", "xlsx"); chooser.setFileFilter(filter); String homePath = System.getProperty("user.home"); File f = new File(new File(homePath + "/Reporte-Servicio-" + this.viewServicioModel.getId() + ".xlsx") .getCanonicalPath()); chooser.setSelectedFile(f); int returnVal = chooser.showSaveDialog(this.mainFrame); if (returnVal == JFileChooser.APPROVE_OPTION) { this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); ParametrosReporte param = new ParametrosReporte(); param.setDestination(chooser.getSelectedFile()); this.aplication.generaReporte(param); } } catch (IllegalArgumentException e) { //no lo guardo por que tenia horribles errores... tambien especializar la excepcion } catch (IOException ex) { CostoServicioView.LOGGER.error(ex); } finally { this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); } }
From source file:ar.edu.uns.cs.vyglab.arq.rockar.gui.JFrameControlPanel.java
public void saveTable() { File currentDir = new File(System.getProperty("user.dir")); JFileChooser saveDialog = new JFileChooser(currentDir); FileNameExtensionFilter filter = new FileNameExtensionFilter("MTF File", "mtf", "mtf"); saveDialog.setFileFilter(filter);//from www.ja v a 2 s . co m int response = saveDialog.showSaveDialog(this); if (response == saveDialog.APPROVE_OPTION) { File file = saveDialog.getSelectedFile(); if (file.getName().lastIndexOf(".") == -1) { file = new File(file.getName() + ".mtf"); } DataCenter.fileMineralList = file; try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); // root elements Document doc = docBuilder.newDocument(); Element rootElement = doc.createElement("table"); doc.appendChild(rootElement); // para cada mineral en la tabla de minerales, agrego un Element for (int i = 0; i < this.jTableMineralsModel.getRowCount(); i++) { Element mineral = doc.createElement("mineral"); // set attribute id to mineral element Attr attr = doc.createAttribute("key"); //attr.setValue(this.jTableMinerales.getModel().getValueAt(i, 0).toString()); attr.setValue(this.jTableMineralsModel.getValueAt(i, 0).toString()); mineral.setAttributeNode(attr); // set attribute name to mineral element attr = doc.createAttribute("name"); attr.setValue(this.jTableMineralsModel.getValueAt(i, 1).toString()); mineral.setAttributeNode(attr); // set attribute color to mineral element attr = doc.createAttribute("color"); attr.setValue(String.valueOf(((Color) this.jTableMineralsModel.getValueAt(i, 2)).getRGB())); mineral.setAttributeNode(attr); // agrego el mineral a los minerales rootElement.appendChild(mineral); } // write the content into xml file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(DataCenter.fileMineralList); transformer.transform(source, result); } catch (Exception e) { } } }
From source file:au.com.jwatmuff.eventmanager.gui.main.LoadCompetitionWindow.java
private void loadLicenseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadLicenseButtonActionPerformed JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter("License File", "lic")); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); License license = License.loadFromFile(file); if (license != null) try { licenseManager.setLicense(license); updateLicenseInfo();/* www. j av a2 s .co m*/ } catch (IOException e) { GUIUtils.displayError(this, "Error updating license. You may need to reload the license next time you start EventManager"); } else GUIUtils.displayError(this, "Error while loading license file"); } }
From source file:com.orange.atk.graphAnalyser.LectureJATKResult.java
/** * add all graph from a directory/*from w w w . ja v a 2 s. c o m*/ * */ private void openDirectoryAction(ActionEvent evt) { ConfigFile configFile = null; String JATKpath = Platform.getInstance().getJATKPath(); String pathihmconfig = JATKpath + Platform.FILE_SEPARATOR + "log" + Platform.FILE_SEPARATOR + "ConfigIHM.cfg"; File ihmconfig = new File(pathihmconfig); configFile = new ConfigFile(ihmconfig); //get a value from confile String Scriptpath = getvalueconfigfile(pathihmconfig, "path_READGRAPH"); //open JfileChooser final JFileChooser fc = new JFileChooser(Scriptpath); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showOpenDialog(jMenu1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); Scriptpath = file.getAbsolutePath(); if (Scriptpath != null) configFile.setOption("path_READGRAPH", Scriptpath); configFile.saveConfigFile(); //clean graph cleanlistElement(); analyzerGraphs.createMyDataset(file.getPath()); mapPerfGraph = analyzerGraphs.getMapPerfGraph(); mapAction = analyzerGraphs.getMapAction(); addPerformanceslist(); addMarkerlist(); //Add listener on list of graph and markers setListenerMarkerGraph(); //Crosshair Value Renderer et model setRendererandModelSeries(); } }
From source file:io.gameover.utilities.pixeleditor.Pixelizer.java
public void openFile() { JFileChooser fc = new JFileChooser(); int ret = fc.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { try {/* ww w.j a v a2 s . co m*/ BufferedImage image = ImageIO.read(fc.getSelectedFile()); if (image.getHeight() > Frame.NB_PIXELS || image.getWidth() % Frame.NB_PIXELS != 0 || image.getHeight() != Frame.NB_PIXELS) { int retOption = JOptionPane.showConfirmDialog(this, "Image seems not a pixel image (height > " + Frame.NB_PIXELS + "px or length not a multiple of " + Frame.NB_PIXELS + "). Would you like to convert it to pixel?"); if (retOption == JOptionPane.OK_OPTION) { convertToPixelImage(image); } } else { openImage(image); } refreshCurrentColors(); savedStates.clear(); currentStateIndex = 0; clearSelection(); refresh(); } catch (IOException ex) { ex.printStackTrace(); } } }
From source file:com.mirth.connect.client.ui.panels.export.MessageExportPanel.java
private void browseSelected() { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (userPreferences != null) { File currentDir = new File(userPreferences.get("currentDirectory", "")); if (currentDir.exists()) { chooser.setCurrentDirectory(currentDir); }// w w w . java 2s . co m } if (chooser.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) { if (userPreferences != null) { userPreferences.put("currentDirectory", chooser.getCurrentDirectory().getPath()); } rootPathTextField.setText(chooser.getSelectedFile().getAbsolutePath()); } }
From source file:edu.ku.brc.specify.tools.LocalizerSearchHelper.java
/** * @param baseDir//from w w w. j av a 2 s . c o m * @return */ public Vector<Pair<String, String>> findOldL10NKeys(final String[] fileNames) { initLucene(true); //if (srcCodeFilesDir == null) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (srcCodeFilesDir != null) { chooser.setSelectedFile(new File(FilenameUtils.getName(srcCodeFilesDir.getAbsolutePath()))); chooser.setSelectedFile(new File(srcCodeFilesDir.getParent())); } if (chooser.showOpenDialog(UIRegistry.getMostRecentWindow()) == JFileChooser.APPROVE_OPTION) { srcCodeFilesDir = new File(chooser.getSelectedFile().getAbsolutePath()); } else { return null; } } indexSourceFiles(); Vector<Pair<String, String>> fullNotFoundList = new Vector<Pair<String, String>>(); try { ConversionLogger convLogger = new ConversionLogger(); convLogger.initialize("resources", "Resources"); for (String fileName : fileNames) { Vector<Pair<String, String>> notFoundList = new Vector<Pair<String, String>>(); Vector<String> terms = new Vector<String>(); String propFileName = baseDir.getAbsolutePath() + "/" + fileName; File resFile = new File(propFileName + ".properties"); if (resFile.exists()) { List<?> lines = FileUtils.readLines(resFile); for (String line : (List<String>) lines) { if (!line.startsWith("#")) { int inx = line.indexOf("="); if (inx > -1) { String[] toks = StringUtils.split(line, "="); if (toks.length > 1) { terms.add(toks[0]); } } } } } else { System.err.println("Doesn't exist: " + resFile.getAbsolutePath()); } String field = "contents"; QueryParser parser = new QueryParser(Version.LUCENE_36, field, analyzer); for (String term : terms) { Query query; try { if (term.equals("AND") || term.equals("OR")) continue; query = parser.parse(term); String subTerm = null; int hits = getTotalHits(query, 10); if (hits == 0) { int inx = term.indexOf('.'); if (inx > -1) { subTerm = term.substring(inx + 1); hits = getTotalHits(parser.parse(subTerm), 10); if (hits == 0) { int lastInx = term.lastIndexOf('.'); if (lastInx > -1 && lastInx != inx) { subTerm = term.substring(lastInx + 1); hits = getTotalHits(parser.parse(subTerm), 10); } } } } if (hits == 0 && !term.endsWith("_desc")) { notFoundList.add(new Pair<String, String>(term, subTerm)); log.debug("'" + term + "' was not found " + (subTerm != null ? ("SubTerm[" + subTerm + "]") : "")); } } catch (ParseException e) { e.printStackTrace(); } } String fullName = propFileName + ".html"; TableWriter tblWriter = convLogger.getWriter(FilenameUtils.getName(fullName), propFileName); tblWriter.startTable(); tblWriter.logHdr("Id", "Full Key", "Sub Key"); int cnt = 1; for (Pair<String, String> pair : notFoundList) { tblWriter.log(Integer.toString(cnt++), pair.first, pair.second != null ? pair.second : " "); } tblWriter.endTable(); fullNotFoundList.addAll(notFoundList); if (notFoundList.size() > 0 && resFile.exists()) { List<String> lines = (List<String>) FileUtils.readLines(resFile); Vector<String> linesCache = new Vector<String>(); for (Pair<String, String> p : notFoundList) { linesCache.clear(); linesCache.addAll(lines); int lineInx = 0; for (String line : linesCache) { if (!line.startsWith("#")) { int inx = line.indexOf("="); if (inx > -1) { String[] toks = StringUtils.split(line, "="); if (toks.length > 1) { if (toks[0].equals(p.first)) { lines.remove(lineInx); break; } } } } lineInx++; } } FileUtils.writeLines(resFile, linesCache); } } convLogger.closeAll(); } catch (IOException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(LocalizerSearchHelper.class, ex); ex.printStackTrace(); } return fullNotFoundList; }
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
public void fileSaveSpj(SpinCADBank bank) { // Create a file chooser String savedPath = prefs.get("MRUSpjFolder", ""); String[] spnFileNames = new String[8]; final JFileChooser fc = new JFileChooser(savedPath); // In response to a button click: FileNameExtensionFilter filter = new FileNameExtensionFilter("Spin Project Files", "spj"); fc.setFileFilter(filter);/*from ww w. j av a2s . co m*/ // XXX debug fc.showSaveDialog(new JFrame()); File fileToBeSaved = fc.getSelectedFile(); if (!fc.getSelectedFile().getAbsolutePath().endsWith(".spj")) { fileToBeSaved = new File(fc.getSelectedFile() + ".spj"); } int n = JOptionPane.YES_OPTION; if (fileToBeSaved.exists()) { JFrame frame1 = new JFrame(); n = JOptionPane.showConfirmDialog(frame1, "Would you like to overwrite it?", "File already exists!", JOptionPane.YES_NO_OPTION); } if (n == JOptionPane.YES_OPTION) { // filePath points at the desired Spj file String filePath = fileToBeSaved.getPath(); String folder = fileToBeSaved.getParent().toString(); // export the individual SPN files for (int i = 0; i < 8; i++) { try { String asmFileNameRoot = FilenameUtils.removeExtension(bank.patch[i].patchFileName); String asmFileName = folder + "\\" + asmFileNameRoot + ".spn"; if (bank.patch[i].patchFileName != "Untitled") { fileSaveAsm(bank.patch[i], asmFileName); spnFileNames[i] = asmFileName; } } catch (IOException e) { JOptionPane.showOptionDialog(null, "File save error!", "Error", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); e.printStackTrace(); } finally { } } // now create the Spin Project file fileToBeSaved.delete(); BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(fileToBeSaved, true)); } catch (IOException e1) { e1.printStackTrace(); } try { writer.write("NUMDOCS:8"); writer.newLine(); } catch (IOException e1) { e1.printStackTrace(); } for (int i = 0; i < 8; i++) { try { if (bank.patch[i].patchFileName != "Untitled") { writer.write(spnFileNames[i] + ",1"); } else { writer.write(",0"); } writer.newLine(); } catch (IOException e) { JOptionPane.showOptionDialog(null, "File save error!\n" + filePath, "Error", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); e.printStackTrace(); } } // write the build flags try { writer.write(",1,1,1"); writer.newLine(); } catch (IOException e1) { e1.printStackTrace(); } try { writer.close(); } catch (IOException e) { e.printStackTrace(); } saveMRUSpjFolder(filePath); } }
From source file:controller.CCInstance.java
private String userLoadLibraryPKCS11() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(Bundle.getBundle().getString("openLibrary")); int userSelection = fileChooser.showSaveDialog(null); if (userSelection == JFileChooser.APPROVE_OPTION) { String dest = fileChooser.getSelectedFile().getAbsolutePath(); File file = new File(dest); if (file.exists()) { return dest; }/*from w w w .ja v a2 s . c o m*/ } return null; }