mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
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:
@@ -3490,6 +3490,10 @@
|
||||
<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>
|
||||
<description>Improved code robustness</description>
|
||||
|
||||
@@ -38,13 +38,25 @@ 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()));
|
||||
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());
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -121,9 +126,18 @@ 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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user