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

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

源代码1 项目: keystore-explorer   文件: DPreferences.java
private void browsePressed() {
	JFileChooser chooser = FileChooserFactory.getKeyStoreFileChooser();

	if ((caCertificatesFile.getParentFile() != null) && (caCertificatesFile.getParentFile().exists())) {
		chooser.setCurrentDirectory(caCertificatesFile.getParentFile());
	} else {
		chooser.setCurrentDirectory(CurrentDirectory.get());
	}

	chooser.setDialogTitle(res.getString("DPreferences.ChooseCACertificatesKeyStore.Title"));

	chooser.setMultiSelectionEnabled(false);

	int rtnValue = chooser.showDialog(this, res.getString("DPreferences.CaCertificatesKeyStoreFileChooser.button"));
	if (rtnValue == JFileChooser.APPROVE_OPTION) {
		File chosenFile = chooser.getSelectedFile();
		CurrentDirectory.updateForFile(chosenFile);
		jtfCaCertificatesFile.setText(chosenFile.toString());
		jtfCaCertificatesFile.setCaretPosition(0);
	}
}
 
源代码2 项目: jaamsim   文件: DisplayEntityFactory.java
/**
 * Opens a FileDialog for selecting images to import.
 *
 * @param gui - the Control Panel.
 */
public static void importImages(GUIFrame gui) {

	// Create a file chooser
	final JFileChooser chooser = new JFileChooser(GUIFrame.getImageFolder());
	chooser.setMultiSelectionEnabled(true);

	// Set the file extension filters
	chooser.setAcceptAllFileFilterUsed(false);
	FileNameExtensionFilter[] imgFilters = FileInput.getFileNameExtensionFilters("Image",
			ImageModel.VALID_FILE_EXTENSIONS, ImageModel.VALID_FILE_DESCRIPTIONS);
	for (int i = 0; i < imgFilters.length; i++) {
		chooser.addChoosableFileFilter(imgFilters[i]);
	}
	chooser.setFileFilter(imgFilters[0]);

	// Show the file chooser and wait for selection
	int returnVal = chooser.showDialog(gui, "Import Images");

	// Create the selected graphics files
	if (returnVal == JFileChooser.APPROVE_OPTION) {
		File[] files = chooser.getSelectedFiles();
		GUIFrame.setImageFolder(files[0].getParent());
		DisplayEntityFactory.importImageFiles(files);
	}
}
 
源代码3 项目: netbeans   文件: RunJarPanel.java
private void btnWorkDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnWorkDirActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(null);
    chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    
    String workDir = txtWorkDir.getText();
    if (workDir.equals("")) { //NOI18N
        workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath();
    }
    chooser.setSelectedFile(new File(workDir));
    chooser.setDialogTitle(org.openide.util.NbBundle.getMessage(RunJarPanel.class, "TIT_SelectWorkingDirectory"));
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N
        File file = FileUtil.normalizeFile(chooser.getSelectedFile());
        txtWorkDir.setText(file.getAbsolutePath());
    }
}
 
源代码4 项目: portecle   文件: DOptions.java
/**
 * Browse button pressed or otherwise activated. Allow the user to choose a CA certs file.
 */
private void browsePressed()
{
	JFileChooser chooser = FileChooserFactory.getKeyStoreFileChooser(null);

	if (m_fCaCertsFile.getParentFile().exists())
	{
		chooser.setCurrentDirectory(m_fCaCertsFile.getParentFile());
	}

	chooser.setDialogTitle(RB.getString("DOptions.ChooseCACertsKeyStore.Title"));

	chooser.setMultiSelectionEnabled(false);

	int iRtnValue = chooser.showDialog(this, RB.getString("DOptions.CaCertsKeyStoreFileChooser.button"));
	if (iRtnValue == JFileChooser.APPROVE_OPTION)
	{
		m_jtfCaCertsFile.setText(chooser.getSelectedFile().toString());
		m_jtfCaCertsFile.setCaretPosition(0);
	}
}
 
源代码5 项目: netbeans   文件: OpenFileAction.java
/**
 * Creates and initializes a file chooser.
 *
 * @return  the initialized file chooser
 */
protected JFileChooser prepareFileChooser() {
    FileChooserBuilder fcb = new FileChooserBuilder(OpenFileAction.class);
    fcb.setSelectionApprover(new OpenFileSelectionApprover());
    fcb.setFilesOnly(true);
    fcb.addDefaultFileFilters();
    for (OpenFileDialogFilter filter :
            Lookup.getDefault().lookupAll(OpenFileDialogFilter.class)) {
        fcb.addFileFilter(filter);
    }
    JFileChooser chooser = fcb.createFileChooser();
    chooser.setMultiSelectionEnabled(true);
    chooser.getCurrentDirectory().listFiles(); //preload
    chooser.setCurrentDirectory(getCurrentDirectory());
    if (currentFileFilter != null) {
        for (FileFilter ff : chooser.getChoosableFileFilters()) {
            if (currentFileFilter.equals(ff.getDescription())) {
                chooser.setFileFilter(ff);
                break;
            }
        }
    }
    HelpCtx.setHelpIDString(chooser, getHelpCtx().getHelpID());
    return chooser;
}
 
源代码6 项目: netbeans-mmd-plugin   文件: PreferencesPanel.java
private void buttonGraphvizDotFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGraphvizDotFileActionPerformed
  final JFileChooser fileChooser = new JFileChooser(this.textFieldPathToGraphvizDot.getText());
  fileChooser.setDialogTitle("Select GraphViz dot executable file");
  fileChooser.setApproveButtonText("Select");
  fileChooser.setAcceptAllFileFilterUsed(true);
  fileChooser.setMultiSelectionEnabled(false);

  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

  if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
    final File file = fileChooser.getSelectedFile();
    this.textFieldPathToGraphvizDot.setText(file.getAbsolutePath());
  }
}
 
源代码7 项目: jenetics   文件: EvolvingImages.java
private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButtonActionPerformed
	final File dir = lastOpenDirectory();
	final JFileChooser chooser = dir != null
		? new JFileChooser(dir)
		: new JFileChooser();
	chooser.setDialogTitle("Choose Image");
	chooser.setDialogType(JFileChooser.OPEN_DIALOG);
	chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
	chooser.setMultiSelectionEnabled(false);
	chooser.addChoosableFileFilter(new FileNameExtensionFilter(
		format(
			"Images (%s)",
			Stream.of(ImageIO.getReaderFileSuffixes())
				.map(s -> format(" *.%s", s))
				.collect(Collectors.joining(","))
		),
		ImageIO.getReaderFileSuffixes()
	));

	final int returnVal = chooser.showOpenDialog(this);
	if (returnVal == JFileChooser.APPROVE_OPTION) {
		final File imageFile = chooser.getSelectedFile();
		try {
			update(ImageIO.read(imageFile));
			if (imageFile.getParentFile() != null) {
				lastOpenDirectory(imageFile.getParentFile());
			}
		} catch (IOException e) {
			JOptionPane.showMessageDialog(
				rootPane,
				format("Error while loading image '%s'.", imageFile),
				e.toString(),
				JOptionPane.ERROR_MESSAGE
			);
		}
	}
}
 
/**
 * Creates the file chooser.
 *
 * @return the initialized file chooser.
 */
protected JFileChooser createFileChooser() {
    final JFileChooser fc = new JFileChooser();
    fc.addChoosableFileFilter(
        new ExtensionFileFilter(getFileDescription(), getFileExtension())
    );
    fc.setMultiSelectionEnabled(false);
    fc.setCurrentDirectory(getCurrentDirectory());
    return fc;
}
 
源代码9 项目: raccoon4   文件: ShareToolBuilder.java
@Override
protected JPanel assemble() {
	JPanel ret = new JPanel();
	TitleStrip titleStrip = new TitleStrip(Messages.getString(ID + ".title"),
			Messages.getString(ID + ".subtitle"), new ImageIcon(getClass()
					.getResource("/icons/appicon.png")));
	transfer = new QrPanel(300);
	transfer.withActions(new CopyContentAction(globals, transfer));
	transfer.setBorder(new TitledBorder(Messages.getString(ID + ".transfer")));

	chooser = new JFileChooser(globals.get(Layout.class).shareDir);
	chooser.setMultiSelectionEnabled(true);
	chooser.setControlButtonsAreShown(false);
	chooser.addPropertyChangeListener(this);

	ret.setLayout(new GridBagLayout());
	GridBagConstraints gbc = new GridBagConstraints();
	gbc.gridx = 0;
	gbc.gridy = 0;
	gbc.gridwidth = 2;
	gbc.weightx = 1;
	gbc.weighty = 1;
	gbc.fill = GridBagConstraints.BOTH;
	gbc.anchor = GridBagConstraints.NORTHWEST;
	ret.add(titleStrip, gbc);

	gbc.gridy = 1;
	gbc.gridwidth = 1;
	gbc.fill = GridBagConstraints.NONE;
	ret.add(chooser, gbc);

	gbc.gridx = 1;
	gbc.insets = new Insets(7, 7, 7, 7);
	ret.add(transfer, gbc);

	return ret;
}
 
源代码10 项目: ehacks-pro   文件: DebugMe.java
@Override
public void run() {
    Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();
    JFileChooser fileopen = new JFileChooser();
    fileopen.setFileFilter(new OpenFileFilter("bsh", "BSH files (*.bsh)"));
    fileopen.setAcceptAllFileFilterUsed(false);
    fileopen.setMultiSelectionEnabled(false);
    fileopen.setPreferredSize(new Dimension(scr.width - 350, scr.height - 350));
    if (fileopen.showOpenDialog(null) == 0) {
        DebugMe.scriptFile = fileopen.getSelectedFile();
    } else {
        DebugMe.scriptFile = null;
    }
    dialogOpened.set(false);
}
 
源代码11 项目: netbeans   文件: LoadGeneratorCustomizer.java
private JFileChooser getFileChooser() {
    if (fileChooser == null) {
        JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.setMultiSelectionEnabled(false);
        chooser.setDialogType(JFileChooser.OPEN_DIALOG);
        chooser.setDialogTitle(Bundle.LoadGeneratorCustomizer_ChooseScriptDialogCaption());

        chooser.setFileFilter(new FileFilter() {
                private Set<String> extensions = new HashSet<String>();

                {
                    LoadGenPlugin lg = Lookup.getDefault().lookup(LoadGenPlugin.class);
                    extensions = lg.getSupportedExtensions();
                }

                public boolean accept(File f) {
                    return f.isDirectory() || extensions.contains(FileUtil.getExtension(f.getPath()));
                }

                public String getDescription() {
                    return Bundle.LoadGeneratorCustomizer_SupportedFiles();
                }
            });

        fileChooser = chooser;
    }

    return fileChooser;
}
 
源代码12 项目: snap-desktop   文件: ExportColorPaletteAction.java
@Override
public void actionPerformed(ActionEvent e) {
    SnapFileFilter fileFilter1 = new SnapFileFilter("CSV", ".csv", "CSV files"); // I18N
    SnapFileFilter fileFilter2 = new SnapFileFilter("TXT", ".txt", "Text files"); // I18N
    JFileChooser fileChooser = new JFileChooser();
    File lastDir = new File(getPreferences().getPropertyString(KEY_LAST_OPEN, "."));
    fileChooser.setCurrentDirectory(lastDir);
    RasterDataNode raster = getSelectedRaster();
    fileChooser.setSelectedFile(new File(lastDir, raster.getName() + "-palette.csv"));
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.addChoosableFileFilter(fileFilter1);
    fileChooser.addChoosableFileFilter(fileFilter2);
    fileChooser.setFileFilter(fileFilter1);
    fileChooser.setMultiSelectionEnabled(true);
    fileChooser.setDialogTitle(Bundle.CTL_ExportColorPaletteAction_DialogTitle());
    if (fileChooser.showSaveDialog(SnapApp.getDefault().getMainFrame()) == JFileChooser.APPROVE_OPTION
            && fileChooser.getSelectedFile() != null) {
        getPreferences().setPropertyString(KEY_LAST_OPEN, fileChooser.getCurrentDirectory().getAbsolutePath());
        File file = fileChooser.getSelectedFile();
        if (fileChooser.getFileFilter() instanceof SnapFileFilter) {
            SnapFileFilter fileFilter = (SnapFileFilter) fileChooser.getFileFilter();
            file = FileUtils.ensureExtension(file, fileFilter.getDefaultExtension());
        }
        try {
            writeColorPalette(raster, file);
        } catch (IOException ie) {
            Dialogs.showError(Bundle.CTL_ExportColorPaletteAction_DialogTitle(),
                                  "Failed to export colour palette:\n" + ie.getMessage());
        }
    }
}
 
源代码13 项目: keystore-explorer   文件: ExamineFileAction.java
private File chooseFile() {
	JFileChooser chooser = FileChooserFactory.getCertFileChooser();
	chooser.setCurrentDirectory(CurrentDirectory.get());
	chooser.setDialogTitle(res.getString("ExamineFileAction.ExamineFile.Title"));
	chooser.setMultiSelectionEnabled(false);

	int rtnValue = chooser.showDialog(frame, res.getString("ExamineFileAction.ExamineFile.button"));
	if (rtnValue == JFileChooser.APPROVE_OPTION) {
		File openFile = chooser.getSelectedFile();
		CurrentDirectory.updateForFile(openFile);
		return openFile;
	}
	return null;
}
 
源代码14 项目: myqq   文件: SendFileFrame.java
/**
 * @param seletMode
 * @return 
 */
public String showDialog(int seletMode)
{
	JFileChooser chooser = new JFileChooser();
	chooser.setFileSelectionMode(seletMode);
	chooser.setMultiSelectionEnabled(true);//璁剧疆澶氶?鏂囦欢
	int result = chooser.showOpenDialog(this);
	if (result == JFileChooser.APPROVE_OPTION)
	{
		String filePath = chooser.getSelectedFile().getAbsolutePath();
		return filePath;
	}
	return null;
}
 
源代码15 项目: openstego   文件: OpenStegoUI.java
/**
 * Method to get the display file chooser and return the selected file name
 *
 * @param dialogTitle Title for the file chooser dialog box
 * @param filterDesc Description to be displayed for the filter in file chooser
 * @param allowedExts Allowed file extensions for the filter
 * @param allowFileDir Type of objects allowed to be selected (FileBrowser.ALLOW_FILE,
 *        FileBrowser.ALLOW_DIRECTORY or FileBrowser.ALLOW_FILE_AND_DIR)
 * @param multiSelect Flag to indicate whether multiple file selection is allowed or not
 * @return Name of the selected file (null if no file was selected)
 */
public String getFileName(String dialogTitle, String filterDesc, List<String> allowedExts, int allowFileDir, boolean multiSelect) {
    int retVal = 0;
    String fileName = null;
    File[] files = null;

    JFileChooser chooser = new JFileChooser(lastFolder);
    chooser.setMultiSelectionEnabled(multiSelect);
    switch (allowFileDir) {
        case ALLOW_FILE:
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            break;
        case ALLOW_DIRECTORY:
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            break;
        case ALLOW_FILE_AND_DIR:
            chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            break;
    }

    if (filterDesc != null) {
        chooser.setFileFilter(new FileBrowserFilter(filterDesc, allowedExts));
    }
    chooser.setDialogTitle(dialogTitle);
    retVal = chooser.showOpenDialog(null);

    if (retVal == JFileChooser.APPROVE_OPTION) {
        if (multiSelect) {
            StringBuffer fileList = new StringBuffer();
            files = chooser.getSelectedFiles();
            for (int i = 0; i < files.length; i++) {
                if (i != 0) {
                    fileList.append(";");
                }
                fileList.append(files[i].getPath());
            }
            fileName = fileList.toString();
        } else {
            fileName = chooser.getSelectedFile().getPath();
        }
        lastFolder = chooser.getSelectedFile().getParent();
    }

    return fileName;
}
 
源代码16 项目: netbeans   文件: ExportDiffSupport.java
private JFileChooser createFileChooser(File curentDir) {
    final JFileChooser chooser = new AccessibleJFileChooser(NbBundle.getMessage(ExportDiffSupport.class, "ACSD_Export"));
    chooser.setDialogTitle(NbBundle.getMessage(ExportDiffSupport.class, "CTL_Export_Title"));
    chooser.setMultiSelectionEnabled(false);
    javax.swing.filechooser.FileFilter[] old = chooser.getChoosableFileFilters();
    for (int i = 0; i < old.length; i++) {
        javax.swing.filechooser.FileFilter fileFilter = old[i];
        chooser.removeChoosableFileFilter(fileFilter);

    }
    chooser.setCurrentDirectory(curentDir); // NOI18N
    chooser.addChoosableFileFilter(getFileFilter());

    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.setApproveButtonMnemonic(NbBundle.getMessage(ExportDiffSupport.class, "MNE_Export_ExportAction").charAt(0));
    chooser.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String state = e.getActionCommand();
            if (state.equals(JFileChooser.APPROVE_SELECTION)) {
                File destination = chooser.getSelectedFile();
                destination = getTargetFile(destination);
                if (destination.exists()) {
                    NotifyDescriptor nd = new NotifyDescriptor.Confirmation(NbBundle.getMessage(ExportDiffSupport.class, "BK3005", destination.getAbsolutePath()));
                    nd.setOptionType(NotifyDescriptor.YES_NO_OPTION);
                    DialogDisplayer.getDefault().notify(nd);
                    if (nd.getValue().equals(NotifyDescriptor.OK_OPTION) == false) {
                        return;
                    }
                }
                preferences.put("ExportDiff.saveFolder", destination.getParent()); // NOI18N
                panel.setOutputFileText(destination.getAbsolutePath());
            } else {
                dd.setValue(null);
            }
            if(dialog != null) {
                dialog.dispose();
            }
        }
    });
    return chooser;
}
 
源代码17 项目: rtg-tools   文件: RocPlot.java
/**
 * Creates a new swing plot.
 * @param precisionRecall true defaults to precision recall graph
 * @param interpolate if true, enable curve interpolation
 */
RocPlot(boolean precisionRecall, boolean interpolate) {
  mInterpolate = interpolate;
  mMainPanel = new JPanel();
  UIManager.put("FileChooser.readOnly", Boolean.TRUE);
  mFileChooser = new JFileChooser();
  final Action details = mFileChooser.getActionMap().get("viewTypeDetails");
  if (details != null) {
    details.actionPerformed(null);
  }
  mFileChooser.setMultiSelectionEnabled(true);
  mFileChooser.setFileFilter(new RocFileFilter());
  mZoomPP = new RocZoomPlotPanel();
  mZoomPP.setOriginIsMin(true);
  mZoomPP.setTextAntialiasing(true);
  mProgressBar = new JProgressBar(-1, -1);
  mProgressBar.setVisible(true);
  mProgressBar.setStringPainted(true);
  mProgressBar.setIndeterminate(true);
  mStatusLabel = new JLabel();
  mPopup = new JPopupMenu();
  mRocLinesPanel = new RocLinesPanel(this);
  mScrollPane = new JScrollPane(mRocLinesPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
  mScrollPane.setWheelScrollingEnabled(true);
  mLineWidthSlider = new JSlider(JSlider.HORIZONTAL, LINE_WIDTH_MIN, LINE_WIDTH_MAX, 1);
  mScoreCB = new JCheckBox("Show Scores");
  mScoreCB.setSelected(true);
  mSelectAllCB = new JCheckBox("Select / Deselect all");
  mTitleEntry = new JTextField("ROC");
  mTitleEntry.setMaximumSize(new Dimension(Integer.MAX_VALUE, mTitleEntry.getPreferredSize().height));
  mOpenButton = new JButton("Open...");
  mOpenButton.setToolTipText("Add a new curve from a file");
  mCommandButton = new JButton("Cmd...");
  mCommandButton.setToolTipText("Send the equivalent rocplot command-line to the terminal");
  final ImageIcon icon = createImageIcon("com/rtg/graph/resources/realtimegenomics_logo.png", "RTG Logo");
  mIconLabel = new JLabel(icon);
  mIconLabel.setBackground(new Color(16, 159, 205));
  mIconLabel.setForeground(Color.WHITE);
  mIconLabel.setOpaque(true);
  mIconLabel.setFont(new Font("Arial", Font.BOLD, 24));
  mIconLabel.setHorizontalAlignment(JLabel.LEFT);
  mIconLabel.setIconTextGap(50);
  if (icon != null) {
    mIconLabel.setMinimumSize(new Dimension(icon.getIconWidth(), icon.getIconHeight()));
  }
  mGraphType = new JComboBox<>(new String[] {ROC_PLOT, PRECISION_SENSITIVITY});
  mGraphType.setSelectedItem(precisionRecall ? PRECISION_SENSITIVITY : ROC_PLOT);
  configureUI();
}
 
源代码18 项目: lizzie   文件: ConfigDialog.java
private String getEngineLine() {
  String engineLine = "";
  File engineFile = null;
  File weightFile = null;
  JFileChooser chooser = new JFileChooser(".");
  if (isWindows()) {
    FileNameExtensionFilter filter =
        new FileNameExtensionFilter(
            resourceBundle.getString("LizzieConfig.title.engine"), "exe", "bat", "sh");
    chooser.setFileFilter(filter);
  } else {
    setVisible(false);
  }
  chooser.setMultiSelectionEnabled(false);
  chooser.setDialogTitle(resourceBundle.getString("LizzieConfig.prompt.selectEngine"));
  int result = chooser.showOpenDialog(this);
  if (result == JFileChooser.APPROVE_OPTION) {
    engineFile = chooser.getSelectedFile();
    if (engineFile != null) {
      enginePath = engineFile.getAbsolutePath();
      enginePath = relativizePath(engineFile.toPath(), this.curPath);
      getCommandHelp();
      JFileChooser chooserw = new JFileChooser(".");
      chooserw.setMultiSelectionEnabled(false);
      chooserw.setDialogTitle(resourceBundle.getString("LizzieConfig.prompt.selectWeight"));
      result = chooserw.showOpenDialog(this);
      if (result == JFileChooser.APPROVE_OPTION) {
        weightFile = chooserw.getSelectedFile();
        if (weightFile != null) {
          weightPath = relativizePath(weightFile.toPath(), this.curPath);
          EngineParameter ep = new EngineParameter(enginePath, weightPath, this);
          ep.setVisible(true);
          if (!ep.commandLine.isEmpty()) {
            engineLine = ep.commandLine;
          }
        }
      }
    }
  }
  return engineLine;
}
 
源代码19 项目: netbeans   文件: J2SEPlatformCustomizer.java
private static boolean select(
    final PathModel model,
    final File[] currentDir,
    final Component parentComponent) {
    final JFileChooser chooser = new JFileChooser ();
    chooser.setMultiSelectionEnabled (true);
    String title = null;
    String message = null;
    String approveButtonName = null;
    String approveButtonNameMne = null;
    if (model.type == SOURCES) {
        title = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenSources");
        message = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_Sources");
        approveButtonName = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenSources");
        approveButtonNameMne = NbBundle.getMessage (J2SEPlatformCustomizer.class,"MNE_OpenSources");
    } else if (model.type == JAVADOC) {
        title = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenJavadoc");
        message = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_Javadoc");
        approveButtonName = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenJavadoc");
        approveButtonNameMne = NbBundle.getMessage (J2SEPlatformCustomizer.class,"MNE_OpenJavadoc");
    }
    chooser.setDialogTitle(title);
    chooser.setApproveButtonText(approveButtonName);
    chooser.setApproveButtonMnemonic (approveButtonNameMne.charAt(0));
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    if (Utilities.isMac()) {
        //New JDKs and JREs are bundled into package, allow JFileChooser to navigate in
        chooser.putClientProperty("JFileChooser.packageIsTraversable", "always");   //NOI18N
    }
    //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
    chooser.setAcceptAllFileFilterUsed( false );
    chooser.setFileFilter (new ArchiveFileFilter(message,new String[] {"ZIP","JAR"}));   //NOI18N
    if (currentDir[0] != null) {
        chooser.setCurrentDirectory(currentDir[0]);
    }
    if (chooser.showOpenDialog(parentComponent) == JFileChooser.APPROVE_OPTION) {
        File[] fs = chooser.getSelectedFiles();
        boolean addingFailed = false;
        for (File f : fs) {
            //XXX: JFileChooser workaround (JDK bug #5075580), double click on folder returns wrong file
            // E.g. for /foo/src it returns /foo/src/src
            // Try to convert it back by removing last invalid name component
            if (!f.exists()) {
                File parent = f.getParentFile();
                if (parent != null && f.getName().equals(parent.getName()) && parent.exists()) {
                    f = parent;
                }
            }
            if (f.exists()) {
                addingFailed|=!model.addPath (f);
            }
        }
        if (addingFailed) {
            new NotifyDescriptor.Message (NbBundle.getMessage(J2SEPlatformCustomizer.class,"TXT_CanNotAddResolve"),
                    NotifyDescriptor.ERROR_MESSAGE);
        }
        currentDir[0] = FileUtil.normalizeFile(chooser.getCurrentDirectory());
        return true;
    }
    return false;
}
 
源代码20 项目: beast-mcmc   文件: MainFrame.java
public final void doGenerateXML() {

        if (getTreesCount() == 0) {

            tabbedPane.setSelectedComponent(treesPanel);
            Utils.showDialog("Please load at least one tree file before generating XML.");


        } else {

            JFileChooser chooser = new JFileChooser();
            chooser.setDialogTitle("Generate XML...");
            chooser.setMultiSelectionEnabled(false);
            chooser.setCurrentDirectory(workingDirectory);

            int returnVal = chooser.showSaveDialog(Utils.getActiveFrame());
            if (returnVal == JFileChooser.APPROVE_OPTION) {

                File file = chooser.getSelectedFile();

                generateXML(file);

                File tmpDir = chooser.getCurrentDirectory();
                if (tmpDir != null) {
                    workingDirectory = tmpDir;
                }

            }// END: approve check

        }// END: tree loaded check

    }