When editing component colors, honor the specified 'alpha' value

specified on each color individually in addition to the component-level
alpha property
This commit is contained in:
bancika
2021-01-17 00:09:21 +01:00
parent bcb1b3c082
commit fa56fd79cf
4 changed files with 52 additions and 13 deletions
@@ -3489,6 +3489,10 @@
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Flatpak integration for easier deployments to Linux systems</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>When editing component colors, honor the specified 'alpha' value specified on each color individually in addition to the component-level alpha property</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
@@ -37,14 +37,26 @@ public class ColorConverter extends com.thoughtworks.xstream.converters.extended
@Override
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext context) {
Color c = (Color) object;
writer.addAttribute("hex", String.format("%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue()));
Color c = (Color) object;
if (c.getAlpha() == 255) {
writer.addAttribute("hex", String.format("%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue()));
} else {
writer.addAttribute("hex", String.format("%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue()));
writer.addAttribute("alpha", String.format("%02x", c.getAlpha()));
}
}
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
if (reader.getAttribute("hex") != null)
return Color.decode("#" + reader.getAttribute("hex"));
if (reader.getAttribute("hex") != null) {
String hex = reader.getAttribute("hex");
String alpha = reader.getAttribute("alpha");
Color color = Color.decode("#" + hex);
if (alpha == null)
return color;
else
return new Color(color.getRed(), color.getGreen(), color.getBlue(), (int)Long.parseLong(alpha, 16));
}
return super.unmarshal(reader, context);
}
@@ -107,7 +107,7 @@ public class ProjectFileManager {
xStream.alias("point", java.awt.geom.Point2D.class);
xStream.alias("point", java.awt.geom.Point2D.Double.class);
xStream.alias("font", java.awt.Font.class);
// xStream.alias("color", java.awt.Color.class);
xStream.alias("color", java.awt.Color.class);
xStream.alias("project", Project.class);
xStream.aliasPackage("diylc", "org.diylc.components");
xStream.registerConverter(new PointConverter());