Class FileFilter
GtkFileFilter can be used to restrict the files being shown in a
file chooser. Files can be filtered based on their name (with
addPattern(java.lang.String) or addSuffix(java.lang.String))
or on their mime type (with addMimeType(java.lang.String)).
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 GtkFileFilter allows wildcards for the
subtype of a mime type, so you can e.g. filter for image/\\*.
Normally, file filters are used by adding them to a file chooser
(see FileDialog.setFilters(org.gnome.gio.ListModel)), but it is also possible to
manually use a file filter on any FilterListModel containing
GFileInfo objects.
GtkFileFilter as GtkBuildable
The GtkFileFilter implementation of the GtkBuildable interface
supports adding rules using the <mime-types> and <patterns> and
<suffixes> elements and listing the rules within. Specifying a
<mime-type> or <pattern> or <suffix> has the same effect as
as calling
addMimeType(java.lang.String) or
addPattern(java.lang.String) or
addSuffix(java.lang.String).
An example of a UI definition fragment specifying GtkFileFilter
rules:
<object class="GtkFileFilter">
<property name="name" translatable="yes">Text and Images</property>
<mime-types>
<mime-type>text/plain</mime-type>
<mime-type>image/ *</mime-type>
</mime-types>
<patterns>
<pattern>*.txt</pattern>
</patterns>
<suffixes>
<suffix>png</suffix>
</suffixes>
</object>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classFileFilter.Builder<B extends FileFilter.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.Nested classes/interfaces inherited from class org.gnome.gtk.Filter
Filter.ChangedCallback, Filter.FilterClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface org.gnome.gtk.Buildable
Buildable.Buildable$Impl, Buildable.BuildableIface -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new FileFilter.FileFilter(MemorySegment address) Create a FileFilter proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMimeType(String mimeType) Adds a rule allowing a given mime type.voidaddPattern(String pattern) Adds a rule allowing a shell style glob pattern.voidDeprecated.Use the api of your image loading framework (e.g.voidAdds a suffix match rule to a filter.protected FileFilterasParent()Returns this instance as if it were its parent type.static FileFilter.Builder<? extends FileFilter.Builder> builder()AFileFilter.Builderobject constructs aFileFilterwith the specified properties.static FileFilterfromGvariant(Variant variant) Deserialize a file filter from aGVariant.String[]Gets the attributes that need to be filled in for theGFileInfopassed to this filter.@Nullable StringgetName()Gets the human-readable name for the filter.static @Nullable TypegetType()Get the GType of the FileFilter classvoidSets a human-readable name of the filter.Serialize a file filter to ana{sv}variant.Methods inherited from class org.gnome.gtk.Filter
changed, emitChanged, getMemoryLayout, getStrictness, match, onChangedMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gnome.gtk.Buildable
getBuildableId
-
Constructor Details
-
FileFilter
Create a FileFilter proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
FileFilter
public FileFilter()Creates a new FileFilter.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
fromGvariant
Deserialize a file filter from aGVariant.The variant must be in the format produced by
toGvariant().- Parameters:
variant- ana{sv}GVariant- Returns:
- a new
GtkFileFilterobject
-
addMimeType
Adds a rule allowing a given mime type.- Parameters:
mimeType- name of a MIME type
-
addPattern
Adds a rule allowing a shell style glob pattern.Note that it depends on the platform whether pattern matching ignores case or not. On Windows, it does, on other platforms, it doesn't.
- Parameters:
pattern- a shell style glob pattern
-
addPixbufFormats
Deprecated.Use the api of your image loading framework (e.g. glycin) to enumerate supported formatsAdds a rule allowing image files in the formats supported byGdkPixbuf.This is equivalent to calling
addMimeType(java.lang.String)for all the supported mime types. -
addSuffix
Adds a suffix match rule to a filter.This is similar to adding a match for the pattern "*.
suffix"An exaple to filter files with the suffix ".sub":
gtk_file_filter_add_suffix (filter, "sub");Filters with multiple dots are allowed.
In contrast to pattern matches, suffix matches are always case-insensitive.
- Parameters:
suffix- filename suffix to match- Since:
- 4.4
-
getAttributes
Gets the attributes that need to be filled in for theGFileInfopassed to this filter.This function will not typically be used by applications; it is intended for use in file chooser implementation.
- Returns:
- the attributes
-
getName
Gets the human-readable name for the filter.- Returns:
- the human-readable name of the filter
-
setName
Sets a human-readable name of the filter.This is the string that will be displayed in the user interface if there is a selectable list of filters.
- Parameters:
name- the human-readable name for the filter
-
toGvariant
Serialize a file filter to ana{sv}variant.- Returns:
- a new, floating,
GVariant
-
builder
AFileFilter.Builderobject constructs aFileFilterwith the specified properties. Use the variousset...()methods to set properties, and finish construction withFileFilter.Builder.build().- Returns:
- the builder object
-