Class StringList
- All Implemented Interfaces:
Iterable<StringObject>, Collection<StringObject>, List<StringObject>, SequencedCollection<StringObject>, ListModel<StringObject>, Buildable, Proxy, ListModelJavaList<StringObject>, ListModelJavaListMutable<StringObject>, ListModelJavaListSpliceable<StringObject>
A list model that wraps an array of strings.
The objects in the model are of type StringObject and have
a "string" property that can be used inside expressions.
GtkStringList is well-suited for any place where you would
typically use a char*[], but need a list model.
GtkStringList as GtkBuildable
The GtkStringList implementation of the GtkBuildable interface
supports adding items directly using the <items> element and
specifying <item> elements for each item. Each <item> element
supports the regular translation attributes “translatable”,
“context” and “comments”.
Here is a UI definition fragment specifying a GtkStringList
<object class="GtkStringList">
<items>
<item translatable="yes">Factory</item>
<item translatable="yes">Home</item>
<item translatable="yes">Subway</item>
</items>
</object>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classStringList.Builder<B extends StringList.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classNested classes/interfaces inherited from class GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface Buildable
Buildable.Buildable$Impl, Buildable.BuildableIfaceNested classes/interfaces inherited from interface ListModel
ListModel.ItemsChangedCallback, ListModel.ListModel$Impl, ListModel.ListModelInterfaceNested classes/interfaces inherited from interface ListModelJavaList
ListModelJavaList.SubList<E,List> Nested classes/interfaces inherited from interface ListModelJavaListSpliceable
ListModelJavaListSpliceable.SubList<E,List> -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new StringList.StringList(@Nullable String @Nullable [] strings) Creates a newGtkStringListwith the givenstrings.StringList(MemorySegment address) Create a StringList instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoidAppendsstringtoself.voidAdd the specified element to the end of the list.protected StringListasParent()Return this instance as if it were its parent type.static StringList.Builder<? extends StringList.Builder> builder()AStringList.Builderobject constructs aStringListwith the specified properties.intGets the position of thestringinself.static MemoryLayoutThe memory layout of the native struct.@Nullable StringgetString(int position) Gets the string that is atpositioninself.static @Nullable TypegetType()Get the GType of the StringList class.voidremoveAt(int position) Removes the string atpositionfromself.voidChanges this StringList by removingnRemovalsstrings and addingadditionsto it.voidsplice(int index, int nRemovals, Collection<? extends StringObject> additions) Modify this list by removingnRemovalselements starting atindexand replacing them with the elements inadditions.voidsplice(int index, int nRemovals, StringObject[] additions) Modify this list by removingnRemovalselements starting atindexand replacing them with the elements inadditions.voidAddsstringto self at the end, and takes ownership of it.Methods inherited from class 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 TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class ProxyInstance
equals, handle, hashCodeMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Buildable
getBuildableIdMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface List
addFirst, addLast, equals, getFirst, getLast, hashCode, removeFirst, removeLast, replaceAll, reversed, sort, spliteratorMethods inherited from interface ListModel
emitItemsChanged, getItem, getItemType, getNItems, itemsChanged, onItemsChangedMethods inherited from interface ListModelJavaList
contains, containsAll, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeAll, retainAll, size, toArray, toArrayMethods inherited from interface ListModelJavaListMutable
add, remove
-
Constructor Details
-
StringList
Create a StringList instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
StringList
Creates a newGtkStringListwith the givenstrings.- Parameters:
strings- The strings to put in the model
-
StringList
public StringList()Create a new StringList.
-
-
Method Details
-
splice
Modify this list by removingnRemovalselements starting atindexand replacing them with the elements inadditions.- Specified by:
splicein interfaceListModelJavaListSpliceable<StringObject>- Parameters:
index- the index at which to splice the listnRemovals- the number of elements to removeadditions- the elements to insert at the index- Throws:
IndexOutOfBoundsException- if the index is out of range
-
splice
Modify this list by removingnRemovalselements starting atindexand replacing them with the elements inadditions.- Specified by:
splicein interfaceListModelJavaListSpliceable<StringObject>- Parameters:
index- the index at which to splice the listnRemovals- the number of elements to removeadditions- the elements to insert at the index- Throws:
IndexOutOfBoundsException- if the index is out of range
-
append
Add the specified element to the end of the list.- Specified by:
appendin interfaceListModelJavaListMutable<StringObject>- Parameters:
e- element to be appended to the list
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Return this instance as if it were its parent type. Comparable to the Javasuperkeyword, but ensures the parent typeclass is also used in native code. -
append
Appends
stringtoself.The
stringwill be copied. Seetake(String)for a way to avoid that.- Parameters:
string- the string to insert
-
find
Gets the position of the
stringinself.If this StringList does not contain
stringitem,G_MAXUINTis returned.- Parameters:
string- the string to find- Returns:
- the position of the string
- Since:
- 4.18
-
getString
Gets the string that is at
positioninself.If this StringList does not contain
positionitems,nullis returned.This function returns the const char *. To get the object wrapping it, use g_list_model_get_item().
- Parameters:
position- the position to get the string for- Returns:
- the string at the given position
-
removeAt
public void removeAt(int position) Removes the string at
positionfromself.positionmust be smaller than the current length of the list.- Specified by:
removeAtin interfaceListModelJavaListMutable<StringObject>- Parameters:
position- the position of the string that is to be removed
-
splice
Changes this StringList by removing
nRemovalsstrings and addingadditionsto it.This function is more efficient than
append(StringObject)andStringList.remove, because it only emits the ::items-changed signal once for the change.This function copies the strings in
additions.The parameters
positionandnRemovalsmust be correct (ie:position+nRemovalsmust be less than or equal to the length of the list at the time this function is called).- Parameters:
position- the position at which to make the changenRemovals- the number of strings to removeadditions- The strings to add
-
take
Adds
stringto self at the end, and takes ownership of it.This variant of
append(StringObject)is convenient for formatting strings:gtk_string_list_take (self, g_strdup_print ("%d dollars", lots));- Parameters:
string- the string to insert
-
builder
AStringList.Builderobject constructs aStringListwith the specified properties. Use the variousset...()methods to set properties, and finish construction withStringList.Builder.build().- Returns:
- the builder object
-