Java Code Examples for javax.swing.JFileChooser#setMultiSelectionEnabled()

The following examples show how to use javax.swing.JFileChooser#setMultiSelectionEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DPreferences.java    From keystore-explorer with GNU General Public License v3.0 6 votes vote down vote up
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);
	}
}
 
Example 2
Source File: OpenFileAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: DOptions.java    From portecle with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 4
Source File: RunJarPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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());
    }
}
 
Example 5
Source File: DisplayEntityFactory.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 6
Source File: PreferencesPanel.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
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());
  }
}
 
Example 7
Source File: EvolvingImages.java    From jenetics with Apache License 2.0 5 votes vote down vote up
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
			);
		}
	}
}
 
Example 8
Source File: AbstractFileSelectionAction.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 9
Source File: ShareToolBuilder.java    From raccoon4 with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 10
Source File: DebugMe.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example 11
Source File: LoadGeneratorCustomizer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: ExportColorPaletteAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@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());
        }
    }
}
 
Example 13
Source File: ExamineFileAction.java    From keystore-explorer with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: SendFileFrame.java    From myqq with MIT License 5 votes vote down vote up
/**
 * @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;
}
 
Example 15
Source File: ExportDiffSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 16
Source File: RocPlot.java    From rtg-tools with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * 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();
}
 
Example 17
Source File: ConfigDialog.java    From lizzie with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 18
Source File: J2SEPlatformCustomizer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 19
Source File: OpenStegoUI.java    From openstego with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 20
Source File: MainFrame.java    From beast-mcmc with GNU Lesser General Public License v2.1 3 votes vote down vote up
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

    }