List of usage examples for javax.swing JFileChooser getSelectedFile
public File getSelectedFile()
From source file:it.unibas.spicygui.controllo.file.ActionCsvFileChooserSchema.java
public void actionPerformed(ActionEvent e) { executeInjection();/*from www. j a v a2s. co m*/ JFileChooser chooser = vista.getFileChooserApriCSV(); File file; int returnVal = chooser.showOpenDialog(WindowManager.getDefault().getMainWindow()); if (returnVal == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); //giannisk Add schema file path to previous ones csvConfigurationPM.addToSchemaPathList(file.getAbsolutePath()); } }
From source file:cloud.gui.DistributionSelectionActionListener.java
@SuppressWarnings("static-access") @Override//w w w . java 2 s .c om public void actionPerformed(ActionEvent e) { String name = (String) gui.getDistributions().getSelectedItem(); if (DistributionName.EXPONENTIAL.getName().equals(name)) { gui.decorateExponentialDistribution(); } else if (DistributionName.UNIFORM.getName().equals(name)) { gui.decorateForUniformDistribution(); } else if (DistributionName.CONSTANT.getName().equals(name)) { gui.decorateForConstantDistribution(); } else if (DistributionName.CUSTOM.getName().equals(name)) { JFileChooser fileChooser = new JFileChooser(); int returnVal = fileChooser.showOpenDialog(gui); if (returnVal == fileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); try { List<String> lines = FileUtils.readLines(file); boolean result = validate(lines); if (!result) { gui.decorateForInValidDistribution(); logger.error("Invalid Distribution file " + file.getName()); } else { gui.decorateForCustomDistribution(lines); logger.info("File " + file.getName() + " is imported to generate the distribution from"); } } catch (IOException e1) { e1.printStackTrace(); } } else { gui.getDistributions().setSelectedIndex(0); gui.decorateForUniformDistribution(); } } }
From source file:MessageDigestTest.java
public void loadFile() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); int r = chooser.showOpenDialog(this); if (r == JFileChooser.APPROVE_OPTION) { String name = chooser.getSelectedFile().getAbsolutePath(); computeDigest(loadBytes(name));//from w w w .j a v a 2 s.c om } }
From source file:task5.Histogram.java
private void getImage() { String userDir = System.getProperty("user.home"); JFileChooser fileChooser = new JFileChooser(userDir + "/Desktop"); int result = fileChooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); try {/*from w w w . j a v a 2 s.co m*/ img = ImageIO.read(selectedFile); myframe = get_MYIMAGE(); } catch (IOException ex) { Logger.getLogger(MyImage.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:it.unibas.spicygui.controllo.file.ActionFileChooserSchema.java
public void actionPerformed(ActionEvent e) { executeInjection();/* ww w . j a v a 2s. c om*/ JFileChooser chooser = vista.getFileChooserApriXSD(); File file; int returnVal = chooser.showOpenDialog(WindowManager.getDefault().getMainWindow()); if (returnVal == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); xmlConfigurationPM.setSchemaPath(file.getAbsolutePath()); } }
From source file:eu.apenet.dpt.standalone.gui.XsltAdderActionListener.java
public void actionPerformed(ActionEvent e) { JFileChooser xsltChooser = new JFileChooser(); xsltChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (xsltChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { File file = xsltChooser.getSelectedFile(); if (isXSLT(file)) { if (saveXslt(file)) { JRadioButton newButton = new JRadioButton(file.getName()); newButton.addActionListener(new XsltSelectorListener(dataPreparationToolGUI)); dataPreparationToolGUI.getGroupXslt().add(newButton); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().addToXsltPanel(newButton); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane() .addToXsltPanel(Box.createRigidArea(new Dimension(0, 10))); JOptionPane.showMessageDialog(parent, labels.getString("xsltSaved") + ".", labels.getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon); } else { JOptionPane.showMessageDialog(parent, labels.getString("xsltNotSaved") + ".", labels.getString("fileNotSaved"), JOptionPane.ERROR_MESSAGE, Utilities.icon); }/* w w w . j a v a 2 s . co m*/ } else { JOptionPane.showMessageDialog(parent, labels.getString("xsltNotSaved") + ".", labels.getString("fileNotSaved"), JOptionPane.ERROR_MESSAGE, Utilities.icon); } } }
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);// w w w . j a v a2 s . c o m 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:org.pgptool.gui.ui.tools.browsefs.ExistingFileChooserDialog.java
public String askUserForFile() { JFileChooser ofd = buildFileChooserDialog(); int result = ofd.showOpenDialog(optionalParent); if (result != JFileChooser.APPROVE_OPTION) { return handleFileWasChosen(null); }/* ww w . jav a 2s. c o m*/ File retFile = ofd.getSelectedFile(); if (retFile == null) { return handleFileWasChosen(null); } String ret = retFile.getAbsolutePath(); ret = handleFileWasChosen(ret); configPairs.put(configPairNameToRemember, FilenameUtils.getFullPathNoEndSeparator(ret)); return ret; }
From source file:com.nubits.nubot.launch.toolkit.LaunchUI.java
private String askUser() { //Create Options for option dialog String path = ""; // Set cross-platform Java L&F (also called "Metal") try {/*from ww w.j av a 2 s . c o m*/ UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); final ImageIcon icon = new ImageIcon(local_path + "/" + ICON_PATH); //Ask the user to ask for scratch Object[] options = { "Import existing JSON option file", "Configure the bot from scratch" }; int n = JOptionPane.showOptionDialog(new JFrame(), "Chose one of the following options:", "NuBot UI Launcher", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, icon, //do not use a custom Icon options, //the titles of buttons options[0]); //default button title if (n == JOptionPane.YES_OPTION) { //Prompt user to chose a file. JFileChooser fileChooser = createFileChoser(); int result = fileChooser.showOpenDialog(new JFrame()); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); path = selectedFile.getAbsolutePath(); LOG.info("Option file selected : " + path); } else { LOG.info("Closing Launch UI utility."); System.exit(0); } } } catch (ClassNotFoundException | UnsupportedLookAndFeelException | IllegalAccessException | InstantiationException e) { LOG.error(e.toString()); } return path; }