Skip to content

Commit ee271ac

Browse files
committed
Update README.md
1 parent fc1f588 commit ee271ac

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ import org.gnome.gtk.*;
2626
import org.gnome.gio.ApplicationFlags;
2727

2828
public class HelloWorld {
29+
private final Application app;
2930

3031
public static void main(String[] args) {
3132
new HelloWorld(args);
3233
}
3334

34-
private final Application app;
35-
3635
public HelloWorld(String[] args) {
3736
app = new Application("my.example.HelloApp", ApplicationFlags.DEFAULT_FLAGS);
3837
app.onActivate(this::activate);
@@ -45,10 +44,10 @@ public class HelloWorld {
4544
window.setDefaultSize(300, 200);
4645

4746
var box = Box.builder()
48-
.setOrientation(Orientation.VERTICAL)
49-
.setHalign(Align.CENTER)
50-
.setValign(Align.CENTER)
51-
.build();
47+
.setOrientation(Orientation.VERTICAL)
48+
.setHalign(Align.CENTER)
49+
.setValign(Align.CENTER)
50+
.build();
5251

5352
var button = Button.withLabel("Hello world!");
5453
button.onClicked(window::close);
@@ -68,7 +67,7 @@ repositories {
6867
}
6968
7069
dependencies {
71-
implementation 'org.java-gi:gtk:0.14.0'
70+
implementation 'org.java-gi:gtk:0.14.1'
7271
}
7372
```
7473

@@ -84,6 +83,8 @@ You can find some examples [here](https://github.com/jwharm/java-gi-examples). E
8483
| ---- | ---- | ---- | ---- |
8584
| [Web Browser](https://github.com/jwharm/java-gi-examples/tree/main/Browser) | [Peg Solitaire](https://github.com/jwharm/java-gi-examples/tree/main/PegSolitaire) | [Calculator](https://github.com/jwharm/java-gi-examples/tree/main/Calculator) | [Notepad](https://github.com/jwharm/java-gi-examples/tree/main/Notepad) |
8685

86+
The [java-gi-app-template](https://github.com/jwharm/java-gi-app-template) repository offers a ready-to-run GNOME application template with translations, resources, settings, icons and much more. The template is setup to be built and installed as a Flatpak application.
87+
8788
## Generate bindings for other libraries
8889

8990
Java-GI offers a command-line utility to generate bindings for any library that supports GObject-Introspection. It is documented [here](https://jwharm.github.io/java-gi/generate/).
@@ -116,7 +117,7 @@ Interfaces are mapped to Java interfaces, using `default` interface methods to c
116117

117118
Type aliases (`typedef`s in C) for classes, records and interfaces are represented in Java with a subclass of the original type. Aliases for primitive types such as `int` or `float` are represented by simple wrapper classes.
118119

119-
Enumerations are represented as Java `enum` types, and flag parameters are mapped to `EnumSet`.
120+
Enumerations are represented as Java `enum` types, and flag (bitfield) parameters are mapped to `EnumSet`.
120121

121122
Most classes have one or more constructors. However, constructors in GTK are often overloaded, and the name contains valuable information for the user. Java-GI therefore maps constructors named "new" to regular Java constructors, and generates static factory methods for all other constructors:
122123

@@ -131,7 +132,7 @@ var button2 = Button.withLabel("Open...");
131132
var button3 = Button.fromIconName("document-open");
132133
```
133134

134-
Some struct types (called "records" in GObject-Introspection) don't have constructors, because in C these are meant to be stack-allocated. An example is `Gdk.RGBA`. Java-GI adds constructors that will allocate a new struct in an [Arena](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/foreign/Arena.html) of your choice. You can either allocate an empty struct (`var color = new RGBA();`) and fill in the values later, or pass the values immediately: `var purple = new RGBA(0.9f, 0.1f, 0.9f, 1.0f);`
135+
Many struct types don't have constructors, because in C they are meant to be stack-allocated. Java-GI adds constructors that will allocate a new struct in an [Arena](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/foreign/Arena.html) of your choice. You can either allocate an empty struct (`var color = new RGBA();`) and fill in the values later, or pass the values immediately: `var purple = new RGBA(0.9f, 0.1f, 0.9f, 1.0f);`
135136

136137
### Signals, callbacks and closures
137138

@@ -144,9 +145,9 @@ button.onClicked(window::close);
144145

145146
For every signal, a method to connect (e.g. `onClicked`) and emit the signal (`emitClicked`) is included in the API. New signal connections return a `SignalConnection` object, that allows you to disconnect, block and unblock a signal, or check whether the signal is still connected.
146147

147-
Functions with callback parameters are supported too. The generated Java bindings contain `@FunctionalInterface` definitions for all callback functions to ensure type safety.
148+
Functions with callback parameters are supported too. The generated Java bindings contain `@FunctionalInterface` definitions for all callbacks to ensure type safety.
148149

149-
[Closures](https://docs.gtk.org/gobject/struct.Closure.html) are marshaled to Java methods using reflection.
150+
Java-GI can create [GClosures](https://docs.gtk.org/gobject/struct.Closure.html) (dynamically-typed callbacks) using the [JavaClosure](https://java-gi.org/javadoc/org/javagi/gobject/JavaClosure.html) class, which uses reflection to marshal and unmarshal method- or lambda parameters to and from `GValues ` as required for a GClosure.
150151

151152
### Registering new types
152153

@@ -155,6 +156,7 @@ Java-GI registers GObject-derived Java classes as a GType. When overriding virtu
155156
```java
156157
public class Player extends GObject {
157158
private String name;
159+
private int lives;
158160

159161
public int getLives() {
160162
return lives;
@@ -204,7 +206,7 @@ You can read more about template classes in [the documentation](https://jwharm.g
204206

205207
Java-GI takes care of marshaling Java values from and to native values. When working with arrays, Java-GI will automatically copy native array contents from and to a Java array, marshaling the contents to the correct types along the way. A `null` terminator is added where applicable. You also don't need to specify the array length as a separate parameter.
206208

207-
Nullability of parameters (as defined in the GObject-introspection attributes) is indicated with `@Nullable` and `@NotNull` attributes, and checked at runtime. The nullability attributes are imported from Jetbrains Annotations (as a compile-time-only dependency).
209+
Nullability of parameters (as defined in the GObject-introspection attributes) is indicated with JSpecify `@NullMarked` and `@Nullable` attributes, and checked at runtime.
208210

209211
Variadic functions (varargs) are supported too:
210212

@@ -227,8 +229,9 @@ Out-parameters are mapped to a simple `Out<T>` container-type in Java, that offe
227229
```java
228230
File file = ...
229231
Out<byte[]> contents = new Out<byte[]>();
230-
file.loadContents(null, contents, null));
231-
System.out.printf("Read %d bytes%n", contents.get().length);
232+
if (file.loadContents(null, contents, null))) {
233+
System.out.printf("Read %d bytes%n", contents.get().length);
234+
}
232235
```
233236

234237
### Builder pattern

0 commit comments

Comments
 (0)