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:ch.tatool.app.export.FileDataExporter.java
private String getStorageDirectory(Component parentFrame) { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileFilter() { @Override/*ww w . j av a 2 s . co m*/ public String getDescription() { return "CSV (*.csv)"; } @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } String extension = getExtension(f); if (extension != null) { if (extension.equals("csv")) { return true; } else { return false; } } return false; } }); chooser.setAcceptAllFileFilterUsed(false); // chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); int returnVal = chooser.showSaveDialog(parentFrame); if (returnVal == JFileChooser.APPROVE_OPTION) { File f = chooser.getSelectedFile(); String filename = ""; if (f == null) { throw new RuntimeException(); } String extension = getExtension(f); if (extension == null || !getExtension(f).equals("csv")) { filename = f + ".csv"; } else { filename = f.getPath(); } return filename; } else { return null; } }
From source file:CompareFiles.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: String userDir = System.getProperty("user.home"); JFileChooser folder = new JFileChooser(userDir + "/Desktop"); // folder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); folder.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Excel Files (*.xls)", "xls"); folder.setFileFilter(xmlfilter);// ww w . ja v a2 s . com int returnvalue = folder.showSaveDialog(this); File myfolder = null; if (returnvalue == JFileChooser.APPROVE_OPTION) { myfolder = folder.getSelectedFile(); // System.out.println(myfolder); } if (myfolder != null) { JOptionPane.showMessageDialog(null, "The current choosen file directory is : " + myfolder); jLabel2.setText(myfolder.toString()); } }
From source file:de.codesourcery.jasm16.ide.ui.views.EmulationOptionsView.java
public EmulationOptionsView() { emulatorPanel.setLayout(new GridBagLayout()); GridBagConstraints cnstrs = constraints(0, 0, false, false, GridBagConstraints.NONE); emulatorPanel.add(new JLabel("Emulation speed"), cnstrs); cnstrs = constraints(1, 0, true, true, GridBagConstraints.NONE); cnstrs.anchor = GridBagConstraints.WEST; emulatorPanel.setBorder(BorderFactory.createTitledBorder("General options")); speedBox.setRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(javax.swing.JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { final java.awt.Component result = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);//from ww w . j av a2 s. c o m if (value != null) { switch ((EmulationSpeed) value) { case MAX_SPEED: setText("Max."); break; case REAL_SPEED: setText("100 kHz"); break; default: setText(value.toString()); break; } } return result; }; }); emulatorPanel.add(speedBox, cnstrs); // disk drive panel selectedFileField.setColumns(25); diskDrivePanel.setLayout(new GridBagLayout()); cnstrs = constraints(0, 0, false, true, GridBagConstraints.NONE); cnstrs.anchor = GridBagConstraints.CENTER; diskDrivePanel.setBorder(BorderFactory.createTitledBorder("Disk drive")); diskDrivePanel.add(selectedFileField, cnstrs); cnstrs = constraints(1, 0, false, true, GridBagConstraints.NONE); cnstrs.anchor = GridBagConstraints.CENTER; diskDrivePanel.add(fileChooserButton, cnstrs); fileChooserButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JFileChooser chooser; if (getSelectedFile() != null) { chooser = new JFileChooser(getSelectedFile().getParentFile()); } else { chooser = new JFileChooser(); } final int result = chooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION && chooser.getSelectedFile().isFile()) { selectedFileField.setText(chooser.getSelectedFile().getAbsolutePath()); } } }); cnstrs = constraints(2, 0, false, true, GridBagConstraints.NONE); cnstrs.anchor = GridBagConstraints.CENTER; diskDrivePanel.add(writeProtected, cnstrs); }
From source file:com.sciaps.utils.Util.java
public static void saveCSVFile(StringBuilder strBuilder) { JFileChooser chooser = new JFileChooser(); int retrival = chooser.showSaveDialog(Constants.MAIN_FRAME); if (retrival == JFileChooser.APPROVE_OPTION) { ProgressStatusPanel progressbar = new ProgressStatusPanel(); final CustomDialog progressDialog = new CustomDialog(Constants.MAIN_FRAME, "Exporting CSV file", progressbar, CustomDialog.NONE_OPTION); progressDialog.setSize(400, 100); SwingUtilities.invokeLater(new Runnable() { @Override//w ww .j a v a 2s.c om public void run() { progressDialog.setVisible(true); } }); try { String fileName = chooser.getSelectedFile().toString(); if (!fileName.endsWith(".csv") && !fileName.endsWith(".CSV")) { fileName = fileName + ".csv"; } FileWriter fw = new FileWriter(fileName); BufferedWriter bw = new BufferedWriter(fw); bw.write(strBuilder.toString()); bw.close(); } catch (Exception ex) { ex.printStackTrace(); System.out.println(ex.getMessage()); } progressDialog.dispose(); } }
From source file:com.mirth.connect.client.ui.MessageImportDialog.java
private void browseSelected() { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); if (userPreferences != null) { File currentDir = new File(userPreferences.get("currentDirectory", "")); if (currentDir.exists()) { chooser.setCurrentDirectory(currentDir); }/*w ww . j a va 2 s.c o m*/ } if (chooser.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) { if (userPreferences != null) { userPreferences.put("currentDirectory", chooser.getCurrentDirectory().getPath()); } fileTextField.setText(chooser.getSelectedFile().getAbsolutePath()); } }
From source file:ch.randelshofer.cubetwister.PreferencesTemplatesPanel.java
private void exportInternalTemplate(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportInternalTemplate if (exportFileChooser == null) { exportFileChooser = new JFileChooser(); exportFileChooser.setFileFilter(new ExtensionFileFilter("zip", "Zip Archive")); exportFileChooser.setSelectedFile( new File(userPrefs.get("cubetwister.exportedHTMLTemplate", "CubeTwister HTML-Template.zip"))); exportFileChooser.setApproveButtonText(labels.getString("filechooser.export")); }/*from ww w . j a va 2 s.c o m*/ if (JFileChooser.APPROVE_OPTION == exportFileChooser.showSaveDialog(this)) { userPrefs.put("cubetwister.exportedHTMLTemplate", exportFileChooser.getSelectedFile().getPath()); final File target = exportFileChooser.getSelectedFile(); new BackgroundTask() { @Override public void construct() throws IOException { if (!target.getParentFile().exists()) { target.getParentFile().mkdirs(); } InputStream in = null; OutputStream out = null; try { in = getClass().getResourceAsStream("/htmltemplates.tar.bz"); out = new FileOutputStream(target); exportTarBZasZip(in, out); } finally { try { if (in != null) { in.close(); } } finally { if (out != null) { out.close(); } } } } private void exportTarBZasZip(InputStream in, OutputStream out) throws IOException { ZipOutputStream zout = new ZipOutputStream(out); TarInputStream tin = new TarInputStream(new BZip2CompressorInputStream(in)); for (TarArchiveEntry inEntry = tin.getNextEntry(); inEntry != null;) { ZipEntry outEntry = new ZipEntry(inEntry.getName()); zout.putNextEntry(outEntry); if (!inEntry.isDirectory()) { Files.copyStream(tin, zout); } zout.closeEntry(); } zout.finish(); } }.start(); } }
From source file:org.cytoscape.dyn.internal.graphMetrics.GraphMetricsResultsPanel.java
/** * // w ww . j ava 2s . co m */ public void saveData() { JFileChooser saveFileDialog = new JFileChooser(); int save = saveFileDialog.showSaveDialog(null); if (save == JFileChooser.APPROVE_OPTION) { FileWriter writer = null; try { File file = saveFileDialog.getSelectedFile(); if (file.exists()) { if (JOptionPane.showConfirmDialog(null, "The specified file already exists. Do you want to overwrite it?", "Warning - File Exists", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { writer = new FileWriter(file); for (int i = 0; i < this.dataset.getSeriesCount(); i++) { writer.write(this.dataset.getSeries(i).getKey().toString() + "\n"); for (int j = 0; j < this.dataset.getSeries(i).getItemCount(); j++) { writer.write(this.dataset.getSeries(i).getDataItem(j).toString() + "\n"); } } } } else { writer = new FileWriter(file); for (int i = 0; i < this.dataset.getSeriesCount(); i++) { writer.write(this.dataset.getSeries(i).getKey().toString() + "\n"); for (int j = 0; j < this.dataset.getSeries(i).getItemCount(); j++) { writer.write(this.dataset.getSeries(i).getDataItem(j).toString() + "\n"); } } } } catch (Exception e) { e.printStackTrace(); } try { writer.flush(); writer.close(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.LoadGenericDRDataController.java
/** * Private methods/*from w ww . ja va 2s . c om*/ */ //init view private void initDataLoadingPanel() { dataLoadingPanel = new DRDataLoadingPanel(); /** * Action Listeners. */ //Popup file selector and import and parse the file dataLoadingPanel.getChooseFileButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Open a JFile Chooser JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle( "Choose a tabular file (XLS, XLSX, CSV, TSV) for the import of the experiment"); // to select only appropriate files fileChooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } int index = f.getName().lastIndexOf("."); String extension = f.getName().substring(index + 1); return extension.equals("xls") || extension.equals("xlsx") || extension.equals("csv") || extension.equals("tsv"); } @Override public String getDescription() { return (".xls, .xlsx, .csv and .tsv files"); } }); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setAcceptAllFileFilterUsed(false); // in response to the button click, show open dialog int returnVal = fileChooser.showOpenDialog(dataLoadingPanel); if (returnVal == JFileChooser.APPROVE_OPTION) { File chosenFile = fileChooser.getSelectedFile(); // // create and execute a new swing worker with the selected file for the import // ImportExperimentSwingWorker importExperimentSwingWorker = new ImportExperimentSwingWorker(chosenFile); // importExperimentSwingWorker.execute(); parseDRFile(chosenFile); if (doseResponseController.getImportedDRDataHolder().getDoseResponseData() != null) { dataLoadingPanel.getFileLabel().setText(chosenFile.getAbsolutePath()); doseResponseController.getGenericDRParentPanel().getNextButton().setEnabled(true); } } else { JOptionPane.showMessageDialog(dataLoadingPanel, "Command cancelled by user", "", JOptionPane.INFORMATION_MESSAGE); } } }); dataLoadingPanel.getLogTransformCheckBox().addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { doseResponseController.setLogTransform(true); } else { doseResponseController.setLogTransform(false); } } }); }
From source file:com.github.rholder.gradle.ui.DependencyViewerStandalone.java
private void promptForGradleBaseDir() { JFileChooser c = new JFileChooser(); c.setDialogTitle(// w w w. j a v a2 s . c o m "Pick the top level directory to use when viewing dependencies (in case you have a multi-module project)"); c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = c.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { gradleBaseDir = c.getSelectedFile().getPath(); } }
From source file:SaveImage.java
public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox) e.getSource(); if (cb.getActionCommand().equals("SetFilter")) { setOpIndex(cb.getSelectedIndex()); repaint();//from ww w . ja v a2 s. c o m } else if (cb.getActionCommand().equals("Formats")) { /* * Save the filtered image in the selected format. The selected item will * be the name of the format to use */ String format = (String) cb.getSelectedItem(); /* * Use the format name to initialise the file suffix. Format names * typically correspond to suffixes */ File saveFile = new File("savedimage." + format); JFileChooser chooser = new JFileChooser(); chooser.setSelectedFile(saveFile); int rval = chooser.showSaveDialog(cb); if (rval == JFileChooser.APPROVE_OPTION) { saveFile = chooser.getSelectedFile(); /* * Write the filtered image in the selected format, to the file chosen * by the user. */ try { ImageIO.write(biFiltered, format, saveFile); } catch (IOException ex) { } } } }