List of usage examples for javax.swing JFileChooser showSaveDialog
public int showSaveDialog(Component parent) throws HeadlessException
From source file:com.igormaznitsa.jhexed.swing.editor.ui.dialogs.hexeditors.DialogEditSVGImageValue.java
private void buttonSaveAsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveAsActionPerformed final JFileChooser dlg = new JFileChooser(); dlg.addChoosableFileFilter(new FileFilter() { @Override//from w w w .ja va 2 s . co m public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase(Locale.ENGLISH).endsWith(".svg"); } @Override public String getDescription() { return "SVG files (*.svg)"; } }); if (dlg.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File file = dlg.getSelectedFile(); if (FilenameUtils.getExtension(file.getName()).isEmpty()) { file = new File(file.getParentFile(), file.getName() + ".svg"); } if (file.exists() && JOptionPane.showConfirmDialog(this.parent, "Overwrite file '" + file.getAbsolutePath() + "\'?", "Overwriting", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) { return; } try { FileUtils.writeByteArrayToFile(file, this.value.getImage().getImageData()); } catch (IOException ex) { Log.error("Can't write image [" + file + ']', ex); JOptionPane.showMessageDialog(this, "Can't save the file for error!", "IO Error", JOptionPane.ERROR_MESSAGE); } } }
From source file:edu.ku.brc.specify.tasks.AttachmentsTask.java
/** * //from w w w . java2s. co m */ private void exportAttachment(final CommandAction cmdAction) { exportFile = null; Object data = cmdAction.getData(); if (data instanceof ImageDataItem) { ImageDataItem idi = (ImageDataItem) data; System.out.println(idi.getImgName()); String origFilePath = BasicSQLUtils.querySingleObj( "SELECT OrigFilename FROM attachment WHERE AttachmentID = " + idi.getAttachmentId()); if (StringUtils.isNotEmpty(origFilePath)) { origFilePath = FilenameUtils.getName(origFilePath); } else { origFilePath = idi.getTitle(); } String usrHome = System.getProperty("user.home"); JFileChooser dlg = new JFileChooser(usrHome); dlg.setSelectedFile(new File(origFilePath)); int rv = dlg.showSaveDialog((Frame) UIRegistry.getTopWindow()); if (rv == JFileChooser.APPROVE_OPTION) { File file = dlg.getSelectedFile(); if (file != null) { String fullPath = file.getAbsolutePath(); String oldExt = FilenameUtils.getExtension(origFilePath); String newExt = FilenameUtils.getExtension(fullPath); if (StringUtils.isEmpty(newExt) && StringUtils.isNotEmpty(oldExt)) { fullPath += "." + oldExt; exportFile = new File(fullPath); } else { exportFile = file; } boolean isOK = true; if (exportFile.exists()) { isOK = UIRegistry.displayConfirmLocalized("ATTCH.FILE_EXISTS", "ATTCH.REPLACE_MSG", "ATTCH.REPLACE", "CANCEL", JOptionPane.QUESTION_MESSAGE); } if (isOK) { ImageLoader loader = new ImageLoader(idi.getImgName(), idi.getMimeType(), true, -1, this); ImageLoaderExector.getInstance().loadImage(loader); } } System.out.println(file.toPath()); } } }
From source file:gui.QTLResultsPanel.java
void saveTXT() { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(Prefs.gui_dir)); fc.setDialogTitle("Save QTL Results"); while (fc.showSaveDialog(MsgBox.frm) == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // Make sure it has an appropriate extension if (!file.exists()) { if (file.getName().indexOf(".") == -1) { file = new File(file.getPath() + ".csv"); }//from w w w .j a va 2 s .c o m } // Confirm overwrite if (file.exists()) { int response = MsgBox.yesnocan(file + " already exists.\nDo " + "you want to replace it?", 1); if (response == JOptionPane.NO_OPTION) { continue; } else if (response == JOptionPane.CANCEL_OPTION || response == JOptionPane.CLOSED_OPTION) { return; } } // Otherwise it's ok to save... Prefs.gui_dir = "" + fc.getCurrentDirectory(); saveTXTFile(file); return; } }
From source file:org.nekorp.workflow.desktop.view.AppLayoutView.java
private void reporteGlobalButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reporteGlobalButtonActionPerformed try {//from w w w .j a v a 2 s .c o m parametrosReporteGlobal.setFechaInicial(new Date()); parametrosReporteGlobal.setFechaFinal(new Date()); parametrosReporteGlobalDialogFactory.createDialog(mainFrame, true).setVisible(true); if (parametrosReporteGlobal.isEjecutar()) { 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-Global" + ".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)); ParametrosReporteGlobal param = new ParametrosReporteGlobal(); param.setDestination(chooser.getSelectedFile()); DateTime fechaInicial = new DateTime(parametrosReporteGlobal.getFechaInicial()); DateTime fechaFinal = new DateTime(parametrosReporteGlobal.getFechaFinal()); fechaFinal = new DateTime(fechaFinal.getYear(), fechaFinal.getMonthOfYear(), fechaFinal.getDayOfMonth(), fechaFinal.hourOfDay().getMaximumValue(), fechaFinal.minuteOfHour().getMaximumValue(), fechaFinal.secondOfMinute().getMaximumValue(), fechaFinal.millisOfSecond().getMaximumValue(), fechaFinal.getZone()); param.setFechaInicial(fechaInicial); param.setFechaFinal(fechaFinal); this.aplication.generaReporteGlobal(param); } } } catch (IOException ex) { AppLayoutView.LOGGER.error("Exploto al tratar de generar el reporte global", ex); } finally { this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); } }
From source file:com.ga.forms.DailyLogUI.java
private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed System.out.print(/* ww w . j ava 2s . com*/ "REGEX: " + monthCombo.getSelectedItem().toString() + "-" + yearCombo.getSelectedItem().toString()); JFrame fileChooserFrame = new JFrame(); JFileChooser saveFileDialog = new JFileChooser(); FileNameExtensionFilter fileExtentionFilter = new FileNameExtensionFilter("Comma Seperated Values (*.csv)", "csv"); saveFileDialog.setFileFilter(fileExtentionFilter); int saveFileDialogStatus = saveFileDialog.showSaveDialog(fileChooserFrame); if (saveFileDialogStatus == JFileChooser.APPROVE_OPTION) { String fileSaveDetails = saveFileDialog.getSelectedFile().toString(); args = new HashMap(); HashMap regex = new HashMap(); regex.put("$regex", monthCombo.getSelectedItem().toString() + "-" + yearCombo.getSelectedItem().toString()); args.put("date", regex); DailyLogRecord record = new DailyLogRecord(); ArrayList logs = record.retrieveRecord(args); String[] columnNames = new String[] { "Date", "Day", "In", "Out", "Break", "Duration", "Under-Time", "Over-Time" }; ArrayList data = null; if (!logs.isEmpty()) { data = new ArrayList(); data.add(String.join(",", columnNames)); for (int logIndex = 0; logIndex < logs.size(); logIndex++) { JSONObject logJSONOBject = new JSONObject((Map) logs.get(logIndex)); String csvRecord = logJSONOBject.get("date").toString() + "," + logJSONOBject.get("day").toString() + "," + logJSONOBject.get("check-in").toString() + "," + logJSONOBject.get("check-out").toString() + "," + logJSONOBject.get("break").toString() + "," + logJSONOBject.get("duration").toString() + "," + logJSONOBject.get("under-time").toString() + "," + logJSONOBject.get("over-time").toString(); data.add(csvRecord); } } DailyLogCSVExport csvExporter = new DailyLogCSVExport(); csvExporter.save(data, fileSaveDetails); } }
From source file:pl.dpbz.poid.zadanie3.GUI.java
private void savePhaseJButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_savePhaseJButton1ActionPerformed try {/* w ww . j a v a 2 s . c o m*/ // TODO zapis sekwencji na fazie do pliku JFileChooser fc = new JFileChooser(); fc.showSaveDialog(this); String path = fc.getSelectedFile().getAbsolutePath(); path += ".wav"; Integer[] ints = WaveToSamplesConverter.convertWaveToIntSamples(this.f); double samplingFrequency = WaveToSamplesConverter.getSamplingFrequency(this.f); System.out.println("Samples overview " + ints.length); int samplesPerPart = Integer.parseInt(this.samplesPerPartJTextField1.getText()); SamplesToWaveConverter conv = new PhaseSpaceSampleConverter(samplingFrequency, samplesPerPart, WaveToSamplesConverter.getAudioFormat(f)); conv.setupFrequenciesFromSamples(ints); System.out.println("Zapisuj"); conv.saveGeneratedSamples(path); } catch (IOException ex) { Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedAudioFileException ex) { Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:pl.dpbz.poid.zadanie3.GUI.java
private void saveCombJButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveCombJButton1ActionPerformed try {/*from w w w . ja v a2 s . co m*/ // TODO zapisz sekwencje na grzebieniu //Test sekwencji na grzebieniu JFileChooser fc = new JFileChooser(); fc.showSaveDialog(this); String path = fc.getSelectedFile().getAbsolutePath(); path += ".wav"; Integer[] ints = WaveToSamplesConverter.convertWaveToIntSamples(this.f); double samplingFrequency = WaveToSamplesConverter.getSamplingFrequency(this.f); System.out.println("Samples overview " + ints.length); int samplesPerPart = Integer.parseInt(this.samplesPerPartJTextField1.getText()); SamplesToWaveConverter conv2 = new CombFilteringSampleConverter(samplingFrequency, samplesPerPart, WaveToSamplesConverter.getAudioFormat(f)); conv2.setupFrequenciesFromSamples(ints); System.out.println("Zapisuj"); conv2.saveGeneratedSamples(path); } catch (IOException ex) { Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedAudioFileException ex) { Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.mycompany.zad1.MainWindow.java
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed JFileChooser chooser = new JFileChooser(); int dialogResult = chooser.showSaveDialog(this); if (dialogResult == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try {/*from w ww . ja va 2s .co m*/ imageInOut.saveImageToFile(imageBuff, file, "bmp"); } catch (Exception ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java
private void saveReferenceXML() { JFileChooser chooser = new JFileChooser( "Save as alignment xml format. YOUR EVALUATION WILL NOT BE SAVED, ONLY A COPY OF THE INPUT."); chooser.setCurrentDirectory(new File(".")); int returnVal = chooser.showSaveDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile().exists() && (JOptionPane.showConfirmDialog(frame, "File already exists. Overwrite?") != JOptionPane.YES_OPTION)) { return; }/*from ww w . j a v a 2s .co m*/ frame.saveReferenceXML(chooser.getSelectedFile(), true); } }
From source file:de.ep3.ftpc.controller.portal.CrawlerDownloadController.java
@Override public void mouseClicked(MouseEvent e) { CrawlerResultsItem.PreviewPanel previewPanel = (CrawlerResultsItem.PreviewPanel) e.getSource(); CrawlerResult crawlerResult = previewPanel.getCrawlerResult(); CrawlerFile crawlerFile = crawlerResult.getFile(); FTPClient ftpClient = crawlerResult.getFtpClient(); if (ftpClient.isConnected()) { JOptionPane.showMessageDialog(portalFrame, i18n.translate("crawlerDownloadWhileConnected"), null, JOptionPane.ERROR_MESSAGE); return;/*from w w w .j ava 2 s . c o m*/ } String fileExtension = crawlerFile.getExtension(); JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter chooserFilter = new FileNameExtensionFilter( i18n.translate("fileType", fileExtension.toUpperCase()), crawlerFile.getExtension()); chooser.setApproveButtonText(i18n.translate("buttonSave")); chooser.setDialogTitle(i18n.translate("fileDownloadTo")); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setFileFilter(chooserFilter); chooser.setSelectedFile(new File(crawlerFile.getName())); int selection = chooser.showSaveDialog(portalFrame); if (selection == JFileChooser.APPROVE_OPTION) { File fileToSave = chooser.getSelectedFile(); Server relatedServer = crawlerResult.getServer(); try { ftpClient.connect(relatedServer.need("server.ip"), Integer.parseInt(relatedServer.need("server.port"))); int replyCode = ftpClient.getReplyCode(); if (!FTPReply.isPositiveCompletion(replyCode)) { throw new IOException(i18n.translate("crawlerServerRefused")); } if (relatedServer.has("user.name")) { String userName = relatedServer.get("user.name"); String userPassword = ""; if (relatedServer.hasTemporary("user.password")) { userPassword = relatedServer.getTemporary("user.password"); } boolean loggedIn = ftpClient.login(userName, userPassword); if (!loggedIn) { throw new IOException(i18n.translate("crawlerServerAuthFail")); } } ftpClient.setFileType(FTP.BINARY_FILE_TYPE); /* Download file */ InputStream is = ftpClient.retrieveFileStream(crawlerFile.getFullName()); if (is != null) { byte[] rawFile = new byte[(int) crawlerFile.getSize()]; int i = 0; while (true) { int b = is.read(); if (b == -1) { break; } rawFile[i] = (byte) b; i++; /* Occasionally update the download progress */ if (i % 1024 == 0) { int progress = Math.round((((float) i) / crawlerFile.getSize()) * 100); status.add(i18n.translate("crawlerDownloadProgress", progress)); } } is.close(); is = null; if (!ftpClient.completePendingCommand()) { throw new IOException(); } Files.write(fileToSave.toPath(), rawFile); } /* Logout and disconnect */ ftpClient.logout(); tryDisconnect(ftpClient); status.add(i18n.translate("crawlerDownloadDone")); } catch (IOException ex) { tryDisconnect(ftpClient); JOptionPane.showMessageDialog(portalFrame, i18n.translate("crawlerDownloadFailed", ex.getMessage()), null, JOptionPane.ERROR_MESSAGE); } } }