Skip to content

Commit

Permalink
docs(framework): Fix some javadoc issues
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStegii committed May 25, 2024
1 parent 9e32a62 commit 84ab699
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 8 deletions.
10 changes: 10 additions & 0 deletions framework/src/main/java/org/fulib/fx/FulibFxApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@

import static org.fulib.fx.util.FrameworkUtil.error;

/**
* The starting point of a FulibFx application offering many utilities and functionality.
* <p>
* Extend from this class and override and call {@link FulibFxApp#start(Stage)} to start.
*/
public abstract class FulibFxApp extends Application {

public static final Scheduler FX_SCHEDULER = Schedulers.from(Platform::runLater);
Expand Down Expand Up @@ -160,6 +165,7 @@ public static void setResourcesPath(@NotNull Path path) {
* @param component The component instance
* @param params The arguments passed to the component
* @param onDestroy A disposable which will be modified to include the disposable of the component
* @param <T> The type of component to render
* @return The rendered component
*/
public @NotNull <T extends Node> T initAndRender(@NotNull T component, @NotNull Map<@NotNull String, @Nullable Object> params, @Nullable DisposableContainer onDestroy) {
Expand Down Expand Up @@ -344,13 +350,17 @@ public void registerRoutes(Object routes) {

/**
* Sets the default resource bundle to use for FXML files if no resource bundle is provided in the controller/component.
*
* @param resourceBundle The default resource bundle
*/
public void setDefaultResourceBundle(ResourceBundle resourceBundle) {
this.frameworkComponent.controllerManager().setDefaultResourceBundle(resourceBundle);
}

/**
* Returns auto refresher of the application.
*
* @return The auto refresher of the application
*/
public AutoRefresher autoRefresher() {
return this.frameworkComponent.autoRefresher();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,16 @@
*/
Type type() default Type.PRESSED;

/**
* Possible targets for registering key events.
*/
enum Target {
STAGE, SCENE
}

/**
* Enum representation for different {@link KeyEvent} types.
*/
enum Type {
ANY(KeyEvent.ANY),
PRESSED(KeyEvent.KEY_PRESSED),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class For<Node extends javafx.scene.Node, Item> {

/**
* Use the factory methods to create a new For loop.
*
* @param controllerManager The controller manager for initializing the components
*/
protected For(ControllerManager controllerManager) {
this.controllerManager = controllerManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import java.util.Map;
import java.util.function.BiConsumer;

/**
* Factory class for {@link For} loops.
*/
@Singleton
public class FxFor {

Expand All @@ -37,6 +40,8 @@ public FxFor(ControllerManager controllerManager) {
* @param nodeProvider The provider to create the controller for each item
* @param beforeInit The method to call when the controller is created (useful for setting the item)
* @param params The parameters to pass to the created controller
* @param <Item> The type of item
* @param <Node> The node to display for each item
* @return The For loop
*/
public <Node extends javafx.scene.Node, Item> For<Node, Item> of(@NotNull Parent container, @NotNull ObservableList<@NotNull Item> items, @NotNull Provider<@NotNull Node> nodeProvider, @NotNull Map<@NotNull String, @Nullable Object> params, @NotNull BiConsumer<@NotNull Node, @Nullable Item> beforeInit) {
Expand All @@ -63,6 +68,8 @@ public <Node extends javafx.scene.Node, Item> For<Node, Item> of(@NotNull Parent
* @param items The list of items to display
* @param nodeProvider The provider to create the controller for each item
* @param beforeInit The method to call when the controller is created (useful for setting the item)
* @param <Item> The type of item
* @param <Node> The node to display for each item
* @return The For loop
*/
public <Node extends javafx.scene.Node, Item> For<Node, Item> of(@NotNull Parent container, @NotNull ObservableList<@NotNull Item> items, @NotNull Provider<@NotNull Node> nodeProvider, @NotNull BiConsumer<@NotNull Node, @Nullable Item> beforeInit) {
Expand All @@ -83,6 +90,8 @@ public <Node extends javafx.scene.Node, Item> For<Node, Item> of(@NotNull Parent
* @param container The container to add the nodes to
* @param items The list of items to display
* @param nodeProvider The provider to create the controller for each item
* @param <Item> The type of item
* @param <Node> The node to display for each item
* @return The For loop
*/
public <Node extends javafx.scene.Node, Item> For<Node, Item> of(@NotNull Parent container, @NotNull ObservableList<@NotNull Item> items, @NotNull Provider<@NotNull Node> nodeProvider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.reactivex.rxjava3.schedulers.Schedulers;
import org.fulib.fx.FulibFxApp;
import org.fulib.fx.util.FileUtil;
import org.fulib.fx.util.FrameworkUtil;

import javax.inject.Inject;
import javax.inject.Singleton;
Expand All @@ -16,6 +15,9 @@
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
import static org.fulib.fx.util.FrameworkUtil.error;

/**
* Class used for automatically reloading controllers when their corresponding FXML file changes.
*/
@Singleton
public class AutoRefresher {

Expand All @@ -33,6 +35,12 @@ public class AutoRefresher {
public AutoRefresher() {
}

/**
* Registers the auto refresher for the given directory.
*
* @param directory The directory to check for updates
* @throws RuntimeException If the given path is not a directory
*/
public void setup(Path directory) {

if (!Files.isDirectory(directory)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public void cleanup() {
*
* @param fileName The name of the fxml resource file (with path and file extension)
* @param instance The controller instance to use
* @param setRoot Whether to set the instance as the FXML root element
* @return A parent representing the fxml file
*/
@ApiStatus.Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import static org.fulib.fx.util.FrameworkUtil.error;

/**
* A custom building-factory for instantiating controllers. If an element in an FXML file is of a class annotated with @Controller and a field providing an instance of the same class exists, the provided instance will be used as the controller for the element.
* A custom building-factory for instantiating controllers.
* If an element in an FXML file is of a class annotated with @Controller and a field providing an instance of the same
* class exists, the provided instance will be used as the controller for the element.
*/
@ApiStatus.Internal
public class ControllerBuildFactory implements BuilderFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@
import java.util.*;

/**
* This class is a copy of the ControllerProxyBuilder from the JavaFX framework.
* It is used to load controllers from FXML files and support the injection of subcontrollers, e.g. provided by Dagger.
* This class is a modified copy of the {@link com.sun.javafx.fxml.builder.ProxyBuilder} from JavaFX.
* It is used to load controllers from FXML files and support the injection of subcomponents.
* <p>
* This builder is strongly modified to support the injection of subcontrollers.
* Besides the modification of the instance creation, various parts have been optimized and simplified with new Java features.
*
* @param <T> The type to be built
*/
@ApiStatus.Internal
public class ControllerProxyBuilder<T> extends AbstractMap<String, Object> implements Builder<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import static org.fulib.fx.util.FrameworkUtil.error;

/**
* Exception thrown if a route has been added to the router twice.
*/
public class ControllerDuplicatedRouteException extends RuntimeException {

public ControllerDuplicatedRouteException(String route, Class<?> oldController, Class<?> newController) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.fulib.fx.controller.exception;

/**
* Thrown when navigating to an invalid route.
*/
public class ControllerInvalidRouteException extends RuntimeException {

public ControllerInvalidRouteException(String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import java.util.Map;
import java.util.ResourceBundle;

/**
* Internal class for managing controllers.
* @param <T> The type of the controller
*/
public interface FxSidecar<T> {
void init(T instance, Map<String, Object> params);

Expand Down
5 changes: 5 additions & 0 deletions framework/src/main/java/org/fulib/fx/data/Either.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

import java.util.Optional;

/**
* A class representing two possible values with different types.
* @param <L> The first type (left)
* @param <R> The second type (right)
*/
public class Either<L, R> {

private final @Nullable L left;
Expand Down
5 changes: 5 additions & 0 deletions framework/src/main/java/org/fulib/fx/data/EvictingQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

import static org.fulib.fx.util.FrameworkUtil.error;

/**
* A queue with a certain site overwriting the oldest entry when full.
*
* @param <T> The type of items in the queue
*/
public class EvictingQueue<T> implements SizeableTraversableQueue<T> {

private int size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import java.util.List;

/**
* Interface for a queue that can be traversed by going forwards or backwards.
*
* @param <T> The type of items saved in the queue
*/
public interface TraversableQueue<T> {

void insert(T value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.fulib.fx.duplicate.duplicators.impl;

import org.fulib.fx.duplicate.duplicators.LabeledDuplicator;
import javafx.scene.control.Button;
import org.fulib.fx.duplicate.duplicators.LabeledDuplicator;

public class ButtonDuplicator<T extends Button> extends LabeledDuplicator<T>
{
public class ButtonDuplicator<T extends Button> extends LabeledDuplicator<T> {

@Override
public T duplicate(T button) {
Expand Down
4 changes: 4 additions & 0 deletions framework/src/main/java/org/fulib/fx/util/ControllerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
import static org.fulib.fx.util.FrameworkUtil.error;
import static org.fulib.fx.util.ReflectionUtil.getProvidedClass;

/**
* Different utilities for managing controllers.
* Mostly internal, use with care.
*/
public class ControllerUtil {

private ControllerUtil() {
Expand Down
4 changes: 4 additions & 0 deletions framework/src/main/java/org/fulib/fx/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import java.nio.file.Files;
import java.nio.file.Path;

/**
* Utilities for managing files.
* Mostly internal, use with care.
*/
public class FileUtil {

private FileUtil() {
Expand Down
7 changes: 7 additions & 0 deletions framework/src/main/java/org/fulib/fx/util/FrameworkUtil.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package org.fulib.fx.util;

import org.jetbrains.annotations.ApiStatus;

import java.util.Locale;
import java.util.ResourceBundle;

/**
* Different miscellaneous utilities for the framework.
* Mostly internal, use with care.
*/
@ApiStatus.Internal
public class FrameworkUtil {

private static final ResourceBundle ERROR_BUNDLE = ResourceBundle.getBundle("org.fulib.fx.lang.error", Locale.ROOT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,37 @@ public static boolean canBeAssigned(@NotNull Class<?> type, @Nullable Object val
return getWrapperType(type).isAssignableFrom(valueType);
}

/**
* Returns the wrapped type of the given type.
*
* @param type The type to be wrapped
* @return the wrapped type or the given type if not a primitive type
*/
public static Class<?> getWrapperType(@NotNull Class<?> type) {
return type.isPrimitive() ? wrap(type) : type;
}

// https://stackoverflow.com/questions/1704634/simple-way-to-get-wrapper-class-type-in-java/62219759#62219759

/**
* Wraps an unwrapped type.
*
* @param unwrapped The unwrapped type
* @param <T> The unwrapped type
* @return The wrapped type
*/
@SuppressWarnings("unchecked")
public static <T> Class<T> wrap(@NotNull Class<T> unwrapped) {
return (Class<T>) MethodType.methodType(unwrapped).wrap().returnType();
}

/**
* Unwraps a wrapped type.
*
* @param wrapped The wrapped type
* @param <T> The wrapped type
* @return The unwrapped type
*/
@SuppressWarnings("unchecked")
public static <T> Class<T> unwrap(@NotNull Class<T> wrapped) {
return (Class<T>) MethodType.methodType(wrapped).unwrap().returnType();
Expand Down

0 comments on commit 84ab699

Please sign in to comment.