Class Sorter

All Implemented Interfaces:
Proxy
Direct Known Subclasses:
ColumnViewSorter, CustomSorter, MultiSorter, NumericSorter, StringSorter, TreeListRowSorter

@Generated("org.javagi.JavaGI") public class Sorter extends GObject

Describes sorting criteria for a SortListModel.

Its primary user is SortListModel

The model will use a sorter to determine the order in which its items should appear by calling compare(GObject, GObject) for pairs of items.

Sorters may change their sorting behavior through their lifetime. In that case, they will emit the Gtk.Sorter::changed signal to notify that the sort order is no longer valid and should be updated by calling gtk_sorter_compare() again.

GTK provides various pre-made sorter implementations for common sorting operations. ColumnView has built-in support for sorting lists via the Gtk.ColumnViewColumn:sorter property, where the user can change the sorting by clicking on list headers.

Of course, in particular for large lists, it is also possible to subclass GtkSorter and provide one's own sorter.

  • Constructor Details

    • Sorter

      public Sorter(MemorySegment address)
      Create a Sorter instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Sorter

      public Sorter()
      Create a new Sorter.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Sorter class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected Sorter asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • changed

      public void changed(SorterChange change)

      Notifies all users of the sorter that it has changed.

      This emits the Gtk.Sorter::changed signal. Users of the sorter should then update the sort order via compare(GObject, GObject).

      Depending on the change parameter, it may be possible to update the sort order without a full resorting. Refer to the Gtk.SorterChange documentation for details.

      This function is intended for implementers of GtkSorter subclasses and should not be called from other functions.

      Parameters:
      change - How the sorter changed
    • compare

      public Ordering compare(GObject item1, GObject item2)

      Compares two given items according to the sort order implemented by the sorter.

      Sorters implement a partial order:

      • It is reflexive, ie a = a
      • It is antisymmetric, ie if a < b and b < a, then a = b
      • It is transitive, ie given any 3 items with a ≤ b and b ≤ c, then a ≤ c

      The sorter may signal it conforms to additional constraints via the return value of getOrder().

      Parameters:
      item1 - first item to compare
      item2 - second item to compare
      Returns:
      Ordering.EQUAL if item1 == item2, Ordering.SMALLER if item1 < item2, Ordering.LARGER if item1 > item2
    • getOrder

      public SorterOrder getOrder()

      Gets the order that this Sorter conforms to.

      See Gtk.SorterOrder for details of the possible return values.

      This function is intended to allow optimizations.

      Returns:
      The order
    • onChanged

      Emitted whenever the sorter changed.

      Users of the sorter should then update the sort order again via gtk_sorter_compare().

      SortListModel handles this signal automatically.

      Depending on the change parameter, it may be possible to update the sort order without a full resorting. Refer to the Gtk.SorterChange documentation for details.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitChanged

      public void emitChanged(SorterChange change)
      Emits the "changed" signal. See onChanged(Sorter.ChangedCallback).
    • builder

      public static Sorter.Builder<? extends Sorter.Builder> builder()
      A Sorter.Builder object constructs a Sorter with the specified properties. Use the various set...() methods to set properties, and finish construction with Sorter.Builder.build().
      Returns:
      the builder object