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:eu.delving.sip.actions.MediaImportAction.java
@Override public void actionPerformed(ActionEvent actionEvent) { int choiceMade = chooser.showOpenDialog(parent); if (choiceMade == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); sipModel.getPreferences().put(RECENT_DIR, file.getAbsolutePath()); selectDirectory(file); // it's a boolean }/* www . jav a2 s . c o m*/ }
From source file:com.ibm.watson.WatsonVRTraining.util.images.PhotoCaptureFrame.java
PhotoCaptureFrame() { jp = new JPanel(); jp.setLayout(new BoxLayout(jp, BoxLayout.Y_AXIS)); JScrollPane scrollPane = new JScrollPane(jp); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); scrollPane.setPreferredSize(new Dimension(dim.width / 2 - 40, dim.height - 117)); JButton btn = new JButton("Upload Image"); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(System.getenv("user.home")); fc.setFileFilter(new JPEGImageFileFilter()); int res = fc.showOpenDialog(null); // We have an image! try { if (res == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); //SharedResources.sharedCache.getCapturedImageList().add(file); File tmpf_name = File.createTempFile("tmp", "." + FilenameUtils.getExtension(file.getName())); System.out.println("cp " + file.getPath() + " " + AppConstants.vr_process_img_dir_path + File.separator + tmpf_name.getName()); new CommandsUtils().executeCommand("bash", "-c", "cp " + file.getPath() + " " + AppConstants.vr_process_img_dir_path + File.separator + tmpf_name.getName()); }/*from w ww . ja va2s .co m*/ } catch (Exception iOException) { } } }); ImageRemainingProcessingLabel = new JLabel("REMAINIG IMAGES:0"); ImageRemainingProcessingLabel.setHorizontalAlignment(SwingConstants.LEFT); ImageRemainingProcessingLabel.setFont(new Font("Arial", Font.BOLD, 13)); ImagebeingProcessedLabel = new JLabel(" PROCESSING IMAGES:0"); ImagebeingProcessedLabel.setHorizontalAlignment(SwingConstants.LEFT); ImagebeingProcessedLabel.setFont(new Font("Arial", Font.BOLD, 13)); appIDLabel = new JLabel("APP-ID:" + AppConstants.unique_app_id); appIDLabel.setHorizontalAlignment(SwingConstants.LEFT); appIDLabel.setFont(new Font("Arial", Font.BOLD, 13)); headerPanel = new JPanel(new FlowLayout()); headerPanel.add(ImageRemainingProcessingLabel); headerPanel.add(ImagebeingProcessedLabel); headerPanel.add(btn); headerPanel.add(appIDLabel); headerPanel.setSize(new Dimension(getWidth(), 10)); JPanel contentPane = new JPanel(); contentPane.add(headerPanel); contentPane.add(scrollPane); f = new JFrame("IBM Watson Visual Prediction Window"); f.setContentPane(contentPane); f.setSize(dim.width / 2 - 30, dim.height - 40); f.setLocation(dim.width / 2, 0); f.setResizable(false); f.setPreferredSize(new Dimension(dim.width / 2 - 30, dim.height - 60)); f.setVisible(true); }
From source file:analysers.ExportValidated.java
@Override public void analyze(Cell currentCell) { JFileChooser fc = new JFileChooser(); fc.addChoosableFileFilter(new FileNameExtensionFilter("Comma Separated Values", "csv")); fc.addChoosableFileFilter(new FileNameExtensionFilter("JSON file", "json")); int rv = fc.showSaveDialog(null); if (rv == JFileChooser.APPROVE_OPTION) { int b = Prefs.getInt(".TrackApp.FilterValidatedDialog.exportMean", 1); if (b != 0) { IJ.log("Exporting mean intensity values."); } else {/*w w w . jav a 2 s . c o m*/ IJ.log("Exporting sum of intensity values."); } File ff = fc.getSelectedFile(); String fn = fc.getSelectedFile().getAbsolutePath(); if (fc.getFileFilter().getDescription().contains("JSON")) { if (!fn.toLowerCase().endsWith(".json")) { fn = fn + ".json"; ff = new File(ff + ".json"); } IJ.log("Writing a JSON file."); } else { if (!fn.toLowerCase().endsWith(".csv")) { fn = fn + ".csv"; ff = new File(ff + ".csv"); } IJ.log("Writing a CSV file."); } IJ.log("Writing to " + fn); if (fn.endsWith(".csv")) { writeCSV(ff); } else if (fn.endsWith(".json")) { writeJSON(ff); } else { IJ.log("Unknown output format for file name " + fn); } } }
From source file:com.floreantpos.bo.actions.DataImportAction.java
@Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = DataExportAction.getFileChooser(); int option = fileChooser.showOpenDialog(com.floreantpos.util.POSUtil.getBackOfficeWindow()); if (option != JFileChooser.APPROVE_OPTION) { return;//from w w w. ja va 2 s .c o m } File file = fileChooser.getSelectedFile(); try { importMenuItemsFromFile(file); POSMessageDialog.showMessage(com.floreantpos.util.POSUtil.getFocusedWindow(), Messages.getString("DataImportAction.1")); //$NON-NLS-1$ } catch (Exception e1) { PosLog.error(getClass(), e1); POSMessageDialog.showMessage(com.floreantpos.util.POSUtil.getFocusedWindow(), e1.getMessage()); } }
From source file:iotest.ModifyArtifactsTest.java
@Test public void modifyAppServletXml() throws UnsupportedEncodingException, FileNotFoundException, IOException, JDOMException { System.out.println("please select app-servlet.xml file "); JFileChooser fc = new JFileChooser(); int retValue = fc.showOpenDialog(new JPanel()); if (retValue == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); SAXBuilder builder = new SAXBuilder(); Document document = (Document) builder.build(f); Element rootNode = document.getRootElement(); List<Element> list = rootNode.getChildren("component-scan", Namespace.getNamespace("http://www.springframework.org/schema/context")); Element e = list.get(0);/*from w w w. jav a 2 s . c om*/ String cnt = "<context:exclude-filter type=\"regex\" expression=\"pegasus\\.module\\.jfilelooder\\..*\" />"; e.addContent(cnt); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()) { @Override public String escapeElementEntities(String str) { return str; } }; Writer writer = new OutputStreamWriter(new FileOutputStream(f), "utf-8"); outputter.output(document, writer); writer.close(); } else { System.out.println("Next time select a file."); System.exit(1); } }
From source file:ZipTest.java
public ZipTestFrame() { setTitle("ZipTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // add the menu and the Open and Exit menu items JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open"); menu.add(openItem);//from ww w. j a v a2 s .c om openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); int r = chooser.showOpenDialog(ZipTestFrame.this); if (r == JFileChooser.APPROVE_OPTION) { zipname = chooser.getSelectedFile().getPath(); fileCombo.removeAllItems(); scanZipFile(); } } }); JMenuItem exitItem = new JMenuItem("Exit"); menu.add(exitItem); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); menuBar.add(menu); setJMenuBar(menuBar); // add the text area and combo box fileText = new JTextArea(); fileCombo = new JComboBox(); fileCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { loadZipFile((String) fileCombo.getSelectedItem()); } }); add(fileCombo, BorderLayout.SOUTH); add(new JScrollPane(fileText), BorderLayout.CENTER); }
From source file:org.vimarsha.ui.TimeSlicedClassiferForm.java
public TimeSlicedClassiferForm() { for (String str : UIHandler.getInstance().getArchitectureList()) { architectureComboBox.addItem(str); }// w w w . j av a2 s . com classifyButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { UIHandler.getInstance().classifyTimeSliced(); XYSeriesCollection data = UIHandler.getInstance().getXYChartDataSet(); displayTimeSlicedChart(data); } }); exportButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { File file = null; JFileChooser fc = new JFileChooser(); int returnVal = fc.showSaveDialog(Tab3); if (returnVal == JFileChooser.APPROVE_OPTION) { System.out.println(fc.getSelectedFile()); UIHandler.getInstance().exportTimeSlicedAsCSV(fc.getSelectedFile()); } } }); }
From source file:org.pgptool.gui.ui.tools.browsefs.SaveFileChooserDialog.java
public String askUserForFile() { JFileChooser ofd = prepareFileChooser(); boolean userWantsToSelectOtherFile = true; File retFile = null;//from w ww . j a v a2 s .c om while (userWantsToSelectOtherFile) { int result = ofd.showSaveDialog(parentWindow); if (result != JFileChooser.APPROVE_OPTION) { return onDialogClosed(null, ofd); } retFile = ofd.getSelectedFile(); if (retFile == null) { return onDialogClosed(null, ofd); } File retFileWithExt = new File(enforceExtension(retFile.getAbsolutePath(), ofd)); if (userWantsToSelectOtherFile = retFileWithExt.exists()) { if (UiUtils.confirm("confirm.overWriteExistingFile", new Object[] { retFileWithExt.getAbsolutePath() }, parentWindow)) { userWantsToSelectOtherFile = false; } } } Preconditions.checkState(retFile != null, "Useless check but it makes Eclipse NPE checker happier"); String ret = retFile.getAbsolutePath(); ret = onDialogClosed(ret, ofd); return ret; }
From source file:modelibra.swing.app.util.FileSelector.java
/** * Gets the opened file given a file path. * /*from ww w .j av a 2 s.c o m*/ * @param path * path * @param lang * language * @return file */ public File getOpenFile(String path, NatLang lang) { File selectedFile = null; File currentFile = null; if (path != null && !path.equalsIgnoreCase("?")) { currentFile = new File(path); } else currentFile = lastOpenedFile; JFileChooser chooser = new JFileChooser(); chooser.setLocale(lang.getLocale()); if (currentFile != null) { chooser.setCurrentDirectory(currentFile); } int returnVal = chooser.showOpenDialog(chooser); if (returnVal == JFileChooser.APPROVE_OPTION) { selectedFile = chooser.getSelectedFile(); } lastOpenedFile = selectedFile; return selectedFile; }
From source file:FileChooserDemo2.java
public void actionPerformed(ActionEvent e) { // Set up the file chooser. if (fc == null) { fc = new JFileChooser(); // Add a custom file filter and disable the default // (Accept All) file filter. fc.addChoosableFileFilter(new ImageFilter()); fc.setAcceptAllFileFilterUsed(false); // Add custom icons for file types. fc.setFileView(new ImageFileView()); // Add the preview pane. fc.setAccessory(new ImagePreview(fc)); }// w w w . j a va2 s.c o m // Show it. int returnVal = fc.showDialog(FileChooserDemo2.this, "Attach"); // Process the results. if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); log.append("Attaching file: " + file.getName() + "." + newline); } else { log.append("Attachment cancelled by user." + newline); } log.setCaretPosition(log.getDocument().getLength()); // Reset the file chooser for the next time it's shown. fc.setSelectedFile(null); }