|
|
@@ -16,7 +16,10 @@ import net.ranides.grammars.generated.CssGrammarLexer;
|
|
|
import net.ranides.grammars.generated.CssGrammarParser;
|
|
|
|
|
|
import javax.swing.*;
|
|
|
+import javax.swing.border.BevelBorder;
|
|
|
import javax.swing.border.Border;
|
|
|
+import javax.swing.border.EtchedBorder;
|
|
|
+import javax.swing.border.SoftBevelBorder;
|
|
|
import java.awt.*;
|
|
|
import java.util.NoSuchElementException;
|
|
|
import java.util.List;
|
|
|
@@ -301,28 +304,69 @@ public class CssParser {
|
|
|
CustomBevelBorder.newInstance(size.map(CssBorderSize::getSize), color, CustomBevelBorder.LOWERED)
|
|
|
);
|
|
|
}
|
|
|
-// case SWING_ETCHED: {
|
|
|
-// List<Color> colors = node.children("color").map(v -> COLOR.single(v)).list();
|
|
|
-// Object color1;
|
|
|
-// Object color2;
|
|
|
-// if(colors.size() == 1) {
|
|
|
-// Color color0 = colors.get(0);
|
|
|
-// color1 = color0.brighter();
|
|
|
-// color2 = color0.darker();
|
|
|
-// } else {
|
|
|
-// color1 = colors.get(0);
|
|
|
-// color2 = colors.get(1);
|
|
|
-// }
|
|
|
-//
|
|
|
-// Integer size0 = node.children("numberUnit").single().map(v -> NUMBER_UNIT.single(v)).get();
|
|
|
-//
|
|
|
-// BorderFactory.createEtchedBorder(size0, )
|
|
|
-// }
|
|
|
default:
|
|
|
throw new UnsupportedOperationException("Unsupported border style: " + style);
|
|
|
}
|
|
|
|
|
|
|
|
|
+ })
|
|
|
+ .mapRule("borderSwingSimple", node -> {
|
|
|
+ CssBorderStyle style = BORDER_STYLE.first(node.child("borderSwingSimple_Style"));
|
|
|
+ String type = node.child("borderSwingSimple_Type").text();
|
|
|
+ List<Color> colors = node.children("color").map(v -> COLOR.single(v)).list();
|
|
|
+
|
|
|
+ boolean typeRaised;
|
|
|
+ switch (type) {
|
|
|
+ case "lowered":
|
|
|
+ typeRaised = false;
|
|
|
+ break;
|
|
|
+ case "raised":
|
|
|
+ typeRaised = true;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new UnsupportedOperationException("Unsupported botder type: " + type);
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (style) {
|
|
|
+ case SWING_ETCHED: {
|
|
|
+ int etchedType = typeRaised ? EtchedBorder.RAISED : EtchedBorder.LOWERED;
|
|
|
+ if (colors.size() == 2) {
|
|
|
+ return BorderFactory.createEtchedBorder(etchedType, colors.get(0), colors.get(1));
|
|
|
+ }
|
|
|
+ if (colors.size() == 1) {
|
|
|
+ return BorderFactory.createEtchedBorder(etchedType, colors.get(0).brighter(), colors.get(0).darker());
|
|
|
+ }
|
|
|
+ if (colors.size() == 0) {
|
|
|
+ return BorderFactory.createEtchedBorder(etchedType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ case SWING_BEVEL: {
|
|
|
+ int bevelType = typeRaised ? BevelBorder.RAISED : BevelBorder.LOWERED;
|
|
|
+ if (colors.size() == 2) {
|
|
|
+ return BorderFactory.createBevelBorder(bevelType, colors.get(0), colors.get(1));
|
|
|
+ }
|
|
|
+ if (colors.size() == 1) {
|
|
|
+ return BorderFactory.createBevelBorder(bevelType, colors.get(0).brighter(), colors.get(0).darker());
|
|
|
+ }
|
|
|
+ if (colors.size() == 0) {
|
|
|
+ return BorderFactory.createBevelBorder(bevelType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ case SWING_BEVEL_SOFT: {
|
|
|
+ int softBevelType = typeRaised ? SoftBevelBorder.RAISED : SoftBevelBorder.LOWERED;
|
|
|
+ if (colors.size() == 2) {
|
|
|
+ return BorderFactory.createSoftBevelBorder(softBevelType, colors.get(0), colors.get(1));
|
|
|
+ }
|
|
|
+ if (colors.size() == 1) {
|
|
|
+ return BorderFactory.createSoftBevelBorder(softBevelType, colors.get(0).brighter(), colors.get(0).darker());
|
|
|
+ }
|
|
|
+ if (colors.size() == 0) {
|
|
|
+ return BorderFactory.createSoftBevelBorder(softBevelType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ throw new UnsupportedOperationException("Unsupported border style: " + style);
|
|
|
+ }
|
|
|
})
|
|
|
.prepare();
|
|
|
|