1818package dev .dediamondpro .minemark ;
1919
2020import dev .dediamondpro .minemark .style .Style ;
21+ import dev .dediamondpro .minemark .utils .StyleType ;
2122
2223import java .awt .*;
24+ import java .util .HashMap ;
2325
2426/**
2527 * Class that will be given to an element at parsing time
@@ -36,8 +38,9 @@ public class LayoutStyle {
3638 private boolean partOfLink ;
3739 private boolean partOfCodeBlock ;
3840 private boolean preFormatted ;
41+ private final HashMap <StyleType <?>, Object > customStyles ;
3942
40- public LayoutStyle (Alignment alignment , float fontSize , Color textColor , boolean bold , boolean italic , boolean underlined , boolean strikethrough , boolean partOfLink , boolean partOfCodeBlock , boolean preFormatted ) {
43+ public LayoutStyle (Alignment alignment , float fontSize , Color textColor , boolean bold , boolean italic , boolean underlined , boolean strikethrough , boolean partOfLink , boolean partOfCodeBlock , boolean preFormatted , HashMap < StyleType <?>, Object > customStyles ) {
4144 this .alignment = alignment ;
4245 this .fontSize = fontSize ;
4346 this .textColor = textColor ;
@@ -48,14 +51,15 @@ public LayoutStyle(Alignment alignment, float fontSize, Color textColor, boolean
4851 this .preFormatted = preFormatted ;
4952 this .partOfCodeBlock = partOfCodeBlock ;
5053 this .strikethrough = strikethrough ;
54+ this .customStyles = customStyles ;
5155 }
5256
5357 public LayoutStyle (Style style ) {
54- this (Alignment .LEFT , style .getTextStyle ().getDefaultFontSize (), style .getTextStyle ().getDefaultTextColor (), false , false , false , false , false , false , false );
58+ this (Alignment .LEFT , style .getTextStyle ().getDefaultFontSize (), style .getTextStyle ().getDefaultTextColor (), false , false , false , false , false , false , false , new HashMap <>() );
5559 }
5660
5761 public LayoutStyle clone () {
58- return new LayoutStyle (alignment , fontSize , new Color (textColor .getRGB ()), bold , italic , underlined , strikethrough , partOfLink , partOfCodeBlock , preFormatted );
62+ return new LayoutStyle (alignment , fontSize , new Color (textColor .getRGB ()), bold , italic , underlined , strikethrough , partOfLink , partOfCodeBlock , preFormatted , ( HashMap < StyleType <?>, Object >) customStyles . clone () );
5963 }
6064
6165 public Alignment getAlignment () {
@@ -138,6 +142,22 @@ public void setPartOfCodeBlock(boolean partOfCodeBlock) {
138142 this .partOfCodeBlock = partOfCodeBlock ;
139143 }
140144
145+ public <T > void put (StyleType <T > styleType , T value ) {
146+ customStyles .put (styleType , value );
147+ }
148+
149+ public <T > boolean has (StyleType <T > styleType ) {
150+ return customStyles .containsKey (styleType );
151+ }
152+
153+ public <T > T get (StyleType <T > styleType ) {
154+ return styleType .getStyleClass ().cast (customStyles .get (styleType ));
155+ }
156+
157+ public <T > T getOrDefault (StyleType <T > styleType , T defaultValue ) {
158+ return styleType .getStyleClass ().cast (customStyles .getOrDefault (styleType , defaultValue ));
159+ }
160+
141161 public enum Alignment {
142162 CENTER , LEFT , RIGHT
143163 }
0 commit comments