List of usage examples for javax.swing JFileChooser showSaveDialog
public int showSaveDialog(Component parent) throws HeadlessException
From source file:com.haulmont.cuba.desktop.gui.components.DesktopExportDisplay.java
private void saveFileAction(String fileName, JFrame frame, ExportDataProvider dataProvider) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setSelectedFile(new File(fileName)); if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); boolean success = saveFile(dataProvider, selectedFile); TopLevelFrame mainFrame = App.getInstance().getMainFrame(); if (success) { mainFrame.showNotification(messages.getMessage(DesktopExportDisplay.class, "export.saveSuccess"), Frame.NotificationType.TRAY); } else {/*w ww . ja v a 2s . com*/ mainFrame.showNotification(messages.getMessage(DesktopExportDisplay.class, "export.saveError"), Frame.NotificationType.ERROR); } } }
From source file:Result3.java
public void createImage() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File("Documents")); int retrival = chooser.showSaveDialog(null); if (retrival == JFileChooser.APPROVE_OPTION) { try {/*from w ww. ja v a2 s.c om*/ ImageIO.write(bImage1, "png", new File(chooser.getSelectedFile() + ".png")); } catch (IOException ex) { Logger.getLogger(Result1.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:Result3.java
public void createImageJPG() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File("Documents")); int retrival = chooser.showSaveDialog(null); if (retrival == JFileChooser.APPROVE_OPTION) { try {/* ww w . j a v a 2 s.c o m*/ ImageIO.write(bImage1, "jpg", new File(chooser.getSelectedFile() + ".jpg")); } catch (IOException ex) { Logger.getLogger(Result1.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:cmsc105_mp2.Panels.java
public void createGraph(Data d, float window, Double threshold) { XYSeries data = new XYSeries("data"); double max = Double.MIN_VALUE; for (double num : d.plots) { if (max < num) max = num;/*from ww w . ja v a 2 s .co m*/ } max += 1; ArrayList<XYSeries> xy = new ArrayList(); ArrayList<Integer> points = new ArrayList(); for (int j = (int) (window / 2); j < d.plots.length - (window / 2); j++) { data.add(j, d.plots[j]); //System.out.println(points.size()); if (d.plots[j] > threshold) { points.add(j); } else { if (points.size() >= window) { //System.out.println("MIN!"); XYSeries series = new XYSeries("trend"); for (int n : points) { series.add(n, max); } xy.add(series); } points = new ArrayList(); } } if (points.size() >= window) { XYSeries series = new XYSeries("trend"); for (int n : points) { series.add(n, max); } xy.add(series); } XYSeriesCollection my_data_series = new XYSeriesCollection(); my_data_series.addSeries(data); for (XYSeries x : xy) { my_data_series.addSeries(x); } XYSeries thresh = new XYSeries("threshold"); for (int j = 0; j < d.plots.length; j++) { thresh.add(j, threshold); } my_data_series.addSeries(thresh); //System.out.println(d.name); JFreeChart XYLineChart = ChartFactory.createXYLineChart(d.name, "Position", "Average", my_data_series, PlotOrientation.VERTICAL, true, true, false); bImage1 = (BufferedImage) XYLineChart.createBufferedImage(690, 337); imageIcon = new ImageIcon(bImage1); jLabel1.setIcon(imageIcon); jLabel1.revalidate(); jLabel1.repaint(); jButton1.setText("Save as PNG"); jButton1.repaint(); jButton1.revalidate(); jButton1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File("Documents")); int retrival = chooser.showSaveDialog(null); if (retrival == JFileChooser.APPROVE_OPTION) { try { ImageIO.write(bImage1, "png", new File(chooser.getSelectedFile() + ".png")); } catch (IOException ex) { System.out.println("Unable to Print!"); } } } }); }
From source file:com.reelfx.controller.AbstractController.java
public void askForAndSaveRecording() { JFileChooser fileSelect = new JFileChooser(); int returnVal = fileSelect.showSaveDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileSelect.getSelectedFile(); saveRecording(file);//from w ww. ja va 2 s. c om } }
From source file:it.unibas.spicygui.controllo.file.ActionSaveMappingTask.java
private void richiediUtilizzoFileChooser(MappingTask mappingTask, File file) throws HeadlessException, MissingResourceException { JFileChooser chooser = vista.getFileChooserSalvaXmlXsd(); continua = true;//from w w w . jav a 2s . c o m while (continua) { int returnVal = chooser.showSaveDialog(WindowManager.getDefault().getMainWindow()); if (returnVal == JFileChooser.APPROVE_OPTION) { try { file = chooser.getSelectedFile(); if (!file.exists()) { daoMappingTask.saveMappingTask(mappingTask, file.getAbsolutePath()); mappingTask.setModified(false); mappingTask.setToBeSaved(false); continua = false; esito = true; // modello.putBean(Costanti.ACTUAL_SAVE_FILE, file); Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO); scenario.setSaveFile(file); MappingTaskTopComponent mappingTaskTopComponent = scenario.getMappingTaskTopComponent(); mappingTaskTopComponent.initNameTab(); enableActions(); } else { chiediConferma(file, mappingTask); } } catch (DAOException ex) { DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.SAVE_ERROR) + " : " + ex.getMessage(), DialogDescriptor.ERROR_MESSAGE)); logger.error(ex); continua = false; esito = true; } } else { continua = false; esito = false; } } }
From source file:com.seanmadden.net.fast.FastInterpretype.java
public boolean saveLogToFile() { JFileChooser jfc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Text Files", "txt"); jfc.setFileFilter(filter);//from w w w .jav a 2s . c om int retVal = jfc.showSaveDialog(null); if (retVal == JFileChooser.APPROVE_OPTION) { String filename = jfc.getSelectedFile().getPath(); mw.saveWindowToFile(filename); return true; } return false; }
From source file:com.titan.storagepanel.DownloadImageDialog.java
public DownloadImageDialog(final Frame frame) { super(frame, true); setTitle("Openstack vm os image"); setBounds(100, 100, 947, 706);//from w w w . j a v a 2 s .co m getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(new BorderLayout(0, 0)); { JPanel panel = new JPanel(); contentPanel.add(panel, BorderLayout.NORTH); panel.setLayout(new MigLayout("", "[41px][107.00px][27px][95.00px][24px][95.00px][]", "[27px]")); { JLabel lblSearch = new JLabel("Search"); panel.add(lblSearch, "cell 0 0,alignx left,aligny center"); } { searchTextField = new JSearchTextField(); searchTextField.setPreferredSize(new Dimension(150, 40)); panel.add(searchTextField, "cell 1 0,growx,aligny center"); } { JLabel lblType = new JLabel("Type"); panel.add(lblType, "cell 2 0,alignx left,aligny center"); } { typeComboBox = new JComboBox( new String[] { "All", "Ubuntu", "Fedora", "Redhat", "CentOS", "Gentoo", "Windows" }); panel.add(typeComboBox, "cell 3 0,growx,aligny top"); } { JLabel lblSize = new JLabel("Size"); panel.add(lblSize, "cell 4 0,alignx left,aligny center"); } { sizeComboBox = new JComboBox(new String[] { "0-700MB", ">700MB" }); panel.add(sizeComboBox, "cell 5 0,growx,aligny top"); } { JButton btnSearch = new JButton("Search"); btnSearch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { d.setVisible(true); } }); panel.add(btnSearch, "cell 6 0"); } } { JScrollPane scrollPane = new JScrollPane(); contentPanel.add(scrollPane, BorderLayout.CENTER); { table = new JTable(); table.setModel(tableModel); table.addMouseListener(new JTableButtonMouseListener(table)); table.addMouseMotionListener(new JTableButtonMouseListener(table)); scrollPane.setViewportView(table); } } { JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.SOUTH); { JButton downloadButton = new JButton("Download"); downloadButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (table.getSelectedRowCount() == 1) { JFileChooser jf = new JFileChooser(); int x = jf.showSaveDialog(frame); if (x == JFileChooser.APPROVE_OPTION) { DownloadImage p = (DownloadImage) table.getValueAt(table.getSelectedRow(), 0); DownloadFileDialog d = new DownloadFileDialog(frame, "Downloading image", true, p.file, jf.getSelectedFile()); CommonLib.centerDialog(d); d.setVisible(true); } } } }); panel.add(downloadButton); } } d = new JProgressBarDialog(frame, true); d.progressBar.setIndeterminate(true); d.progressBar.setStringPainted(true); d.thread = new Thread() { public void run() { InputStream in = null; tableModel.columnNames.clear(); tableModel.columnNames.add("image"); tableModel.editables.clear(); tableModel.editables.put(0, true); Vector<Object> col1 = new Vector<Object>(); try { d.progressBar.setString("connecting to titan image site"); in = new URL("http://titan-image.kingofcoders.com/titan-image.xml").openStream(); String xml = IOUtils.toString(in); NodeList list = TitanCommonLib.getXPathNodeList(xml, "/images/image"); for (int x = 0; x < list.getLength(); x++) { DownloadImage downloadImage = new DownloadImage(); downloadImage.author = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/author/text()"); downloadImage.authorEmail = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/authorEmail/text()"); downloadImage.License = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/License/text()"); downloadImage.description = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/description/text()"); downloadImage.file = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/file/text()"); downloadImage.os = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/os/text()"); downloadImage.osType = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/osType/text()"); downloadImage.uploadDate = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse( TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/uploadDate/text()")); downloadImage.size = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/size/text()"); downloadImage.architecture = TitanCommonLib.getXPath(xml, "/images/image[" + (x + 1) + "]/architecture/text()"); col1.add(downloadImage); } } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(frame, "Unable to connect titan image site !", "Error", JOptionPane.ERROR_MESSAGE); } finally { IOUtils.closeQuietly(in); } tableModel.values.clear(); tableModel.values.add(col1); tableModel.fireTableStructureChanged(); table.getColumnModel().getColumn(0).setCellRenderer(new DownloadImageTableCellRenderer()); // table.getColumnModel().getColumn(0).setCellEditor(new DownloadImageTableCellEditor()); for (int x = 0; x < table.getRowCount(); x++) { table.setRowHeight(x, 150); } } }; d.setVisible(true); }
From source file:modelibra.swing.app.util.FileSelector.java
/** * Gets the saved file given a file path. * // w w w . j a v a2 s.com * @param path * path * @param lang * language * @return file */ public File getSaveFile(String path, NatLang lang) { File selectedFile = null; File currentFile = null; if (path != null && !path.equalsIgnoreCase("?")) { currentFile = new File(path); } else currentFile = lastSavedFile; JFileChooser chooser = new JFileChooser(); chooser.setLocale(lang.getLocale()); if (currentFile != null) { chooser.setCurrentDirectory(currentFile); } int returnVal = chooser.showSaveDialog(chooser); if (returnVal == JFileChooser.APPROVE_OPTION) { selectedFile = chooser.getSelectedFile(); // a complete path if (selectedFile.exists()) { if (!replaceFile(null, lang)) { selectedFile = null; } } } lastSavedFile = selectedFile; return selectedFile; }
From source file:net.atomique.ksar.ui.GraphView.java
private String askSaveFilename(String title, File chdirto) { String filename = null;/*from www .ja v a 2 s . co m*/ JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(title); if (chdirto != null) { chooser.setCurrentDirectory(chdirto); } int returnVal = chooser.showSaveDialog(GlobalOptions.getUI()); if (returnVal == JFileChooser.APPROVE_OPTION) { filename = chooser.getSelectedFile().getAbsolutePath(); } if (filename == null) { return null; } if (new File(filename).exists()) { String[] choix = { "Yes", "No" }; int resultat = JOptionPane.showOptionDialog(null, "Overwrite " + filename + " ?", "File Exist", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, choix, choix[1]); if (resultat != 0) { return null; } } return filename; }