diff --git a/diylc/diylc-core/src/org/diylc/presenter/update.xml b/diylc/diylc-core/src/org/diylc/presenter/update.xml index 964f9ca9..735138eb 100644 --- a/diylc/diylc-core/src/org/diylc/presenter/update.xml +++ b/diylc/diylc-core/src/org/diylc/presenter/update.xml @@ -3489,6 +3489,10 @@ NEW_FEATURE Flatpak integration for easier deployments to Linux systems + + + NEW_FEATURE + When editing component colors, honor the specified 'alpha' value specified on each color individually in addition to the component-level alpha property IMPROVEMENT diff --git a/diylc/diylc-core/src/org/diylc/serialization/ColorConverter.java b/diylc/diylc-core/src/org/diylc/serialization/ColorConverter.java index e5a2e347..f66b5471 100644 --- a/diylc/diylc-core/src/org/diylc/serialization/ColorConverter.java +++ b/diylc/diylc-core/src/org/diylc/serialization/ColorConverter.java @@ -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); } diff --git a/diylc/diylc-core/src/org/diylc/serialization/ProjectFileManager.java b/diylc/diylc-core/src/org/diylc/serialization/ProjectFileManager.java index bb630901..007a9b70 100644 --- a/diylc/diylc-core/src/org/diylc/serialization/ProjectFileManager.java +++ b/diylc/diylc-core/src/org/diylc/serialization/ProjectFileManager.java @@ -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()); diff --git a/diylc/diylc-swing/src/org/diylc/swing/gui/editor/ColorEditor.java b/diylc/diylc-swing/src/org/diylc/swing/gui/editor/ColorEditor.java index 523ae599..4ecf74fc 100644 --- a/diylc/diylc-swing/src/org/diylc/swing/gui/editor/ColorEditor.java +++ b/diylc/diylc-swing/src/org/diylc/swing/gui/editor/ColorEditor.java @@ -99,7 +99,7 @@ public class ColorEditor extends JPanel { colorLabel.setOpaque(true); colorLabel.setHorizontalAlignment(SwingConstants.CENTER); colorLabel.setBorder(BorderFactory.createEtchedBorder()); - colorLabel.setBackground((Color) property.getValue()); + colorLabel.setBackground(new Color(((Color) property.getValue()).getRGB())); colorLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); colorLabel.addMouseListener(new MouseAdapter() { @@ -108,9 +108,14 @@ public class ColorEditor extends JPanel { Color newColor = JColorChooser.showDialog(ColorEditor.this, "Choose Color", getBackground()); if (newColor != null) { property.setChanged(true); - property.setValue(newColor); - getColorLabel().setBackground(newColor); - getColorField().setText(Integer.toHexString(newColor.getRGB()).substring(2).toUpperCase()); + property.setValue(new Color(newColor.getRGB())); + if (newColor.getAlpha() == 255) { + getColorField().setText(Integer.toHexString(newColor.getRGB()).substring(2).toUpperCase()); + getColorLabel().setBackground(newColor); + } else { // has alpha, convert to RGBA + getColorField().setText(Integer.toHexString(newColor.getRGB()).toUpperCase()); + getColorLabel().setBackground(new Color(newColor.getRGB())); + } } } }); @@ -120,10 +125,19 @@ public class ColorEditor extends JPanel { public JTextField getColorField() { if (colorField == null) { - Color color = (Color) property.getValue(); - colorField = - new JTextField(property.isUnique() ? Integer.toHexString(color.getRGB()).substring(2).toUpperCase() : ""); - colorField.setColumns(6); + Color color = (Color) property.getValue(); + + colorField = new JTextField(); + + if (property.isUnique()) { + if (color.getAlpha() == 255) { + colorField.setText(Integer.toHexString(color.getRGB()).substring(2).toUpperCase()); + } else { // has alpha, convert to RGBA + colorField.setText(Integer.toHexString((color.getRGB())).toUpperCase()); + } + } + + colorField.setColumns(8); colorField.getDocument().addDocumentListener(new DocumentListener() { @Override @@ -154,6 +168,15 @@ public class ColorEditor extends JPanel { property.setChanged(true); property.setValue(newColor); } + } else if (getColorField().getText().length() == 8) { + int rgba = (int)Long.parseLong(getColorField().getText(), 16); + Color newColor = new Color(rgba, true); + if (newColor != null && getColorLabel().getBackground() != newColor) { + getColorLabel().setBackground(new Color(newColor.getRGB())); + getColorLabel().setText(title); + property.setChanged(true); + property.setValue(newColor); + } } } }