List of usage examples for javax.swing JFileChooser APPROVE_OPTION
int APPROVE_OPTION
To view the source code for javax.swing JFileChooser APPROVE_OPTION.
Click Source Link
From source file:de.dfki.owlsmx.gui.ResultVisualization.java
private void saveActionPerformed(java.awt.event.ActionEvent event) {//GEN-FIRST:event_saveActionPerformed try {//from w w w . jav a2 s .co m if (event.getSource().equals(save)) { if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { if (fc.getFileFilter().getClass().equals((new PNGFilter()).getClass())) if (fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".png")) ChartUtilities.saveChartAsPNG(fc.getSelectedFile(), chart, graphPrintWidth, graphPrintHeight); else ChartUtilities.saveChartAsPNG(new File(fc.getSelectedFile().getAbsolutePath() + ".png"), chart, graphPrintWidth, graphPrintHeight); else if (fc.getFileFilter().getClass().equals((new JPGFilter()).getClass())) if (fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".png")) ChartUtilities.saveChartAsJPEG(fc.getSelectedFile(), chart, graphPrintWidth, graphPrintHeight); else ChartUtilities.saveChartAsJPEG( new File(fc.getSelectedFile().getAbsolutePath() + ".png"), chart, graphPrintWidth, graphPrintHeight); else if (fc.getFileFilter().getClass().equals((new PDFFilter()).getClass())) if (fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".pdf")) Converter.convertToPdf(chart, graphPrintWidth, graphPrintHeight, fc.getSelectedFile().getAbsolutePath()); else Converter.convertToPdf(chart, graphPrintWidth, graphPrintHeight, fc.getSelectedFile().getAbsolutePath() + ".pdf"); else if (fc.getFileFilter().getClass().equals((new EPSFilter()).getClass())) printGraphics2DtoEPS(fc.getSelectedFile().getAbsolutePath()); } } } catch (Exception e) { GUIState.displayWarning(e.getClass().toString(), "Couldn't save file " + fc.getSelectedFile().getAbsolutePath()); e.printStackTrace(); } }
From source file:au.org.ala.delta.editor.ui.ImageDetailsPanel.java
private File getMediaFile(FileFilter filter) { String imagePath = _dataSet.getImagePath(); JFileChooser chooser = new JFileChooser(imagePath); chooser.setFileFilter(filter);/*from w ww .j a va2 s . c o m*/ if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File imageFile = chooser.getSelectedFile(); ImageSettings settings = _dataSet.getImageSettings(); if (settings.isOnResourcePath(imageFile)) { String name = imageFile.getName(); boolean exists = false; if (_selectedImage != null) { List<ImageOverlay> existingSounds = _selectedImage.getSounds(); for (ImageOverlay sound : existingSounds) { if (name.equals(sound.overlayText)) { exists = true; break; } } } if (exists) { int result = _messageHelper.confirmDuplicateFileName(); if (result == JOptionPane.YES_OPTION) { imageFile = new File(imageFile.getAbsolutePath()); } else if (result == JOptionPane.NO_OPTION) { return getMediaFile(filter); } else { imageFile = null; } } else { // Turn the file into a relative one. imageFile = new File(name); } } else { // Ask about it or copy it to the image path. int result = _messageHelper.confirmNotOnImagePath(); if (result == JOptionPane.YES_OPTION) { imageFile = new File(imageFile.getAbsolutePath()); } else if (result == JOptionPane.NO_OPTION) { return getMediaFile(filter); } else { imageFile = null; } } return imageFile; } return null; }
From source file:cs.cirg.cida.CIDAView.java
@Action public void exportSynopsisTable() { JFileChooser chooser = new JFileChooser(experimentController.getDataDirectory()); //model.getActiveExperiment().getName() + ".csv" chooser.setSelectedFile(new File(CIDAConstants.DEFAULT_TABLE_NAME)); int returnVal = chooser.showOpenDialog(this.getComponent()); if (returnVal == JFileChooser.APPROVE_OPTION) { experimentController.exportSynopsisTable(chooser.getSelectedFile()); }/*from w w w. j av a 2 s.co m*/ }
From source file:is.iclt.jcorpald.CorpaldView.java
private void doSaveAs() { int returnVal = queryChooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = queryChooser.getSelectedFile(); controller.saveQueryAs(file);/*from w ww . j a v a2 s .c o m*/ } }
From source file:org.nekorp.workflow.desktop.view.AppLayoutView.java
private void reporteGlobalButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reporteGlobalButtonActionPerformed try {/*from www . jav a 2s.c om*/ 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:dylemator.UserResultList.java
private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed if (this.filenameCombo.getSelectedIndex() == 0) return;/*ww w . j a v a2 s . c om*/ String sheetName = (String) this.filenameCombo.getSelectedItem(); Workbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet(sheetName); Row headerRow = sheet.createRow(0); String[] headers = exportData.get(0); int numOfColumns = headers.length; for (int i = 0, j = 0; i < numOfColumns; i++) { if (i == 1 || i == 2 || i == 3) // opuszcz. date, imie, nazwisko continue; Cell cell = headerRow.createCell(j++); cell.setCellValue(headers[i]); } int rowCount = exportData.size(); for (int rownum = 1; rownum < rowCount; rownum++) { Row row = sheet.createRow(rownum); String[] values = exportData.get(rownum); for (int i = 0, j = 0; i < numOfColumns; i++) { if (i == 1 || i == 2 || i == 3) // opuszcz. date, imie, nazwisko continue; Cell cell = row.createCell(j++); cell.setCellValue(values[i]); } } String defaultFilename = "Export.xlsx"; JFileChooser f = new JFileChooser(System.getProperty("user.dir")); f.setSelectedFile(new File(defaultFilename)); f.setDialogTitle("Wybierz nazw dla pliku eksportu"); f.setFileSelectionMode(JFileChooser.FILES_ONLY); FileFilter ff = new FileFilter() { @Override public boolean accept(File file) { if (file.getName().endsWith(".xlsx")) return true; return false; } @Override public String getDescription() { return ""; } }; f.setFileFilter(ff); File file = null; int save = f.showSaveDialog(this); if (save == JFileChooser.APPROVE_OPTION) file = f.getSelectedFile(); else return; FileOutputStream out; try { out = new FileOutputStream(file); wb.write(out); out.close(); } catch (FileNotFoundException ex) { Logger.getLogger(UserResultList.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(UserResultList.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:licorice.gui.MainPanel.java
private void fileDialogBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileDialogBtnActionPerformed int ret = fc.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { try {/*from w w w .j a va 2 s .c om*/ File file = fc.getSelectedFile(); log.info("Opening: " + file.getName() + "."); fileNameField.setText(file.getCanonicalPath()); } catch (IOException ex) { log.error(ex.getMessage()); ex.printStackTrace(); } } }
From source file:ec.util.chart.swing.Charts.java
public static void saveChart(@Nonnull ChartPanel chartPanel) throws IOException { JFileChooser fileChooser = new JFileChooser(); FileFilter defaultFilter = new FileNameExtensionFilter("PNG (.png)", "png"); fileChooser.addChoosableFileFilter(defaultFilter); fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("JPG (.jpg) (.jpeg)", "jpg", "jpeg")); if (Charts.canWriteChartAsSVG()) { fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("SVG (.svg)", "svg")); fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Compressed SVG (.svgz)", "svgz")); }/*from w ww . ja va 2s.c o m*/ fileChooser.setFileFilter(defaultFilter); File currentDir = chartPanel.getDefaultDirectoryForSaveAs(); if (currentDir != null) { fileChooser.setCurrentDirectory(currentDir); } if (fileChooser.showSaveDialog(chartPanel) == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); try (OutputStream stream = Files.newOutputStream(file.toPath())) { writeChart(getMediaType(file), stream, chartPanel.getChart(), chartPanel.getWidth(), chartPanel.getHeight()); } chartPanel.setDefaultDirectoryForSaveAs(fileChooser.getCurrentDirectory()); } }
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);/*from w ww . ja va2 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(); } }