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

The following examples show how to use javax.swing.JFileChooser#getDialogType() . 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: WindowsDirectoryChooserUI.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
private void updateView(JFileChooser chooser) {
  if (chooser.getApproveButtonText() != null) {
    approveButton.setText(chooser.getApproveButtonText());
    approveButton.setMnemonic(chooser.getApproveButtonMnemonic());
  } else {
    if (JFileChooser.OPEN_DIALOG == chooser.getDialogType()) {
      approveButton.setText(openButtonText);
      approveButton.setToolTipText(openButtonToolTipText);
      approveButton.setMnemonic(openButtonMnemonic);
    } else {
      approveButton.setText(saveButtonText);
      approveButton.setToolTipText(saveButtonToolTipText);
      approveButton.setMnemonic(saveButtonMnemonic);
    }
  }

  cancelButton.setText(cancelButtonText);
  cancelButton.setMnemonic(cancelButtonMnemonic);

  buttonPanel.setVisible(chooser.getControlButtonsAreShown());
}
 
Example 2
Source File: FileChooserUI.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
private Icon getApproveButtonIcon(JFileChooser fc) {
	if (fc.getDialogType() == JFileChooser.OPEN_DIALOG) {
		return FILECHOOSER_OPEN_ICON;
	}
	if (fc.getDialogType() == JFileChooser.SAVE_DIALOG) {
		return FILECHOOSER_SAVE_ICON;
	}
	if (fc.getDialogType() == JFileChooser.CUSTOM_DIALOG) {
		return FILECHOOSER_SELECT_ICON;
	}
	return FILECHOOSER_SELECT_ICON;
}
 
Example 3
Source File: FileChooserUI.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
private void doDialogTypeChanged(PropertyChangeEvent e) {
	JFileChooser chooser = getFileChooser();
	this.approveButton.setText(getApproveButtonText(chooser));
	this.approveButton.setToolTipText(getApproveButtonToolTipText(chooser));
	this.approveButton.setIcon(getApproveButtonIcon(chooser));
	if (chooser.getDialogType() == JFileChooser.SAVE_DIALOG) {
		this.lookInLabel.setText(this.saveInLabelText);
	} else {
		this.lookInLabel.setText(this.lookInLabelText);
	}
}
 
Example 4
Source File: CFileChooser.java    From binnavi with Apache License 2.0 5 votes vote down vote up
private static int showNativeFileDialog(final JFileChooser chooser) {
  final FileDialog result = new FileDialog((Frame) chooser.getParent());

  result.setDirectory(chooser.getCurrentDirectory().getPath());

  final File selected = chooser.getSelectedFile();
  result.setFile(selected == null ? "" : selected.getPath());
  result.setFilenameFilter(new FilenameFilter() {
    @Override
    public boolean accept(final File dir, final String name) {
      return chooser.getFileFilter().accept(new File(dir.getPath() + File.pathSeparator + name));
    }
  });

  if (chooser.getDialogType() == SAVE_DIALOG) {
    result.setMode(FileDialog.SAVE);
  } else {
    // The native dialog only support Open and Save
    result.setMode(FileDialog.LOAD);
  }

  if (chooser.getFileSelectionMode() == DIRECTORIES_ONLY) {
    System.setProperty("apple.awt.fileDialogForDirectories", "true");
  }

  // Display dialog
  result.setVisible(true);

  System.setProperty("apple.awt.fileDialogForDirectories", "false");
  if (result.getFile() == null) {
    return CANCEL_OPTION;
  }

  final String selectedDir = result.getDirectory();
  chooser
      .setSelectedFile(new File(FileUtils.ensureTrailingSlash(selectedDir) + result.getFile()));
  return APPROVE_OPTION;
}