From ab158db3e74f64f3ecea421f1fc8c8fa88aa16b2 Mon Sep 17 00:00:00 2001 From: Konrad Neitzel Date: Fri, 30 Oct 2026 19:38:48 +0100 Subject: [PATCH] Add a person-desk example and a guide for the fx library. The example replaces the call sites of the removed JavaFX units so the module can build again. Co-authored-by: Cursor --- README.md | 4 +- fx-example/README.md | 11 + fx-example/pom.xml | 25 +- .../neitzel/fx/component/example/Address.java | 29 -- .../fx/component/example/ExampleApp.java | 56 --- .../de/neitzel/fx/component/example/Main.java | 24 - .../neitzel/fx/component/example/Person.java | 29 -- .../java/de/neitzel/fx/example/DeskApp.java | 70 +++ .../main/java/de/neitzel/fx/example/Main.java | 23 + .../de/neitzel/fx/example/model/Address.java | 73 ++++ .../de/neitzel/fx/example/model/Person.java | 137 ++++++ .../neitzel/fx/example/view/AddressForm.java | 51 +++ .../neitzel/fx/example/view/AgeConverter.java | 58 +++ .../de/neitzel/fx/example/view/AgeSuffix.java | 25 ++ .../fx/example/view/DeskController.java | 104 +++++ .../fx/injectfx/example/JavaFXApp.java | 49 --- .../de/neitzel/fx/injectfx/example/Main.java | 33 -- .../fx/injectfx/example/MainWindow.java | 68 --- fx-example/src/main/resources/address.fxml | 16 - .../neitzel/fx/example/view/AddressForm.fxml | 25 ++ .../de/neitzel/fx/example/view/Desk.fxml | 78 ++++ .../fx/injectfx/example/MainWindow.fxml | 13 - fx-example/src/main/resources/person.fxml | 18 - .../de/neitzel/fx/example/DeskLoadsTest.java | 118 +++++ fx/README.md | 246 +++++++++++ mvnw.cmd | 410 +++++++++--------- pom.xml | 2 +- 27 files changed, 1249 insertions(+), 546 deletions(-) create mode 100644 fx-example/README.md delete mode 100644 fx-example/src/main/java/de/neitzel/fx/component/example/Address.java delete mode 100644 fx-example/src/main/java/de/neitzel/fx/component/example/ExampleApp.java delete mode 100644 fx-example/src/main/java/de/neitzel/fx/component/example/Main.java delete mode 100644 fx-example/src/main/java/de/neitzel/fx/component/example/Person.java create mode 100644 fx-example/src/main/java/de/neitzel/fx/example/DeskApp.java create mode 100644 fx-example/src/main/java/de/neitzel/fx/example/Main.java create mode 100644 fx-example/src/main/java/de/neitzel/fx/example/model/Address.java create mode 100644 fx-example/src/main/java/de/neitzel/fx/example/model/Person.java create mode 100644 fx-example/src/main/java/de/neitzel/fx/example/view/AddressForm.java create mode 100644 fx-example/src/main/java/de/neitzel/fx/example/view/AgeConverter.java create mode 100644 fx-example/src/main/java/de/neitzel/fx/example/view/AgeSuffix.java create mode 100644 fx-example/src/main/java/de/neitzel/fx/example/view/DeskController.java delete mode 100644 fx-example/src/main/java/de/neitzel/fx/injectfx/example/JavaFXApp.java delete mode 100644 fx-example/src/main/java/de/neitzel/fx/injectfx/example/Main.java delete mode 100644 fx-example/src/main/java/de/neitzel/fx/injectfx/example/MainWindow.java delete mode 100644 fx-example/src/main/resources/address.fxml create mode 100644 fx-example/src/main/resources/de/neitzel/fx/example/view/AddressForm.fxml create mode 100644 fx-example/src/main/resources/de/neitzel/fx/example/view/Desk.fxml delete mode 100644 fx-example/src/main/resources/de/neitzel/fx/injectfx/example/MainWindow.fxml delete mode 100644 fx-example/src/main/resources/person.fxml create mode 100644 fx-example/src/test/java/de/neitzel/fx/example/DeskLoadsTest.java create mode 100644 fx/README.md diff --git a/README.md b/README.md index 641a032..638e4a0 100644 --- a/README.md +++ b/README.md @@ -43,11 +43,11 @@ Some encryption classes that use format-preserving-encryption. ### fx -Some JavaFX additions. +JavaFX library that binds an FXML View to an ordinary Java Model. See [fx/README.md](fx/README.md). ### fx-example -Some example programs that use the fx component +Person desk that shows how to use `fx`. Run `mvn -pl fx-example javafx:run`. ### gson diff --git a/fx-example/README.md b/fx-example/README.md new file mode 100644 index 0000000..9056906 --- /dev/null +++ b/fx-example/README.md @@ -0,0 +1,11 @@ +# fx-example + +A person desk that uses the [`fx`](../fx/README.md) library: a Direct binding, a Converter, a Computed binding, a nested Component, a Repeat, a list of simple values, and Messages. + +From the NeitzelLib root, with Java 21: + +```bash +mvn -pl fx-example javafx:run +``` + +The launch class is `de.neitzel.fx.example.Main`. The Model is an ordinary `Person`. The View is `Desk.fxml`. diff --git a/fx-example/pom.xml b/fx-example/pom.xml index 7dca1fb..b8cc2d9 100644 --- a/fx-example/pom.xml +++ b/fx-example/pom.xml @@ -16,27 +16,46 @@ ${project.artifactId} ${project.artifactId} ${project.artifactId} - de.neitzel.fx.injectfx.example.Main + de.neitzel.fx.example.Main ${project.artifactId}-${project.version} - de.neitzel.lib fx ${project.version} + + org.slf4j + slf4j-simple + runtime + ${jar.filename} + + org.apache.maven.plugins + maven-compiler-plugin + + + none + + + + org.openjfx + javafx-maven-plugin + ${javafx.maven.plugin} + + ${main.class} + + com.github.spotbugs spotbugs-maven-plugin - org.apache.maven.plugins maven-pmd-plugin diff --git a/fx-example/src/main/java/de/neitzel/fx/component/example/Address.java b/fx-example/src/main/java/de/neitzel/fx/component/example/Address.java deleted file mode 100644 index e1a13cb..0000000 --- a/fx-example/src/main/java/de/neitzel/fx/component/example/Address.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.neitzel.fx.component.example; - -import lombok.Getter; -import lombok.Setter; - -/** - * Simple address model used in the FX example component. - */ -@Getter -@Setter -public class Address { - - /** - * Street name and number. - */ - private String street; - - /** - * City name. - */ - private String city; - - /** - * Default constructor only - */ - public Address() { - // default constructor only - } -} \ No newline at end of file diff --git a/fx-example/src/main/java/de/neitzel/fx/component/example/ExampleApp.java b/fx-example/src/main/java/de/neitzel/fx/component/example/ExampleApp.java deleted file mode 100644 index 8eed94d..0000000 --- a/fx-example/src/main/java/de/neitzel/fx/component/example/ExampleApp.java +++ /dev/null @@ -1,56 +0,0 @@ -package de.neitzel.fx.component.example; - -import de.neitzel.fx.component.ComponentLoader; -import javafx.application.Application; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.stage.Stage; - -/** - * Example JavaFX application demonstrating the {@link de.neitzel.fx.component.ComponentLoader} usage. - */ -public class ExampleApp extends Application { - - /** - * Default constructor only - */ - public ExampleApp() { - // default constructor only - } - - /** - * Launches the JavaFX application. - * - * @param args command line arguments - */ - public static void main(String[] args) { - launch(args); - } - - /** - * Initializes sample model data, loads the FX component and shows the primary stage. - * - * @param primaryStage the primary stage for this application - */ - @Override - public void start(Stage primaryStage) throws Exception { - // Beispielmodel initialisieren - Address address = new Address(); - address.setStreet("Sample Street 1"); - address.setCity("Sample City"); - - Person person = new Person(); - person.setName("Max Mustermann"); - person.setAddress(address); - - // ComponentLoader verwenden - ComponentLoader loader = new ComponentLoader(); - Parent root = loader.load(person, "/person.fxml"); - - // Scene erstellen und anzeigen - Scene scene = new Scene(root); - primaryStage.setTitle("ComponentLoader Example"); - primaryStage.setScene(scene); - primaryStage.show(); - } -} \ No newline at end of file diff --git a/fx-example/src/main/java/de/neitzel/fx/component/example/Main.java b/fx-example/src/main/java/de/neitzel/fx/component/example/Main.java deleted file mode 100644 index 4ac3c9b..0000000 --- a/fx-example/src/main/java/de/neitzel/fx/component/example/Main.java +++ /dev/null @@ -1,24 +0,0 @@ -package de.neitzel.fx.component.example; - -/** - * Another Main class as workaround when the JavaFX Application ist started without - * taking care os Classloader Requirements of JavaFX. (Important when starting from inside NetBeans!) - */ -public class Main { - - /** - * Default constructor only - */ - public Main() { - // default constructor only - } - - /** - * Additional main methode to start Application. - * - * @param args Commandline Arguments. - */ - public static void main(String[] args) { - ExampleApp.main(args); - } -} diff --git a/fx-example/src/main/java/de/neitzel/fx/component/example/Person.java b/fx-example/src/main/java/de/neitzel/fx/component/example/Person.java deleted file mode 100644 index e77a086..0000000 --- a/fx-example/src/main/java/de/neitzel/fx/component/example/Person.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.neitzel.fx.component.example; - -import lombok.Getter; -import lombok.Setter; - -/** - * Simple person model used in the FX example component. - */ -@Getter -@Setter -public class Person { - - /** - * The person's full name. - */ - private String name; - - /** - * The address of the person. - */ - private Address address; - - /** - * Default constructor only - */ - public Person() { - // default constructor only - } -} diff --git a/fx-example/src/main/java/de/neitzel/fx/example/DeskApp.java b/fx-example/src/main/java/de/neitzel/fx/example/DeskApp.java new file mode 100644 index 0000000..1ba8d82 --- /dev/null +++ b/fx-example/src/main/java/de/neitzel/fx/example/DeskApp.java @@ -0,0 +1,70 @@ +package de.neitzel.fx.example; + +import de.neitzel.fx.example.model.Address; +import de.neitzel.fx.example.model.Person; +import de.neitzel.fx.example.view.DeskController; +import de.neitzel.fx.view.LoadedView; +import de.neitzel.fx.view.MessagePopup; +import de.neitzel.fx.view.ViewLoader; +import de.neitzel.injection.ApplicationContext; +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.stage.Stage; + +import java.util.ArrayList; +import java.util.List; + +/** + * Opens the person desk for one ordinary {@link Person}. + */ +public class DeskApp extends Application { + + /** + * Creates the JavaFX application. + */ + public DeskApp() { + } + + /** + * Builds the person the desk edits. + * + * @return a person with a home address, one visit, and two tags + */ + public static Person sample() { + Address home = new Address("Sample Street 1", "Sample City"); + Address visit = new Address("Work Road 2", "Office City"); + Person person = new Person(); + person.setName("Ada Lovelace"); + person.setAge(36); + person.setHome(home); + person.setVisits(new ArrayList<>(List.of(visit))); + person.setSelectedVisit(visit); + person.setTags(new ArrayList<>(List.of("dns", "math"))); + return person; + } + + /** + * Launches the desk. + * + * @param args unused + */ + public static void main(String[] args) { + launch(args); + } + + /** + * Loads the desk for {@link #sample()} and shows it. + * + * @param stage the primary stage + */ + @Override + public void start(Stage stage) { + ApplicationContext context = new ApplicationContext(DeskApp.class); + Person person = sample(); + LoadedView loaded = ViewLoader.load(DeskController.class.getResource("Desk.fxml"), person, context); + MessagePopup.showNewMessages(loaded.getViewModel()); + stage.setTitle("fx example"); + stage.setScene(new Scene(loaded.getRoot())); + stage.show(); + } +} diff --git a/fx-example/src/main/java/de/neitzel/fx/example/Main.java b/fx-example/src/main/java/de/neitzel/fx/example/Main.java new file mode 100644 index 0000000..717567b --- /dev/null +++ b/fx-example/src/main/java/de/neitzel/fx/example/Main.java @@ -0,0 +1,23 @@ +package de.neitzel.fx.example; + +import javafx.application.Application; + +/** + * Launches the example without extending {@link Application}. + *

+ * JavaFX on the classpath is started from a class that is not itself an {@link Application}. + */ +public final class Main { + + private Main() { + } + + /** + * Starts the person desk. + * + * @param args unused + */ + public static void main(String[] args) { + Application.launch(DeskApp.class, args); + } +} diff --git a/fx-example/src/main/java/de/neitzel/fx/example/model/Address.java b/fx-example/src/main/java/de/neitzel/fx/example/model/Address.java new file mode 100644 index 0000000..1621577 --- /dev/null +++ b/fx-example/src/main/java/de/neitzel/fx/example/model/Address.java @@ -0,0 +1,73 @@ +package de.neitzel.fx.example.model; + +/** + * An ordinary address the desk edits. + */ +public class Address { + + private String street = ""; + private String city = ""; + + /** + * Creates an empty address. + */ + public Address() { + } + + /** + * Creates an address with the given street and city. + * + * @param street the street + * @param city the city + */ + public Address(String street, String city) { + this.street = street; + this.city = city; + } + + /** + * Returns the street. + * + * @return the street + */ + public String getStreet() { + return street; + } + + /** + * Sets the street. + * + * @param street the street + */ + public void setStreet(String street) { + this.street = street; + } + + /** + * Returns the city. + * + * @return the city + */ + public String getCity() { + return city; + } + + /** + * Sets the city. + * + * @param city the city + */ + public void setCity(String city) { + this.city = city; + } + + /** + * Returns the street and city, for a combo box row. + * + * @return the street and city + */ + @Override + public String toString() { + return street + ", " + city; + } +} diff --git a/fx-example/src/main/java/de/neitzel/fx/example/model/Person.java b/fx-example/src/main/java/de/neitzel/fx/example/model/Person.java new file mode 100644 index 0000000..e3de57e --- /dev/null +++ b/fx-example/src/main/java/de/neitzel/fx/example/model/Person.java @@ -0,0 +1,137 @@ +package de.neitzel.fx.example.model; + +import java.util.ArrayList; +import java.util.List; + +/** + * An ordinary person the desk edits. + *

+ * Read-write attributes are what the View binds to. The class carries no JavaFX types. + */ +public class Person { + + private String name = ""; + private Integer age; + private Address home; + private List

visits = new ArrayList<>(); + private Address selectedVisit; + private List tags = new ArrayList<>(); + + /** + * Creates an empty person. + */ + public Person() { + } + + /** + * Returns the name. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Sets the name. + * + * @param name the name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Returns the age in years. + * + * @return the age, or {@code null} when none is set + */ + public Integer getAge() { + return age; + } + + /** + * Sets the age in years. + * + * @param age the age + */ + public void setAge(Integer age) { + this.age = age; + } + + /** + * Returns the home address. + * + * @return the home address, or {@code null} when none is set + */ + public Address getHome() { + return home; + } + + /** + * Sets the home address. + * + * @param home the home address + */ + public void setHome(Address home) { + this.home = home; + } + + /** + * Returns the visits. + *

+ * After the View has loaded, this is the list the View is watching. + * + * @return the visits + */ + public List

getVisits() { + return visits; + } + + /** + * Sets the visits. + * + * @param visits the visits + */ + public void setVisits(List
visits) { + this.visits = visits; + } + + /** + * Returns the visit chosen in the combo box. + * + * @return the selected visit, or {@code null} when none is selected + */ + public Address getSelectedVisit() { + return selectedVisit; + } + + /** + * Sets the visit chosen in the combo box. + * + * @param selectedVisit the selected visit + */ + public void setSelectedVisit(Address selectedVisit) { + this.selectedVisit = selectedVisit; + } + + /** + * Returns the tags. + *

+ * After the View has loaded, this is the list the View is watching. + * + * @return the tags + */ + public List getTags() { + return tags; + } + + /** + * Sets the tags. + * + * @param tags the tags + */ + public void setTags(List tags) { + this.tags = tags; + } +} diff --git a/fx-example/src/main/java/de/neitzel/fx/example/view/AddressForm.java b/fx-example/src/main/java/de/neitzel/fx/example/view/AddressForm.java new file mode 100644 index 0000000..e2d01c6 --- /dev/null +++ b/fx-example/src/main/java/de/neitzel/fx/example/view/AddressForm.java @@ -0,0 +1,51 @@ +package de.neitzel.fx.example.view; + +import jakarta.inject.Singleton; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.scene.layout.VBox; + +/** + * Component that edits one address. + *

+ * The class is the root and the Controller of {@code AddressForm.fxml}. A parent View sets + * {@link #modelProperty()} from a Direct binding. A repeated row gets its own instance. + */ +@Singleton +public class AddressForm extends VBox { + + private final ObjectProperty model = new SimpleObjectProperty<>(this, "model"); + + /** + * Creates an empty form. The container calls this constructor. + */ + public AddressForm() { + } + + /** + * Returns the model property a parent View sets. + * + * @return the model property + */ + public ObjectProperty modelProperty() { + return model; + } + + /** + * Returns the address this form edits. + * + * @return the address, or {@code null} when none is set + */ + public Object getModel() { + return model.get(); + } + + /** + * Sets the address this form edits. + * + * @param model the address + */ + public void setModel(Object model) { + this.model.set(model); + } +} diff --git a/fx-example/src/main/java/de/neitzel/fx/example/view/AgeConverter.java b/fx-example/src/main/java/de/neitzel/fx/example/view/AgeConverter.java new file mode 100644 index 0000000..8f3424c --- /dev/null +++ b/fx-example/src/main/java/de/neitzel/fx/example/view/AgeConverter.java @@ -0,0 +1,58 @@ +package de.neitzel.fx.example.view; + +import de.neitzel.fx.view.Converter; +import jakarta.inject.Inject; +import jakarta.inject.Singleton; + +/** + * Translates an age between the Model and the text field. + */ +@Singleton +public class AgeConverter implements Converter { + + private final AgeSuffix suffix; + + /** + * Creates a converter that reads its suffix from the injected service. + * + * @param suffix the suffix written in front of the age + */ + @Inject + public AgeConverter(AgeSuffix suffix) { + this.suffix = suffix; + } + + /** + * Writes the suffix in front of the age. + * + * @param attributeValue the age + * @return the text shown in the field + */ + @Override + public Object toControlValue(Object attributeValue) { + if (attributeValue == null) { + return ""; + } + return suffix.prefix() + attributeValue; + } + + /** + * Reads an age that starts with the suffix. + * + * @param controlValue the field text + * @return the age + */ + @Override + public Object toAttributeValue(Object controlValue) { + String text = controlValue == null ? "" : controlValue.toString(); + String prefix = suffix.prefix(); + if (!text.startsWith(prefix)) { + throw new IllegalArgumentException("Age must start with \"" + prefix.trim() + "\": " + text); + } + try { + return Integer.valueOf(text.substring(prefix.length()).trim()); + } catch (NumberFormatException failure) { + throw new IllegalArgumentException("Age must be a whole number: " + text); + } + } +} diff --git a/fx-example/src/main/java/de/neitzel/fx/example/view/AgeSuffix.java b/fx-example/src/main/java/de/neitzel/fx/example/view/AgeSuffix.java new file mode 100644 index 0000000..079b237 --- /dev/null +++ b/fx-example/src/main/java/de/neitzel/fx/example/view/AgeSuffix.java @@ -0,0 +1,25 @@ +package de.neitzel.fx.example.view; + +import jakarta.inject.Singleton; + +/** + * The suffix an {@link AgeConverter} writes in front of an age. + */ +@Singleton +public class AgeSuffix { + + /** + * Creates the suffix used by the desk. + */ + public AgeSuffix() { + } + + /** + * Returns the text written in front of the age. + * + * @return the suffix, including its trailing space + */ + public String prefix() { + return "years "; + } +} diff --git a/fx-example/src/main/java/de/neitzel/fx/example/view/DeskController.java b/fx-example/src/main/java/de/neitzel/fx/example/view/DeskController.java new file mode 100644 index 0000000..7acb8a5 --- /dev/null +++ b/fx-example/src/main/java/de/neitzel/fx/example/view/DeskController.java @@ -0,0 +1,104 @@ +package de.neitzel.fx.example.view; + +import de.neitzel.fx.example.model.Address; +import de.neitzel.fx.view.HasViewModel; +import de.neitzel.fx.view.Message; +import de.neitzel.fx.view.ViewModel; +import jakarta.inject.Singleton; +import javafx.fxml.FXML; +import javafx.scene.control.TextField; + +import java.util.List; + +/** + * Controller for the person desk. + *

+ * The container creates this class and injects nothing else. {@link #setViewModel} receives the + * ViewModel before the binding elements run, so {@link #greeting()} can read the name field on + * its first call. + */ +@Singleton +public class DeskController implements HasViewModel { + + @FXML + private TextField nameField; + + @FXML + private TextField tagField; + + private ViewModel viewModel; + + /** + * Creates the controller. The container calls this constructor. + */ + public DeskController() { + } + + /** + * Receives the ViewModel for the person on the desk. + * + * @param viewModel the ViewModel + */ + @Override + public void setViewModel(ViewModel viewModel) { + this.viewModel = viewModel; + } + + /** + * Returns the greeting written to the label. + *

+ * The method reads the name field. It does not write the Model. + * + * @return the greeting + */ + public String greeting() { + String name = nameField.getText(); + if (name == null || name.isBlank()) { + return "Hello"; + } + return "Hello, " + name.trim(); + } + + /** + * Adds a visit and leaves the previous selection in place. + */ + @FXML + public void addVisit() { + visits().add(new Address("New street", "New city")); + } + + /** + * Adds the tag field's text to the tag list and clears the field. + */ + @FXML + public void addTag() { + String tag = tagField.getText(); + if (tag == null || tag.isBlank()) { + return; + } + tags().add(tag.trim()); + tagField.clear(); + } + + /** + * Adds an info Message that quotes the name already stored on the Model. + */ + @FXML + public void leaveNote() { + Object name = viewModel.property("name").getValue(); + viewModel.addMessage(new Message( + Message.Severity.INFO, + "The model already has the name " + name + ".", + "desk")); + } + + @SuppressWarnings("unchecked") + private List

visits() { + return (List
) viewModel.property("visits").getValue(); + } + + @SuppressWarnings("unchecked") + private List tags() { + return (List) viewModel.property("tags").getValue(); + } +} diff --git a/fx-example/src/main/java/de/neitzel/fx/injectfx/example/JavaFXApp.java b/fx-example/src/main/java/de/neitzel/fx/injectfx/example/JavaFXApp.java deleted file mode 100644 index cf3b85f..0000000 --- a/fx-example/src/main/java/de/neitzel/fx/injectfx/example/JavaFXApp.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.neitzel.fx.injectfx.example; - -import javafx.application.Application; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.stage.Stage; - -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Minimal JavaFX application launcher used by the examples. - * - *

This class initializes the JavaFX runtime, loads {@code MainWindow.fxml} and shows - * the primary stage. It is intended as a small bootstrap used by IDEs or test runs - * to start the JavaFX UI for demonstration purposes. - */ -public class JavaFXApp extends Application { - - private static final Logger LOGGER = Logger.getLogger(JavaFXApp.class.getName()); - - /** - * Default constructor only. - * - *

The constructor does not perform UI initialization. UI setup happens in {@link #start(Stage)} - * after JavaFX has set up the application thread. - */ - public JavaFXApp() { - // default constructor only - } - - public static void main(String[] args) { - launch(args); - } - - @Override - public void start(Stage primaryStage) { - try { - primaryStage.setTitle("Hello World!"); - FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MainWindow.fxml")); - Parent root = fxmlLoader.load(); - primaryStage.setScene(new Scene(root)); - primaryStage.show(); - } catch (Exception ex) { - LOGGER.log(Level.SEVERE, "Exception while starting JavaFXApp", ex); - } - } -} diff --git a/fx-example/src/main/java/de/neitzel/fx/injectfx/example/Main.java b/fx-example/src/main/java/de/neitzel/fx/injectfx/example/Main.java deleted file mode 100644 index 20e7997..0000000 --- a/fx-example/src/main/java/de/neitzel/fx/injectfx/example/Main.java +++ /dev/null @@ -1,33 +0,0 @@ -package de.neitzel.fx.injectfx.example; - -/** - * Another Main class as workaround when the JavaFX Application ist started without - * taking care os Classloader Requirements of JavaFX. (Important when starting from inside NetBeans!) - */ -public class Main { - - /** - * Creates a new helper instance of {@code Main}. - * - *

This constructor is intentionally empty. The {@code Main} class serves as an alternative - * entry point to launch the JavaFX application via {@link JavaFXApp#main(String[])} in - * environments (IDEs, build tools) where directly starting a class that extends - * {@code javafx.application.Application} may fail due to classloader or JVM startup constraints. - * - *

Do not perform application initialization here; use the static {@code main} method to - * start the JavaFX runtime. This constructor exists to allow tooling and frameworks to - * instantiate the class reflectively if required. - */ - public Main() { - // default constructor only - } - - /** - * Additional main methode to start Application. - * - * @param args Commandline Arguments. - */ - public static void main(String[] args) { - JavaFXApp.main(args); - } -} diff --git a/fx-example/src/main/java/de/neitzel/fx/injectfx/example/MainWindow.java b/fx-example/src/main/java/de/neitzel/fx/injectfx/example/MainWindow.java deleted file mode 100644 index 8418183..0000000 --- a/fx-example/src/main/java/de/neitzel/fx/injectfx/example/MainWindow.java +++ /dev/null @@ -1,68 +0,0 @@ -package de.neitzel.fx.injectfx.example; - -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.control.TextField; - -import java.net.URL; -import java.util.ResourceBundle; - -/** - * Controller for the MainWindow FXML view. - * - *

This class acts as the backing controller for the {@code MainWindow.fxml} UI. It demonstrates a - * minimal example of a JavaFX controller that: - *

    - *
  • receives UI element injection via {@link FXML} (the {@link #textField} field),
  • - *
  • initializes the view in {@link #initialize(URL, ResourceBundle)}, and
  • - *
  • handles user actions via {@link #onButtonClick(ActionEvent)}.
  • - *
- * - *

Usage notes: - *

    - *
  • Fields annotated with {@link FXML} are injected by the {@code FXMLLoader} before - * {@link #initialize(URL, ResourceBundle)} is called — do not expect them to be non-null - * in the constructor.
  • - *
  • All UI updates must run on the JavaFX Application Thread. Methods called by FXML - * (such as {@link #onButtonClick(ActionEvent)}) are executed on that thread by the - * JavaFX runtime.
  • - *
  • The controller keeps a simple click counter and updates {@link #textField} to reflect - * the current count using {@link #displayCounter()}.
  • - *
- */ -public class MainWindow implements Initializable { - - /** - * Counter for button clicks shown in the UI. - */ - private int counter = 0; - - /** - * Text field UI control showing the click counter. - */ - @FXML - private TextField textField; - - /** - * Default constructor only - */ - public MainWindow() { - // default constructor only - } - - @Override - public void initialize(URL location, ResourceBundle resources) { - displayCounter(); - } - - private void displayCounter() { - textField.setText("Click counter: " + counter); - } - - @FXML - private void onButtonClick(ActionEvent actionEvent) { - counter++; - displayCounter(); - } -} diff --git a/fx-example/src/main/resources/address.fxml b/fx-example/src/main/resources/address.fxml deleted file mode 100644 index ae8f780..0000000 --- a/fx-example/src/main/resources/address.fxml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/fx-example/src/main/resources/de/neitzel/fx/example/view/AddressForm.fxml b/fx-example/src/main/resources/de/neitzel/fx/example/view/AddressForm.fxml new file mode 100644 index 0000000..75176bf --- /dev/null +++ b/fx-example/src/main/resources/de/neitzel/fx/example/view/AddressForm.fxml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/fx-example/src/main/resources/de/neitzel/fx/example/view/Desk.fxml b/fx-example/src/main/resources/de/neitzel/fx/example/view/Desk.fxml new file mode 100644 index 0000000..e61314d --- /dev/null +++ b/fx-example/src/main/resources/de/neitzel/fx/example/view/Desk.fxml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +