Skip to content

Commit

Permalink
Fonts for CounterDetailViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Brent committed Sep 14, 2023
1 parent 71d6bd3 commit 3167225
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class FontOrganizer extends AbstractConfigurable {
public static final String VASSAL_MONOSPACED_FONT = "VassalMono";
public static final String VASSAL_CONDENSED_FONT = "VassalCondensed";
public static final String VASSAL_EDITOR_FONT = "VassalEditor";
public static final String VASSAL_DEFAULT_FONT = VASSAL_SERIF_FONT; // Improvement on good old Dialog

public static final String FONTS = "Fonts";
public static final String FONTS_FOLDER = "fonts"; // Folder in Vengine containing font files
Expand Down
11 changes: 0 additions & 11 deletions vassal-app/src/main/java/VASSAL/build/module/font/VassalFont.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,6 @@ private VassalFont(String fontFamily, String fontName, String fontFile, boolean
this.registered = false;
}

// /** Create an Empty Font for use by the Root Node of a Font tree */
// public VassalFont() {
// this(null, null, null, false);
// }
//
// /** Create a Dummy Font for use by a non-leaf nodes of a Font tree */
// public VassalFont(String fontFamily, String fontName) {
// this(fontFamily, fontName, null, false);
// }


public String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import VASSAL.build.module.Map;
import VASSAL.build.module.PlayerHand;
import VASSAL.build.module.documentation.HelpFile;
import VASSAL.build.module.font.FontOrganizer;
import VASSAL.build.module.map.boardPicker.Board;
import VASSAL.build.module.map.boardPicker.board.mapgrid.Zone;
import VASSAL.build.module.properties.SumProperties;
Expand All @@ -42,6 +43,7 @@
import VASSAL.configure.PropertyExpression;
import VASSAL.configure.StringArrayConfigurer;
import VASSAL.configure.StringEnum;
import VASSAL.configure.StructuredFontConfigurer;
import VASSAL.configure.TranslatableStringEnum;
import VASSAL.configure.VisibilityCondition;
import VASSAL.counters.BasicPiece;
Expand Down Expand Up @@ -101,7 +103,7 @@
*/
public class CounterDetailViewer extends AbstractConfigurable implements Drawable, DragSourceMotionListener, MouseMotionListener, MouseListener, KeyListener {

public static final String LATEST_VERSION = "4"; //NON-NLS
public static final String LATEST_VERSION = "5"; //NON-NLS
public static final String USE_KEYBOARD = "ShowCounterDetails"; //NON-NLS
public static final String PREFERRED_DELAY = "PreferredDelay"; //NON-NLS

Expand Down Expand Up @@ -150,6 +152,7 @@ public class CounterDetailViewer extends AbstractConfigurable implements Drawabl
public static final String BG_COLOR = "bgColor"; //NON-NLS
public static final String BORDER_COLOR = "borderColor"; //NON-NLS
public static final String FONT_SIZE = "fontSize"; //NON-NLS
public static final String FONT = "font";
public static final String EXTRA_TEXT_PADDING = "extraTextPadding"; //NON-NLS
public static final String PROPERTY_FILTER = "propertyFilter"; //NON-NLS
public static final String STOP_AFTER_SHOWING = "stopAfterShowing"; //NON-NLS
Expand Down Expand Up @@ -237,7 +240,7 @@ public class CounterDetailViewer extends AbstractConfigurable implements Drawabl
protected Color bgColor;
protected Color borderColor = Color.black;
protected int fontSize = 9;
protected Font font = new Font("Dialog", Font.PLAIN, fontSize); //NON-NLS
protected Font font = new Font(FontOrganizer.VASSAL_DEFAULT_FONT, Font.PLAIN, fontSize); //NON-NLS
protected PropertyExpression propertyFilter = new PropertyExpression();

protected Rectangle bounds = new Rectangle();
Expand Down Expand Up @@ -270,6 +273,10 @@ public CounterDetailViewer() {
delayTimer.setRepeats(false);
}

private boolean isPreVersion5() {
return List.of("1", "2", "3", "4").contains(version);
}

/**
* @return This CounterDetailViewer's parent map
*/
Expand Down Expand Up @@ -1344,6 +1351,8 @@ else if (drawSingleDeprecated) {
borderColor = fgColor;
}

// No migration for version 4 to 5, font is already set

version = LATEST_VERSION;
}

Expand Down Expand Up @@ -1380,6 +1389,7 @@ public String[] getAttributeNames() {
VERTICAL_BOTTOM_TEXT,
SHOW_TEXT_SINGLE_DEPRECATED,
FONT_SIZE,
FONT,
SUMMARY_REPORT_FORMAT,
COUNTER_REPORT_FORMAT,
EMPTY_HEX_REPORT_FORMAT,
Expand Down Expand Up @@ -1438,6 +1448,7 @@ public String[] getAttributeDescriptions() {
Resources.getString("Editor.MouseOverStackViewer.vertical_bottom_text"), //$NON-NLS-1$
Resources.getString("Editor.MouseOverStackViewer.display_text_obsolete"), //$NON-NLS-1$ Obsolete
Resources.getString("Editor.font_size"), //$NON-NLS-1$
Resources.getString("Editor.TextLabel.label_font"), //$NON-NLS-1$
Resources.getString("Editor.MouseOverStackViewer.summary_text"), //$NON-NLS-1$
Resources.getString("Editor.MouseOverStackViewer.text_below"), //$NON-NLS-1$
Resources.getString("Editor.MouseOverStackViewer.text_empty"), //$NON-NLS-1$
Expand Down Expand Up @@ -1497,6 +1508,7 @@ public Class<?>[] getAttributeTypes() {
Integer.class,
Boolean.class,
Integer.class,
FontConfig.class,
ReportFormatConfig.class,
CounterFormatConfig.class,
EmptyFormatConfig.class,
Expand Down Expand Up @@ -1591,6 +1603,17 @@ public Configurer getConfigurer(AutoConfigurable c, String key, String name) {
}
}

public static class FontConfig implements ConfigurerFactory {
@Override
public Configurer getConfigurer(AutoConfigurable c, String key, String name) {
final StructuredFontConfigurer config = new StructuredFontConfigurer(key, name);
config.setPlainOnly(false);
config.setModuleSpecific(true);
config.setLimitedSizes(false);
return config;
}
}

@Override
public Class<?>[] getAllowableConfigureComponents() {
return new Class<?>[0];
Expand Down Expand Up @@ -1913,9 +1936,18 @@ else if (FONT_SIZE.equals(name)) {
value = Integer.valueOf((String) value);
}
if (value != null) {
fontSize = (Integer) value;
font = font.deriveFont((float) fontSize);
if (isPreVersion5()) {
fontSize = (Integer) value;
font = font.deriveFont((float) fontSize);
}
}
}
else if (FONT.equals(name)) {
if (value instanceof String) {
value = StructuredFontConfigurer.decode((String) value);
}
font = (Font) value;
fontSize = font.getSize();
}
else if (PROPERTY_FILTER.equals(name)) {
propertyFilter.setExpression((String) value);
Expand Down Expand Up @@ -2100,6 +2132,9 @@ else if (BORDER_COLOR.equals(name)) {
else if (FONT_SIZE.equals(name)) {
return String.valueOf(fontSize);
}
else if (FONT.equals(name)) {
return StructuredFontConfigurer.encode(font);
}
else if (PROPERTY_FILTER.equals(name)) {
return propertyFilter.getExpression();
}
Expand Down Expand Up @@ -2142,7 +2177,10 @@ public VisibilityCondition getAttributeVisibility(String name) {
if (List.of(CENTER_PIECES_VERTICALLY, BORDER_WIDTH, DRAW_PIECES_AT_ZOOM, VERTICAL_OFFSET).contains(name)) {
return () -> drawPieces;
}
else if (List.of(FONT_SIZE, SUMMARY_REPORT_FORMAT, COUNTER_REPORT_FORMAT, ENABLE_HTML, CENTER_TEXT, EXTRA_TEXT_PADDING, VERTICAL_TOP_TEXT, VERTICAL_BOTTOM_TEXT, STRETCH_WIDTH_SUMMARY).contains(name)) {
else if (FONT_SIZE.equals(name)) {
return () -> showText && isPreVersion5();
}
else if (List.of(FONT, SUMMARY_REPORT_FORMAT, COUNTER_REPORT_FORMAT, ENABLE_HTML, CENTER_TEXT, EXTRA_TEXT_PADDING, VERTICAL_TOP_TEXT, VERTICAL_BOTTOM_TEXT, STRETCH_WIDTH_SUMMARY).contains(name)) {
return () -> showText;
}
else if (STRETCH_WIDTH_PIECES.equals(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ public void setLimitedSizes(boolean limitedSizes) {
this.limitedSizes = limitedSizes;
}

public void setSizeEditable(boolean editable) {
fontSizeConfig.setEditable(editable);
}

@Override
public void setValue(String s) {
setValue(decode(s));
Expand Down

0 comments on commit 3167225

Please sign in to comment.