0.11.0
Java-GI 0.11.0 features a lot of improvements and bugfixes all over the board.
What's Changed
Improvements:
- Java-GI 0.11.0 upgrades the Java bindings to the GNOME 47 platform versions. Read the What's new for developers section of the GNOME 47 Release Notes for an overview of the changes in this GNOME release.
- The GListModel interface has been made generic in Java:
ListModel<T extends GObject>
. The entire hierarchy of classes and interfaces that implement GListModel is now generic as well. - Furthermore, the ListModel interface now extends
java.util.List
, so all list models can now be used as a Java collection (enhanced for loop, process withstream()
, ...). - #123: An additional no-argument constructor has been added to classes that have ambiguity between the default MemorySegment-constructor and another constructor with one (optional) parameter, when passing
null
. To passnull
, users had to cast it. The new constructors resolve this. (Thanks to David Goodenough for reporting this.) Example:
// Old
var frame = new Frame((String) null);
// New
var frame = new Frame();
- #126: It is now possible to connect signals from Builder objects. For example:
var button = Button.builder()
.setLabel("Close")
.onClicked(window::close)
.build;
- The Gtk functions
StyleContext.addProviderForDisplay
andremoveProviderForDisplay
have been copied toGtk.styleContextAddProviderForDisplay
andGtk.styleContextRemoveProviderForDisplay
because theStyleContext
class is deprecated. The functions can now be called from theGtk
class to avoid deprecation warnings. - Gtk composite template classes are now registered with
TemplateTypes.register(class)
instead of the oldTypes.register(class)
. In previous java-gi versions, there were twoTypes
classes, one in GObject and one in Gtk (to register template classes), and users had to carefully import the correct one. Renaming the GtkTypes
class toTemplateTypes
will make the distinction clear. The old class is still available in this release, but has been deprecated and will be removed in an upcoming release. - Many functions that required closure parameters now expect callback methods (or lambdas). This makes much more sense in a statically-typed language like Java. (Technically this means that when regular functions in GObject-Introspection are "shadowed by" a
_with_closures
function, we ignore the "shadowed by" annotation.) - #129: A new API has been added to create GObject property bindings with transformations. It works the same as in Gtk-rs: The second example on this page would look like this in Java:
button1.<Integer, Integer>bindProperty("number", button2, "number")
.transformTo(n -> n + 1)
.transformFrom(n -> n - 1)
.bidirectional()
.syncCreate()
.build();
- #131: Java-GI now contains a custom
org.gnome.glib.HashTable
wrapper class for GHashTable that implements thejava.util.Map<K,V>
interface. The keys and values can be strings, pointers (MemorySegments in Java), or heap-allocated classes/structs (i.e. anything that implements the Java-GIProxy
interface). The class is not meant to be used instead ofjava.util.HashMap
, but will help Java developers work with native functions that return or expect a GHashTable. - #139: The API to manually override a GObject virtual method with a Java lambda has been removed. It is still possible to override a virtual method with a
java.lang.reflect.Method
parameter (as used byTypes.register(classname)
). Furthermore, no accessors will be generated anymore to directly get/set theparent_class
field of typeclasses. These APIs were unsafe to use (to put it mildly) and with these changes, the amount of generated code in Java-GI has been reduced significantly. - #140: Trailing flag parameters can now be set with either a
Set
or varargs. For example, to create a new application, use one of these two constructors:
public Application(@Nullable String applicationId, Set<ApplicationFlags> flags);
public Application(@Nullable String applicationId, ApplicationFlags... flags);
- #141: It is now possible to specify the name of the namespace for your own GObject-derived classes in
package-info.java
with the new@Namespace(name="...")
annotation. The namespace name will be prefixed to the class name. - Improved parameter references in generated Javadoc.
- All code examples on the website are now available in both Java and Kotlin.
Fixes:
- #106: The different length of
long
native data types on Windows (long
is 32-bit) versus Linux and macOS (long
is 64-bit) is now fully implemented in Java-GI. The generated Java API supports the lowest common denominator (int
), and casts to the correct native datatype at runtime. Classes, interfaces and structs withlong
fields use two separateMemoryLayout
s in Java internally that contain the correct alignment and padding for the applicable platform. - #117: Fixed a ClassCastException when casting the ListModel items returned by
File.openMultipleFinish()
toFile
. (Thanks @SudoDios for reporting this.) - The wrapper classes for GList and GSList now properly free the list items after use.
- #120: Fixed a crash when using variadic functions on macOS.
- Improved the MemoryLayout generator to correctly handle nested structs and unions.
- #124: Copy structs and boxed types when returned from a native function without ownership transfer. This will call the
copy
orref
function defined for that type (org_boxed_copy
for boxed types). This prevents a segfault when the struct is disposed somewhere else while Java is still using it. - #125: Improve memory management for methods with callback parameters that have a DestroyNotify callback.
Miscellanious:
- The
allocate()
factory methods on struct/boxed types have been removed. These methods were replaced by constructors and had already been deprecated in the previous release. - The Gtk "Getting Started" guide has been ported to Java, and is now available on the Java-GI website, with all example code.
- Two new examples were added to the java-gi-examples repository: ColumnViewDatagrid and Spacewar.
Availability and dependencies:
- The new release is available on Maven Central.
- Java-GI requires OpenJDK 22 or later.
- The bindings are based on the GNOME 47 libraries. These need to be installed.
Full Changelog: 0.10.2...0.11.0