Skip to content

Commit

Permalink
examples improved
Browse files Browse the repository at this point in the history
  • Loading branch information
dave committed Nov 23, 2024
1 parent 110af8e commit 7b0ef33
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public RemoteConnectionPanel(EmbedControlContext context, MenuItem item,
control = new RemoteMenuComponentControl(controller, navigationManager);
dialogManager = new RemoteDialogManager();
editorFactory = new JfxMenuEditorFactory(control, Platform::runLater, dialogManager);
//
// at this point you can add custom panels to render certain submenus. You could check on the UUID of the
// connection and then add custom panels. See the `embeddedJavaDeviceUI` where `StatusPanelDrawable` is
// added to replace the Auto-UI for the status menu. See ``
//
} catch (Exception e) {
logger.log(ERROR, "Failed to start controller " + persistedConnection.getName(), e);
}
Expand Down
11 changes: 9 additions & 2 deletions java/embeddedJavaDeviceUI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ The application is split up into several files:

### Components required for operation

* `EmbeddedJavaDemoApp` - this is the class that starts up your application and initialises any plugins you selected. You should not touch this class as it is overwritten every time around.
* `EmbeddedJavaDemoApp` - this is the class that starts up your application and initialises any plugins you selected. This is the starting point and you're free to rearrange as needed.
* `EmbeddedJavaDemoMenu` - this is the class that holds all the menu definitions and the menu tree. It is available in the spring context, and you can inject it into any of your components that need it. It also has short-cut methods to get every menu item.
* `EmbeddedJavaDemoController` - this is where any callbacks that you register go, at the moment we support only one controller, in future we may provide support for more than one. Each function callback that you declare in TcMenu Designer will turn into a method in here. This also allows you to listen for any menu item, and for start and stop events. Further, you can change the controller's constructor to include other components if needed.
* `EmbeddedJavaDemoController` - this is the controller for the menu front-end. Any callbacks that you register in designer will go here, at the moment we support only one controller, in future we may provide support for more than one. Each function callback that you declare in TcMenu Designer will turn into a method in here. This also allows you to listen for any menu item, and for start and stop events. Further, you can change the controller's constructor to include other components if needed. Scroll choice callbacks that request the data for scroll choice items are also added.
* `MenuConfig` - this is generally used to wire together all of your components. You can create additional components in this class by creating a function annotated with `@TcComponent`, any parameters to the function will be auto-wired using components already available in the context.

### Components that are optional
Expand All @@ -36,3 +36,10 @@ If you use the standard maven setup, after running the above build steps, you sh

If you used a modular build (IE you have a `module-info.java` file in the `src/main/java` directory) then to run the application ensure that the right version of Java using `java -version` is on your path and then the run command should be `java --module-path ../deps "-Dprism.lcdtext=false" --add-modules com.thecoderscorner.menuexample.embeddedjavademo com.thecoderscorner.menu.devicedemo.EmbeddedJavaDemoApp`. Given TcMenu is JPMS compliant, it can be packaged using `jpackage`.

## The simple application context and the MenuConfig class

The menu configuration system within TcMenu allows for very simple arrangements of components. We populate the context with all the components needed to build a UI using JavaFX. There is no absolute requirement that you have to use the UI components, and in fact you could have either no UI, or a different UI technology.

Consider the `MenuConfig` class somewhat like a storage object that can hold instances of objects needed for the running of the application. configuration

## More details about using the Controller class
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

/**
* This class is the application class that is run when the application starts. You can organize the application in
* here into a series of components. This is and example of how to arrange such an application.
* here into a series of components. This is the starting point of a Java embedded application, you can rearrange
* as needed, but to continue round trips with the designer UI ensure the file with menu definitions remains unaltered
* and that the controller is kept in the same place.
*/
public class EmbeddedJavaDemoApp {
private final MenuManagerServer manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@

import static java.lang.System.Logger.Level.INFO;

/**
* This class represents the controller for the EmbeddedJavaDemoMenu. It implements the MenuManagerListener interface.
* The controller is responsible for creating instances of objects that are required around the application, you can
* get hold of these objects later using getBean, and you can add extra ones wrapping an object creation with asBean(..).
*
* Unless you delete this file it will not be recreated as you can edit it too.
* @see MenuManagerListener
*/
/// The EmbeddedJavaDemoController class implements the MenuManagerListener interface
/// to handle various interactions with the menu system and manage the graphical user interface
/// components of the application. TcMenu Designer will update the file to add any new callbacks
/// that are added in designer during a round trip.
///
/// You can add any additional object dependencies you need in the constructor, this object is
/// created in `MenuConfig` and will be automatically wired using any components declared in there.
/// @see MenuConfig
public class EmbeddedJavaDemoController implements MenuManagerListener {
private final System.Logger logger = System.getLogger(getClass().getSimpleName());
private final EmbeddedJavaDemoMenu menuDef;
Expand All @@ -46,6 +46,8 @@ public EmbeddedJavaDemoController(EmbeddedJavaDemoMenu menuDef, JfxNavigationMan
this.globalSettings = settings;
}

// Start of menu callbacks

@MenuCallback(id=15, listResult=true)
public void listHasChanged(Object sender, RuntimeListMenuItem item, ListResponse listResponse) {
logger.log(INFO, String.format("List %s has changed: %s", item, listResponse));
Expand Down Expand Up @@ -78,19 +80,23 @@ public void menuItemHasChanged(Object sender, MenuItem item) {
@Override
public void managerWillStart() {
Platform.runLater(() -> {
// Here we demonstrate adding a couple of title widgets that appear on the right of the navigation bar.
// This is an example showing how you could present the current WiFi signal strength. Just replace the
// random value we set it to in the task below.
TitleWidget<Image> wifiWidget = JfxNavigationHeader.standardWifiWidget();
navigationManager.addTitleWidget(wifiWidget);
executorService.scheduleAtFixedRate(() -> wifiWidget.setCurrentState((int) (Math.random() * 5)), 1000, 100, TimeUnit.MILLISECONDS);

// Here we add a settings widget that is used to present a settings panel in the current stack.
TitleWidget<Image> settingsWidget = JfxNavigationHeader.standardSettingsWidget();
navigationManager.addTitleWidget(settingsWidget);

navigationManager.addWidgetClickedListener((actionEvent, widget) -> {
if(widget == settingsWidget) {
navigationManager.pushNavigation(new ColorSettingsPresentable(globalSettings, navigationManager, "Global", false));
}
});

// add some data to the list menu item.
MenuItemHelper.setMenuState(menuDef.getStatusMyListItem(), List.of("Item 1", "Item 2", "Item 3"), menuDef.getMenuTree());
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

/// This class creates an application context out of all these components, and you can request any components that are
/// put into the context using getBean(ClassName.class). See the base class `BaseMenuConfig` for more details.
///
/// In summary, every function annotated with `@TcComponent` will be added to the "context" and you can then request
/// it later using `getBean`. Consider it a lightweight spring that is JPMS module system compliant. Anything that is
/// marked as a `TcComponent` will be available automatically to other methods marked `TcComponent`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public class JfxLocalAutoUI extends Application {
private JfxNavigationHeader navigationHeader;
private LocalDialogManager dlgMgr;
private MenuAppVersion versionData;
private LocalTreeComponentManager localTree;
private EmbeddedJavaDemoMenu menuTree;
private GlobalSettings globalSettings;

Expand Down Expand Up @@ -92,7 +91,7 @@ public void start(Stage stage) {
localController, mgr, new CondColorFromGlobal(globalSettings)));
navigationHeader.initialiseUI(dlgMgr, localController, scroller);

localTree = new LocalTreeComponentManager(mgr, navigationHeader, executor);
var localTree = new LocalTreeComponentManager(mgr, navigationHeader, executor);
mgr.start();
navigationHeader.pushMenuNavigation(MenuTree.ROOT, ctx.getBean(MenuItemStore.class));

Expand Down

0 comments on commit 7b0ef33

Please sign in to comment.