Skip to content

Commit

Permalink
Merge pull request #30 from Mathis-Hu/main
Browse files Browse the repository at this point in the history
Add colors to Group Widgets
  • Loading branch information
kasemir authored Sep 5, 2023
2 parents 8c0508d + 76ed09a commit 3133eba
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 41 deletions.
62 changes: 40 additions & 22 deletions src/main/java/dbwr/widgets/GroupWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class GroupWidget extends BaseMacroWidget
private final String name;
private final int style;
private final FontInfo font;
private String foreground_color, line_color, background_color,background_color_label;
private final boolean transparent;
private final List<Widget> children = new ArrayList<>();

public GroupWidget(final ParentWidget parent, final Element xml) throws Exception
Expand All @@ -44,13 +46,13 @@ public GroupWidget(final ParentWidget parent, final Element xml) throws Exceptio
{
switch (XMLUtil.getChildInteger(xml, "border_style").orElse(0))
{
case 13:
// GROUP
style = 0;
break;
default:
// NONE
style = 3;
case 13:
// GROUP
style = 0;
break;
default:
// NONE
style = 3;
}
}
else
Expand All @@ -66,6 +68,20 @@ public GroupWidget(final ParentWidget parent, final Element xml) throws Exceptio
final Widget child = WidgetFactory.createWidget(this, widget_xml);
children.add(child);
}

foreground_color = XMLUtil.getColor(xml, "foreground_color").orElse("#000");
background_color = XMLUtil.getColor(xml, "background_color").orElse("#FFF");
background_color_label = background_color;
line_color = XMLUtil.getColor(xml, "line_color").orElse(null);
if(line_color == null) {
line_color = foreground_color;
if (style == 1)
foreground_color = background_color;
}

transparent = XMLUtil.getChildBoolean(xml, "transparent").orElse(false);
if (transparent)
background_color = "#FFF";
}

@Override
Expand All @@ -84,46 +100,48 @@ else if (style == 1)
if (style == 1)
{ // Group name as box on top with outline below
HTMLUtil.indent(html, indent+1);
html.print("<div class=\"GroupTitle\" style=\"top: 0px; left: 0px; width: " + (width-3) +"px; " + font + " color: white; background-color: black;\">");
html.print("<div class=\"GroupTitle\" style=\"top: 0px; left: 0px; width: " + (width-3) +"px; " + font + " color: " + foreground_color + "; background-color: " + line_color + ";\">");
html.print(name);
html.println("</div>");
HTMLUtil.indent(html, indent+1);
html.println("<svg width=\"" + width + "px\" height=\"" + height + "px\" style=\"" + font + "\">");
html.println("<svg width=\"" + width + "px\" height=\"" + height + "px\" style=\"" + font + " background-color : " + background_color + "\">");
HTMLUtil.indent(html, indent+2);
html.println("<rect x=\"1\" y=\"1\" width=\"" + (width-3) + "\" height=\"" + (height-3) + "\" stroke=\"#000\" stroke-width=\"2\" fill=\"transparent\"\"/>");
html.println("<rect x=\"1\" y=\"1\" width=\"" + (width-3) + "\" height=\"" + (height-3) + "\" stroke=\"" + line_color + "\" stroke-width=\"2\" fill=\"transparent\"\"/>");
HTMLUtil.indent(html, indent+1);
html.println("</svg>");
}
else if (style != 3)
else
{ // SVG for border
HTMLUtil.indent(html, indent+1);
html.println("<svg width=\"" + width + "px\" height=\"" + height + "px\" style=\"" + font + "\">");
HTMLUtil.indent(html, indent+2);
html.println("<rect x=\"" + hinset + "\" y=\"" + vinset + "\" width=\"" + (width-2*hinset) + "\" height=\"" + (height-2*vinset) + "\" stroke=\"#000\" stroke-width=\"2\" fill=\"transparent\"\"/>");
HTMLUtil.indent(html, indent+1);
html.println("<svg width=\"" + width + "px\" height=\"" + height + "px\" style=\"" + font + " background-color : " + background_color + "\">");
if(style != 3){
HTMLUtil.indent(html, indent+2);
html.println("<rect x=\"" + hinset + "\" y=\"" + vinset + "\" width=\"" + (width-2*hinset) + "\" height=\"" + (height-2*vinset) + "\" stroke=\"" + line_color + "\" stroke-width=\"2\" fill=\"transparent\"\"/>");
HTMLUtil.indent(html, indent+1);
}
html.println("</svg>");
}
if (style == 0)
{ // Group name as label on top of border
HTMLUtil.indent(html, indent+1);
html.print("<div class=\"GroupLabel\" style=\"top: 0px; left: " + 2*hinset + "px; " + font + " background-color: white;\">");
html.print("<div class=\"GroupLabel\" style=\"top: 0px; left: " + 2*hinset + "px; " + font + " color: " + foreground_color + "; background-color: " + background_color_label + ";\">");
html.print(name);
html.println("</div>");
}
if (style != 3)
{ // Wrap content in <div>
// if (style != 3)
// { // Wrap content in <div>
HTMLUtil.indent(html, indent+1);
html.println("<div class=\"GroupBox\" style=\"top: " + 2*vinset + "px; left: " + 2*hinset + "px; width: " + (width-4*hinset) + "px; height: " + (height - 4*vinset) + "px;\">");
}
// }

for (final Widget child : children)
child.getHTML(html, indent+2);

if (style != 3)
{ // Close the content-div
// if (style != 3)
// { // Close the content-div
HTMLUtil.indent(html, indent+1);
html.println("</div>");
}
// }

HTMLUtil.indent(html, indent);
}
Expand Down
19 changes: 0 additions & 19 deletions src/main/webapp/widgets/group.js

This file was deleted.

0 comments on commit 3133eba

Please sign in to comment.