From c059853d7fb9b7f650079691acc198f07fbdd17d Mon Sep 17 00:00:00 2001 From: jmr3366 Date: Mon, 18 Nov 2024 09:58:14 -0500 Subject: [PATCH] #3414 Feature to lock an overlay --- .../functions/MacroDialogFunctions.java | 19 +++++++++++++++---- .../rptools/maptool/client/ui/AppMenuBar.java | 6 +++++- .../client/ui/htmlframe/HTMLFrameFactory.java | 12 +++++++++++- .../ui/htmlframe/HTMLOverlayManager.java | 13 +++++++++++-- .../client/ui/htmlframe/HTMLOverlayPanel.java | 5 +++-- .../client/ui/sheet/stats/StatSheet.java | 1 + 6 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/rptools/maptool/client/functions/MacroDialogFunctions.java b/src/main/java/net/rptools/maptool/client/functions/MacroDialogFunctions.java index 5203d2d8cb..867342fb3b 100644 --- a/src/main/java/net/rptools/maptool/client/functions/MacroDialogFunctions.java +++ b/src/main/java/net/rptools/maptool/client/functions/MacroDialogFunctions.java @@ -26,11 +26,8 @@ import java.util.concurrent.ExecutionException; import java.util.regex.Pattern; import net.rptools.maptool.client.MapTool; -import net.rptools.maptool.client.ui.htmlframe.HTMLDialog; -import net.rptools.maptool.client.ui.htmlframe.HTMLFrame; -import net.rptools.maptool.client.ui.htmlframe.HTMLFrameFactory; +import net.rptools.maptool.client.ui.htmlframe.*; import net.rptools.maptool.client.ui.htmlframe.HTMLFrameFactory.FrameType; -import net.rptools.maptool.client.ui.htmlframe.HTMLOverlayManager; import net.rptools.maptool.language.I18N; import net.rptools.maptool.model.library.Library; import net.rptools.maptool.model.library.LibraryManager; @@ -57,6 +54,7 @@ private MacroDialogFunctions() { "closeOverlay", "setOverlayVisible", "isOverlayVisible", + "isOverlayLocked", "getFrameProperties", "getDialogProperties", "getOverlayProperties", @@ -127,6 +125,11 @@ public Object childEvaluate( String name = parameters.get(0).toString(); return isOverlayVisible(name) ? BigDecimal.ONE : BigDecimal.ZERO; } + if (functionName.equalsIgnoreCase("isOverlayLocked")) { + FunctionUtil.checkNumberParam(functionName, parameters, 1, 1); + String name = parameters.get(0).toString(); + return isOverlayLocked(name) ? BigDecimal.ONE : BigDecimal.ZERO; + } if (functionName.equalsIgnoreCase("resetFrame")) { FunctionUtil.checkNumberParam(functionName, parameters, 1, 1); HTMLFrame.center(parameters.get(0).toString()); @@ -272,6 +275,14 @@ private boolean isOverlayVisible(String name) { return false; } + private boolean isOverlayLocked(String name) { + HTMLOverlayManager overlay = MapTool.getFrame().getOverlayPanel().getOverlay(name); + if (overlay != null) { + return overlay.getLocked(); + } + return false; + } + /** * Verify the function and thisarg identifier, then run the script. * diff --git a/src/main/java/net/rptools/maptool/client/ui/AppMenuBar.java b/src/main/java/net/rptools/maptool/client/ui/AppMenuBar.java index 27f457b2ff..6d12c7dd76 100644 --- a/src/main/java/net/rptools/maptool/client/ui/AppMenuBar.java +++ b/src/main/java/net/rptools/maptool/client/ui/AppMenuBar.java @@ -432,7 +432,11 @@ public static void addToOverlayMenu(HTMLOverlayManager overlayManager) { JCheckBoxMenuItem menuItem = new RPCheckBoxMenuItem(new AppActions.ToggleOverlayAction(overlayManager), overlayMenu); menuItem.setText(overlayManager.getName()); - overlayMenu.add(menuItem); + if (overlayManager.getLocked()) { + overlayMenu.add(menuItem).setEnabled(false); + } else { + overlayMenu.add(menuItem); + } overlayMenu.setEnabled(true); overlayItems.put(overlayManager.getName(), menuItem); } diff --git a/src/main/java/net/rptools/maptool/client/ui/htmlframe/HTMLFrameFactory.java b/src/main/java/net/rptools/maptool/client/ui/htmlframe/HTMLFrameFactory.java index 118a32ddc2..4c15554e04 100644 --- a/src/main/java/net/rptools/maptool/client/ui/htmlframe/HTMLFrameFactory.java +++ b/src/main/java/net/rptools/maptool/client/ui/htmlframe/HTMLFrameFactory.java @@ -59,6 +59,7 @@ public static void show( int width = -1; int height = -1; int zOrder = 0; + boolean locked = false; String title = name; String tabTitle = null; Object frameValue = null; @@ -114,6 +115,15 @@ public static void show( String msg = I18N.getText("macro.function.general.argumentKeyTypeI", funcName, keyLC); throw new ParserException(msg); } + } else if (keyLC.equals("locked")) { + try { + int v = Integer.parseInt(value); + if (v != 0) { + locked = true; + } + } catch (NumberFormatException e) { + // Ignoring the value; shouldn't we warn the user? + } } else if (keyLC.equals("title")) { title = value; } else if (keyLC.equals("noframe")) { @@ -165,7 +175,7 @@ public static void show( frameValue, html); } else if (frameType == FrameType.OVERLAY) { - MapTool.getFrame().getOverlayPanel().showOverlay(name, zOrder, html, frameValue); + MapTool.getFrame().getOverlayPanel().showOverlay(name, zOrder, locked, html, frameValue); } } diff --git a/src/main/java/net/rptools/maptool/client/ui/htmlframe/HTMLOverlayManager.java b/src/main/java/net/rptools/maptool/client/ui/htmlframe/HTMLOverlayManager.java index c1b0f3e020..c6ef6a6ff0 100644 --- a/src/main/java/net/rptools/maptool/client/ui/htmlframe/HTMLOverlayManager.java +++ b/src/main/java/net/rptools/maptool/client/ui/htmlframe/HTMLOverlayManager.java @@ -73,6 +73,8 @@ public class HTMLOverlayManager extends HTMLWebViewManager implements HTMLPanelC /** The ZOrder of the overlay. */ private int zOrder; + private boolean locked; + /** The name of the overlay. */ private final String name; @@ -82,11 +84,12 @@ public class HTMLOverlayManager extends HTMLWebViewManager implements HTMLPanelC /** The map of the macro callbacks. */ private final Map macroCallbacks = new HashMap<>(); - HTMLOverlayManager(String name, int zOrder) { + HTMLOverlayManager(String name, int zOrder, boolean locked) { super("overlay", name); addActionListener(this); // add the action listeners for form events this.name = name; this.zOrder = zOrder; + this.locked = locked; } @Override @@ -101,6 +104,10 @@ public int getZOrder() { return zOrder; } + public boolean getLocked() { + return locked; + } + /** * Sets the zOrder of the overlay. * @@ -246,7 +253,8 @@ public Component add(Component component) { public void remove(Component component) {} /** - * Returns a JsonObject with the properties of the overlay. Includes name, zorder, and visible. + * Returns a JsonObject with the properties of the overlay. Includes name, zorder, locked, and + * visible. * * @return the properties */ @@ -254,6 +262,7 @@ public JsonObject getProperties() { JsonObject jobj = new JsonObject(); jobj.addProperty("name", getName()); jobj.addProperty("zorder", getZOrder()); + jobj.addProperty("locked", getLocked() ? BigDecimal.ONE : BigDecimal.ZERO); jobj.addProperty("visible", isVisible() ? BigDecimal.ONE : BigDecimal.ZERO); return jobj; } diff --git a/src/main/java/net/rptools/maptool/client/ui/htmlframe/HTMLOverlayPanel.java b/src/main/java/net/rptools/maptool/client/ui/htmlframe/HTMLOverlayPanel.java index 27ee49a384..a41a16e79e 100644 --- a/src/main/java/net/rptools/maptool/client/ui/htmlframe/HTMLOverlayPanel.java +++ b/src/main/java/net/rptools/maptool/client/ui/htmlframe/HTMLOverlayPanel.java @@ -238,9 +238,10 @@ public void removeAllOverlays() { * * @param name the name of the overlay * @param zOrder the zOrder of the overlay + * @param locked the locked state of the overlay * @param html the HTML of the overlay */ - public void showOverlay(String name, int zOrder, String html, Object frameValue) { + public void showOverlay(String name, int zOrder, boolean locked, String html, Object frameValue) { getDropTarget().setActive(false); // disables drop on overlay, drop goes to map setVisible(true); Platform.runLater( @@ -258,7 +259,7 @@ public void showOverlay(String name, int zOrder, String html, Object frameValue) overlays.add(overlayManager); } } else { - overlayManager = new HTMLOverlayManager(name, zOrder); + overlayManager = new HTMLOverlayManager(name, zOrder, locked); overlayManager.setupWebView(new WebView()); overlays.add(overlayManager); root.getChildren().add(overlayManager.getWebView()); diff --git a/src/main/java/net/rptools/maptool/client/ui/sheet/stats/StatSheet.java b/src/main/java/net/rptools/maptool/client/ui/sheet/stats/StatSheet.java index 15277fce7d..32b9f67bc0 100644 --- a/src/main/java/net/rptools/maptool/client/ui/sheet/stats/StatSheet.java +++ b/src/main/java/net/rptools/maptool/client/ui/sheet/stats/StatSheet.java @@ -60,6 +60,7 @@ public void setContent(Token token, String content, URL entry, StatSheetLocation .showOverlay( AppConstants.INTERNAL_MAP_UNDER_POINTER_HTML_OVERLAY_NAME, Integer.MAX_VALUE, + Boolean.TRUE, output, null); }