ColorRGBAPropertyEditor - a little improvement

Hi,

I’m taking a look at JDK code and learning how to extend/add new functionality. I would like to suggest a little improvement to the ColorRGBAPropertyEditor. When a color property is displayed in the properties panel, it looks like this:

I changed a few lines of codes in order to display a little box in order to show the actual color as follow:

Here is the patch:

# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: D:\java\SDK30final\3.0final\sdk\jme3-core
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: src/com/jme3/gde/core/properties/ColorRGBADialog.java
--- src/com/jme3/gde/core/properties/ColorRGBADialog.java Base (BASE)
+++ src/com/jme3/gde/core/properties/ColorRGBADialog.java Locally Modified (Based On LOCAL)
@@ -53,6 +53,7 @@
         super(parent, modal);
         this.editor = editor;
         initComponents();
+        jColorChooser1.setColor(new Color(((ColorRGBA)editor.getValue()).asIntARGB()));
         alphaSlider.setValue(Math.round(((ColorRGBA)editor.getValue()).getAlpha()*100));
     }
 
Index: src/com/jme3/gde/core/properties/ColorRGBAPropertyEditor.java
--- src/com/jme3/gde/core/properties/ColorRGBAPropertyEditor.java Base (BASE)
+++ src/com/jme3/gde/core/properties/ColorRGBAPropertyEditor.java Locally Modified (Based On LOCAL)
@@ -48,24 +48,38 @@
 public class ColorRGBAPropertyEditor implements PropertyEditor {
 
     private LinkedList<PropertyChangeListener> listeners = new LinkedList<PropertyChangeListener>();
-    private ColorRGBA color = new ColorRGBA();
+    private ColorRGBA color = null;
 
     public void setValue(Object value) {
         if (value instanceof ColorRGBA) {
+            if (color == null) {
+                color = new ColorRGBA((ColorRGBA) value);
+            } else {
             color.set((ColorRGBA) value);
         }
     }
+    }
 
     public Object getValue() {
         return color;
     }
 
+    @Override
     public boolean isPaintable() {
-        return false;
+        return true;
     }
 
+    @Override
     public void paintValue(Graphics gfx, Rectangle box) {
-        throw new UnsupportedOperationException("Not supported yet.");
+        final int width = box.height - 2;
+        final int height = box.height - 2;
+        java.awt.Color oldColor = gfx.getColor();
+        gfx.setColor(java.awt.Color.BLACK);
+        gfx.drawRect(box.x, box.y + 1, width, height);
+        gfx.setColor(new java.awt.Color(color.asIntARGB(), true));
+        gfx.fillRect(box.x + 1, box.y + 2, width - 1, height - 1);
+        gfx.setColor(oldColor);
+        gfx.drawString(getAsText(), box.x + width + 5, box.y + (box.height / 2) + 4);
     }
 
     public String getJavaInitializationString() {

let me know if it is ok.

6 Likes

looks good!
I’ll integrate it

It’s been integrated on master.
Thanks.

no problem! I’m glad to help! :smiley:

By the way.
Maybe next time, you could make a pull request on github.
Posting patches is fine, and already appreciated, but pull requests are now more the official way to contribute.
See the contribution guidelines here

1 Like