List of usage examples for javax.swing JFileChooser getSelectedFile
public File getSelectedFile()
From source file:it.isislab.dmason.util.SystemManagement.Worker.WorkerUpdater.java
public File showFileChooser() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(FTP_HOME)); int n = fileChooser.showOpenDialog(WorkerUpdater.this); if (n == JFileChooser.APPROVE_OPTION) { return fileChooser.getSelectedFile(); } else//from w w w. ja va 2 s . c o m return null; }
From source file:table.FrequencyTablePanel.java
public String doSaveAs(File f) throws IOException { JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF Files", "pdf"); fileChooser.addChoosableFileFilter(filter); fileChooser.setFileFilter(filter);/*from ww w . ja v a 2s. c om*/ String filename = ""; int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { filename = fileChooser.getSelectedFile().getPath(); if (!filename.endsWith(".png")) { filename = filename + ".png"; } saveTableAsPNG(new File(filename), this.table, getWidth(), getHeight()); } return filename; }
From source file:pt.lsts.neptus.console.plugins.AirOSPeers.java
public AirOSPeers(ConsoleLayout console) { super(console); setLayout(new BorderLayout()); chart = ChartFactory.createTimeSeriesChart(null, "Time of day", "Link Quality", tsc, true, true, true); chart.getPlot().setBackgroundPaint(Color.black); cpanel = new ChartPanel(chart); add(cpanel, BorderLayout.CENTER); cpanel.getPopupMenu().add(I18n.text("Load Addresses")).addActionListener(new ActionListener() { @Override/* w ww .jav a 2 s .co m*/ public void actionPerformed(ActionEvent e) { try { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(GuiUtils.getCustomFileFilter("CSV Files", "csv")); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int op = chooser.showOpenDialog(AirOSPeers.this); if (op == JFileChooser.APPROVE_OPTION) WiFiMacAddresses.parseAddresses(new FileReader(chooser.getSelectedFile())); } catch (Exception ex) { GuiUtils.errorMessage(getConsole(), ex); ex.printStackTrace(); } } }); cpanel.getPopupMenu().addSeparator(); cpanel.getPopupMenu().add(I18n.text("Clear")).addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tsc.removeAllSeries(); } }); }
From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.ChartDisplayPanel.java
/** * Displays a dialog for saving the complex parameter data into a text file. * <p>// w w w. j a v a2 s.c om * If the user presses the "Save" button of the shown dialog, the complex parameter is * saved to the chosen file. * </p> */ private void saveChartData() { JFileChooser saveFileDialog = new JFileChooser(); int saveIt = saveFileDialog.showSaveDialog(this); if (saveIt == JFileChooser.APPROVE_OPTION) { FileWriter writer = null; try { File file = saveFileDialog.getSelectedFile(); if (Utils.canSave(file, this)) { writer = new FileWriter(file); visualizer.getComplexParam().save(writer, false); } } catch (IOException ex) { Utils.showErrorBox(this, Messages.DT_IOERROR, Messages.SM_OERROR); } finally { if (writer != null) { try { writer.close(); } catch (IOException ex) { // Fall through } } } } }
From source file:net.sf.mzmine.modules.visualization.ida.IDAPlot.java
@Override public void actionPerformed(final ActionEvent event) { super.actionPerformed(event); final String command = event.getActionCommand(); if ("SAVE_EMF".equals(command)) { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("EMF Image", "EMF"); chooser.setFileFilter(filter);// www . j a v a2s . c om int returnVal = chooser.showSaveDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { String file = chooser.getSelectedFile().getPath(); if (!file.toLowerCase().endsWith(".emf")) file += ".emf"; int width = (int) this.getSize().getWidth(); int height = (int) this.getSize().getHeight(); // Save image SaveImage SI = new SaveImage(getChart(), file, width, height, FileType.EMF); new Thread(SI).start(); } } if ("SAVE_EPS".equals(command)) { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("EPS Image", "EPS"); chooser.setFileFilter(filter); int returnVal = chooser.showSaveDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { String file = chooser.getSelectedFile().getPath(); if (!file.toLowerCase().endsWith(".eps")) file += ".eps"; int width = (int) this.getSize().getWidth(); int height = (int) this.getSize().getHeight(); // Save image SaveImage SI = new SaveImage(getChart(), file, width, height, FileType.EPS); new Thread(SI).start(); } } }
From source file:filesscanner.MainWindow.java
private void saveToJSONBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveToJSONBtnActionPerformed JSONObject object = new JSONObject(); for (int i = 0; i < modelFiles.getSize(); i++) { object.put("filename" + i, modelFiles.get(i).toString()); }/*from w ww .j a v a 2 s . co m*/ File file = new File("C:"); JFileChooser chooser = ShowChooser(file); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogType(JFileChooser.SAVE_DIALOG); int res = chooser.showDialog(this, " ? ??!!!"); if (res == JFileChooser.APPROVE_OPTION) { try { Writer writer = new FileWriter(chooser.getSelectedFile()); object.writeJSONString(writer); JOptionPane.showMessageDialog(rootPane, "SAVED SUCCESFULLY!!!"); writer.flush(); writer.close(); } catch (IOException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(rootPane, "Something bad!!!"); } } }
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);//from ww w. j a v a 2 s .c om 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:com.antelink.sourcesquare.gui.controller.SourceSquareController.java
public void bind() { this.view.getSelectButtonLabel().addMouseListener(new MouseListener() { @Override/*from w w w.j a v a 2 s . c o m*/ public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseClicked(MouseEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileHidingEnabled(false); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int showDialog = fileChooser.showDialog(SourceSquareController.this.view, "Select directory"); if (showDialog == JFileChooser.APPROVE_OPTION) { SourceSquareController.this.view.getTextField() .setText(fileChooser.getSelectedFile().getAbsolutePath()); } } }); this.view.getScanButtonLabel().addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseClicked(MouseEvent arg0) { File toScan = new File(SourceSquareController.this.view.getTextField().getText()); if (!toScan.exists() || toScan.list().length == 0) { JOptionPane.showMessageDialog(SourceSquareController.this.view, "Choose a valid and not empty directory", null, JOptionPane.ERROR_MESSAGE); return; } SourceSquareController.this.view.setVisible(false); SourceSquareController.this.eventBus.fireEvent(new StartScanEvent(toScan)); } }); }
From source file:PeerPanel.java
private void saveLocationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveLocationButtonActionPerformed JFileChooser jfc = new JFileChooser(); jfc.setCurrentDirectory(saveDirectory); jfc.setMultiSelectionEnabled(false); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { saveDirectory = jfc.getSelectedFile(); saveLocationDisplay.setText(saveDirectory.getAbsolutePath()); }/*ww w .j a va2s. c o m*/ }
From source file:CompareFiles.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: String userDir = System.getProperty("user.home"); JFileChooser folder = new JFileChooser(userDir + "/Desktop"); folder.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Excel Files (*.xls)", "xls"); folder.setFileFilter(xmlfilter);//from w ww .j ava2 s.c o m // folder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 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); jLabel1.setText(myfolder.toString()); } }