Skip to content

Commit

Permalink
Improvements to custom panel based on 4.4.1 API improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
davetcc committed Nov 10, 2024
1 parent a9e2029 commit 96ac053
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion java/embedControlJavaFx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ It is likely before any public release that you'll want to customize the applica
* `fximg/embedCONTROL.ico` is the start-up application icon, only used by the packager on Windows
* `fximg/MyIcons.icns` is the start-up application icon, only used by the packager on macOS

You can use the EmbedControl icon or logo to show compatibility with TagVal protocol.
## Layout of the application

## Overriding how pages are drawn

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public void dialogUpdate(MenuDialogCommand cmd) {

// handle the case where it's already connected really quick!
if (controller.getConnector().getAuthenticationStatus() == AuthStatus.CONNECTION_READY) {
if(navigationManager.currentNavigationPanel() instanceof JfxMenuPresentable) {
if(navigationManager.currentNavigationPanel() instanceof UpdatablePanel) {
statusHasChanged(AuthStatus.CONNECTION_READY);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicReference;

/**
* This is the local UI plugin, it provides a local UI that will by default render your menu tree onto the display using
* Java FX. The default UI can be overridden by adding custom panels to the navigationHeader, see below where we've done
* this for one of the submenu items.
*/
/// This provides a local UI frame that will by default render your menu tree onto the display using
/// Java FX. The default UI can be overridden by adding custom panels to the navigationHeader, see below
/// where we've done this for one of the submenu items. There is an image showing the overall structure
/// within the readme file, along with a description of how it is intended to work.
public class JfxLocalAutoUI extends Application {
private static final AtomicReference<MenuConfig> GLOBAL_CONTEXT = new AtomicReference<>(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
* Goes with the local UI, this handles changes on behalf of the local UI in both directions. You can add additional
* functionality as needed here.
*/
/// Part of the local UI, this handles changes on behalf of the local UI in both directions.
/// It subscribes to the menu manager and ensures that any updates result in events being
/// provided to the UI. It is implemented as a listener on the menu manager.
public class LocalTreeComponentManager implements MenuManagerListener {
private final MenuManagerServer menuMgr;
private final JfxNavigationManager navigationManager;
Expand Down Expand Up @@ -46,15 +45,11 @@ private void tickProc() {
@Override
public void menuItemHasChanged(Object sender, MenuItem item) {
Platform.runLater(() -> {
if (navigationManager.currentNavigationPanel() instanceof JfxMenuPresentable menuPanel) {
if (navigationManager.currentNavigationPanel() instanceof UpdatablePanel menuPanel) {
if (item == null) {
menuPanel.entirelyRebuildGrid();
} else {
menuPanel.getGridComponent().itemHasUpdated(item);
}
} else if(navigationManager.currentNavigationPanel() instanceof UpdatablePanel panel) {
if(item != null) {
panel.itemHasUpdated(item);
menuPanel.itemHasUpdated(item);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
import static com.thecoderscorner.embedcontrol.customization.customdraw.CustomDrawingConfiguration.NumericColorRange;

/// Demonstrates how to create your own panel to be presented instead of an automatic menu panel. Simply
/// register this panel with the navigation manager class and it will be presented instead of the standard
/// panel. See `JfxLocalAutoUI` where this panel is added. As the base class implements `UpdatablePanel`
/// register this panel with the navigation manager class, and it will be presented instead of the standard
/// panel. See `JfxLocalAutoUI` where this panel is added. As the base class extends `BaseCustomMenuPanel`
/// it will automatically be told when menu items have updated, and be provided with a tick function for
/// animations. You can override the methods in `UpdatablePanel` if you use controls other than the
/// standard menu controls created from `ComponentSettings` which will automatically update.
/// standard menu controls created from `ComponentSettings` to update such items yourself.
public class StatusPanelDrawable extends BaseCustomMenuPanel {
private final EmbeddedJavaDemoMenu menuDef;
private final MenuComponentControl componentControl;
Expand All @@ -53,8 +53,9 @@ public StatusPanelDrawable(EmbeddedJavaDemoMenu menuDef, ScheduledExecutorServic
}

protected void populateGrid() {
// here we create a JavaFX grid using the regular way of doing so. You can consult the JavaFx documentation
// for more on how to create grids.
// An empty gridPane has been created for us, we just need to ensure the rows and cols
// are correctly set up and then populate it. Here we just create three rows of fixed
// height and split the grid into four equal columns. Adjust here as needed.
gridPane.getRowConstraints().add(new RowConstraints(80));
gridPane.getRowConstraints().add(new RowConstraints(20));
gridPane.getRowConstraints().add(new RowConstraints(20));
Expand All @@ -63,18 +64,21 @@ protected void populateGrid() {
gridPane.getColumnConstraints().add(cc);
}

// now we add some labels into the grid on the left.
// now we add some labels into the grid on the left for each menu item
gridPane.add(new Label("Case Temperature"), 0, 0);
gridPane.add(new Label("Light Color"), 0, 1);
gridPane.add(new Label("Authenticator"), 0, 2);

// and on the right we create a custom simulation button, that when we click it causes some
// menu items to update automatically
gridPane.add(new Label("Start Simulating"), 2, 0);
var runSimButton = new Button("Run Sim");
runSimButton.setOnAction(_ -> executor.scheduleAtFixedRate(this::updateTemp, 200L, 200L, TimeUnit.MILLISECONDS));
gridPane.add(runSimButton, 2, 1);

// and now we add in a component that will render using the VU meter style. It is a float item, and we provide
// custom drawing configuration for it, so it has three ranges, green, orange, red.
// custom drawing configuration for it, so it has three ranges: green, orange, red. There are many forms of
// custom drawing, this is one common example.
FontInformation font100Pc = new FontInformation(100, SizeMeasurement.PERCENT);
var greenOrangeRed = new NumberCustomDrawingConfiguration(List.of(
new NumericColorRange(0.0, 70.0, fromFxColor(Color.GREEN), fromFxColor(Color.WHITE)),
Expand All @@ -87,31 +91,33 @@ protected void populateGrid() {
greenOrangeRed, true)
);

// Here we create an IoT manager button that represents the IoT Monitor menu item
putIntoGrid(menuDef.getStatusIoTMonitor(), new ComponentSettings(
globalColors, font100Pc, PortableAlignment.RIGHT,
new ComponentPositioning(2, 1), RedrawingMode.SHOW_VALUE, ControlType.AUTH_IOT_CONTROL,
NO_CUSTOM_DRAWING, true));

// Here we create an RGB control from the status light color menu item.
putIntoGrid(menuDef.getStatusLightColor(), new ComponentSettings(
globalColors, font100Pc, PortableAlignment.RIGHT,
new ComponentPositioning(1, 1), RedrawingMode.SHOW_VALUE, ControlType.RGB_CONTROL,
NO_CUSTOM_DRAWING, true));
}

// When the simulate button is pressed, this is called frequently to update a couple of menu items.
private void updateTemp() {
manager.updateMenuItem(this, menuDef.getStatusCaseTempOC(), Math.random() * 100);
manager.updateMenuItem(this, menuDef.getLED1Brightness(), Math.random() * 100 );
}


@Override
public String getPanelName() {
if (componentControl == null) return "empty";
// here you just return the name of the panel as it should appear in the title.
return "Status Panel";
}

@Override
public boolean canBeRemoved() {
return true;
public void entirelyRebuildGrid() {
// in here you put anything that would be needed should the menu structurally change.
}
}

0 comments on commit 96ac053

Please sign in to comment.