Skip to content

Commit

Permalink
Merge pull request #2757 from Mathis-Hu/master
Browse files Browse the repository at this point in the history
Change color title of group container widget independently #2743
  • Loading branch information
shroffk authored Aug 8, 2023
2 parents c14b18b + d7ab370 commit ce2ac91
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propBackgroundColor;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propFont;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propForegroundColor;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propLineColor;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propTransparent;
import static org.csstudio.display.builder.model.properties.InsetsWidgetProperty.runtimePropExtendedInsets;

Expand Down Expand Up @@ -56,20 +57,23 @@
@SuppressWarnings("nls")
public class GroupWidget extends MacroWidget
{
/** Group Widget version */
public static final Version GROUP_WIDGET_VERSION = new Version(3, 0, 0);

/** Widget descriptor */
public static final WidgetDescriptor WIDGET_DESCRIPTOR =
new WidgetDescriptor("group", WidgetCategory.STRUCTURE,
Messages.GroupWidget_Name,
"/icons/group.png",
Messages.GroupWidget_Description,
Arrays.asList("org.csstudio.opibuilder.widgets.groupingContainer"))
{
@Override
public Widget createWidget()
{
return new GroupWidget();
}
};
new WidgetDescriptor("group", WidgetCategory.STRUCTURE,
Messages.GroupWidget_Name,
"/icons/group.png",
Messages.GroupWidget_Description,
Arrays.asList("org.csstudio.opibuilder.widgets.groupingContainer"))
{
@Override
public Widget createWidget()
{
return new GroupWidget();
}
};

/** Group widget style */
public enum Style
Expand Down Expand Up @@ -99,16 +103,16 @@ public String toString()

/** 'style' property */
static final WidgetPropertyDescriptor<Style> propStyle =
new WidgetPropertyDescriptor<>(
WidgetPropertyCategory.DISPLAY, "style", Messages.Style)
{
@Override
public EnumWidgetProperty<Style> createProperty(final Widget widget,
final Style default_value)
{
return new EnumWidgetProperty<>(this, widget, default_value);
}
};
new WidgetPropertyDescriptor<>(
WidgetPropertyCategory.DISPLAY, "style", Messages.Style)
{
@Override
public EnumWidgetProperty<Style> createProperty(final Widget widget,
final Style default_value)
{
return new EnumWidgetProperty<>(this, widget, default_value);
}
};

/** Convert legacy "border_style"
*
Expand All @@ -119,30 +123,30 @@ static Style convertLegacyStyle(final int border_style)
{
switch (border_style)
{
case 0: // NONE
case 15: // EMPTY
return Style.NONE;

case 1: // LINE
case 2: // RAISED
case 3: // LOWERED
case 4: // ETCHED
case 5: // RIDGED
case 6: // BUTTON_RAISED
case 7: // BUTTON_PRESSED
case 8: // DOTTED
case 9: // DASHED
case 10: // DASH_DOT
case 11: // DASH_DOT_DOT
case 14: // ROUND_RECTANGLE_BACKGROUND
return Style.LINE;

case 12: // TITLE_BAR
return Style.TITLE;

case 13: // GROUP_BOX
default:
return Style.GROUP;
case 0: // NONE
case 15: // EMPTY
return Style.NONE;

case 1: // LINE
case 2: // RAISED
case 3: // LOWERED
case 4: // ETCHED
case 5: // RIDGED
case 6: // BUTTON_RAISED
case 7: // BUTTON_PRESSED
case 8: // DOTTED
case 9: // DASHED
case 10: // DASH_DOT
case 11: // DASH_DOT_DOT
case 14: // ROUND_RECTANGLE_BACKGROUND
return Style.LINE;

case 12: // TITLE_BAR
return Style.TITLE;

case 13: // GROUP_BOX
default:
return Style.GROUP;
}
}

Expand All @@ -161,12 +165,13 @@ public boolean configureFromXML(final ModelReader model_reader, final Widget wid
if (! super.configureFromXML(model_reader, widget, xml))
return false;

final GroupWidget group_widget = (GroupWidget) widget;
if (xml_version.getMajor() < 2)
{
final GroupWidget group_widget = (GroupWidget) widget;

// Translate border styles
XMLUtil.getChildInteger(xml, "border_style")
.ifPresent(old -> group_widget.style.setValue(convertLegacyStyle(old)));
.ifPresent(old -> group_widget.style.setValue(convertLegacyStyle(old)));

// Legacy had 'border_color'.
// It wasn't used by Group Box style, which had built-in gray,
Expand All @@ -177,6 +182,15 @@ public boolean configureFromXML(final ModelReader model_reader, final Widget wid
group_widget.foreground.readFromXML(model_reader, text);
}

if (xml_version.getMajor() < 3) {
final Element text_foreground = XMLUtil.getChildElement(xml, "foreground_color");
if (text_foreground != null)
group_widget.line.readFromXML(model_reader, text_foreground);
final Element text_background = XMLUtil.getChildElement(xml, "background_color");
if (text_background != null && group_widget.style.getValue() == Style.TITLE)
group_widget.foreground.readFromXML(model_reader, text_background);
}

return true;
}
}
Expand All @@ -185,6 +199,7 @@ public boolean configureFromXML(final ModelReader model_reader, final Widget wid
private volatile WidgetProperty<Style> style;
private volatile WidgetProperty<WidgetColor> foreground;
private volatile WidgetProperty<WidgetColor> background;
private volatile WidgetProperty<WidgetColor> line;
private volatile WidgetProperty<Boolean> transparent;
private volatile WidgetProperty<WidgetFont> font;
private volatile WidgetProperty<int[]> insets;
Expand All @@ -203,6 +218,7 @@ protected void defineProperties(final List<WidgetProperty<?>> properties)
properties.add(style = propStyle.createProperty(this, Style.GROUP));
properties.add(font = propFont.createProperty(this, WidgetFontService.get(NamedWidgetFonts.DEFAULT)));
properties.add(foreground = propForegroundColor.createProperty(this, WidgetColorService.getColor(NamedWidgetColors.TEXT)));
properties.add(line = propLineColor.createProperty(this, WidgetColorService.getColor(NamedWidgetColors.TEXT)));
properties.add(background = propBackgroundColor.createProperty(this, WidgetColorService.getColor(NamedWidgetColors.BACKGROUND)));
properties.add(transparent = propTransparent.createProperty(this, false));
properties.add(insets = runtimePropExtendedInsets.createProperty(this, new int[] { 0, 0, 0, 0 }));
Expand Down Expand Up @@ -236,6 +252,12 @@ public void expandMacros(final Macros input)
child.expandMacros(propMacros().getValue());
}

@Override
public Version getVersion()
{
return GROUP_WIDGET_VERSION;
}

/** @return Runtime 'children' property */
public ChildrenProperty runtimeChildren()
{
Expand All @@ -260,6 +282,11 @@ public WidgetProperty<WidgetColor> propBackgroundColor()
return background;
}

public WidgetProperty<WidgetColor> propLineColor()
{
return line;
}

/** @return 'transparent' property */
public WidgetProperty<Boolean> propTransparent()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<name>Demo</name>
<zero_ten>7</zero_ten>
</widget>
<widget type="group" version="2.0.0">
<widget type="group" version="3.0.0">
<name>My Group</name>
<widget type="base" version="2.0.0">
<name>Jänner</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public class GroupRepresentation extends JFXBaseRepresentation<Pane, GroupWidget
private static final int BORDER_WIDTH = 1;
static final BorderWidths EDIT_NONE_BORDER = new BorderWidths(0.5, 0.5, 0.5, 0.5, false, false, false, false);
static final BorderStrokeStyle EDIT_NONE_DASHED = new BorderStrokeStyle(
StrokeType.INSIDE,
StrokeLineJoin.MITER,
StrokeLineCap.BUTT,
10,
0,
List.of(Double.valueOf(11.11), Double.valueOf(7.7), Double.valueOf(3.3), Double.valueOf(7.7))
StrokeType.INSIDE,
StrokeLineJoin.MITER,
StrokeLineCap.BUTT,
10,
0,
List.of(Double.valueOf(11.11), Double.valueOf(7.7), Double.valueOf(3.3), Double.valueOf(7.7))
);

private final DirtyFlag dirty_border = new DirtyFlag();
Expand All @@ -63,7 +63,7 @@ public class GroupRepresentation extends JFXBaseRepresentation<Pane, GroupWidget

private volatile boolean firstUpdate = true;
private volatile int inset = 10;
private volatile Color foreground_color, background_color;
private volatile Color foreground_color, line_color, background_color;

@Override
public Pane createJFXNode() throws Exception
Expand All @@ -87,6 +87,7 @@ protected void registerListeners()
{
super.registerListeners();
model_widget.propForegroundColor().addUntypedPropertyListener(borderChangedListener);
model_widget.propLineColor().addUntypedPropertyListener(borderChangedListener);
model_widget.propBackgroundColor().addUntypedPropertyListener(borderChangedListener);
model_widget.propTransparent().addUntypedPropertyListener(borderChangedListener);
model_widget.propName().addUntypedPropertyListener(borderChangedListener);
Expand All @@ -100,6 +101,7 @@ protected void registerListeners()
protected void unregisterListeners()
{
model_widget.propForegroundColor().removePropertyListener(borderChangedListener);
model_widget.propLineColor().removePropertyListener(borderChangedListener);
model_widget.propBackgroundColor().removePropertyListener(borderChangedListener);
model_widget.propTransparent().removePropertyListener(borderChangedListener);
model_widget.propName().removePropertyListener(borderChangedListener);
Expand All @@ -119,6 +121,7 @@ private void borderChanged(final WidgetProperty<?> property, final Object old_va

private void computeColors()
{
line_color = JFXUtil.convert(model_widget.propLineColor().getValue());
foreground_color = JFXUtil.convert(model_widget.propForegroundColor().getValue());
background_color = JFXUtil.convert(model_widget.propBackgroundColor().getValue());
}
Expand Down Expand Up @@ -179,7 +182,7 @@ public void updateChanges()
// In edit mode, show outline because otherwise hard to
// handle the totally invisible group
if (toolkit.isEditMode())
jfx_node.setBorder(new Border(new BorderStroke(foreground_color, EDIT_NONE_DASHED, CornerRadii.EMPTY, EDIT_NONE_BORDER)));
jfx_node.setBorder(new Border(new BorderStroke(line_color, EDIT_NONE_DASHED, CornerRadii.EMPTY, EDIT_NONE_BORDER)));
else
jfx_node.setBorder(null);

Expand All @@ -194,7 +197,7 @@ public void updateChanges()
insets[2] = 2 * insets[0];
insets[3] = 2 * insets[1];

jfx_node.setBorder(new Border(new BorderStroke(foreground_color, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
jfx_node.setBorder(new Border(new BorderStroke(line_color, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
label.setVisible(false);
break;
}
Expand All @@ -206,13 +209,13 @@ public void updateChanges()
insets[2] = 2 * insets[0];
insets[3] = insets[0] + insets[1];

jfx_node.setBorder(new Border(new BorderStroke(foreground_color, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
jfx_node.setBorder(new Border(new BorderStroke(line_color, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
label.setVisible(true);
label.relocate(0, BORDER_WIDTH);
label.setPadding(TITLE_PADDING);
label.setPrefSize(width + ( ( !firstUpdate && hasChildren ) ? insets[2] : 0 ), inset);
label.setTextFill(background_color);
label.setBackground(new Background(new BackgroundFill(foreground_color, CornerRadii.EMPTY, Insets.EMPTY)));
label.setTextFill(foreground_color);
label.setBackground(new Background(new BackgroundFill(line_color, CornerRadii.EMPTY, Insets.EMPTY)));
break;
}
case GROUP:
Expand All @@ -224,7 +227,7 @@ public void updateChanges()
insets[2] = 2 * insets[0];
insets[3] = 2 * insets[1];

jfx_node.setBorder(new Border(new BorderStroke(foreground_color, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT, new Insets(inset / 2))));
jfx_node.setBorder(new Border(new BorderStroke(line_color, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT, new Insets(inset / 2))));
label.setVisible(true);
label.relocate(inset, 0);
label.setPadding(TITLE_PADDING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public List<MatchSegment> getMatch(final String text)
{
// Have text for this argument.
segs.add(MatchSegment.match(text.substring(pos, end),
function.getArguments().get(i)));
function.getArguments().get(i)));
if (text.charAt(end) == ')')
{
segs.add(MatchSegment.match(")"));
Expand All @@ -101,7 +101,7 @@ public List<MatchSegment> getMatch(final String text)
else
{
segs.add(MatchSegment.comment(text.substring(pos),
function.getArguments().get(i)));
function.getArguments().get(i)));
pos = end = -1;
}
}
Expand Down Expand Up @@ -130,4 +130,4 @@ public List<MatchSegment> getMatch(final String text)

return segs;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ public List<Proposal> lookup(final String text)

return result;
}
}
}

0 comments on commit ce2ac91

Please sign in to comment.