Skip to content

Commit

Permalink
Merge branch 'develop' into feature-handlbars-helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
cwisniew authored Jul 1, 2023
2 parents f1833e3 + 00f8dee commit e61c4ba
Show file tree
Hide file tree
Showing 25 changed files with 550 additions and 99 deletions.
3 changes: 3 additions & 0 deletions src/main/java/net/rptools/maptool/client/AppConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,7 @@ public class AppConstants {
/** 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";

/** Namespace for built in add-ons. This is used to determine if an add-on is built in or not. */
public static final String MT_BUILTIN_ADD_ON_NAMESPACE = "net.rptools.maptool";
}
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ public void mouseMoved(MouseEvent e) {
SwingUtil.isControlDown(keysDown)));
}
} else if (tokenUnderMouse != oldTokenUnderMouse) {
statSheet = null;
if (oldTokenUnderMouse != null) {
new MapToolEventBus()
.getMainEventBus()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,49 @@
</splitpane>
</children>
</grid>
<grid id="78150" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="78150" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title-resource-bundle="net/rptools/maptool/language/i18n" title-key="library.dialog.development.label"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
<children>
<hspacer id="28b4a">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<vspacer id="61f72">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="fde58" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="net/rptools/maptool/language/i18n" key="library.dialog.copy.title"/>
</properties>
</component>
<component id="456e5" class="javax.swing.JButton" binding="copyThemeCSS">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="net/rptools/maptool/language/i18n" key="library.dialog.copyMTThemeCSS"/>
</properties>
</component>
<component id="35630" class="javax.swing.JButton" binding="copyStatSheetThemeButton" default-binding="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="net/rptools/maptool/language/i18n" key="library.dialog.copyMTStatSheetTheme"/>
</properties>
</component>
</children>
</grid>
</children>
</tabbedpane>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
*/
package net.rptools.maptool.client.ui.addon;

import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import javax.swing.JButton;
Expand All @@ -34,6 +37,7 @@
import javax.swing.JTextPane;
import javax.swing.KeyStroke;
import net.rptools.maptool.client.AppActions.MapPreviewFileChooser;
import net.rptools.maptool.client.AppConstants;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.client.ui.JLabelHyperLinkListener;
import net.rptools.maptool.client.ui.ViewAssetDialog;
Expand Down Expand Up @@ -63,6 +67,8 @@ public class AddOnLibrariesDialogView extends JDialog {
private JLabel addOnLicenseLabel;
private JButton viewReadMeFileButton;
private JButton viewLicenseFileButton;
private JButton copyThemeCSS;
private JButton copyStatSheetThemeButton;

private LibraryInfo selectedAddOn;

Expand Down Expand Up @@ -161,6 +167,44 @@ public void actionPerformed(ActionEvent e) {
buttonRemove.setEnabled(false);
}
});

copyThemeCSS.addActionListener(
e -> {
new LibraryManager()
.getLibrary(AppConstants.MT_BUILTIN_ADD_ON_NAMESPACE)
.ifPresent(
library -> {
URI uri = URI.create(AppConstants.MT_THEME_CSS);
String themeCss = null;
try {
themeCss = library.readAsString(uri.toURL()).get();
} catch (InterruptedException | ExecutionException | IOException ex) {
throw new RuntimeException(ex);
}
Toolkit.getDefaultToolkit()
.getSystemClipboard()
.setContents(new StringSelection(themeCss), null);
});
});

copyStatSheetThemeButton.addActionListener(
e -> {
new LibraryManager()
.getLibrary(AppConstants.MT_BUILTIN_ADD_ON_NAMESPACE)
.ifPresent(
library -> {
URI uri = URI.create(AppConstants.MT_THEME_STAT_SHEET_CSS);
String themeCss = null;
try {
themeCss = library.readAsString(uri.toURL()).get();
} catch (InterruptedException | ExecutionException | IOException ex) {
throw new RuntimeException(ex);
}
Toolkit.getDefaultToolkit()
.getSystemClipboard()
.setContents(new StringSelection(themeCss), null);
});
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public class AddOnLibraryImporter {
/** The name of the file with the stat sheets. */
public static final String STATS_SHEET_FILE = "stat_sheets.json";

/** The directory where metadata from the root dir of the zip directory is copied to. */
public static final String METADATA_DIR = "metadata/";

/**
* Returns the {@link FileFilter} for add on library files.
*
Expand Down Expand Up @@ -176,6 +179,9 @@ public AddOnLibrary importFromFile(File file) throws IOException {
.merge(new InputStreamReader(zip.getInputStream(statSheetEntry)), statSheetsBuilder);
}

// Copy Metadata
addMetaData(builder.getNamespace(), zip, pathAssetMap);

var addOnLib = builder.build();
byte[] data = Files.readAllBytes(file.toPath());
var asset = Type.MTLIB.getFactory().apply(addOnLib.getNamespace(), data);
Expand All @@ -191,6 +197,23 @@ public AddOnLibrary importFromFile(File file) throws IOException {
}
}

private void addMetaData(
String namespace, ZipFile zip, Map<String, Pair<MD5Key, Type>> pathAssetMap)
throws IOException {
var entries = zip.stream().filter(e -> !e.getName().contains("/")).toList();
for (var entry : entries) {
String path = METADATA_DIR + entry.getName();
try (InputStream inputStream = zip.getInputStream(entry)) {
byte[] bytes = inputStream.readAllBytes();
MediaType mediaType = Asset.getMediaType(entry.getName(), bytes);
Asset asset =
Type.fromMediaType(mediaType).getFactory().apply(namespace + "/" + path, bytes);
addAsset(asset);
pathAssetMap.put(path, Pair.with(asset.getMD5Key(), asset.getType()));
}
}
}

/**
* Reads the assets from the add-on library and adds them to the asset manager.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import net.rptools.maptool.client.AppConstants;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.client.MapToolMacroContext;
import net.rptools.maptool.language.I18N;
Expand Down Expand Up @@ -71,31 +72,31 @@ private String processHandlebarsTemplate(ResourceDetails rd) {
}
}

private final Map<String, String> cache = new ConcurrentHashMap<>();
private static final Map<String, String> cache = new ConcurrentHashMap<>();

private final String name = "MapTool Built-In Library";
private final String namespace = "net.rptools.maptool";
private final String version = "1.0.0";
private static final String name = "MapTool Built-In Library";
private static final String namespace = AppConstants.MT_BUILTIN_ADD_ON_NAMESPACE;
private static final String version = "1.0.0";

private final String website = "https://www.rptools.net";
private static final String website = "https://www.rptools.net";

private final String gitUrl = "https://github.com/RPTools/maptool";
private static final String gitUrl = "https://github.com/RPTools/maptool";

private final String[] authors = new String[] {"RPTools Team"};
private static final String[] authors = new String[] {"RPTools Team"};

private final String license = "AGPLv3";
private static final String license = "AGPLv3";

private final String description = "MapTool Built-In Library";
private static final String description = "MapTool Built-In Library";

private final String shortDescription = "MapTool Built-In Library";
private static final String shortDescription = "MapTool Built-In Library";

private final boolean allowsUriAccess = true;
private static final boolean allowsUriAccess = true;

private final String readMeFile = "";
private static final String readMeFile = "";

private final String licenseFile = "";
private static final String licenseFile = "";

private final String[] tags = new String[] {};
private static final String[] tags = new String[] {};

@Override
public CompletableFuture<String> getVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class ThemeCssContext {
/** The theme color CSS context. */
private final ColorCssContext themeColor;

private final ThemeHeader themeHeader;

/** Creates a new instance of the theme CSS context. */
public ThemeCssContext() {
var uiDef = UIManager.getDefaults();
Expand All @@ -56,6 +58,7 @@ public ThemeCssContext() {
button = new ButtonCssContext(uiDef);
textInput = new TextInputCssContext(uiDef);
themeColor = new ColorCssContext(uiDef);
themeHeader = new ThemeHeader(uiDef);
}

/**
Expand Down Expand Up @@ -141,4 +144,13 @@ public ColorCssContext getThemeColor() {
public String getForegroundColorDisabled() {
return foregroundColorDisabled;
}

/**
* Gets the theme header CSS context.
*
* @return The theme header CSS context.
*/
public ThemeHeader getThemeHeader() {
return themeHeader;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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.model.library.builtin.themecss;

import javax.swing.JLabel;
import javax.swing.UIDefaults;

public class ThemeHeader {

public static class Header {
private final String fontFamily;
private final String fontSize;

public Header(String fontFamily, String fontSize) {
this.fontFamily = fontFamily;
this.fontSize = fontSize;
}

public String getFontFamily() {
return fontFamily;
}

public String getFontSize() {
return fontSize;
}
}

private final Header h1;
private final Header h2;

private final Header h3;

private final Header h4;

private final Header h5;

private final Header h6;

public ThemeHeader(UIDefaults uiDef) {
JLabel h1Label = new JLabel();
h1Label.putClientProperty("FlatLaf.styleClass", "h1");
h1 = new Header(h1Label.getFont().getFamily(), h1Label.getFont().getSize() + "px");

JLabel h2Label = new JLabel();
h2Label.putClientProperty("FlatLaf.styleClass", "h2");
h2 = new Header(h2Label.getFont().getFamily(), h2Label.getFont().getSize() + "px");

JLabel h3Label = new JLabel();
h3Label.putClientProperty("FlatLaf.styleClass", "h3");
h3 = new Header(h3Label.getFont().getFamily(), h3Label.getFont().getSize() + "px");

JLabel h4Label = new JLabel();
h4Label.putClientProperty("FlatLaf.styleClass", "h4");
h4 = new Header(h4Label.getFont().getFamily(), h4Label.getFont().getSize() + "px");

JLabel h5Label = new JLabel();
h5Label.putClientProperty("FlatLaf.styleClass", "h5");
h5 = new Header(h5Label.getFont().getFamily(), h5Label.getFont().getSize() + "px");

JLabel h6Label = new JLabel();
h6Label.putClientProperty("FlatLaf.styleClass", "h6");
h6 = new Header(h6Label.getFont().getFamily(), h6Label.getFont().getSize() + "px");
}

public Header getH1() {
return h1;
}

public Header getH2() {
return h2;
}

public Header getH3() {
return h3;
}

public Header getH4() {
return h4;
}

public Header getH5() {
return h5;
}

public Header getH6() {
return h6;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2757,7 +2757,11 @@ library.dialog.table.remove = Remove Library
library.dialog.table.removeData = Remove Library and Data
library.dialog.delete.confirm = Are you sure you want to remove add-on library {0}?
library.dialog.deleteData.confirm = Are you sure you want to remove add-on library {0} and all its data?

library.dialog.copy.title = <html>The copied CSS is for testing \
purposes only.<br/>Within your add-on use<br/>lib://net.rptools.maptool/css/mt-stat-sheet.css \
or<br/> lib://net.rptools.maptool/css/mt-theme.css</html>
library.dialog.copyMTThemeCSS = Copy CSS Theme to clipbaord
library.dialog.copyMTStatSheetTheme = Copy Stat Sheet Theme to clipbaord

# Game Data
data.error.cantConvertTo = Can''t convert {0} to {1}.
Expand Down
Loading

0 comments on commit e61c4ba

Please sign in to comment.