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. 45
      sdk/jme3-core/src/com/jme3/gde/core/properties/QuaternionPropertyEditor.java
  3. 33
      sdk/jme3-core/src/com/jme3/gde/core/properties/Vector2fPropertyEditor.java
  4. 33
      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;
} }
float[] floats = new float[3];
for (int i = 0; i < values.length; i++) { if (a.length == 3) {
String string = values[i]; float[] floats = new float[3];
floats[i] = (float)Math.toRadians(Float.parseFloat(string)); 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); old.set(quaternion);
quaternion.fromAngles(floats); parseInto(text, quaternion);
notifyListeners(old,quaternion); notifyListeners(old, quaternion);
} }
public String[] getTags() { public String[] getTags() {

@ -75,22 +75,33 @@ public class Vector2fPropertyEditor implements PropertyEditor {
public String getAsText() { public String getAsText() {
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 f = Float.parseFloat(text);
res.set(f, f);
return;
} }
float[] floats = new float[2];
for (int i = 0; i < values.length; i++) { if (a.length == 2) {
String string = values[i]; res.set(Float.parseFloat(a[0]), Float.parseFloat(a[1]));
floats[i] = Float.parseFloat(string); 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);
} }

@ -75,22 +75,33 @@ public class Vector3fPropertyEditor implements PropertyEditor {
public String getAsText() { public String getAsText() {
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 f = Float.parseFloat(text);
res.set(f, f, f);
return;
} }
float[] floats = new float[3];
for (int i = 0; i < values.length; i++) { if (a.length == 3) {
String string = values[i]; res.set(Float.parseFloat(a[0]), Float.parseFloat(a[1]), Float.parseFloat(a[2]));
floats[i] = Float.parseFloat(string); 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