filechooser-abstraction

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

License

License

GroupId

GroupId

org.wiztools
ArtifactId

ArtifactId

filechooser-abstraction
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

filechooser-abstraction
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Project URL

Project URL

https://github.com/wiztools/filechooser-abstraction
Source Code Management

Source Code Management

https://github.com/wiztools/filechooser-abstraction

Download filechooser-abstraction

How to add to project

<!-- https://jarcasting.com/artifacts/org.wiztools/filechooser-abstraction/ -->
<dependency>
    <groupId>org.wiztools</groupId>
    <artifactId>filechooser-abstraction</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.wiztools/filechooser-abstraction/
implementation 'org.wiztools:filechooser-abstraction:0.1.0'
// https://jarcasting.com/artifacts/org.wiztools/filechooser-abstraction/
implementation ("org.wiztools:filechooser-abstraction:0.1.0")
'org.wiztools:filechooser-abstraction:jar:0.1.0'
<dependency org="org.wiztools" name="filechooser-abstraction" rev="0.1.0">
  <artifact name="filechooser-abstraction" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.wiztools', module='filechooser-abstraction', version='0.1.0')
)
libraryDependencies += "org.wiztools" % "filechooser-abstraction" % "0.1.0"
[org.wiztools/filechooser-abstraction "0.1.0"]

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

WizTools.org FileChooser Abstraction Library

An abstraction library (adapter pattern) to easily switch between JFileChooser and FileDialog.

Usage

Typical usage:

import org.wiztools.filechooser.*;

...

FileChooser fc = new JFCFileChooser(); // To use JFileChooser
FileChooser fc = new FDFileChooser();  // To use FileDialog

...

fc.setDialogTitle("JFileChooser");
FileChooserResponse res = fc.showOpenDialog(this); // `this' could be Frame / Dialog
if(res == FileChooserResponse.APPROVE_OPTION) {
	File f = fc.getSelectedFile();
	// your code
}
else if(res == FileChooserResponse.CANCEL_OPTION) {
	// your code
}

Using FileFilter:

import org.wiztools.filechooser.*;

...

// 1. Define FileChooser:
FileChooser fc = ...;


// 2. Define FileFilter:
FileFilter ff = new FileFilter() {
	public boolean accept(File file) {
		if(file.getName().endsWith(".xml")) {
			return true;
		}
		return false;
	}

	public String getDescription() {
		return "XML";
	}
};

// 3. Assign the FileFilter to the FileChooser:
fc.setFileFilter(ff);

Why?

JFileChooser is the preferred way of doing things in Java. But, if you want to comply to Apple Sandbox requirements when on-boarding your app to Mac App Store, you must use FileDialog instead of JFileChooser (FileDialog uses NSOpenDialog and NSSaveDialog internally).

This library may be used to:

  1. Modify your app to use FileDialog with minimal code change.
  2. Support FileDialog in Mac platform, and JFileChooser in other platforms, with very less code specific to each platform.
org.wiztools

WizTools.org

Passion meets programming.

Versions

Version
0.1.0