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
3.0
rem..om 12 years ago
parent 76dcabae66
commit 89d1f64739
  1. 2
      sdk/jme3-core/src/com/jme3/gde/core/properties/EmitterShapePropertyEditor.java
  2. 43
      sdk/jme3-core/src/com/jme3/gde/core/properties/QuaternionPropertyEditor.java
  3. 31
      sdk/jme3-core/src/com/jme3/gde/core/properties/Vector2fPropertyEditor.java
  4. 31
      sdk/jme3-core/src/com/jme3/gde/core/properties/Vector3fPropertyEditor.java

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

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

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

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

Loading…
Cancel
Save