Skip to content

Releases: jwharm/java-gi

0.11.2

04 Jan 21:21
Compare
Choose a tag to compare

Java-GI 0.11.2 is a minor feature and bugfix release.

What's Changed

API changes

  • The deprecated class io.github.jwharm.javagi.gtk.types.Types has been removed. This class was renamed from Types to TemplateTypes in an earlier version of Java-GI.
  • The generic type parameters on the method signature of Types.register() have been removed. Kotlin users might have to fix a compile error when using Types.register<MyClass, ParentClass>(MyClass::class.java); to fix it, remove the generic arguments.

Improvements

  • #163: Added support for registering Java interfaces and enums in the GObject type system:

    • You can now create an interface in Java (complete with signals and property definitions), and register it in the GObject type system just like it was already possible for classes, with one simple call: Types.register(MyInterface.class). You can optionally specify prerequisites in the @RegisteredType annotation.
    • For custom enums, few practical use cases exist. But in case anyone needs them anyway, they will be happy to discover that the Types.register() API recognizes Java enums and will register a GObject enum or flags type (when annotated as @Flags).
  • #164: Added an internal mapping of Java classes to GTypes. As a result, the declaration of a public static Type getType() method has now become redundant, and it is now possible to construct new instances using GObject.newInstance(Foo.class). This means the GType has (for most use cases) been moved "behind the scenes" and Java developers can simply work with the class itself!

    An example of the new, shorter way to register a class and construct new instances:

    public class Foo extends GObject {
        static {
            Types.register(Foo.class);
        }
    
        public static Foo newInstance() {
            return GObject.newInstance(Foo.class);
        }
    
        public Foo(MemorySegment address) {
            super(address);
        }
    }
  • #165: Getter and setter method pairs in Java will automatically be recognized as GObject properties when the class is registered as a GType. If your class follows the usual get/set naming convention, the @Property annotation can be omitted. (@Property can still be used to set flags and override the property name.)

    // Will result in a "max-speed" property of type "int"
    public int getMaxSpeed() {
        ...
    }
    
    public void setMaxSpeed(int maxSpeed) {
        ...
    }

    For boolean properties, you can also use isFoo()/setFoo() pairs.
    Kotlin creates get- and set-methods for Kotlin properties automatically, so in practice a Kotlin property will be registered as a GObject property.

  • #168: Extended the @Property annotation to allow setting a minimum, maximum and default value for GObject properties in a GObject-derived Java class, that will be set in the GParamSpec:

    @Property(minimumValue = "1", maximumValue = "12", defaultValue = "1")
    public void setMonth(int month) {
        this.month = month;
    }
  • #170: Added toString() methods for GType and GVariant, to ease printing and debugging.

  • #171: Added support for mutable ListModels, and allows patches to pick implementation classes for generics where appropriate (like StringList now implements ListModel<StringObject> as its documentation suggests). Thanks to @JFronny for the PR.

  • #178: Created a unified way to add toString() methods to generated classes using the existing patch-mechanism, to replace the custom code for GType, GVariant, GValue, StringFilter and others. Thanks again to @JFronny for implementing most of this.

Fixes

  • #160: Removed the automatic override of the return type of named constructor functions. (It is now only overridden for Gtk Widgets.) This fixes an issue in bindings generated for ICal-GLib.
  • #162: Changed the generateSources Gradle task to make it compatible with the Gradle configuration cache, and enabled the configuration cache.
  • #169: Generate methods for <union> GIR types. As a result, a couple missing GMutex methods are now available. (Thanks to @leinardi for reporting)
  • #172: Allow extending GstMapFlags with additional flags, such as GstGL.MAP_GL. (Thanks to @BwackNinja for reporting)
  • #173: Generate missing accessors for fields containing a GList or GSList, for example in Pango.LayoutLine. (Thanks to @BwackNinja for reporting)
  • Fixed the build script of the GstPbutils module so it generates bindings from the correct gir file.
  • #175: Compare parameter types of virtual methods and their invoker methods, and only combine them in one Java method when the parameter types match exactly. This fixes a compile error in bindings generated for GstGL (thanks again to @BwackNinja for reporting)

Miscellanious

  • Two Scala example applications (a "Hello world" app and a simple image viewer) were added to the java-gi-examples collection, and the Calculator example was ported from Java to Kotlin. (Thanks to @poach3r for the contribution)

Full Changelog: 0.11.1...0.11.2

0.11.1

08 Dec 15:09
Compare
Choose a tag to compare

Java-GI 0.11.1 is a minor feature and bugfix release.

What's Changed

Improvements:

#150: Java-GI can now be used as a command-line tool to generate Java bindings manually from a GObject-Introspection repository (gir) file. Download the zip file below, extract it, and run java-gi <filename.gir> to generate bindings. More info is available on the Java-GI website, or run java-gi --help.

Fixes:

#151: Added missing support for the gir <doc-stability> element.
#153: Fixed the MemoryCleaner functionality to automatically free struct/union types.
#154: Added support for array aliases (thanks to @leinardi for reporting)
#155: Fixed an issue where internal GdkModifierKey flags caused Java-GI to throw an exception (thanks to @poach3r for reporting)
#156: Various fixes to generate Java bindings for Libical (thanks to @tintou for reporting)
#159: Fixed an issue in the new command-line tool (thanks to @poach3r for reporting)
#161: Fixed an issue with passing signal arguments to Java methods from GtkBuilder ui files (thanks to @Nyeksenn for reporting)

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.11.0...0.11.1

0.11.0

30 Oct 20:01
Compare
Choose a tag to compare

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 with stream(), ...).
  • #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 pass null, 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 and removeProviderForDisplay have been copied to Gtk.styleContextAddProviderForDisplay and Gtk.styleContextRemoveProviderForDisplay because the StyleContext class is deprecated. The functions can now be called from the Gtk class to avoid deprecation warnings.
  • Gtk composite template classes are now registered with TemplateTypes.register(class) instead of the old Types.register(class). In previous java-gi versions, there were two Types classes, one in GObject and one in Gtk (to register template classes), and users had to carefully import the correct one. Renaming the Gtk Types class to TemplateTypes 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 the java.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-GI Proxy interface). The class is not meant to be used instead of java.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 by Types.register(classname)). Furthermore, no accessors will be generated anymore to directly get/set the parent_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 with long fields use two separate MemoryLayouts 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() to File. (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 or ref function defined for that type (or g_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

0.10.2

07 Jul 19:03
Compare
Choose a tag to compare

This release contains small bugfixes and enhancements.

What's Changed

Fixes:

  • #104: Fixed loading native libraries built by MSVC (thanks @Kontiterit)
  • #105: Fixed the GitHub action to build Gtk Windows libraries (thanks @JFronny)
  • #103: Fixed handling of toggle references in async code (thanks @pontaoski)
  • #111 and #113: Fixed crash caused by incorrect ListModel ownership handling (thanks @JFronny, @SudoDios and @badcel)
  • Improved the toggle reference functionality to be faster and thread-safe
  • Fixed double ref of initially unowned (i.e. floating) objects
  • Removed an unused Cleaner action that was attached to all GObject instances

Improvements:

  • Functions in enumerations where the first parameter is the enumeration type itself, will now be available in Java as an instance method on that enumeration. For example, EventType.getFlags(EventType.TAG) has changed to EventType.TAG.getFlags().
    The applicable functions are auto-detected by the Java-GI bindings generator. The functions that have been changed in this release are listed here.
  • In the Javadoc of all signal connect methods (starting with "on...", like Button.onClicked()), a link has been added to the declaration of the signal handler method prototype. No more need to guess the expected callback parameters!
  • Error messages when registering a Java class as a new GType have been improved to log the relevant error cause.

This release is based on OpenJDK 22 and GNOME 46. The new release is available on Maven Central.

Full Changelog: 0.10.1...0.10.2

Natives for GTK 4.16.12 and libadwaita 1.6.3

17 Jun 10:16
Compare
Choose a tag to compare
libraries

Add links to IDEs to website

0.10.1

01 Jun 21:30
0441999
Compare
Choose a tag to compare

This is a bugfix release.

What's Changed

  • Fixed bug #17 - Nested arrays are unsupported: Java-GI now supports functions returning String[][]
  • Fixed bug #101 - Gio Files aren't GObjects: The default superclass for interface instances (when not specified in the prerequisites) has been changed back to GObject
  • Testcases were added for string and array marshaling; this uncovered several bugs that are now fixed
  • An unnecessary null-check in the generated memory-address-constructors has been removed
  • GIR files were updated to the latest GNOME 46 versions

The new release is available on Maven Central.

Full Changelog: 0.10.0...0.10.1

0.10.0

13 May 20:26
Compare
Choose a tag to compare

What's Changed

Java-GI has now been upgraded to the latest version of the "Panama" Foreign Function & Memory API (JEP 454), that was released with OpenJDK 22. As a result, Java-GI doesn't depend on OpenJDK preview features any longer!

Additionally, the bindings were updated to the latest GNOME 46 release.

A number of other changes:

  • New Java classes were added for GList and GSList, that implement java.util.List so they are very easy to use.
  • Flag parameters have been changed from int constants to EnumSet. This means you pass flag parameters using Set.of(flag1, flag2, ...) instead of the custom or() and combined() methods that existed previously.
  • A number of fixes and improvements were applied to the Javadoc generator.
  • Method handles are now generated as final static fields, to allow inlining by the jit compiler, improving performance.
  • Native libraries are now loaded using the platform-native shared library loader (dlopen on Linux) so in many cases the Java library path doesn't need to be manually updated anymore.
  • Several bugs with memory management and caching were fixed. Thanks to @BwackNinja for the detailed reports.
  • Interface instances are now derived from TypeInstance instead of GObject (unless specified otherwise in the prerequisites).
  • The gircore/gir-files repository is now included as a git submodule.
  • The website was improved and uses a more modern theme.

Full Changelog: 0.9.2...0.10.0

0.9.2

04 May 20:19
Compare
Choose a tag to compare

This release contains a bugfix for Gtk composite template classes.
Special thanks to @EliasDevis for logging this issue.

This release is based on OpenJDK 21 and GNOME 45.

Full Changelog: 0.9.1...0.9.2

0.9.1

07 Apr 21:04
Compare
Choose a tag to compare

This release is still based on OpenJDK 21 and GNOME 45. It contains bugfixes and a number of improvements.

Special thanks go to @pontaoski and @Tennessene for logging issues and testing fixes.

What's Changed

Fixes:

  • Fixed image URL prefixes in generated Javadoc.
  • Fixed allocating and accessing nested record types.
  • Fixed overriding protected methods in custom GObject-derived classes.
  • Fixed issues with generating boxed types, that prevented generating bindings for spice-client-glib.
  • Gtk class CustomLayout was removed. This type is not meant to be used in language bindings.
  • Removed all "...Private" types from the generated bindings again (this was a regression in 0.9.0).

Improvements:

  • Added constructors to record types, to replace the existing allocate methods.
  • Added constructor overloads without an Arena parameter, defaulting to Arena::ofAuto.
  • Added a test method to the Bitfield base class, to test if one or more flags are set; added a better Bitfield::toString as well.
  • Alias types now have a from method to "cast" an alias from its target type.

Minor enhancements:

  • Renamed GErrorException::getGError() to ::toGError(), the old method is marked deprecated
  • Better Javadoc descriptions for packages
  • Added support for Alias<MemorySegment> parameters (like GstClockID).

Full Changelog: 0.9.0...0.9.1

Please log a GitHub issue or join java-gi:matrix.org if you encounter problems with this release.

0.9.0

28 Feb 21:18
Compare
Choose a tag to compare

This release has been built with a completely rebuilt code generator, based on JavaPoet. The output should be the same as the previous version, save for some bugfixes that were done during testing. The only API changes are:

  • Any changes to the GIR files in the gir-core repository since Java-GI 0.8.1 was released. These changes should be really minor, because the GIR files were not updated beyond the supported point-releases listed in the README.
  • the deprecated builder setter syntax has been removed
  • the deprecated struct allocate() methods that default to an "auto" allocator have been removed
  • the deprecated static factory methods with new prefixes have been removed

These removals were all announced, and explained, in the Java-GI 0.8.0 release notes.

Even though I tried to test this release as well as I could, there can be bugs/regressions compared to previous releases. Please log any issues you encounter. As a fallback, it's possible to keep using release 0.8.1.

Full Changelog: 0.8.1...0.9.0

As always, the release is available on Maven Central.