java-gnome version 4.0.19

org.gnome.gtk
Class FileFilter

Object
  extended by org.freedesktop.bindings.Pointer
      extended by org.freedesktop.bindings.Proxy
          extended by org.gnome.glib.Object
              extended by org.gnome.gtk.Object
                  extended by org.gnome.gtk.FileFilter

public class FileFilter
extends Object

FileFilters objects are used to restrict the files being shown on a FileChooser.

The most typical usage is to only show the file types the application can deal with. On "Open" Dialogs, a FileFilter can be used to only shown the files the application can open. On the other side, on "Save as" Dialogs they can be used as a way to let users choose the format in which to save the document.

You will usually add several FileFilters to your FileChooser Widget. The FileChooser will show a ComboBox with the different Filters, that the user can use to choose a specific file type. You should use the setName() method to set the name used as the label for the FileFilter on the ComboBox.

In a FileFilter, you specify the files to shown either as with its MIME type, with the addMimeType() method, or as a shell style glob pattern, with the addPattern() method. You can add several MIME types or patterns to a single FileFilter. This is useful, for example, to provide a "All Supported Files" filter.

As an example, consider the following code:

 FileChooserDialog openDialog;
 FileFilter pngImages, jpegImages, allImages;
 
 openDialog = new FileChooserDialog("Open...", w, FileChooserAction.OPEN);
 
 // you can specify a MIME type...
 pngImages = new FileFilter("Portable Network Graphics (PNG)");
 pngImages.addMimeType("image/png");
 
 // ...or a pattern
 jpegImages = new FileFilter("JPEG Image");
 jpegImages.addPattern("*.jpg");
 
 // of course you can use several patterns or MIME types per filter
 jpegImages.addPattern("*.jpeg");
 
 // and you can use both MIME types and patterns in a single filter
 allImages = new FileFilter("All supported images");
 allImages.addMimeType("image/png");
 allImages.addPattern("*.jpg");
 allImages.addPattern("*.jpeg");
 
 // Finally, you should add each filter to the FileChooser
 openDialog.addFilter(allImages);
 openDialog.addFilter(pngImages);
 openDialog.addFilter(jpegImages);
 

Since:
4.0.12
Author:
Vreixo Formoso

Nested Class Summary
 
Nested classes/interfaces inherited from class org.gnome.gtk.Object
Object.Destroy
 
Constructor Summary
FileFilter()
          Create a new FileFilter
FileFilter(String name)
          Create a new FileFilter with the given name.
 
Method Summary
 void addMimeType(String mimeType)
          Add a rule allowing a given MIME type to the filter.
 void addPattern(String pattern)
          Adds a rule allowing a shell style glob to the filter.
 void setName(String name)
          Sets the human-readable name of the filter; this is the String that will be displayed in the FileChooser user interface if there is a selectable list of filters.
 
Methods inherited from class org.gnome.gtk.Object
connect, destroy
 
Methods inherited from class org.freedesktop.bindings.Pointer
toString
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileFilter

public FileFilter()
Create a new FileFilter

Since:
4.0.12

FileFilter

public FileFilter(String name)
Create a new FileFilter with the given name. This is equivalent to create a FileFilter and the call setName() method.

Since:
4.0.12
Method Detail

addMimeType

public void addMimeType(String mimeType)
Add a rule allowing a given MIME type to the filter.

Filtering by MIME types handles aliasing and subclassing of mime types; e.g. a filter for "text/plain" also matches a file with MIME type "application/rtf", since "application/rtf" is a subclass of "text/plain". Note that FileFilter allows wildcards for the subtype of a MIME type, so you can e.g. filter for "image/*".

Since:
4.0.12

addPattern

public void addPattern(String pattern)
Adds a rule allowing a shell style glob to the filter.

Since:
4.0.12

setName

public void setName(String name)
Sets the human-readable name of the filter; this is the String that will be displayed in the FileChooser user interface if there is a selectable list of filters.

Since:
4.0.12


java-gnome