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

Add token note types #3879

Merged
merged 9 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public void setText(String text) {
gui.setText(text);
}

public String getTextType() {
return gui.getTextStyle();
}

public void setTextType(String type) {
gui.setTextStyle(type);
}

public String getSelectedText() {
return gui.getSelectedText();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.rptools.maptool.client.swing.htmleditorsplit.HtmlEditorSplitGui">
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
Expand All @@ -10,7 +10,7 @@
<children>
<tabbedpane id="297f1" binding="tabPanel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="200" height="200"/>
</grid>
</constraints>
Expand All @@ -20,24 +20,6 @@
</properties>
<border type="none"/>
<children>
<grid id="d2e47" binding="htmlTab" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="2" left="2" bottom="6" right="2"/>
<constraints>
<tabbedpane title-resource-bundle="net/rptools/maptool/language/i18n" title-key="EditTokenDialog.tab.hero.html"/>
</constraints>
<properties>
<name value=""/>
</properties>
<border type="none"/>
<children>
<component id="fe9a4" class="javafx.embed.swing.JFXPanel" binding="jfxPanel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
<grid id="2ed87" binding="textTab" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="4" right="0"/>
<constraints>
Expand All @@ -60,9 +42,9 @@
<scrollpane id="be0cb" class="org.fife.ui.rtextarea.RTextScrollPane" binding="textScrollPane">
<constraints border-constraint="Center"/>
<properties>
<foldIndicatorEnabled value="true"/>
<iconRowHeaderEnabled value="true"/>
<lineNumbersEnabled value="true"/>
<foldIndicatorEnabled value="false"/>
<iconRowHeaderEnabled value="false"/>
<lineNumbersEnabled value="false"/>
</properties>
<border type="none"/>
<children>
Expand All @@ -85,8 +67,47 @@
</grid>
</children>
</grid>
<grid id="d2e47" binding="htmlTab" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="2" left="2" bottom="6" right="2"/>
<constraints>
<tabbedpane title-resource-bundle="net/rptools/maptool/language/i18n" title-key="EditTokenDialog.tab.hero.html"/>
</constraints>
<properties>
<name value=""/>
</properties>
<border type="none"/>
<children>
<component id="fe9a4" class="javafx.embed.swing.JFXPanel" binding="jfxPanel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
</tabbedpane>
<component id="acc4b" class="javax.swing.JLabel">
<constraints>
<grid row="0" 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 value="Text type"/>
</properties>
</component>
<component id="bfcb9" class="javax.swing.JComboBox" binding="textTypeComboBox">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model/>
</properties>
</component>
<hspacer id="c4cdb">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.*;
import java.lang.reflect.Method;
import java.util.ResourceBundle;
import javafx.application.Platform;
Expand All @@ -34,13 +33,15 @@
import javax.swing.text.JTextComponent;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.language.I18N;
import net.rptools.maptool.util.StringUtil;
import org.fife.rsta.ac.LanguageSupportFactory;
import org.fife.rsta.ui.CollapsibleSectionPanel;
import org.fife.rsta.ui.search.FindToolBar;
import org.fife.rsta.ui.search.ReplaceToolBar;
import org.fife.rsta.ui.search.SearchEvent;
import org.fife.rsta.ui.search.SearchListener;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;
import org.fife.ui.rtextarea.SearchContext;
import org.fife.ui.rtextarea.SearchEngine;
Expand All @@ -57,7 +58,10 @@ public class HtmlEditorSplitGui {
private RTextScrollPane textScrollPane;
private RSyntaxTextArea sourceTextArea;
private JFXPanel jfxPanel;
private JComboBox textTypeComboBox;

/* spotless:off */

{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
Expand All @@ -74,17 +78,11 @@ public class HtmlEditorSplitGui {
*/
private void $$$setupUI$$$() {
rootPanel = new JPanel();
rootPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
rootPanel.setLayout(new GridLayoutManager(2, 3, new Insets(0, 0, 0, 0), -1, -1));
tabPanel = new JTabbedPane();
tabPanel.setName("");
tabPanel.setTabPlacement(3);
rootPanel.add(tabPanel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(200, 200), null, 0, false));
htmlTab = new JPanel();
htmlTab.setLayout(new GridLayoutManager(1, 1, new Insets(2, 2, 6, 2), -1, -1));
htmlTab.setName("");
tabPanel.addTab(this.$$$getMessageFromBundle$$$("net/rptools/maptool/language/i18n", "EditTokenDialog.tab.hero.html"), htmlTab);
jfxPanel = new JFXPanel();
htmlTab.add(jfxPanel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
rootPanel.add(tabPanel, new GridConstraints(1, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(200, 200), null, 0, false));
textTab = new JPanel();
textTab.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 4, 0), -1, -1));
textTab.setName("");
Expand All @@ -94,9 +92,9 @@ public class HtmlEditorSplitGui {
sectionPanel.setName("");
textTab.add(sectionPanel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
textScrollPane = new RTextScrollPane();
textScrollPane.setFoldIndicatorEnabled(true);
textScrollPane.setIconRowHeaderEnabled(true);
textScrollPane.setLineNumbersEnabled(true);
textScrollPane.setFoldIndicatorEnabled(false);
textScrollPane.setIconRowHeaderEnabled(false);
textScrollPane.setLineNumbersEnabled(false);
sectionPanel.add(textScrollPane, BorderLayout.CENTER);
sourceTextArea = new RSyntaxTextArea();
sourceTextArea.setCodeFoldingEnabled(true);
Expand All @@ -108,6 +106,21 @@ public class HtmlEditorSplitGui {
sourceTextArea.setSyntaxEditingStyle("text/html");
sourceTextArea.setText("");
textScrollPane.setViewportView(sourceTextArea);
htmlTab = new JPanel();
htmlTab.setLayout(new GridLayoutManager(1, 1, new Insets(2, 2, 6, 2), -1, -1));
htmlTab.setName("");
tabPanel.addTab(this.$$$getMessageFromBundle$$$("net/rptools/maptool/language/i18n", "EditTokenDialog.tab.hero.html"), htmlTab);
jfxPanel = new JFXPanel();
htmlTab.add(jfxPanel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
final JLabel label1 = new JLabel();
label1.setText("Text type");
rootPanel.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
textTypeComboBox = new JComboBox();
final DefaultComboBoxModel defaultComboBoxModel1 = new DefaultComboBoxModel();
textTypeComboBox.setModel(defaultComboBoxModel1);
rootPanel.add(textTypeComboBox, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final Spacer spacer1 = new Spacer();
rootPanel.add(spacer1, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
}

private static Method $$$cachedGetBundleMethod$$$ = null;
Expand All @@ -133,6 +146,7 @@ public class HtmlEditorSplitGui {
public JComponent $$$getRootComponent$$$() {
return rootPanel;
}

/* spotless:on */
private HTMLEditor htmlEditor;

Expand Down Expand Up @@ -182,6 +196,16 @@ public HtmlEditorSplitGui() {
textScrollPane.setFoldIndicatorEnabled(true);
textScrollPane.setLineNumbersEnabled(true);

textTypeComboBox.addItem(SyntaxConstants.SYNTAX_STYLE_NONE);
textTypeComboBox.addItem(SyntaxConstants.SYNTAX_STYLE_HTML);
textTypeComboBox.addItem(SyntaxConstants.SYNTAX_STYLE_MARKDOWN);
textTypeComboBox.addItemListener(
e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
setTextStyle((String) e.getItem());
}
});

LanguageSupportFactory.get().register(sourceTextArea);
var findToolBar = new FindToolBar(searchListener);
SearchContext context = findToolBar.getSearchContext();
Expand Down Expand Up @@ -264,13 +288,23 @@ public void keyPressed(KeyEvent e) {
e -> {
var selectedTab = tabPanel.getSelectedComponent();
if (selectedTab.equals(htmlTab)) {
Platform.runLater(() -> htmlEditor.setHtmlText(sourceTextArea.getText()));
} else {
Platform.runLater(
() -> {
if (sourceTextArea
.getSyntaxEditingStyle()
.equals(SyntaxConstants.SYNTAX_STYLE_MARKDOWN)) {
htmlEditor.setHtmlText(StringUtil.markDownToHtml(sourceTextArea.getText()));
} else {
htmlEditor.setHtmlText(sourceTextArea.getText());
}
});
} else if (!htmlEditor.isDisabled()) {
var html = htmlEditor.getHtmlText();
Document doc = Jsoup.parse(html);
sourceTextArea.setText(doc.html());
sourceTextArea.setText(doc.body().html());
}
});
setTextStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
}

public void setText(String text) {
Expand All @@ -284,13 +318,28 @@ public void setText(String text) {
});
}

public String getText() {
var selectedTab = tabPanel.getSelectedComponent();
if (selectedTab.equals(htmlTab)) {
return htmlEditor.getHtmlText();
public void setTextStyle(String style) {
if (style.equals(SyntaxConstants.SYNTAX_STYLE_HTML)) {
Platform.runLater(() -> htmlEditor.setDisable(false));
tabPanel.setEnabledAt(1, true);
} else if (style.equals(SyntaxConstants.SYNTAX_STYLE_MARKDOWN)) {
Platform.runLater(() -> htmlEditor.setDisable(true));
tabPanel.setEnabledAt(1, true);
} else {
return sourceTextArea.getText();
tabPanel.setSelectedIndex(0);
tabPanel.setEnabledAt(1, false);
}
sourceTextArea.setSyntaxEditingStyle(style);
}

public String getTextStyle() {
return sourceTextArea.getSyntaxEditingStyle();
}

public String getText() {
// first select text tab to force conversion of html
tabPanel.setSelectedComponent(textTab);
return sourceTextArea.getText();
}

public static final String SELECT_TEXT =
Expand Down
19 changes: 4 additions & 15 deletions src/main/java/net/rptools/maptool/client/tool/PointerTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -2010,16 +2010,11 @@ public void paintOverlay(Graphics2D g) {
}

private String createHoverNote(Token marker) {
var notes = marker.getNotes();
var gmNotes = marker.getGMNotes();
var notes = StringUtil.htmlize(marker.getNotes(), marker.getNotesType());
var gmNotes = StringUtil.htmlize(marker.getGMNotes(), marker.getGmNotesType());

var notesWithoutTags =
Optional.ofNullable(notes).map(s -> s.replaceAll("<[^>]*>", "")).orElse(null);
var gmNotesWithoutTags =
Optional.ofNullable(gmNotes).map(s -> s.replaceAll("<[^>]*>", "")).orElse(null);

boolean showGMNotes = MapTool.getPlayer().isGM() && !StringUtil.isEmpty(gmNotesWithoutTags);
boolean showNotes = !StringUtil.isEmpty(notesWithoutTags);
boolean showGMNotes = MapTool.getPlayer().isGM() && !StringUtil.isEmpty(gmNotes);
boolean showNotes = !StringUtil.isEmpty(notes);

StringBuilder builder = new StringBuilder();

Expand All @@ -2036,10 +2031,6 @@ private String createHoverNote(Token marker) {
builder.append("</span></b><br>");
}
if (showNotes) {
if (showGMNotes) {
notes = notes.replaceAll("</html>", "");
notes = notes.replaceAll("</body>", "");
}
builder.append(notes);
// add a gap between player and gmNotes
if (showGMNotes) {
Expand All @@ -2049,8 +2040,6 @@ private String createHoverNote(Token marker) {
if (showGMNotes) {
if (showNotes) {
builder.append("<b><span class='title'>GM Notes</span></b><br>");
gmNotes = gmNotes.replaceAll("<html[^>]*>", "");
gmNotes = gmNotes.replaceAll("<body[^>]*>", "");
}
builder.append(gmNotes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1044,13 +1044,11 @@ public class PreferencesDialogView {
String resultName;
if (fontName == null) {
resultName = currentFont.getName();
}
else {
} else {
Font testFont = new Font(fontName, Font.PLAIN, 10);
if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
resultName = fontName;
}
else {
} else {
resultName = currentFont.getName();
}
}
Expand All @@ -1071,8 +1069,7 @@ public class PreferencesDialogView {
$$$cachedGetBundleMethod$$$ = dynamicBundleClass.getMethod("getBundle", String.class, Class.class);
}
bundle = (ResourceBundle) $$$cachedGetBundleMethod$$$.invoke(null, path, thisClass);
}
catch (Exception e) {
} catch (Exception e) {
bundle = ResourceBundle.getBundle(path);
}
return bundle.getString(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ public void bind(final Token token) {

// NOTES
getGMNotesEditor().setText(token.getGMNotes());
getGMNotesEditor().setTextType(token.getGmNotesType());
getPlayerNotesEditor().setText(token.getNotes());
getPlayerNotesEditor().setTextType(token.getNotesType());

// TYPE
getTypeCombo().setSelectedItem(token.getType());
Expand Down Expand Up @@ -686,7 +688,9 @@ public boolean commit() {

// NOTES
token.setGMNotes(getGMNotesEditor().getText());
token.setGmNotesType(getGMNotesEditor().getTextType());
token.setNotes(getPlayerNotesEditor().getText());
token.setNotesType(getPlayerNotesEditor().getTextType());

// SIZE
token.setSnapToScale(getSizeCombo().getSelectedIndex() != 0);
Expand Down
Loading