List of usage examples for javax.swing JFileChooser setSelectedFile
@BeanProperty(preferred = true) public void setSelectedFile(File file)
From source file:com.smanempat.controller.ControllerClassification.java
public void saveResultFile(JYearChooser thnAjaran1, JYearChooser thnAjaran2, JTable tableResult) throws IOException { JFileChooser dirChooser = new JFileChooser(); dirChooser.setDialogTitle("Save as Excel File"); String thnAjaran = Integer.toString(thnAjaran1.getYear()) + "-" + Integer.toString(thnAjaran2.getYear()); String generateFileName = "Data Hasil Penjurusan Siswa Tahun Ajaran " + thnAjaran + ".xlsx"; dirChooser.setSelectedFile(new File(generateFileName)); int userSelection = dirChooser.showSaveDialog(null); int rowCountData = tableResult.getRowCount(); if (userSelection == dirChooser.APPROVE_OPTION) { File fileToSave = dirChooser.getSelectedFile(); convertToExcel(tableResult, fileToSave); JOptionPane.showMessageDialog(null, "Hasil klasifikasi jurusan berhasil disimpan", "Penyimpanan Berhasil", JOptionPane.INFORMATION_MESSAGE, new ImageIcon("src/com/smanempat/image/success.png")); }/*from ww w. j av a 2s. co m*/ }
From source file:edu.ku.brc.specify.tools.LocalizerSearchHelper.java
/** * @param baseDir/*from w ww . j a va2s.co 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.josue.tileset.editor.Editor.java
private void exportBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportBtnActionPerformed JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("Json file", "json")); String outputFileName = inputFile.getAbsolutePath().split("\\.")[0] + ".json"; fileDialog.setSelectedFile(new File(outputFileName)); if (fileDialog.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { File file = fileDialog.getSelectedFile(); ObjectMapper mapper = new ObjectMapper(); mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE); mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); try {//from w w w .j ava2 s . co m mapper.writeValue(file, loadedTiles); } catch (IOException ex) { Logger.getLogger(Editor.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.GenericDoseResponseController.java
/** * Ask user to choose for a directory and invoke swing worker for creating * PDF report/*from www . j a va 2s .c o m*/ * * @throws IOException */ protected void createPdfReport() throws IOException { // choose directory to save pdf file JFileChooser chooseDirectory = new JFileChooser(); chooseDirectory.setDialogTitle("Choose a directory to save the report"); chooseDirectory.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); // needs more information chooseDirectory.setSelectedFile( new File("Dose Response Report " + importedDRDataHolder.getExperimentNumber() + ".pdf")); // in response to the button click, show open dialog // TEST WHETHER THIS PARENT PANEL/FRAME IS OKAY int returnVal = chooseDirectory.showSaveDialog(cellMissyController.getCellMissyFrame()); if (returnVal == JFileChooser.APPROVE_OPTION) { File directory = chooseDirectory.getCurrentDirectory(); DoseResponseReportSwingWorker doseResponseReportSwingWorker = new DoseResponseReportSwingWorker( directory, chooseDirectory.getSelectedFile().getName()); doseResponseReportSwingWorker.execute(); } else { cellMissyController.showMessage("Open command cancelled by user", "", JOptionPane.INFORMATION_MESSAGE); } }
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 w w.jav a 2s . c o 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:net.sf.nmedit.nomad.core.Nomad.java
public void fileSave(boolean saveAs) { Document d = pageContainer.getSelection(); if (d == null) return;//from w ww . java2 s . com if (!saveAs) { Iterator<FileService> iter = ServiceRegistry.getServices(FileService.class); FileService useService = null; while (iter.hasNext()) { FileService fs = iter.next(); if (fs.isDirectSaveOperationSupported(d)) { useService = fs; break; } } if (useService != null) { useService.save(d, useService.getAssociatedFile(d)); return; } } JFileChooser chooser = new JFileChooser(); chooser.setSelectedFile(lastSaveInFolderLocation); chooser.setMultiSelectionEnabled(false); Iterator<FileService> iter = ServiceRegistry.getServices(FileService.class); while (iter.hasNext()) { FileService fs = iter.next(); boolean add = (saveAs && fs.isSaveOperationSupported(d)) || ((!saveAs) && fs.isDirectSaveOperationSupported(d)); if (add) chooser.addChoosableFileFilter(fs.getFileFilter()); } File sfile = d.getFile(); if (sfile == null && d.getTitle() != null) sfile = new File(d.getTitle()); if (sfile != null) chooser.setSelectedFile(sfile); if (!(chooser.showSaveDialog(mainWindow) == JFileChooser.APPROVE_OPTION)) return; FileService service = FileServiceTool.lookupFileService(chooser); if (service != null) { File newFile = chooser.getSelectedFile(); if (newFile == null) return; if (newFile.exists() && JOptionPane.showConfirmDialog(mainWindow, "Overwrite existing file '" + newFile.getAbsolutePath() + "' ?", "File already exists.", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) return; service.save(d, newFile); lastSaveInFolderLocation = newFile.getParentFile(); } else { JOptionPane.showMessageDialog(mainWindow, "Could not find service to save file."); } }
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
public void fileSavePatchAs(SpinCADPatch p) { // Create a file chooser String savedPath = prefs.get("MRUPatchFolder", ""); final JFileChooser fc = new JFileChooser(savedPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("SpinCAD Files", "spcd"); fc.setFileFilter(filter);//from w w w . j a v a 2 s . c o m fc.setSelectedFile(new File(p.patchFileName)); int returnVal = fc.showSaveDialog(new JFrame()); // need to process user canceling box right here if (returnVal == JFileChooser.APPROVE_OPTION) { // In response to a button click: File fileToBeSaved = fc.getSelectedFile(); if (!fileToBeSaved.getAbsolutePath().endsWith(".spcd")) { fileToBeSaved = new File(fc.getSelectedFile() + ".spcd"); } int n = JOptionPane.YES_OPTION; if (fileToBeSaved.exists()) { JFrame frame = new JFrame(); n = JOptionPane.showConfirmDialog(frame, "Would you like to overwrite it?", "File already exists!", JOptionPane.YES_NO_OPTION); } if (n == JOptionPane.YES_OPTION) { try { String filePath = fileToBeSaved.getPath(); String fileName = fileToBeSaved.getName(); p.patchFileName = fileName; fileSavePatch(p); recentPatchFileList.add(fileToBeSaved); saveMRUPatchFolder(filePath); } catch (Exception e) { // thrown over in SpinCADFile.java e.printStackTrace(); SpinCADDialogs.MessageBox("File save failed!", "look at stack trace for info"); } finally { p.setChanged(false); } } } }
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
public void fileSaveBankAs(SpinCADBank b) { // Create a file chooser String savedPath = prefs.get("MRUBankFolder", ""); final JFileChooser fc = new JFileChooser(savedPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("SpinCAD Bank Files", "spbk"); fc.setFileFilter(filter);// w w w .j av a 2 s . c o m fc.setSelectedFile(new File(b.bankFileName)); int returnVal = fc.showSaveDialog(new JFrame()); // need to process user canceling box right here if (returnVal == JFileChooser.APPROVE_OPTION) { // In response to a button click: File fileToBeSaved = fc.getSelectedFile(); if (!fc.getSelectedFile().getAbsolutePath().endsWith(".spbk")) { fileToBeSaved = new File(fc.getSelectedFile() + ".spbk"); } b.bankFileName = fileToBeSaved.getName(); int n = JOptionPane.YES_OPTION; if (fileToBeSaved.exists()) { JFrame frame = new JFrame(); n = JOptionPane.showConfirmDialog(frame, "Would you like to overwrite it?", "File already exists!", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { try { fileSaveBank(b); } finally { } } } else { fileSaveBank(b); } b.changed = false; recentBankFileList.add(fileToBeSaved); saveMRUBankFolder(fileToBeSaved.getPath()); b.bankFileName = fileToBeSaved.getName(); } }
From source file:com.t3.client.ui.ExportDialog.java
public void browseButtonAction() { JFileChooser chooser = new JFileChooser(); if (exportLocation instanceof LocalLocation) { chooser.setSelectedFile(((LocalLocation) exportLocation).getFile()); }/* w w w. j av a 2 s . c om*/ if (chooser.showOpenDialog(ExportDialog.this) == JFileChooser.APPROVE_OPTION) { interactPanel.setText("locationTextField", chooser.getSelectedFile().getAbsolutePath()); } }
From source file:uk.ac.lkl.cram.ui.ModuleFrame.java
private void exportReport() { JFileChooser jfc = new JFileChooser(); jfc.setAcceptAllFileFilterUsed(false); jfc.setDialogTitle("Export CRAM Module"); FileFilter filter = new FileNameExtensionFilter("Word Document", "docx"); jfc.setFileFilter(filter);/*from w w w. j a va2 s. c o m*/ jfc.setSelectedFile(new File(module.getModuleName() + ".docx")); //Open the dialog and wait for the user to provide a name for the file int returnVal = jfc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = jfc.getSelectedFile(); //Add the file extension if (!jfc.getSelectedFile().getAbsolutePath().endsWith(".docx")) { file = new File(jfc.getSelectedFile() + ".docx"); } try { this.setCursor(WAIT); Report report = new Report(module); report.save(file); } catch (Docx4JException ex) { LOGGER.log(Level.SEVERE, "Failed to export report", ex); JOptionPane.showMessageDialog(this, ex.getLocalizedMessage(), "Failed to export report", JOptionPane.ERROR_MESSAGE); } finally { this.setCursor(Cursor.getDefaultCursor()); } } }