javax.swing.JFileChooser#getSelectedFile ( )源码实例Demo

下面列出了javax.swing.JFileChooser#getSelectedFile ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: AddWebServiceDlg.java
private void jBtnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnBrowseActionPerformed

    jRbnFilesystem.setSelected(false);
    jRbnFilesystem.setSelected(true);
    enableControls();

    JFileChooser chooser = new JFileChooser(previousDirectory);
    chooser.setMultiSelectionEnabled(false);
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.addChoosableFileFilter(WSDL_FILE_FILTER);
    chooser.setFileFilter(WSDL_FILE_FILTER);

    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File wsdlFile = chooser.getSelectedFile();
        jTxtLocalFilename.setText(wsdlFile.getAbsolutePath());
        previousDirectory = wsdlFile.getPath();
    }
}
 
源代码2 项目: zap-extensions   文件: AnalyseTokensDialog.java
private void saveAnalysis() {
    JFileChooser chooser =
            new WritableFileChooser(Model.getSingleton().getOptionsParam().getUserDirectory());
    File file = null;
    int rc = chooser.showSaveDialog(View.getSingleton().getMainFrame());
    if (rc == JFileChooser.APPROVE_OPTION) {
        try {
            file = chooser.getSelectedFile();
            if (file == null) {
                return;
            }

            try (BufferedWriter out = new BufferedWriter(new FileWriter(file))) {
                out.write(getErrorsArea().getText());
                out.write(getDetailsArea().getText());
            }

        } catch (Exception e) {
            View.getSingleton()
                    .showWarningDialog(messages.getString("tokengen.analyse.save.error"));
            log.error(e.getMessage(), e);
        }
    }
}
 
源代码3 项目: netbeans   文件: PanelProjectLocationVisual.java
private void browseLocationAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLocationAction
    String command = evt.getActionCommand();        
    if ( "BROWSE".equals( command ) ) { // NOI18N                
        JFileChooser chooser = new JFileChooser ();
        FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
        chooser.setDialogTitle(NbBundle.getMessage(PanelProjectLocationVisual.class,"LBL_NWP1_SelectProjectLocation"));
        chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
        String path = this.projectLocationTextField.getText();
        if (path.length() > 0) {
            File f = new File (path);
            if (f.exists ()) {
                chooser.setSelectedFile(f);
            }
        }
        if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N
            File projectDir = chooser.getSelectedFile();
            projectLocationTextField.setText( FileUtil.normalizeFile(projectDir).getAbsolutePath() );
        }            
        panel.fireChangeEvent();
    }
}
 
源代码4 项目: ontopia   文件: TypesConfigFrame.java
protected String promptForFile() {
  JFileChooser dialog = new JFileChooser(lastIconPath);

  dialog.setFileSelectionMode(JFileChooser.FILES_ONLY);
  dialog.setAcceptAllFileFilterUsed(false);
  dialog.setDialogTitle(Messages.getString("Viz.SelectIcon"));
  dialog.setSelectedFile(new File(filenameField.getText()));

  SimpleFileFilter filter = new SimpleFileFilter(Messages
      .getString("Viz.ImageFiles"));
  filter.addExtension("JPG");
  filter.addExtension("JPEG");
  filter.addExtension("GIF");
  filter.addExtension("PNG");

  dialog.setFileFilter(filter);

  dialog.showOpenDialog(this);
  File file = dialog.getSelectedFile();
  if (file == null) return null;

  lastIconPath = file.getPath();
  return file.getAbsolutePath();
}
 
源代码5 项目: open-ig   文件: VideoPlayer.java
/** Export the selected videos as PNG images. */
void doExport() {
	JFileChooser jfc = new JFileChooser(lastDir != null ? lastDir : new File("."));
	jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
	if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
		lastDir = jfc.getSelectedFile();
		int[] sels = videoTable.getSelectedRows();
		final List<AVExport> exportList = new ArrayList<>();
           for (int sel : sels) {
               VideoEntry ve = videoModel.rows.get(videoTable.convertRowIndexToModel(sel));

               AVExport ave = new AVExport();
               ave.video = rl.get(ve.path + "/" + ve.name, ResourceType.VIDEO);
               if (ve.audio != null && !ve.audio.isEmpty()) {
                   ave.audio = rl.getExactly(ve.audio, ve.path + "/" + ve.name, ResourceType.AUDIO);
               }
               ave.naming = lastDir.getAbsolutePath() + "/" + ve.name + "_%05d.png";
               exportList.add(ave);
           }
		doExportGUI(exportList);
	}
}
 
源代码6 项目: ApkToolPlus   文件: BrowserMDIFrame.java
private void doOpenClassFile() {

		JFileChooser fileChooser = getClassesFileChooser();
		int result = fileChooser.showOpenDialog(this);
		if (result == JFileChooser.APPROVE_OPTION) {
			repaintNow();
			setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
			File file = fileChooser.getSelectedFile();
			classesChooserPath = fileChooser.getCurrentDirectory()
					.getAbsolutePath();

			BrowserInternalFrame frame;
			if (file.getPath().toLowerCase().endsWith(".class")) {
				frame = openClassFromFile(file);
			} else {
				frame = openClassFromJar(file);
			}

			if (frame != null) {
				try {
					frame.setMaximum(true);
				} catch (PropertyVetoException ex) {
				}
			}
			setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
		}
	}
 
源代码7 项目: constellation   文件: SupportPackageAction.java
/**
 * Show file "Save As" dialog
 *
 * @return File selected by the user or null if no file was selected.
 */
private File getSaveAsDirectory() {

    final JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setDialogTitle(Bundle.MSG_SaveAsTitle());
    chooser.setMultiSelectionEnabled(false);
    chooser.setCurrentDirectory(new File(System.getProperty("user.home")));

    if (JFileChooser.APPROVE_OPTION == chooser.showSaveDialog(WindowManager.getDefault().getMainWindow())) {
        return chooser.getSelectedFile();
    } else {
        return null;
    }
}
 
源代码8 项目: osp   文件: ControlUtils.java
/**
 * Loads control parameters from a text file using a dialog box.
 */
public static void loadParameters(Control control, Component parent) {
  JFileChooser chooser = new JFileChooser(new File(OSPRuntime.chooserDir));
	FontSizer.setFonts(chooser, FontSizer.getLevel());
  int result = chooser.showOpenDialog(parent);
  if(result==JFileChooser.APPROVE_OPTION) {
    try {
      BufferedReader inFile = new BufferedReader(new FileReader(chooser.getSelectedFile()));
      readFile(control, inFile);
      inFile.close();
    } catch(Exception ex) {
      System.err.println(ex.getMessage());
    }
  }
}
 
源代码9 项目: visualvm   文件: AboutDialogControls.java
private void saveFileAs(final File file) {
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle(NbBundle.getMessage(AboutDialogControls.class, "CAPTION_Save_logfile")); // NOI18N
        chooser.setSelectedFile(new File(lastLogfileSave));
        if (chooser.showSaveDialog(WindowManager.getDefault().getMainWindow()) == JFileChooser.APPROVE_OPTION) {
            final File copy = chooser.getSelectedFile();
//            if (copy.isFile()) // TODO: show a confirmation dialog for already existing file
            lastLogfileSave = copy.getAbsolutePath();
            VisualVM.getInstance().runTask(new Runnable() {
                public void run() {
                    ProgressHandle pHandle = null;
                    try {
                        pHandle = ProgressHandleFactory.createHandle(
                                NbBundle.getMessage(AboutDialogControls.class,
                                "MSG_Saving_logfile", file.getName()));  // NOI18N
                        pHandle.setInitialDelay(0);
                        pHandle.start();
                        if (!Utils.copyFile(file, copy)) JOptionPane.showMessageDialog(AboutDialog.getInstance().getDialog(), 
                            NbBundle.getMessage(AboutDialogControls.class, "MSG_Save_logfile_failed"),   // NOI18N
                            NbBundle.getMessage(AboutDialogControls.class, "CAPTION_Save_logfile_failed"),    // NOI18N
                            JOptionPane.ERROR_MESSAGE);
                    } finally {
                        final ProgressHandle pHandleF = pHandle;
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() { if (pHandleF != null) pHandleF.finish(); }
                        });
                    }
                }
            });
        }
    }
 
源代码10 项目: rapidminer-studio   文件: ScatterPlotter.java
@Override
public void save() {
	JFileChooser chooser = SwingTools.createFileChooser("file_chooser.save", null, false, new FileFilter[0]);
	if (chooser.showSaveDialog(ScatterPlotter.this) == JFileChooser.APPROVE_OPTION) {
		File file = chooser.getSelectedFile();
		try (FileWriter fw = new FileWriter(file); PrintWriter out = new PrintWriter(fw)) {
			dataTable.write(out);
		} catch (Exception ex) {
			SwingTools.showSimpleErrorMessage("cannot_write_to_file_0", ex, file);
		}
	}
}
 
源代码11 项目: AILibs   文件: CEOCSTN2Shop2.java
public void print(final CEOCSTNPlanningProblem problem, final String packageName) throws IOException {
	this.packageName = packageName;
	JFileChooser chooser = new JFileChooser();
	chooser.setDialogTitle("Domain-File");
	chooser.showOpenDialog(null);
	File domainFile = chooser.getSelectedFile();

	this.printDomain(domainFile);

	chooser.setDialogTitle("Problem-File");
	chooser.showOpenDialog(null);
	File problemFile = chooser.getSelectedFile();
	this.printProblem(problem, problemFile);
}
 
源代码12 项目: zap-extensions   文件: TokenPanel.java
private void saveTokens() {
    JFileChooser chooser =
            new WritableFileChooser(Model.getSingleton().getOptionsParam().getUserDirectory());
    File file = null;
    int rc = chooser.showSaveDialog(View.getSingleton().getMainFrame());
    if (rc == JFileChooser.APPROVE_OPTION) {
        try {
            file = chooser.getSelectedFile();
            if (file == null) {
                return;
            }

            CharacterFrequencyMap cfm = new CharacterFrequencyMap();

            for (int i = 0; i < this.resultsModel.getRowCount(); i++) {
                MessageSummary msg = this.resultsModel.getMessage(i);
                if (msg.getToken() != null) {
                    cfm.addToken(msg.getToken());
                }
            }

            cfm.save(file);

        } catch (Exception e) {
            View.getSingleton()
                    .showWarningDialog(
                            extension.getMessages().getString("tokengen.generate.save.error"));
            log.error(e.getMessage(), e);
        }
    }
}
 
源代码13 项目: grammarviz2_src   文件: GrammarVizController.java
/**
 * Implements a listener for the "Browse" button at GUI; opens FileChooser and so on.
 * 
 * @return the action listener.
 */
public ActionListener getBrowseFilesListener() {

  ActionListener selectDataActionListener = new ActionListener() {

    public void actionPerformed(ActionEvent e) {

      JFileChooser fileChooser = new JFileChooser();
      fileChooser.setDialogTitle("Select Data File");

      String filename = model.getDataFileName();
      if (!((null == filename) || filename.isEmpty())) {
        fileChooser.setSelectedFile(new File(filename));
      }

      if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();

        // here it calls to model -informing about the selected file.
        //
        model.setDataSource(file.getAbsolutePath());
      }
    }

  };
  return selectDataActionListener;
}
 
源代码14 项目: yeti   文件: UtilFunctions.java
public static String openFile(String fileExtension) {
    JFileChooser dlgFile = new JFileChooser();
    dlgFile.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    dlgFile.setApproveButtonText("Open");

    int returnVal = dlgFile.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = dlgFile.getSelectedFile();
        return file.getAbsolutePath();
    }
    return "";
}
 
public static File openDialog(String desc, String... fileFormat) {
    JFileChooser fileChooser = createFileChooser();
    fileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
    if (fileFormat != null && fileFormat.length > 0) {
        fileChooser.setFileFilter(new FileNameExtensionFilter(desc, fileFormat));
    }
    int option = fileChooser.showOpenDialog(null);
    if (option == JFileChooser.APPROVE_OPTION) {
        return fileChooser.getSelectedFile();
    }
    return null;
}
 
源代码16 项目: PyramidShader   文件: FileUtils.java
public static String askDirectory(java.awt.Frame frame,
        String message,
        boolean load,
        String defaultDirectory) throws IOException {

    if (FileUtils.IS_MAC_OSX) {
        try {
            System.setProperty("apple.awt.fileDialogForDirectories", "true");
            FileDialog fd = new FileDialog(frame, message, load ? FileDialog.LOAD : FileDialog.SAVE);
            fd.setFile(defaultDirectory);
            fd.setVisible(true);
            String fileName = fd.getFile();
            String directory = fd.getDirectory();
            return (fileName == null || directory == null) ? null : directory + fileName;
        } finally {
            System.setProperty("apple.awt.fileDialogForDirectories", "false");
        }
    } else {
        JFileChooser fc = new JFileChooser(defaultDirectory);
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fc.setDialogTitle(message);
        fc.showOpenDialog(null);

        File selFile = fc.getSelectedFile();
        return selFile.getCanonicalPath();
    }
}
 
源代码17 项目: AndroidResizer   文件: AResizerFrame.java
private void BrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BrowseButtonActionPerformed
    //    new FolderChooser().setVisible(true);

    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.showOpenDialog(null);
    //chooser.
    originalDirectory = chooser.getSelectedFile();
    String directoryName = originalDirectory.getAbsolutePath();

    FileField.setText(directoryName);
    // TODO add your handling code here:
}
 
源代码18 项目: MeteoInfo   文件: FrmGifAnimator.java
private void jButton_CreateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CreateActionPerformed
    // TODO add your handling code here:
    this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    
    String path = System.getProperty("user.dir");
    File pathDir = new File(path);
    JFileChooser saveDlg = new JFileChooser();
    saveDlg.setAcceptAllFileFilterUsed(false);
    saveDlg.setCurrentDirectory(pathDir);
    String[] fileExts = new String[]{"gif"};
    GenericFileFilter gifFileFilter = new GenericFileFilter(fileExts, "Gif File (*.gif)");
    saveDlg.setFileFilter(gifFileFilter);
    if (JFileChooser.APPROVE_OPTION == saveDlg.showSaveDialog(this)) {
        File outfile = saveDlg.getSelectedFile();
        String extent = ((GenericFileFilter) saveDlg.getFileFilter()).getFileExtent();
        String fileName = outfile.getAbsolutePath();
        if (!fileName.substring(fileName.length() - extent.length()).equals(extent)) {
            fileName = fileName + "." + extent;
        }            

        DefaultListModel listModel = (DefaultListModel) this.jList_ImageFiles.getModel();
        List<String> fns = new ArrayList<String>();
        for (int i = 0; i < listModel.getSize(); i++) {
            fns.add(listModel.get(i).toString());
        }
        int delay = Integer.parseInt(this.jTextField_Delay.getText());
        int repeat = Integer.parseInt(this.jTextField_Repeat.getText());
        ImageUtil.createGifAnimator(fns, fileName, delay, repeat);
        JOptionPane.showMessageDialog(null, "Gif animator file is created!");
    }
    
    this.setCursor(Cursor.getDefaultCursor());
}
 
源代码19 项目: netbeans   文件: ExportAction.java
private SelectedFile selectExportTargetFile(final ExportProvider exportProvider) {
    File targetDir;
    String targetName;
    String defaultName = exportProvider.getViewName();

    // 1. let the user choose file or directory
    final JFileChooser chooser = getFileChooser();
    if (exportDir != null) {
        chooser.setCurrentDirectory(exportDir);
    }
    int result = chooser.showSaveDialog(WindowManager.getDefault().getRegistry().getActivated());
    if (result != JFileChooser.APPROVE_OPTION) {
        return null; // cancelled by the user
    }

    // 2. process both cases and extract file name and extension to use and set exported file type
    File file = chooser.getSelectedFile();
    String targetExt = null;
    FileFilter selectedFileFilter = chooser.getFileFilter();
    if (selectedFileFilter==null  // workaround for #227659
            ||  selectedFileFilter.getDescription().equals(Bundle.ExportAction_ExportDialogCSVFilter())) {
        targetExt=FILE_EXTENSION_CSV;
        exportedFileType=MODE_CSV;
    } else if (selectedFileFilter.getDescription().equals(Bundle.ExportAction_ExportDialogTXTFilter())) {
        targetExt=FILE_EXTENSION_TXT;
        exportedFileType=MODE_TXT;
    } else if (selectedFileFilter.getDescription().equals(Bundle.ExportAction_ExportDialogBINFilter())) {
        targetExt=FILE_EXTENSION_BIN;
        exportedFileType=MODE_BIN;
    }

    if (file.isDirectory()) { // save to selected directory under default name
        exportDir = file;
        targetDir = file;
        targetName = defaultName;
    } else { // save to selected file
        targetDir = fileChooser.getCurrentDirectory();
        String fName = file.getName();

        // divide the file name into name and extension
        if (fName.endsWith("."+targetExt)) {  // NOI18N
            int idx = fName.lastIndexOf('.'); // NOI18N
            targetName = fName.substring(0, idx);
        } else {            // no extension
            targetName=fName;
        }
    }

    // 3. set type of exported file and return a newly created FileObject

    return new ExportAction.SelectedFile(targetDir, targetName, targetExt);
}
 
源代码20 项目: Logisim   文件: ExportImage.java
static void doExport(Project proj) {
	// First display circuit/parameter selection dialog
	Frame frame = proj.getFrame();
	CircuitJList list = new CircuitJList(proj, true);
	if (list.getModel().getSize() == 0) {
		JOptionPane.showMessageDialog(proj.getFrame(), Strings.get("exportEmptyCircuitsMessage"),
				Strings.get("exportEmptyCircuitsTitle"), JOptionPane.YES_NO_OPTION);
		return;
	}
	OptionsPanel options = new OptionsPanel(list);
	int action = JOptionPane.showConfirmDialog(frame, options, Strings.get("exportImageSelect"),
			JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
	if (action != JOptionPane.OK_OPTION)
		return;
	List<Circuit> circuits = list.getSelectedCircuits();
	double scale = options.getScale();
	boolean printerView = options.getPrinterView();
	if (circuits.isEmpty())
		return;

	ImageFileFilter filter;
	int fmt = options.getImageFormat();
	switch (options.getImageFormat()) {
	case FORMAT_GIF:
		filter = new ImageFileFilter(fmt, Strings.getter("exportGifFilter"), new String[] { "gif" });
		break;
	case FORMAT_PNG:
		filter = new ImageFileFilter(fmt, Strings.getter("exportPngFilter"), new String[] { "png" });
		break;
	case FORMAT_JPG:
		filter = new ImageFileFilter(fmt, Strings.getter("exportJpgFilter"),
				new String[] { "jpg", "jpeg", "jpe", "jfi", "jfif", "jfi" });
		break;
	default:
		System.err.println("unexpected format; aborted"); // OK
		return;
	}

	// Then display file chooser
	Loader loader = proj.getLogisimFile().getLoader();
	JFileChooser chooser = loader.createChooser();
	if (circuits.size() > 1) {
		chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		chooser.setDialogTitle(Strings.get("exportImageDirectorySelect"));
	} else {
		chooser.setFileFilter(filter);
		chooser.setDialogTitle(Strings.get("exportImageFileSelect"));
	}
	int returnVal = chooser.showDialog(frame, Strings.get("exportImageButton"));
	if (returnVal != JFileChooser.APPROVE_OPTION)
		return;

	// Determine whether destination is valid
	File dest = chooser.getSelectedFile();
	chooser.setCurrentDirectory(dest.isDirectory() ? dest : dest.getParentFile());
	if (dest.exists()) {
		if (!dest.isDirectory()) {
			int confirm = JOptionPane.showConfirmDialog(proj.getFrame(), Strings.get("confirmOverwriteMessage"),
					Strings.get("confirmOverwriteTitle"), JOptionPane.YES_NO_OPTION);
			if (confirm != JOptionPane.YES_OPTION)
				return;
		}
	} else {
		if (circuits.size() > 1) {
			boolean created = dest.mkdir();
			if (!created) {
				JOptionPane.showMessageDialog(proj.getFrame(), Strings.get("exportNewDirectoryErrorMessage"),
						Strings.get("exportNewDirectoryErrorTitle"), JOptionPane.YES_NO_OPTION);
				return;
			}
		}
	}

	// Create the progress monitor
	ProgressMonitor monitor = new ProgressMonitor(frame, Strings.get("exportImageProgress"), null, 0, 10000);
	monitor.setMillisToDecideToPopup(100);
	monitor.setMillisToPopup(200);
	monitor.setProgress(0);

	// And start a thread to actually perform the operation
	// (This is run in a thread so that Swing will update the
	// monitor.)
	new ExportThread(frame, frame.getCanvas(), dest, filter, circuits, scale, printerView, monitor).start();

}