Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement the add-on dialog so that it follows the selected MT theme. #4157

Merged
merged 8 commits into from
Jun 24, 2023
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ tasks.register('deleteUiClasses') {
delete("${buildDir}/classes/java/main/net/rptools/maptool/client/ui/preferencesdialog/PreferencesDialogView.class")
delete("${buildDir}/classes/java/main/net/rptools/maptool/client/ui/startserverdialog/StartServerDialogView.class")
delete("${buildDir}/classes/java/main/net/rptools/maptool/client/ui/token/dialog/create/NewTokenDialogView.class")
delete("${buildDir}/classes/java/main/net/rptools/maptool/client/ui/token/dialog/edit/TokenPropertiesDialog..class")
delete("${buildDir}/classes/java/main/net/rptools/maptool/client/ui/token/dialog/edit/TokenPropertiesDialog.class")
delete("${buildDir}/classes/java/main/net/rptools/maptool/client/ui/transferprogressdialog/TransferProgressDialogView.class")
delete("${buildDir}/classes/java/main/net/rptools/maptool/client/ui/addon/AddOnLibrariesDialogView.class")
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/net/rptools/maptool/client/AppActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@
import javax.swing.text.BadLocationException;
import net.rptools.lib.FileUtil;
import net.rptools.lib.MD5Key;
import net.rptools.maptool.client.swing.SwingUtil;
import net.rptools.maptool.client.tool.boardtool.BoardTool;
import net.rptools.maptool.client.tool.gridtool.GridTool;
import net.rptools.maptool.client.ui.*;
import net.rptools.maptool.client.ui.MapToolFrame.MTFrame;
import net.rptools.maptool.client.ui.addon.AddOnLibrariesDialog;
import net.rptools.maptool.client.ui.addon.AddOnLibrariesDialogView;
import net.rptools.maptool.client.ui.addresource.AddResourceDialog;
import net.rptools.maptool.client.ui.assetpanel.AssetPanel;
import net.rptools.maptool.client.ui.assetpanel.Directory;
Expand Down Expand Up @@ -3211,7 +3212,10 @@ public boolean isAvailable() {

@Override
protected void executeAction() {
new AddOnLibrariesDialog().show();
var dialog = new AddOnLibrariesDialogView();
dialog.pack();
SwingUtil.centerOver(dialog, MapTool.getFrame());
dialog.setVisible(true);
}
};

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/rptools/maptool/client/AppConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,11 @@ public class AppConstants {
*/
public static final String INTERNAL_MAP_UNDER_POINTER_HTML_OVERLAY_NAME =
INTERNAL_FRAME_PREFIX + "Internal Map Under Pointer Overlay";

/** CSS used for MT Theme support */
public static final String MT_THEME_CSS = "lib://net.rptools.maptool/css/mt-theme.css";

/** CSS used for MT Stat Sheet Theme support */
public static final String MT_THEME_STAT_SHEET_CSS =
"lib://net.rptools.maptool/css/mt-stat-sheet.css";
}
8 changes: 7 additions & 1 deletion src/main/java/net/rptools/maptool/client/MapTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,16 @@ public static BackupManager getBackupManager() {
*/
public static void showDocument(String url) {
if (Desktop.isDesktopSupported()) {
String lowerCaseUrl = url.toLowerCase();
String urlToBrowse = url;
Desktop desktop = Desktop.getDesktop();
URI uri = null;
try {
uri = new URI(url);
uri = new URI(urlToBrowse);
if (uri.getScheme() == null) {
urlToBrowse = "https://" + urlToBrowse;
}
uri = new URI(urlToBrowse);
desktop.browse(uri);
} catch (Exception e) {
MapTool.showError(I18N.getText("msg.error.browser.cannotStart", uri), e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This software Copyright by the RPTools.net development team, and
* licensed under the Affero GPL Version 3 or, at your option, any later
* version.
*
* MapTool Source Code is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public
* License * along with this source Code. If not, please visit
* <http://www.gnu.org/licenses/> and specifically the Affero license
* text at <http://www.gnu.org/licenses/agpl.html>.
*/
package net.rptools.maptool.client.ui;

import com.formdev.flatlaf.FlatIconColors;
import java.awt.Cursor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JLabel;
import javax.swing.UIManager;
import net.rptools.maptool.client.MapTool;

/**
* This class is a MouseAdapter that will open a browser to the URL specified in the JLabel's text
*/
public class JLabelHyperLinkListener extends MouseAdapter {
/** The JLabel that this listener is attached to */
private final JLabel linkLabel;

/**
* Constructor that takes the JLabel that this listener is attached to as a parameter
*
* @param jlabel The JLabel that this listener is attached to
*/
public JLabelHyperLinkListener(JLabel jlabel) {
linkLabel = jlabel;
linkLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
linkLabel.setForeground(UIManager.getColor(FlatIconColors.ACTIONS_BLUE_DARK.key));
}

@Override
public void mouseClicked(MouseEvent e) {
MapTool.showDocument(linkLabel.getText());
}
}
37 changes: 29 additions & 8 deletions src/main/java/net/rptools/maptool/client/ui/ViewAssetDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebView;
import javax.swing.JDialog;
import net.rptools.maptool.client.AppConstants;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.client.swing.SwingUtil;
import net.rptools.maptool.model.Asset;
Expand Down Expand Up @@ -140,7 +140,29 @@ private void htmlDialog(String html) {
var scene = new Scene(pane, width, height);
jfxPanel.setScene(scene);
var webView = new WebView();
webView.getEngine().loadContent(html);
var webEngine = webView.getEngine();
webEngine
.getLoadWorker()
.stateProperty()
.addListener(
(obs, oldState, newState) -> {
if (newState == javafx.concurrent.Worker.State.SUCCEEDED) {
var doc = webEngine.getDocument();
var cssNode = doc.createElement("link");
cssNode.setAttribute("rel", "stylesheet");
cssNode.setAttribute("href", AppConstants.MT_THEME_CSS);
var head = doc.getDocumentElement().getElementsByTagName("head").item(0);
var first = head.getFirstChild();
if (first != null) {
head.insertBefore(cssNode, first);
} else {
head.appendChild(cssNode);
}
System.out.println(
webEngine.executeScript("document.documentElement.innerHTML"));
}
});
webEngine.loadContent(html);
pane.getChildren().add(webView);
});
}
Expand All @@ -153,12 +175,11 @@ private void htmlDialog(String html) {
private void textDialog(Asset asset) {
Platform.runLater(
() -> {
var pane = new StackPane();
var scene = new Scene(pane, width, height);
jfxPanel.setScene(scene);
var textArea = new TextArea(asset.getDataAsString());
textArea.setEditable(false);
pane.getChildren().add(textArea);
String html =
"<!DOCTYPE html><html><head></head><body><pre>"
+ asset.getDataAsString()
+ "</pre></body></html>";
htmlDialog(html);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
import net.rptools.maptool.client.ui.javfx.SimpleSwingJavaFXDialog;
import net.rptools.maptool.client.ui.javfx.SwingJavaFXDialog;

public class AddOnLibrariesDialog {
public class AddOnLibrariesDialogOld {
/** The path of the FXML file for the dialog. */
private static final String FXML_PATH =
"/net/rptools/maptool/client/ui/fxml/AddOnLibrariesDialog.fxml";
/** The {@link SwingJavaFXDialog} used to display the dialog. */
private final SimpleSwingJavaFXDialog simpleSwingJavaFXDialog;

public AddOnLibrariesDialog() {
public AddOnLibrariesDialogOld() {
simpleSwingJavaFXDialog =
new SimpleSwingJavaFXDialog<AddOnLibrariesDialogController>(
FXML_PATH, "library.dialog.title");
Expand Down
Loading