Pārlūkot izejas kodu

SDK : added convenient way to type Vector3f, Vector2f, Quaternions, Emitter shapes. Thanks to kwando
see http://jmonkeyengine.org/groups/jmonkeyplatform/forum/topic/small-change-to-the-properties-pane-in-scenecomposer/?#post-196107

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9935 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

rem..om 13 gadi atpakaļ
vecāks
revīzija
253ff15f43

+ 1 - 1
jme3-core/src/com/jme3/gde/core/properties/EmitterShapePropertyEditor.java

@@ -123,7 +123,7 @@ public class EmitterShapePropertyEditor implements PropertyEditor {
     public void setAsText(String text) throws IllegalArgumentException {
         text = text.replace('[', ' ').trim();
         text = text.replace(']', ' ').trim();
-        String[] strings = text.split(",");
+        String[] strings = text.split("\\s*(,|\\s)\\s*");
         EmitterShape old=emitter;
         if (strings.length == 0) {
             return;

+ 31 - 14
jme3-core/src/com/jme3/gde/core/properties/QuaternionPropertyEditor.java

@@ -73,26 +73,43 @@ public class QuaternionPropertyEditor implements PropertyEditor {
     }
 
     public String getAsText() {
-        float[] angles=quaternion.toAngles(new float[3]);
-        return "[" + (float)Math.toDegrees(angles[0]) + ", " + (float)Math.toDegrees(angles[1]) + ", " + (float)Math.toDegrees(angles[2]) + "]";
+        float[] angles = quaternion.toAngles(new float[3]);
+        return "[" + (float) Math.toDegrees(angles[0]) + ", " + (float) Math.toDegrees(angles[1]) + ", " + (float) Math.toDegrees(angles[2]) + "]";
     }
 
-    public void setAsText(String text) throws IllegalArgumentException {
+    private void parseInto(String text, Quaternion res) throws IllegalArgumentException {
         text = text.replace('[', ' ');
-        text = text.replace(']', ' ');
-        String[] values = text.split(",");
-        if (values.length != 3) {
-            throw (new IllegalArgumentException("String not correct"));
+        text = text.replace(']', ' ').trim();
+        String[] a = text.split("\\s*(,|\\s)\\s*");
+
+
+        if (a.length == 1) {
+            if (text.trim().toLowerCase().equals("nan")) {
+                res.set(Float.NaN, Float.NaN, Float.NaN, Float.NaN);
+                return;
+            }
+            float f = Float.parseFloat(text);
+            f = (float) Math.toRadians(f);
+            res.fromAngles(f, f, f);
+            return;
         }
-        float[] floats = new float[3];
-        for (int i = 0; i < values.length; i++) {
-            String string = values[i];
-            floats[i] = (float)Math.toRadians(Float.parseFloat(string));
+
+        if (a.length == 3) {
+            float[] floats = new float[3];
+            for (int i = 0; i < a.length; i++) {
+                floats[i] = (float) Math.toRadians(Float.parseFloat(a[i]));
+            }
+            res.fromAngles(floats);
+            return;
         }
-        Quaternion old=new Quaternion();
+        throw new IllegalArgumentException("String not correct");
+    }
+
+    public void setAsText(String text) throws IllegalArgumentException {
+        Quaternion old = new Quaternion();
         old.set(quaternion);
-        quaternion.fromAngles(floats);
-        notifyListeners(old,quaternion);
+        parseInto(text, quaternion);
+        notifyListeners(old, quaternion);
     }
 
     public String[] getTags() {

+ 22 - 11
jme3-core/src/com/jme3/gde/core/properties/Vector2fPropertyEditor.java

@@ -75,22 +75,33 @@ public class Vector2fPropertyEditor implements PropertyEditor {
     public String getAsText() {
         return "[" + vector.x + ", " + vector.y + "]";
     }
-
-    public void setAsText(String text) throws IllegalArgumentException {
+    
+    private void parseInto(String text, Vector2f res) throws IllegalArgumentException {
         text = text.replace('[', ' ');
-        text = text.replace(']', ' ');
-        String[] values = text.split(",");
-        if (values.length != 2) {
-            throw (new IllegalArgumentException("String not correct"));
+        text = text.replace(']', ' ').trim();
+        String[] a = text.split("\\s*(,|\\s)\\s*");
+
+        if (a.length == 1) {
+            if(text.trim().toLowerCase().equals("nan")) {
+                res.set(new Vector2f(Float.NaN, Float.NaN));
+                return;
+            }
+            float f = Float.parseFloat(text);            
+            res.set(f, f);
+            return;
         }
-        float[] floats = new float[2];
-        for (int i = 0; i < values.length; i++) {
-            String string = values[i];
-            floats[i] = Float.parseFloat(string);
+
+        if (a.length == 2) {
+            res.set(Float.parseFloat(a[0]), Float.parseFloat(a[1]));
+            return;
         }
+        throw new IllegalArgumentException("String not correct");
+    }
+    
+    public void setAsText(String text) throws IllegalArgumentException {
         Vector2f old = new Vector2f();
         old.set(vector);
-        vector.set(floats[0], floats[1]);
+        parseInto(text, vector);
         notifyListeners(old, vector);
     }
 

+ 22 - 11
jme3-core/src/com/jme3/gde/core/properties/Vector3fPropertyEditor.java

@@ -75,22 +75,33 @@ public class Vector3fPropertyEditor implements PropertyEditor {
     public String getAsText() {
         return "[" + vector.x + ", " + vector.y + ", " + vector.z + "]";
     }
-
-    public void setAsText(String text) throws IllegalArgumentException {
+    
+    private void parseInto(String text, Vector3f res) throws IllegalArgumentException {
         text = text.replace('[', ' ');
-        text = text.replace(']', ' ');
-        String[] values = text.split(",");
-        if (values.length != 3) {
-            throw (new IllegalArgumentException("String not correct"));
+        text = text.replace(']', ' ').trim();
+        String[] a = text.split("\\s*(,|\\s)\\s*");
+
+        if (a.length == 1) {
+            if(text.trim().toLowerCase().equals("nan")) {
+                res.set(Vector3f.NAN);
+                return;
+            }
+            float f = Float.parseFloat(text);           
+            res.set(f, f, f);
+            return;
         }
-        float[] floats = new float[3];
-        for (int i = 0; i < values.length; i++) {
-            String string = values[i];
-            floats[i] = Float.parseFloat(string);
+
+        if (a.length == 3) {
+            res.set(Float.parseFloat(a[0]), Float.parseFloat(a[1]), Float.parseFloat(a[2]));
+            return;
         }
+        throw new IllegalArgumentException("String not correct");
+    }
+    
+    public void setAsText(String text) throws IllegalArgumentException {
         Vector3f old = new Vector3f();
         old.set(vector);
-        vector.set(floats[0], floats[1], floats[2]);
+        parseInto(text, vector);
         notifyListeners(old, vector);
     }