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 class
FileFilter.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.FilterClass
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
Nested classes/interfaces inherited from interface org.gnome.gtk.Buildable
Buildable.BuildableIface, Buildable.BuildableImpl
-
Field Summary
Fields inherited from class io.github.jwharm.javagi.base.ProxyInstance
address
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new FileFilter.FileFilter
(MemorySegment address) Create a FileFilter proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMimeType
(String mimeType) Adds a rule allowing a given mime type.void
addPattern
(String pattern) Adds a rule allowing a shell style glob pattern.void
Adds a rule allowing image files in the formats supported byGdkPixbuf
.void
Adds a suffix match rule to a filter.protected FileFilter
asParent()
Returns this instance as if it were its parent type.static FileFilter.Builder
<? extends FileFilter.Builder> builder()
AFileFilter.Builder
object constructs aFileFilter
with the specified properties.static FileFilter
fromGvariant
(Variant variant) Deserialize a file filter from aGVariant
.String[]
Gets the attributes that need to be filled in for theGFileInfo
passed to this filter.getName()
Gets the human-readable name for the filter.static Type
getType()
Get the GType of the FileFilter classvoid
Sets 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, onChanged
Methods 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, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods 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 Javasuper
keyword, 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
GtkFileFilter
object
-
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
public void addPixbufFormats()Adds 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 theGFileInfo
passed 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.Builder
object constructs aFileFilter
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withFileFilter.Builder.build()
.
-