Skip to content

Commit

Permalink
Merge pull request #5051 from Jmr3366/j_develop_oLock
Browse files Browse the repository at this point in the history
#3414 Feature to lock an overlay
  • Loading branch information
cwisniew authored Nov 19, 2024
2 parents 58e0ed7 + c059853 commit 5a083a5
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,6 +54,7 @@ private MacroDialogFunctions() {
"closeOverlay",
"setOverlayVisible",
"isOverlayVisible",
"isOverlayLocked",
"getFrameProperties",
"getDialogProperties",
"getOverlayProperties",
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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.
*
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/net/rptools/maptool/client/ui/AppMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -82,11 +84,12 @@ public class HTMLOverlayManager extends HTMLWebViewManager implements HTMLPanelC
/** The map of the macro callbacks. */
private final Map<String, String> 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
Expand All @@ -101,6 +104,10 @@ public int getZOrder() {
return zOrder;
}

public boolean getLocked() {
return locked;
}

/**
* Sets the zOrder of the overlay.
*
Expand Down Expand Up @@ -246,14 +253,16 @@ 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
*/
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 5a083a5

Please sign in to comment.