List of usage examples for javax.swing JFileChooser getSelectedFile
public File getSelectedFile()
From source file:edu.umich.robot.ViewerApplication.java
private Config promptForConfig() { JFileChooser fc = new JFileChooser("config"); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); FileFilter filter = new FileNameExtensionFilter("Text Config File", "txt"); fc.setFileFilter(filter);/* www .j av a 2 s .c o m*/ fc.setMultiSelectionEnabled(false); int ret = fc.showOpenDialog(frame); if (ret == JFileChooser.APPROVE_OPTION) { try { return new ConfigFile(fc.getSelectedFile().getAbsolutePath()); } catch (IOException e) { logger.error(e.getMessage()); } } return null; }
From source file:it.unibo.alchemist.boundary.gui.Perspective.java
private void openFile() { final JFileChooser fc = new JFileChooser(); fc.setMultiSelectionEnabled(false);//from w ww .j a v a 2 s . c o m fc.setFileFilter(FILE_FILTER); fc.setCurrentDirectory(currentDirectory); final int returnVal = fc.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { fileToLoad = fc.getSelectedFile(); currentDirectory = fc.getSelectedFile().getParentFile(); if (fileToLoad.exists()) { status.setText(getString("ready_to_process") + " " + fileToLoad.getAbsolutePath()); status.setOK(); if (sim != null) { sim.addCommand(new Engine.StateCommand<T>().stop().build()); } bar.setFileOK(true); } else { status.setText(FILE_NOT_VALID + " " + fileToLoad.getAbsolutePath()); status.setNo(); bar.setFileOK(false); } } }
From source file:test.integ.be.fedict.performance.util.PerformanceResultDialog.java
public PerformanceResultDialog(PerformanceResultsData data) { super((Frame) null, "Performance test results"); setSize(1000, 800);/* w w w . j ava 2 s . com*/ JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); JMenuItem savePerformanceMenuItem = new JMenuItem("Save Performance"); fileMenu.add(savePerformanceMenuItem); savePerformanceMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Save as PNG..."); int result = fileChooser.showSaveDialog(PerformanceResultDialog.this); if (JFileChooser.APPROVE_OPTION == result) { File file = fileChooser.getSelectedFile(); try { ChartUtilities.saveChartAsPNG(file, performanceChart, 1024, 768); } catch (IOException e) { JOptionPane.showMessageDialog(null, "error saving to file: " + e.getMessage()); } } } }); JMenuItem saveMemoryMenuItem = new JMenuItem("Save Memory"); fileMenu.add(saveMemoryMenuItem); saveMemoryMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Save as PNG..."); int result = fileChooser.showSaveDialog(PerformanceResultDialog.this); if (JFileChooser.APPROVE_OPTION == result) { File file = fileChooser.getSelectedFile(); try { ChartUtilities.saveChartAsPNG(file, memoryChart, 1024, 768); } catch (IOException e) { JOptionPane.showMessageDialog(null, "error saving to file: " + e.getMessage()); } } } }); // memory chart memoryChart = getMemoryChart(data.getIntervalSize(), data.getMemory()); // performance chart performanceChart = getPerformanceChart(data.getIntervalSize(), data.getPerformance(), data.getExpectedRevokedCount()); Container container = getContentPane(); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); if (null != performanceChart) { splitPane.setTopComponent(new ChartPanel(performanceChart)); } if (null != memoryChart) { splitPane.setBottomComponent(new ChartPanel(memoryChart)); } splitPane.setDividerLocation(getHeight() / 2); splitPane.setDividerSize(1); container.add(splitPane); setVisible(true); }
From source file:archive_v1.Archive_Form.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: CreateConnection();//from www.j a v a2 s. co m JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int a = jfc.showOpenDialog(this); if (a == JFileChooser.APPROVE_OPTION) { File file = jfc.getSelectedFile(); try { // What to do with the file, e.g. display it in a TextArea System.out.println(file.getAbsolutePath()); } catch (Exception ex) { System.out.println("problem accessing file" + file.getAbsolutePath()); } File[] folder = new File(file.getAbsolutePath()).listFiles(); for (File vid : folder) { filename = vid.getName(); size = getFileSize(file.getAbsolutePath() + "\\" + filename); tape_id = generateTapeId(); insertArchive(filename, size, tape_id, username); } } else { System.out.println("File access cancelled by user."); } }
From source file:com.intuit.tank.proxy.settings.ui.ProxyConfigDialog.java
private void save(int port, boolean followRedirecs, String outputFile, Set<ConfigInclusionExclusionRule> inclusions, Set<ConfigInclusionExclusionRule> exclusions, Set<ConfigInclusionExclusionRule> bodyInclusions, Set<ConfigInclusionExclusionRule> bodyExclusions, String configFileName) {/* w w w . j a v a 2s.c o m*/ String fileName = ""; if (StringUtils.isEmpty(configFileName)) { JFileChooser fileChooser = new JFileChooser(); File file = new File("."); fileChooser.setCurrentDirectory(file); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setFileFilter(new XmlFileFilter()); int showSaveDialog = fileChooser.showSaveDialog(this); if (showSaveDialog == JFileChooser.APPROVE_OPTION) { String selectedFile = fileChooser.getSelectedFile().getName(); if (!selectedFile.endsWith(".xml")) { selectedFile = selectedFile + ".xml"; } fileName = fileChooser.getSelectedFile().getParent() + "/" + selectedFile; configHandler.setConfigFile(fileName); } else { return; } } else { fileName = configFileName; } CommonsProxyConfiguration.save(port, followRedirecs, outputFile, inclusions, exclusions, bodyInclusions, bodyExclusions, fileName); getProxyConfigPanel().update(); configHandler.setConfigFile(fileName); }
From source file:ImageViewer.java
public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); if (source == openItem) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); chooser.setFileFilter(new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { return f.getName().toLowerCase().endsWith(".gif") || f.isDirectory(); }/*from w w w. j a va2s .c o m*/ public String getDescription() { return "GIF Images"; } }); int r = chooser.showOpenDialog(this); if (r == JFileChooser.APPROVE_OPTION) { String name = chooser.getSelectedFile().getName(); label.setIcon(new ImageIcon(name)); } } else if (source == exitItem) System.exit(0); }
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 {/*from ww w. j a v a 2s . com*/ 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:arduinouno.MainWindow.java
private void jButtonSelectFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectFileActionPerformed JFileChooser fileChooser = new JFileChooser(); int returnVal = fileChooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { saveFile = fileChooser.getSelectedFile(); jTextFieldSaveFile.setText(saveFile.getName()); }/* w ww . j av a2 s.co m*/ }
From source file:TextFileHandler.java
public File openDirectory(String title) { File result = null;/*from w w w .j a va 2s . c o m*/ JFileChooser chooser = new JFileChooser(new File(".")); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (title != null) chooser.setDialogTitle(title); int retVal = chooser.showOpenDialog(null); if (retVal == JFileChooser.APPROVE_OPTION) { result = chooser.getSelectedFile(); } return result; }
From source file:com.naval.gui.Gui.java
private void chargerPartie() { final JFileChooser fc = new JFileChooser(Config.getRepTravail()); fc.addChoosableFileFilter(new GameFileFilter("serial", "Sauv 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 {/*from w ww. j a v a 2 s . c o m*/ partie = Partie.load(file.getAbsolutePath()); menuFac.updateForLoad(); update(); } catch (FileNotFoundException e) { e.printStackTrace(); hintBar.setText(e.getMessage()); } catch (IOException e) { hintBar.setText(e.getMessage()); e.printStackTrace(); } catch (ClassNotFoundException e) { hintBar.setText(e.getMessage()); e.printStackTrace(); } } if (partie.ordres == null || partie.ordres.size() == 0) { for (Navire n : partie.navires) { // creation des 3 ordres pour le tour courant. partie.ordres.add(new Ordre(n.id, partie.minute)); partie.ordres.add(new Ordre(n.id, partie.minute)); partie.ordres.add(new Ordre(n.id, partie.minute)); } } }