Skip to content

0.11.2

Latest
Compare
Choose a tag to compare
@jwharm jwharm released this 04 Jan 21:21
· 14 commits to main since this release

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