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:com.titan.storagepanel.DownloadImageDialog.java
public DownloadImageDialog(final Frame frame) { super(frame, true); setTitle("Openstack vm os image"); setBounds(100, 100, 947, 706);/*w w w . j a v a 2s . c om*/ 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:net.sf.clichart.main.ChartFrame.java
private void saveChart() { JFileChooser chooser = new JFileChooser("."); chooser.addChoosableFileFilter(new ExtensionFileFilter(".jpg", "JPEG files")); chooser.addChoosableFileFilter(new ExtensionFileFilter(".png", "PNG files")); if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File outputFile = chooser.getSelectedFile(); if (outputFile.exists()) { int result = JOptionPane.showConfirmDialog(this, "File exists - overwrite?", "File exists", JOptionPane.OK_CANCEL_OPTION); if (result != JOptionPane.OK_OPTION) { return; }/* w w w .java2s .co m*/ } System.err.println("Saving chart to " + outputFile.getPath()); try { new ChartSaver(m_chart, m_initialWidth, m_initialHeight).saveChart(outputFile); } catch (ChartSaverException e) { JOptionPane.showMessageDialog(this, "Failed to save chart: " + e.getMessage()); } } }
From source file:com.naval.gui.Gui.java
private void creerPartie() { final JFileChooser fc = new JFileChooser(Config.getRepTravail()); fc.addChoosableFileFilter(new GameFileFilter("gm", "Description de partie")); fc.setAcceptAllFileFilterUsed(false); int returnVal = fc.showOpenDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // TODO : load only if game is != try {//ww w .j a v a 2 s.c o m FileReader fr = new FileReader(file); partie = Partie.creer(fr); partie.save(); hintBar.setText("Partie " + partie.nom + " cre avec succes"); } catch (FileNotFoundException e) { hintBar.setText(e.getMessage()); e.printStackTrace(); } catch (IOException e) { hintBar.setText(e.getMessage()); e.printStackTrace(); } } }
From source file:SciTK.Plot.java
/** * Save data for generic plot to file // w ww.j ava 2s . c o m */ public void saveData() { JFileChooser fc = new JFileChooser(); fc.addChoosableFileFilter(new ExtensionFileFilter("CSV", new String[] { "csv,CSV" })); // remove default option: fc.setAcceptAllFileFilterUsed(false); // Select a file using the JFileChooser dialog: int fc_return = fc.showSaveDialog(this); if (fc_return == JFileChooser.APPROVE_OPTION) // user wants to save { //get the file name from the filter: File save_file = fc.getSelectedFile(); // check to see if the user entered an extension: if (!save_file.getName().endsWith(".csv") && !save_file.getName().endsWith(".CSV")) { save_file = new File(save_file.getAbsolutePath() + ".csv"); } // create a string to save String s = toString(); // IO inside a try/catch try { // Create a File Writer FileWriter fw = new FileWriter(save_file); fw.write(s); fw.close(); } // If there was an error, launch an error dialog box: catch (IOException e) { DialogError emsg = new DialogError(this, " There was an error saving the file." + System.getProperty("line.separator") + e.getMessage()); } } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopFileUploadField.java
public DesktopFileUploadField() { fileUploading = AppBeans.get(FileUploadingAPI.NAME); messages = AppBeans.get(Messages.NAME); exportDisplay = AppBeans.get(ExportDisplay.NAME); ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.NAME); uploadButton = (Button) componentsFactory.createComponent(Button.NAME); final JFileChooser fileChooser = new JFileChooser(); uploadButton.setAction(new AbstractAction("") { @Override//from w ww. j a v a 2 s .c o m public void actionPerform(Component component) { if (fileChooser.showOpenDialog(uploadButton.unwrap(JButton.class)) == JFileChooser.APPROVE_OPTION) { uploadFile(fileChooser.getSelectedFile()); } } }); uploadButton.setCaption(messages.getMessage(getClass(), "export.selectFile")); initImpl(); }
From source file:com.original.widget.OPicture.java
/** * very simple method to select an image file. * Please be advised that we will create our own file chooser in the * near future. Since in our system, people will be not encouraged to * access the physical file.//from www .j ava2 s . c o m * * Of course, we need to discuss how to handle this issue. * @return */ private File chooseImgFile() { JFileChooser chooser = new JFileChooser("."); FileFilter imgType = new OriExtFileFilter("Image files", new String[] { ".jpg", ".gif", ".jpeg", ".png" }); chooser.addChoosableFileFilter(imgType); chooser.setAcceptAllFileFilterUsed(false); chooser.setFileFilter(imgType); int status = chooser.showOpenDialog(null); if (status == JFileChooser.APPROVE_OPTION) { File f = chooser.getSelectedFile(); return f; } return null; }
From source file:de.biomedical_imaging.ij.plot.HistogramPlotter.java
public HistogramPlotter(String title, String xlabel, double[][] data, int numberOfParticles, int meanTrackLength, IDatasetCreator datacreator) { super(title); this.title = title; this.xlabel = xlabel; this.numberOfParticles = numberOfParticles; this.meanTrackLength = meanTrackLength; IntervalXYDataset xydataset = datacreator.create(data); boolean isbarplot = (datacreator instanceof BarplotDataset); txt = new JLabel(); Font f = new Font("Verdana", Font.PLAIN, 12); txt.setFont(f);//from w w w. ja v a2 s . c om JFreeChart chart = createChart(xydataset, isbarplot); ChartPanel chartPanel = new ChartPanel(chart); txt.setText(formatSettingsString()); main = new JPanel(); main.setPreferredSize(new java.awt.Dimension(500, 350)); main.add(chartPanel); main.add(txt); setContentPane(main); setLayout(new BoxLayout(main, BoxLayout.Y_AXIS)); pack(); setVisible(true); JMenuItem savebutton = ((JMenuItem) chartPanel.getPopupMenu().getComponent(3)); chartPanel.getPopupMenu().remove(3); // Remove Save button //ActionListener al = savebutton.getActionListeners()[0]; savebutton = new JMenuItem("Save as png"); //savebutton.removeActionListener(al); savebutton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub try { JFileChooser saveFile = new JFileChooser(); saveFile.setAcceptAllFileFilterUsed(false); saveFile.addChoosableFileFilter(new FileNameExtensionFilter("Images", "png")); int userSelection = saveFile.showSaveDialog(main); if (userSelection == JFileChooser.APPROVE_OPTION) { BufferedImage bi = ScreenImage.createImage(main); File fileToSave = saveFile.getSelectedFile(); String filename = fileToSave.getName(); int i = filename.lastIndexOf('.'); String suffix = filename.substring(i + 1); String path = fileToSave.getAbsolutePath(); if (!(suffix.equals("png"))) { path += ".png"; } ScreenImage.writeImage(bi, path); } } catch (IOException e) { // TODO Auto-generated catch block IJ.log("" + e.getMessage()); } } }); chartPanel.getPopupMenu().insert(savebutton, 3); }
From source file:app.NewJFrame.java
public void readFile() { int returnVal = jFileChooser1.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { file = jFileChooser1.getSelectedFile(); readFile = new StringBuilder(); try {//w w w. j ava 2 s. c om // ? ? FileInputStream stream = new FileInputStream(file.getAbsoluteFile()); InputStreamReader reader = new InputStreamReader(stream, "Cp1251"); BufferedReader in = new BufferedReader(reader); try { // ? ? String line; while ((line = in.readLine()) != null) { readFile.append(line); } } finally { in.close(); } } catch (IOException e) { throw new RuntimeException(e); } } }
From source file:net.pms.newgui.Wizard.java
public static void run(final PmsConfiguration configuration) { // Total number of questions int numberOfQuestions = Platform.isMac() ? 4 : 5; // The current question number int currentQuestionNumber = 1; String status = new StringBuilder().append(Messages.getString("Wizard.2")).append(" %d ") .append(Messages.getString("Wizard.4")).append(" ").append(numberOfQuestions).toString(); Object[] okOptions = { Messages.getString("Dialog.OK") }; Object[] yesNoOptions = { Messages.getString("Dialog.YES"), Messages.getString("Dialog.NO") }; Object[] networkTypeOptions = { Messages.getString("Wizard.8"), Messages.getString("Wizard.9"), Messages.getString("Wizard.10") }; if (!Platform.isMac()) { // Ask if they want UMS to start minimized int whetherToStartMinimized = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.3"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[1]); if (whetherToStartMinimized == JOptionPane.YES_OPTION) { configuration.setMinimized(true); } else if (whetherToStartMinimized == JOptionPane.NO_OPTION) { configuration.setMinimized(false); }/*from w w w .j a v a 2 s. co m*/ } // Ask if their network is wired, etc. int networkType = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.7"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, networkTypeOptions, networkTypeOptions[1]); switch (networkType) { case JOptionPane.YES_OPTION: // Wired (Gigabit) configuration.setMaximumBitrate("0"); configuration.setMPEG2MainSettings("Automatic (Wired)"); configuration.setx264ConstantRateFactor("Automatic (Wired)"); break; case JOptionPane.NO_OPTION: // Wired (100 Megabit) configuration.setMaximumBitrate("90"); configuration.setMPEG2MainSettings("Automatic (Wired)"); configuration.setx264ConstantRateFactor("Automatic (Wired)"); break; case JOptionPane.CANCEL_OPTION: // Wireless configuration.setMaximumBitrate("30"); configuration.setMPEG2MainSettings("Automatic (Wireless)"); configuration.setx264ConstantRateFactor("Automatic (Wireless)"); break; default: break; } // Ask if they want to hide advanced options int whetherToHideAdvancedOptions = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.11"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[0]); if (whetherToHideAdvancedOptions == JOptionPane.YES_OPTION) { configuration.setHideAdvancedOptions(true); } else if (whetherToHideAdvancedOptions == JOptionPane.NO_OPTION) { configuration.setHideAdvancedOptions(false); } // Ask if they want to scan shared folders int whetherToScanSharedFolders = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.IsStartupScan"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[0]); if (whetherToScanSharedFolders == JOptionPane.YES_OPTION) { configuration.setScanSharedFoldersOnStartup(true); } else if (whetherToScanSharedFolders == JOptionPane.NO_OPTION) { configuration.setScanSharedFoldersOnStartup(false); } // Ask to set at least one shared folder JOptionPane.showOptionDialog(null, Messages.getString("Wizard.12"), String.format(status, currentQuestionNumber++), JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE, null, okOptions, okOptions[0]); try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { JFileChooser chooser; try { chooser = new JFileChooser(); } catch (Exception ee) { chooser = new JFileChooser(new RestrictedFileSystemView()); } chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle(Messages.getString("Wizard.12")); chooser.setMultiSelectionEnabled(false); if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { configuration.setOnlySharedDirectory(chooser.getSelectedFile().getAbsolutePath()); } else { // If the user cancels this option, the default directories will be used. } } }); } catch (InterruptedException | InvocationTargetException e) { LOGGER.error("Error when saving folders: ", e); } // The wizard finished, do not ask them again configuration.setRunWizard(false); // Save all changes try { configuration.save(); } catch (ConfigurationException e) { LOGGER.error("Error when saving changed configuration: ", e); } }
From source file:com.sri.ai.praise.demo.ChurchPanel.java
@Override public void saveAs() throws IOException { if (churchEditor.canUndo()) { if (currentChurchFile != null) { fileChooser.setSelectedFile(currentChurchFile); }//from w w w . j a va2 s. com int returnVal = fileChooser.showSaveDialog(fileChooserParent); if (returnVal == JFileChooser.APPROVE_OPTION) { currentChurchFile = fileChooser.getSelectedFile(); saveToFile(); } } }