List of usage examples for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter
public FileNameExtensionFilter(String description, String... extensions)
From source file:de.stefanwndelmann.zy1270logger.ZY1270LoggerMain.java
private void saveCSVButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveCSVButtonActionPerformed // TODO add your handling code here: String data = getCSVData();// ww w .j ava 2 s. c o m JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter("CSV Files", "csv")); int retrival = chooser.showSaveDialog(null); if (retrival == JFileChooser.APPROVE_OPTION) { try (FileWriter fw = new FileWriter(chooser.getSelectedFile() + ".csv")) { fw.write(data); } catch (IOException ex) { Logger.getLogger(ZY1270LoggerMain.class.getName()).log(Level.SEVERE, null, ex); } } }
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")); }//w ww. ja v a 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:org.nekorp.workflow.desktop.view.AppLayoutView.java
private void reporteGlobalButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reporteGlobalButtonActionPerformed try {/*from www .j ava2 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:fi.marketing.list.ui.DashboardUI.java
private void openAFileChooser() { FileFilter ft = new FileNameExtensionFilter("Text Files", "txt"); db.addChoosableFileFilter(ft);//from w w w. j ava2 s . co m int returnVal = db.showOpenDialog(this); if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) { java.io.File file = db.getSelectedFile(); if (file.isFile()) { String file_name = file.toString(); //InputStream is = getClass().getClassLoader().getResourceAsStream(file_name); //FileReader just = oper.fileReaderInputStream(is); String name = FilenameUtils.getName(file_name); jTextField1.setText(name); } } }
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 w w . ja v a 2s . c om*/ 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:net.sf.mzmine.chartbasics.gui.swing.EChartPanel.java
/** * Opens a file chooser and gives the user an opportunity to save the chart in PNG format. * * @throws IOException if there is an I/O error. *//*from ww w . j a v a2 s . co m*/ @Override public void doSaveAs() throws IOException { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(this.getDefaultDirectoryForSaveAs()); FileNameExtensionFilter filter = new FileNameExtensionFilter( localizationResources.getString("PNG_Image_Files"), "png"); fileChooser.addChoosableFileFilter(filter); fileChooser.setFileFilter(filter); int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String filename = fileChooser.getSelectedFile().getPath(); if (isEnforceFileExtensions()) { if (!filename.endsWith(".png")) { filename = filename + ".png"; } } ChartUtils.saveChartAsPNG(new File(filename), getChart(), getWidth(), getHeight(), getChartRenderingInfo()); } }
From source file:com.josue.tileset.editor.Editor.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("Image file", "png")); fileDialog.showOpenDialog(null);/*www.ja va2 s . c om*/ inputFile = fileDialog.getSelectedFile(); if (inputFile != null) { loadFile(inputFile); } }
From source file:org.nekorp.workflow.desktop.view.CostoServicioView.java
private void generarReporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generarReporteActionPerformed try {/* w w w . j a v a 2 s . c o 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:com.holycityaudio.SpinCAD.SpinCADFile.java
public void fileSaveAsm(SpinCADPatch patch) { // Create a file chooser String savedPath = prefs.get("MRUSpnFolder", ""); final JFileChooser fc = new JFileChooser(savedPath); // In response to a button click: FileNameExtensionFilter filter = new FileNameExtensionFilter("Spin ASM Files", "spn"); fc.setFileFilter(filter);//from ww w .ja va 2s. c om // XXX DEBUG fc.showSaveDialog(new JFrame()); File fileToBeSaved = fc.getSelectedFile(); if (!fc.getSelectedFile().getAbsolutePath().endsWith(".spn")) { fileToBeSaved = new File(fc.getSelectedFile() + ".spn"); } 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) { String filePath = fileToBeSaved.getPath(); fileToBeSaved.delete(); try { fileSaveAsm(patch, filePath); } catch (IOException e) { JOptionPane.showOptionDialog(null, "File save error!", "Error", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); e.printStackTrace(); } saveMRUSpnFolder(filePath); } }
From source file:generadorqr.jifrNuevoQr.java
void CargarImagen(JLabel label, Integer identificador) { int resultado; // ventana = new CargarFoto(); JFileChooser jfchCargarfoto = new JFileChooser(); FileNameExtensionFilter filtro = new FileNameExtensionFilter("JPG", "jpg"); jfchCargarfoto.setFileFilter(filtro); resultado = jfchCargarfoto.showOpenDialog(null); if (JFileChooser.APPROVE_OPTION == resultado) { fichero = jfchCargarfoto.getSelectedFile(); try {//from www. j a v a 2s . c o m tempImagen[identificador] = fichero.getPath(); tempNombreArchivo[identificador] = fichero.getName(); ImageIcon icon = new ImageIcon(fichero.toString()); Icon icono = new ImageIcon(icon.getImage().getScaledInstance(label.getWidth(), label.getHeight(), Image.SCALE_DEFAULT)); label.setText(null); label.setIcon(icono); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Error abriendo la imagen" + ex); } } }