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:ac.kaist.ccs.presentation.CCSHubSelectionCoverage.java
public CCSHubSelectionCoverage(final String title, List<Double> coverSourceNum) { super(title); this.title = title; final XYDataset dataset = createDataset(coverSourceNum); final JFreeChart chart = createChart(dataset); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BorderLayout()); JButton buttonExport = new JButton("Export"); buttonPanel.add("East", buttonExport); buttonExport.addActionListener(new ActionListener() { ChartPanel chartPanel;//w w w .ja va 2 s . c o m public ActionListener init(ChartPanel chartPanel) { this.chartPanel = chartPanel; return this; } @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub Dimension size = chartPanel.getSize(); try { //String outPath = textFieldSelectPath.getText(); //String filename = "chromatography.png"; //String path = outPath+"/"+filename; JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File("/Users/mac/Desktop")); fileChooser.setFileFilter(new javax.swing.filechooser.FileNameExtensionFilter("JPEG", "jpeg")); int returnVal = fileChooser.showDialog(new JFrame(), "Open File Path"); if (returnVal == JFileChooser.APPROVE_OPTION) { String inputPath = fileChooser.getSelectedFile().getAbsolutePath(); if (!inputPath.endsWith(".jpeg")) inputPath = inputPath + ".jpeg"; OutputStream os = new FileOutputStream(inputPath); System.out.println(inputPath + "///" + size.width + " " + size.height); BufferedImage chartImage = chartPanel.getChart().createBufferedImage(size.width, size.height, null); ImageIO.write(chartImage, "png", os); os.close(); JOptionPane.showMessageDialog(null, "Chart image was saved in " + inputPath); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.init(chartPanel)); panel.add("Center", chartPanel); panel.add("South", buttonPanel); chartPanel.setPreferredSize(new java.awt.Dimension(700, 500)); setContentPane(panel); }
From source file:XPathTest.java
/** * Open a file and load the document. *///ww w.ja va 2 s . c o m public void openFile() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); chooser.setFileFilter(new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase().endsWith(".xml"); } public String getDescription() { return "XML files"; } }); int r = chooser.showOpenDialog(this); if (r != JFileChooser.APPROVE_OPTION) return; File f = chooser.getSelectedFile(); try { byte[] bytes = new byte[(int) f.length()]; new FileInputStream(f).read(bytes); docText.setText(new String(bytes)); doc = builder.parse(f); } catch (IOException e) { JOptionPane.showMessageDialog(this, e); } catch (SAXException e) { JOptionPane.showMessageDialog(this, e); } }
From source file:MessageDigestTest.java
/** * Loads a file and computes its message digest. *//*from www . j a v a2 s . com*/ public void loadFile() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); int r = chooser.showOpenDialog(this); if (r == JFileChooser.APPROVE_OPTION) { try { String name = chooser.getSelectedFile().getAbsolutePath(); computeDigest(loadBytes(name)); } catch (IOException e) { JOptionPane.showMessageDialog(null, e); } } }
From source file:presenter.MainPresenter.java
@Override public void loadMovementsequenceFromFile(ActionEvent e) { JFileChooser fc = new JFileChooser(); if (fc.showOpenDialog((Component) e.getSource()) == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); try {/*from w w w . j a v a 2s.c o m*/ this.movSeq = new Movementsequence(new Scanner(file).useDelimiter("\\A").next()); this.emissionsequenceModel = new EmissionsequenceModel(this.movSeq); this.displayStatus("File was read successfully!"); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }
From source file:ac.kaist.ccs.presentation.CCSHubSelectionCost.java
public CCSHubSelectionCost(final String title, Map<Integer, List<Double>> data) { super(title); this.title = title; final XYDataset dataset = createDataset(data); final JFreeChart chart = createChart(dataset); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BorderLayout()); JButton buttonExport = new JButton("Export"); buttonPanel.add("East", buttonExport); buttonExport.addActionListener(new ActionListener() { ChartPanel chartPanel;//from w ww . j a v a 2s .c o m public ActionListener init(ChartPanel chartPanel) { this.chartPanel = chartPanel; return this; } @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub Dimension size = chartPanel.getSize(); try { //String outPath = textFieldSelectPath.getText(); //String filename = "chromatography.png"; //String path = outPath+"/"+filename; JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File("/Users/mac/Desktop")); fileChooser.setFileFilter(new javax.swing.filechooser.FileNameExtensionFilter("JPEG", "jpeg")); int returnVal = fileChooser.showDialog(new JFrame(), "Open File Path"); if (returnVal == JFileChooser.APPROVE_OPTION) { String inputPath = fileChooser.getSelectedFile().getAbsolutePath(); if (!inputPath.endsWith(".jpeg")) inputPath = inputPath + ".jpeg"; OutputStream os = new FileOutputStream(inputPath); System.out.println(inputPath + "///" + size.width + " " + size.height); BufferedImage chartImage = chartPanel.getChart().createBufferedImage(size.width, size.height, null); ImageIO.write(chartImage, "png", os); os.close(); JOptionPane.showMessageDialog(null, "Chart image was saved in " + inputPath); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.init(chartPanel)); panel.add("Center", chartPanel); panel.add("South", buttonPanel); chartPanel.setPreferredSize(new java.awt.Dimension(700, 500)); setContentPane(panel); }
From source file:de.erdesignerng.visual.editor.openxavaexport.OpenXavaExportEditor.java
private void commandChooseSrcDirectory() { JFileChooser theChooser = new JFileChooser(); theChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (theChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File theBaseDirectory = theChooser.getSelectedFile(); editingView.getSrcDirectory().setText(theBaseDirectory.toString()); }//from www .jav a2 s .c o m }
From source file:ac.kaist.ccs.presentation.CCSHubSelectionCo2Coverage.java
public CCSHubSelectionCo2Coverage(final String title, List<Double> coverSourceNum) { super(title); this.title = title; final XYDataset dataset = createDataset(coverSourceNum); final JFreeChart chart = createChart(dataset); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BorderLayout()); JButton buttonExport = new JButton("Export"); buttonPanel.add("East", buttonExport); buttonExport.addActionListener(new ActionListener() { ChartPanel chartPanel;// w w w .jav a 2 s . c o m public ActionListener init(ChartPanel chartPanel) { this.chartPanel = chartPanel; return this; } @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub Dimension size = chartPanel.getSize(); try { //String outPath = textFieldSelectPath.getText(); //String filename = "chromatography.png"; //String path = outPath+"/"+filename; JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File("/Users/mac/Desktop")); fileChooser.setFileFilter(new javax.swing.filechooser.FileNameExtensionFilter("JPEG", "jpeg")); int returnVal = fileChooser.showDialog(new JFrame(), "Open File Path"); if (returnVal == JFileChooser.APPROVE_OPTION) { String inputPath = fileChooser.getSelectedFile().getAbsolutePath(); if (!inputPath.endsWith(".jpeg")) inputPath = inputPath + ".jpeg"; OutputStream os = new FileOutputStream(inputPath); System.out.println(inputPath + "///" + size.width + " " + size.height); BufferedImage chartImage = chartPanel.getChart().createBufferedImage(size.width, size.height, null); ImageIO.write(chartImage, "png", os); os.close(); JOptionPane.showMessageDialog(null, "Chart image was saved in " + inputPath); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.init(chartPanel)); panel.add("Center", chartPanel); panel.add("South", buttonPanel); chartPanel.setPreferredSize(new java.awt.Dimension(700, 500)); setContentPane(panel); }
From source file:kihira.tails.client.gui.GuiExport.java
@Override protected void actionPerformed(GuiButton button) { //Export to file if (button.id == 0 || button.id == 1 || button.id == 2) { AbstractClientPlayer player = this.mc.thePlayer; File file;//www . j av a2s.co m this.exportMessage = ""; this.exportLoc = null; if (button.id == 0) file = new File(System.getProperty("user.home")); else if (button.id == 1) file = new File(System.getProperty("user.dir")); else { JFileChooser fileChooser = new JFileChooser(new File(System.getProperty("user.dir"))); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fileChooser.showSaveDialog(Display.getParent()) == JFileChooser.APPROVE_OPTION) { file = fileChooser.getSelectedFile(); } else return; } if (file.exists() && file.canWrite()) { this.exportLoc = file.toURI(); file = new File(file, File.separatorChar + player.getCommandSenderName() + ".png"); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { setExportMessage( EnumChatFormatting.DARK_RED + String.format("Failed to create skin file! %s", e)); e.printStackTrace(); } } BufferedImage image = TextureHelper.writePartsDataToSkin(this.partsData, player); if (image != null) { try { ImageIO.write(image, "png", file); } catch (IOException e) { setExportMessage( EnumChatFormatting.DARK_RED + String.format("Failed to save skin file! %s", e)); e.printStackTrace(); } } else { setExportMessage( EnumChatFormatting.DARK_RED + String.format("Failed to export skin, image was null!")); file.delete(); } } if (Strings.isNullOrEmpty(this.exportMessage)) { savePartsData(); this.openFolderButton.visible = true; setExportMessage(EnumChatFormatting.GREEN + I18n.format("tails.export.success", file)); } } if (button.id == 3 && this.exportLoc != null) { try { Desktop.getDesktop().browse(this.exportLoc); } catch (IOException e) { setExportMessage( EnumChatFormatting.DARK_RED + String.format("Failed to open export location: %s", e)); e.printStackTrace(); } } //Upload if (button.id == 10) { final BufferedImage image = TextureHelper.writePartsDataToSkin(this.partsData, this.mc.thePlayer); Runnable runnable = new Runnable() { @Override public void run() { exportMessage = I18n.format("tails.uploading"); new ImgurUpload().uploadImage(image); } }; runnable.run(); } }
From source file:modmanager.MainWindow.java
private void selectSkyrimDirectory(boolean force) { skyrimDirectoryChooser.setDialogTitle("Select Skyrim folder"); skyrimDirectoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); boolean chosen = false; while (skyrimDirectoryChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { /**//from w w w .j a v a 2 s . c om * Use a while loop to check for valid skyrim installation ... */ if (!FileUtils.getFile(skyrimDirectoryChooser.getSelectedFile(), "TESV.exe").exists()) { int result = JOptionPane.showConfirmDialog(this, "It seems that this directory does not contain Skyrim!\nContinue anyways?", "Invalid Skyrim directory", JOptionPane.YES_NO_CANCEL_OPTION); if (result == JOptionPane.CANCEL_OPTION) { break; } if (result == JOptionPane.YES_OPTION) { chosen = true; break; } } else { chosen = true; break; } } if (force && !chosen) { System.exit(0); } modifications.setSkyrimDirectory(skyrimDirectoryChooser.getSelectedFile()); }
From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithChart.java
/** * Add two new menu items to the popup menu, for saving to TSV and CSV files *///from www. ja v a 2 s.com protected void initPopupMenu() { addSeparatorToPopupMenu(); //TSV JMenuItem saveTSVMenuItem = new JMenuItem(TextProvider.getText("SAVE_DATA_AS_TSV")); saveTSVMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JFileChooser fc = new JFileChooser(); int chooserStatus = fc.showOpenDialog(PanelWithChart.this); //if user didn't hit OK, ignore if (chooserStatus != JFileChooser.APPROVE_OPTION) return; File outFile = fc.getSelectedFile(); saveChartDataToTSV(outFile); } }); addItemToPopupMenu(saveTSVMenuItem); //CSV JMenuItem saveCSVMenuItem = new JMenuItem(TextProvider.getText("SAVE_DATA_AS_CSV")); saveCSVMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JFileChooser wfc = new JFileChooser(); int chooserStatus = wfc.showOpenDialog(PanelWithChart.this); //if user didn't hit OK, ignore if (chooserStatus != JFileChooser.APPROVE_OPTION) return; File outFile = wfc.getSelectedFile(); saveChartDataToCSV(outFile); } }); addItemToPopupMenu(saveCSVMenuItem); }