List of usage examples for javax.swing JFileChooser showOpenDialog
public int showOpenDialog(Component parent) throws HeadlessException
From source file:de.ist.clonto.Ontogui.java
private void loadQuery(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_loadQuery JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir") + "/sparql")); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { queryPath = fc.getSelectedFile().toPath(); smellNameField.setText(fc.getSelectedFile().getName()); } else {/*w w w . j av a 2 s.c om*/ JOptionPane.showMessageDialog(this, "Loading query failed"); } }
From source file:coreferenceresolver.gui.MainGUI.java
private void inputFileBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inputFileBtnActionPerformed JFileChooser inputFileChooser = new JFileChooser(defaulPath); inputFileChooser.setDialogTitle("Choose an input file"); inputFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { inputFilePathTF.setText(inputFileChooser.getSelectedFile().getAbsolutePath()); } else {//from ww w . j a v a2 s .c o m noteTF.setText("No input file selected"); } }
From source file:org.martus.client.swingui.FxInSwingMainWindow.java
protected File[] showMultiFileOpenDialog(String title, File directory, Vector<FormatFilter> filters) { JFileChooser fileChooser = createFileChooser(title, directory, filters); fileChooser.setMultiSelectionEnabled(true); int userResult = fileChooser.showOpenDialog(getCurrentActiveFrame().getSwingFrame()); if (userResult != JFileChooser.APPROVE_OPTION) return new File[0]; return fileChooser.getSelectedFiles(); }
From source file:coreferenceresolver.gui.MainGUI.java
private void markupFileBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_markupFileBtnActionPerformed JFileChooser inputFileChooser = new JFileChooser(defaulPath); inputFileChooser.setDialogTitle("Choose an markup file"); inputFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { markupFilePathTF.setText(inputFileChooser.getSelectedFile().getAbsolutePath()); } else {/*from w w w. ja v a2 s. c o m*/ noteTF.setText("No markup file selected"); } }
From source file:coreferenceresolver.gui.MainGUI.java
private void chooseTestingFileBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseTestingFileBtnActionPerformed JFileChooser inputFileChooser = new JFileChooser(defaulPath); inputFileChooser.setDialogTitle("Choose an testing file"); inputFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { testingFilePathTF.setText(inputFileChooser.getSelectedFile().getAbsolutePath()); } else {/*from w w w. j av a 2s . c o m*/ noteTF.setText("No testing file selected"); } }
From source file:coreferenceresolver.gui.MainGUI.java
private void chooseTrainingFileBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseTrainingFileBtnActionPerformed // TODO add your handling code here: JFileChooser inputFileChooser = new JFileChooser(defaulPath); inputFileChooser.setDialogTitle("Choose a training file"); inputFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { trainingFilePathTF.setText(inputFileChooser.getSelectedFile().getAbsolutePath()); } else {/* w w w . j av a 2 s. c o m*/ noteTF.setText("No training file selected"); } }
From source file:au.org.ala.delta.intkey.ui.UIUtils.java
/** * Prompts for a file using the file chooser dialog * // w ww. j a va 2s .co m * @param fileExtensions * Accepted file extensions - must be null if filePrefixes is * non-null * @param filePrefixes * Accepted file prefixes - must be null if fileExtensions is * non-null * @param description * Description of the acceptable files * @param createFileIfNonExistant * if true, the file will be created if it does not exist. Also, * the system's "save" will be used instead of the "open" dialog. * @param startBrowseDirectory * The directory that the file chooser should start in * @param parent * parent component for the file chooser * @return the selected file, or null if no file was selected. * @throws IOException */ public static File promptForFile(List<String> fileExtensions, List<String> filePrefixes, final String description, boolean createFileIfNonExistant, File startBrowseDirectory, Component parent) throws IOException { if (fileExtensions != null && filePrefixes != null) { throw new IllegalArgumentException( "Only one of the file extensions or file prefixes should be non-null"); } JFileChooser chooser = new JFileChooser(startBrowseDirectory); FileFilter filter; if (fileExtensions != null) { String[] extensionsArray = new String[fileExtensions.size()]; fileExtensions.toArray(extensionsArray); filter = new FileNameExtensionFilter(description, extensionsArray); } else { final String[] prefixesArray = new String[filePrefixes.size()]; filePrefixes.toArray(prefixesArray); filter = new FileFilter() { @Override public String getDescription() { return description; } @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } else { return StringUtils.startsWithAny(f.getName(), prefixesArray); } } }; } chooser.setFileFilter(filter); int returnVal; if (createFileIfNonExistant) { returnVal = chooser.showSaveDialog(parent); } else { returnVal = chooser.showOpenDialog(parent); } if (returnVal == JFileChooser.APPROVE_OPTION) { if (createFileIfNonExistant) { File file = chooser.getSelectedFile(); if (!file.exists()) { // if only one file extension was supplied and the filename // does // not end with this extension, add it before // creating the file if (fileExtensions.size() == 1) { String extension = fileExtensions.get(0); String filePath = chooser.getSelectedFile().getAbsolutePath(); if (!filePath.endsWith(extension)) { file = new File(filePath + "." + extension); } } file.createNewFile(); } return file; } else { return chooser.getSelectedFile(); } } else { return null; } }
From source file:com.moneydance.modules.features.importlist.io.DefaultDirectoryChooser.java
@Override void chooseBaseDirectory() { final JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(this.getLocalizable().getDirectoryChooserTitle()); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // disable the "All files" option. fileChooser.setAcceptAllFileFilterUsed(false); try {/* www . j a v a 2 s. co m*/ fileChooser.setCurrentDirectory(FileUtils.getUserDirectory()); } catch (SecurityException e) { LOG.log(Level.WARNING, e.getMessage(), e); } if (this.getBaseDirectory() != null) { final File parentDirectory = this.getBaseDirectory().getParentFile(); fileChooser.setCurrentDirectory(parentDirectory); } if (fileChooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) { return; } this.getPrefs().setBaseDirectory(fileChooser.getSelectedFile().getAbsolutePath()); LOG.info(String.format("Base directory is %s", this.getPrefs().getBaseDirectory())); }
From source file:com.dfki.av.sudplan.vis.wiz.DataSourceSelectionPanel.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed JFileChooser jfc = new JFileChooser(); jfc.addChoosableFileFilter(new FileNameExtensionFilter("ESRI Shapfile (*.shp)", "shp", "Shp", "SHP")); jfc.addChoosableFileFilter(new FileNameExtensionFilter("Zip file (*.zip)", "zip", "ZIP", "Zip")); XMLConfiguration xmlConfig = Configuration.getXMLConfiguration(); String path = xmlConfig.getString("sudplan3D.working.dir"); File dir;//from ww w . java 2s . co m if (path != null) { dir = new File(path); if (dir.exists()) { jfc.setCurrentDirectory(dir); } } int retValue = jfc.showOpenDialog(this); if (retValue == JFileChooser.APPROVE_OPTION) { File f = jfc.getSelectedFile(); if (f != null) { jLabel1.setText(f.getAbsolutePath()); file = f; } } else { if (log.isDebugEnabled()) { log.debug("No shp file selected."); } } dir = jfc.getCurrentDirectory(); path = dir.getAbsolutePath(); xmlConfig.setProperty("sudplan3D.working.dir", path); }
From source file:com.litt.core.security.license.gui.ValidatePanel.java
/** * Create the panel./*from www . ja v a 2 s . c o m*/ */ public ValidatePanel() { GridBagLayout gbl_validatePanel = new GridBagLayout(); gbl_validatePanel.columnWidths = new int[] { 0, 0, 0 }; gbl_validatePanel.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; gbl_validatePanel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE }; gbl_validatePanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; this.setLayout(gbl_validatePanel); JLabel label_10 = new JLabel(""); GridBagConstraints gbc_label_10 = new GridBagConstraints(); gbc_label_10.insets = new Insets(0, 0, 5, 5); gbc_label_10.anchor = GridBagConstraints.EAST; gbc_label_10.gridx = 0; gbc_label_10.gridy = 0; this.add(label_10, gbc_label_10); field_pubKeyFilePath = new JTextField(); field_pubKeyFilePath.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { JFileChooser fileChooser = new JFileChooser(); //fileChooser.setVisible(true); LicenseFileFilter fileFilter = new LicenseFileFilter(new String[] { "key" }); fileChooser.setFileFilter(fileFilter); fileChooser.addChoosableFileFilter(fileFilter); fileChooser.showOpenDialog(e.getComponent()); File pubKeyFile = fileChooser.getSelectedFile(); field_pubKeyFilePath.setText(pubKeyFile.getAbsolutePath()); } }); GridBagConstraints gbc_field_pubKeyFilePath = new GridBagConstraints(); gbc_field_pubKeyFilePath.insets = new Insets(0, 0, 5, 0); gbc_field_pubKeyFilePath.fill = GridBagConstraints.HORIZONTAL; gbc_field_pubKeyFilePath.gridx = 1; gbc_field_pubKeyFilePath.gridy = 0; this.add(field_pubKeyFilePath, gbc_field_pubKeyFilePath); field_pubKeyFilePath.setColumns(10); JLabel label_19 = new JLabel("?"); GridBagConstraints gbc_label_19 = new GridBagConstraints(); gbc_label_19.anchor = GridBagConstraints.EAST; gbc_label_19.insets = new Insets(0, 0, 5, 5); gbc_label_19.gridx = 0; gbc_label_19.gridy = 1; this.add(label_19, gbc_label_19); field_licenseFilePath = new JTextField(); field_licenseFilePath.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { JFileChooser fileChooser = new JFileChooser(); //fileChooser.setVisible(true); LicenseFileFilter fileFilter = new LicenseFileFilter(new String[] { "xml" }); fileChooser.setFileFilter(fileFilter); fileChooser.addChoosableFileFilter(fileFilter); fileChooser.showOpenDialog(e.getComponent()); File licenseFile = fileChooser.getSelectedFile(); field_licenseFilePath.setText(licenseFile.getAbsolutePath()); } }); GridBagConstraints gbc_textField1 = new GridBagConstraints(); gbc_textField1.insets = new Insets(0, 0, 5, 0); gbc_textField1.fill = GridBagConstraints.HORIZONTAL; gbc_textField1.gridx = 1; gbc_textField1.gridy = 1; this.add(field_licenseFilePath, gbc_textField1); field_licenseFilePath.setColumns(10); JLabel lblid = new JLabel("?ID"); lblid.setHorizontalAlignment(SwingConstants.CENTER); GridBagConstraints gbc_lblid = new GridBagConstraints(); gbc_lblid.insets = new Insets(0, 0, 5, 5); gbc_lblid.gridx = 0; gbc_lblid.gridy = 2; this.add(lblid, gbc_lblid); label_licenseId = new JLabel(""); label_licenseId.setHorizontalAlignment(SwingConstants.CENTER); GridBagConstraints gbc_label_licenseId = new GridBagConstraints(); gbc_label_licenseId.insets = new Insets(0, 0, 5, 0); gbc_label_licenseId.gridx = 1; gbc_label_licenseId.gridy = 2; this.add(label_licenseId, gbc_label_licenseId); JLabel label_12 = new JLabel("?"); GridBagConstraints gbc_label_12 = new GridBagConstraints(); gbc_label_12.insets = new Insets(0, 0, 5, 5); gbc_label_12.gridx = 0; gbc_label_12.gridy = 3; this.add(label_12, gbc_label_12); label_licenseType = new JLabel(""); GridBagConstraints gbc_label_licenseType = new GridBagConstraints(); gbc_label_licenseType.insets = new Insets(0, 0, 5, 0); gbc_label_licenseType.gridx = 1; gbc_label_licenseType.gridy = 3; this.add(label_licenseType, gbc_label_licenseType); JLabel label_13 = new JLabel("???"); GridBagConstraints gbc_label_13 = new GridBagConstraints(); gbc_label_13.insets = new Insets(0, 0, 5, 5); gbc_label_13.gridx = 0; gbc_label_13.gridy = 4; this.add(label_13, gbc_label_13); label_productName = new JLabel(""); GridBagConstraints gbc_label_productName = new GridBagConstraints(); gbc_label_productName.insets = new Insets(0, 0, 5, 0); gbc_label_productName.gridx = 1; gbc_label_productName.gridy = 4; this.add(label_productName, gbc_label_productName); JLabel label_14 = new JLabel("???"); GridBagConstraints gbc_label_14 = new GridBagConstraints(); gbc_label_14.insets = new Insets(0, 0, 5, 5); gbc_label_14.gridx = 0; gbc_label_14.gridy = 5; this.add(label_14, gbc_label_14); label_companyName = new JLabel(""); GridBagConstraints gbc_label_companyName = new GridBagConstraints(); gbc_label_companyName.insets = new Insets(0, 0, 5, 0); gbc_label_companyName.gridx = 1; gbc_label_companyName.gridy = 5; this.add(label_companyName, gbc_label_companyName); JLabel label_15 = new JLabel("??"); GridBagConstraints gbc_label_15 = new GridBagConstraints(); gbc_label_15.insets = new Insets(0, 0, 5, 5); gbc_label_15.gridx = 0; gbc_label_15.gridy = 6; this.add(label_15, gbc_label_15); label_customerName = new JLabel(""); GridBagConstraints gbc_label_customerName = new GridBagConstraints(); gbc_label_customerName.insets = new Insets(0, 0, 5, 0); gbc_label_customerName.gridx = 1; gbc_label_customerName.gridy = 6; this.add(label_customerName, gbc_label_customerName); JLabel label_16 = new JLabel(""); GridBagConstraints gbc_label_16 = new GridBagConstraints(); gbc_label_16.insets = new Insets(0, 0, 5, 5); gbc_label_16.gridx = 0; gbc_label_16.gridy = 7; this.add(label_16, gbc_label_16); label_version = new JLabel(""); GridBagConstraints gbc_label_version = new GridBagConstraints(); gbc_label_version.insets = new Insets(0, 0, 5, 0); gbc_label_version.gridx = 1; gbc_label_version.gridy = 7; this.add(label_version, gbc_label_version); JLabel label_11 = new JLabel(""); GridBagConstraints gbc_label_11 = new GridBagConstraints(); gbc_label_11.insets = new Insets(0, 0, 5, 5); gbc_label_11.gridx = 0; gbc_label_11.gridy = 8; this.add(label_11, gbc_label_11); label_createDate = new JLabel(""); GridBagConstraints gbc_label_createDate = new GridBagConstraints(); gbc_label_createDate.insets = new Insets(0, 0, 5, 0); gbc_label_createDate.gridx = 1; gbc_label_createDate.gridy = 8; this.add(label_createDate, gbc_label_createDate); JLabel label_17 = new JLabel(""); GridBagConstraints gbc_label_17 = new GridBagConstraints(); gbc_label_17.insets = new Insets(0, 0, 5, 5); gbc_label_17.gridx = 0; gbc_label_17.gridy = 9; this.add(label_17, gbc_label_17); label_expiredDate = new JLabel(""); GridBagConstraints gbc_label_expiredDate = new GridBagConstraints(); gbc_label_expiredDate.insets = new Insets(0, 0, 5, 0); gbc_label_expiredDate.gridx = 1; gbc_label_expiredDate.gridy = 9; this.add(label_expiredDate, gbc_label_expiredDate); JButton button_2 = new JButton(""); button_2.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { String licenseFilePath = Utility.trimNull(field_licenseFilePath.getText()); String pubKeyFilePath = Utility.trimNull(field_pubKeyFilePath.getText()); if (Utility.isEmpty(licenseFilePath)) { JOptionPane.showMessageDialog(e.getComponent(), "?!"); return; } if (Utility.isEmpty(pubKeyFilePath)) { JOptionPane.showMessageDialog(e.getComponent(), "!"); return; } File licenseFile = new File(licenseFilePath); try { XMLConfiguration config = new XMLConfiguration(licenseFile); config.setAutoSave(true); label_licenseId.setText(config.getString(("licenseId"))); label_licenseType.setText(config.getString("licenseType")); label_productName.setText(config.getString("productName")); label_companyName.setText(config.getString("companyName")); label_customerName.setText(config.getString("customerName")); label_version.setText(config.getString("version")); label_createDate.setText(config.getString("createDate")); label_expiredDate.setText(config.getString("expiredDate")); } catch (Exception e1) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(e.getComponent(), e1.getMessage()); } try { LicenseManager.validateLicense(licenseFile.getAbsolutePath(), pubKeyFilePath); JOptionPane.showMessageDialog(e.getComponent(), "?"); } catch (LicenseException e1) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(e.getComponent(), e1.getMessage()); } } }); GridBagConstraints gbc_button_2 = new GridBagConstraints(); gbc_button_2.gridx = 1; gbc_button_2.gridy = 10; this.add(button_2, gbc_button_2); }