SDK SceneComposer : refactor and cleaner code, more functional code and less sides effects

experimental
Maselbas 10 years ago
parent 07fcde3b73
commit 258fee5753
  1. 14
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/MoveShortcut.java
  2. 14
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/RotateShortcut.java
  3. 14
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/ScaleShortcut.java
  4. 216
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/ShortcutManager.java

@ -78,14 +78,16 @@ public class MoveShortcut extends ShortcutTool {
if (kie.isPressed()) { if (kie.isPressed()) {
Lookup.getDefault().lookup(ShortcutManager.class).activateShortcut(kie); Lookup.getDefault().lookup(ShortcutManager.class).activateShortcut(kie);
Vector3f axis = new Vector3f(); boolean axisChanged = ShortcutManager.isAxisKey(kie);
boolean axisChanged = ShortcutManager.checkAxisKey(kie, axis);
if (axisChanged) { if (axisChanged) {
currentAxis = axis; currentAxis = ShortcutManager.getAxisKey(kie);
} }
boolean numberChanged = ShortcutManager.checkNumberKey(kie, numberBuilder); boolean numberChanged = ShortcutManager.isNumberKey(kie);
boolean enterHit = ShortcutManager.checkEnterHit(kie); if(numberChanged){
boolean escHit = ShortcutManager.checkEscHit(kie); ShortcutManager.setNumberKey(kie, numberBuilder);
}
boolean enterHit = ShortcutManager.isEnterKey(kie);
boolean escHit = ShortcutManager.isEscKey(kie);
if (escHit) { if (escHit) {
cancel(); cancel();

@ -77,14 +77,16 @@ public class RotateShortcut extends ShortcutTool {
if (kie.isPressed()) { if (kie.isPressed()) {
Lookup.getDefault().lookup(ShortcutManager.class).activateShortcut(kie); Lookup.getDefault().lookup(ShortcutManager.class).activateShortcut(kie);
Vector3f axis = new Vector3f(); boolean axisChanged = ShortcutManager.isAxisKey(kie);
boolean axisChanged = ShortcutManager.checkAxisKey(kie, axis);
if (axisChanged) { if (axisChanged) {
currentAxis = axis; currentAxis = ShortcutManager.getAxisKey(kie);
} }
boolean numberChanged = ShortcutManager.checkNumberKey(kie, numberBuilder); boolean numberChanged = ShortcutManager.isNumberKey(kie);
boolean enterHit = ShortcutManager.checkEnterHit(kie); if(numberChanged){
boolean escHit = ShortcutManager.checkEscHit(kie); ShortcutManager.setNumberKey(kie, numberBuilder);
}
boolean enterHit = ShortcutManager.isEnterKey(kie);
boolean escHit = ShortcutManager.isEscKey(kie);
if (escHit) { if (escHit) {
cancel(); cancel();

@ -77,14 +77,16 @@ public class ScaleShortcut extends ShortcutTool {
if (kie.isPressed()) { if (kie.isPressed()) {
Lookup.getDefault().lookup(ShortcutManager.class).activateShortcut(kie); Lookup.getDefault().lookup(ShortcutManager.class).activateShortcut(kie);
Vector3f axis = new Vector3f(); boolean axisChanged = ShortcutManager.isAxisKey(kie);
boolean axisChanged = ShortcutManager.checkAxisKey(kie, axis);
if (axisChanged) { if (axisChanged) {
currentAxis = axis; currentAxis = ShortcutManager.getAxisKey(kie);
} }
boolean numberChanged = ShortcutManager.checkNumberKey(kie, numberBuilder); boolean numberChanged = ShortcutManager.isNumberKey(kie);
boolean enterHit = ShortcutManager.checkEnterHit(kie); if(numberChanged){
boolean escHit = ShortcutManager.checkEscHit(kie); ShortcutManager.setNumberKey(kie, numberBuilder);
}
boolean enterHit = ShortcutManager.isEnterKey(kie);
boolean escHit = ShortcutManager.isEscKey(kie);
if (escHit) { if (escHit) {
cancel(); cancel();

@ -157,13 +157,13 @@ public class ShortcutManager {
} }
private boolean checkCommandeKey(KeyInputEvent kie) { private boolean checkCommandeKey(KeyInputEvent kie) {
if (checkCtrlHit(kie)) { if (isCtrlKey(kie)) {
ctrlDown = kie.isPressed(); ctrlDown = kie.isPressed();
return true; return true;
} else if (checkAltHit(kie)) { } else if (isAltKey(kie)) {
altDown = kie.isPressed(); altDown = kie.isPressed();
return true; return true;
} else if (checkShiftHit(kie)) { } else if (isShiftKey(kie)) {
shiftDown = kie.isPressed(); shiftDown = kie.isPressed();
return true; return true;
} }
@ -178,11 +178,8 @@ public class ShortcutManager {
* @param kie * @param kie
* @return true if the given kie is KEY_RETURN * @return true if the given kie is KEY_RETURN
*/ */
public static boolean checkEnterHit(KeyInputEvent kie) { public static boolean isEnterKey(KeyInputEvent kie) {
if (kie.getKeyCode() == KeyInput.KEY_RETURN) { return (kie.getKeyCode() == KeyInput.KEY_RETURN);
return true;
}
return false;
} }
/** /**
@ -190,11 +187,8 @@ public class ShortcutManager {
* @param kie * @param kie
* @return true if the given kie is KEY_ESCAPE * @return true if the given kie is KEY_ESCAPE
*/ */
public static boolean checkEscHit(KeyInputEvent kie) { public static boolean isEscKey(KeyInputEvent kie) {
if (kie.getKeyCode() == KeyInput.KEY_ESCAPE) { return (kie.getKeyCode() == KeyInput.KEY_ESCAPE);
return true;
}
return false;
} }
/** /**
@ -202,11 +196,8 @@ public class ShortcutManager {
* @param kie * @param kie
* @return true if the given kie is KEY_LCONTROL || KEY_RCONTROL * @return true if the given kie is KEY_LCONTROL || KEY_RCONTROL
*/ */
public static boolean checkCtrlHit(KeyInputEvent kie) { public static boolean isCtrlKey(KeyInputEvent kie) {
if (kie.getKeyCode() == KeyInput.KEY_LCONTROL || kie.getKeyCode() == KeyInput.KEY_RCONTROL) { return (kie.getKeyCode() == KeyInput.KEY_LCONTROL || kie.getKeyCode() == KeyInput.KEY_RCONTROL);
return true;
}
return false;
} }
/** /**
@ -214,11 +205,8 @@ public class ShortcutManager {
* @param kie * @param kie
* @return true if the given kie is KEY_LSHIFT || KEY_RSHIFT * @return true if the given kie is KEY_LSHIFT || KEY_RSHIFT
*/ */
public static boolean checkShiftHit(KeyInputEvent kie) { public static boolean isShiftKey(KeyInputEvent kie) {
if (kie.getKeyCode() == KeyInput.KEY_LSHIFT || kie.getKeyCode() == KeyInput.KEY_RSHIFT) { return (kie.getKeyCode() == KeyInput.KEY_LSHIFT || kie.getKeyCode() == KeyInput.KEY_RSHIFT);
return true;
}
return false;
} }
/** /**
@ -226,9 +214,40 @@ public class ShortcutManager {
* @param kie * @param kie
* @return true if the given kie is KEY_LMENU || KEY_RMENU * @return true if the given kie is KEY_LMENU || KEY_RMENU
*/ */
public static boolean checkAltHit(KeyInputEvent kie) { public static boolean isAltKey(KeyInputEvent kie) {
if (kie.getKeyCode() == KeyInput.KEY_LMENU || kie.getKeyCode() == KeyInput.KEY_RMENU) { return (kie.getKeyCode() == KeyInput.KEY_LMENU || kie.getKeyCode() == KeyInput.KEY_RMENU);
return true; }
/**
*
* @param kie
* @return
*/
public static boolean isNumberKey(KeyInputEvent kie) {
switch (kie.getKeyCode()) {
case KeyInput.KEY_MINUS:
case KeyInput.KEY_0:
case KeyInput.KEY_1:
case KeyInput.KEY_2:
case KeyInput.KEY_3:
case KeyInput.KEY_4:
case KeyInput.KEY_5:
case KeyInput.KEY_6:
case KeyInput.KEY_7:
case KeyInput.KEY_8:
case KeyInput.KEY_9:
case KeyInput.KEY_NUMPAD0:
case KeyInput.KEY_NUMPAD1:
case KeyInput.KEY_NUMPAD2:
case KeyInput.KEY_NUMPAD3:
case KeyInput.KEY_NUMPAD4:
case KeyInput.KEY_NUMPAD5:
case KeyInput.KEY_NUMPAD6:
case KeyInput.KEY_NUMPAD7:
case KeyInput.KEY_NUMPAD8:
case KeyInput.KEY_NUMPAD9:
case KeyInput.KEY_PERIOD:
return true;
} }
return false; return false;
} }
@ -236,65 +255,55 @@ public class ShortcutManager {
/** /**
* store the number kie into the numberBuilder * store the number kie into the numberBuilder
* *
* @param kie * @param kie the KeiInputEvent to be handled as a number.
* @param numberBuilder * @param numberBuilder the number builder that will be modified !
* @return true if the given kie is handled as a number key event
*/ */
public static boolean checkNumberKey(KeyInputEvent kie, StringBuilder numberBuilder) { public static void setNumberKey(KeyInputEvent kie, StringBuilder numberBuilder) {
if (kie.getKeyCode() == KeyInput.KEY_MINUS) { switch (kie.getKeyCode()) {
if (numberBuilder.length() > 0) { case KeyInput.KEY_MINUS:
if (numberBuilder.charAt(0) == '-') { if (numberBuilder.length() > 0) {
numberBuilder.replace(0, 1, ""); if (numberBuilder.charAt(0) == '-') {
numberBuilder.replace(0, 1, "");
} else {
numberBuilder.insert(0, '-');
}
} else { } else {
numberBuilder.insert(0, '-'); numberBuilder.append('-');
} }
} else { break;
numberBuilder.append('-'); case KeyInput.KEY_0:
} case KeyInput.KEY_1:
return true; case KeyInput.KEY_2:
} else if (kie.getKeyCode() == KeyInput.KEY_0 || kie.getKeyCode() == KeyInput.KEY_NUMPAD0) { case KeyInput.KEY_3:
numberBuilder.append('0'); case KeyInput.KEY_4:
return true; case KeyInput.KEY_5:
} else if (kie.getKeyCode() == KeyInput.KEY_1 || kie.getKeyCode() == KeyInput.KEY_NUMPAD1) { case KeyInput.KEY_6:
numberBuilder.append('1'); case KeyInput.KEY_7:
return true; case KeyInput.KEY_8:
} else if (kie.getKeyCode() == KeyInput.KEY_2 || kie.getKeyCode() == KeyInput.KEY_NUMPAD2) { case KeyInput.KEY_9:
numberBuilder.append('2'); case KeyInput.KEY_NUMPAD0:
return true; case KeyInput.KEY_NUMPAD1:
} else if (kie.getKeyCode() == KeyInput.KEY_3 || kie.getKeyCode() == KeyInput.KEY_NUMPAD3) { case KeyInput.KEY_NUMPAD2:
numberBuilder.append('3'); case KeyInput.KEY_NUMPAD3:
return true; case KeyInput.KEY_NUMPAD4:
} else if (kie.getKeyCode() == KeyInput.KEY_4 || kie.getKeyCode() == KeyInput.KEY_NUMPAD4) { case KeyInput.KEY_NUMPAD5:
numberBuilder.append('4'); case KeyInput.KEY_NUMPAD6:
return true; case KeyInput.KEY_NUMPAD7:
} else if (kie.getKeyCode() == KeyInput.KEY_5 || kie.getKeyCode() == KeyInput.KEY_NUMPAD5) { case KeyInput.KEY_NUMPAD8:
numberBuilder.append('5'); case KeyInput.KEY_NUMPAD9:
return true; numberBuilder.append(kie.getKeyChar());
} else if (kie.getKeyCode() == KeyInput.KEY_6 || kie.getKeyCode() == KeyInput.KEY_NUMPAD6) { break;
numberBuilder.append('6'); case KeyInput.KEY_PERIOD:
return true; if (numberBuilder.indexOf(".") == -1) { // if it doesn't exist yet
} else if (kie.getKeyCode() == KeyInput.KEY_7 || kie.getKeyCode() == KeyInput.KEY_NUMPAD7) { if (numberBuilder.length() == 0
numberBuilder.append('7'); || (numberBuilder.length() == 1 && numberBuilder.charAt(0) == '-')) {
return true; numberBuilder.append("0.");
} else if (kie.getKeyCode() == KeyInput.KEY_8 || kie.getKeyCode() == KeyInput.KEY_NUMPAD8) { } else {
numberBuilder.append('8'); numberBuilder.append(".");
return true; }
} else if (kie.getKeyCode() == KeyInput.KEY_9 || kie.getKeyCode() == KeyInput.KEY_NUMPAD9) {
numberBuilder.append('9');
return true;
} else if (kie.getKeyCode() == KeyInput.KEY_PERIOD) {
if (numberBuilder.indexOf(".") == -1) { // if it doesn't exist yet
if (numberBuilder.length() == 0
|| (numberBuilder.length() == 1 && numberBuilder.charAt(0) == '-')) {
numberBuilder.append("0.");
} else {
numberBuilder.append(".");
} }
} break;
return true;
} }
return false;
} }
/** /**
@ -311,25 +320,42 @@ public class ShortcutManager {
} }
/** /**
* Check for axis input for key X,Y,Z and store the corresponding UNIT_ into * Test if the given kie can be handled as en axis input by the getAxisKey()
* the axisStore * method.
* *
* @param kie * @param kie the KeyInputEvent to test
* @param axisStore * @return true is the kie can be handled as an axis input, else false
* @return true if the given kie is handled as a Axis input
*/ */
public static boolean checkAxisKey(KeyInputEvent kie, Vector3f axisStore) { public static boolean isAxisKey(KeyInputEvent kie) {
if (kie.getKeyCode() == KeyInput.KEY_X) { switch (kie.getKeyCode()) {
axisStore.set(Vector3f.UNIT_X); case KeyInput.KEY_X:
return true; case KeyInput.KEY_Y:
} else if (kie.getKeyCode() == KeyInput.KEY_Y) { case KeyInput.KEY_Z:
axisStore.set(Vector3f.UNIT_Y); return true;
return true;
} else if (kie.getKeyCode() == KeyInput.KEY_Z) {
axisStore.set(Vector3f.UNIT_Z);
return true;
} }
return false; return false;
} }
/**
* Handle the Kie as an axis input : return a Vector3f from the kie keyCode.
*
* @param kie the KeyInputEvent to handle as an Axis
* @return UNIT_X for 'x', UNIT_Y for 'y' and UNIT_Z for 'z' kie.
*/
public static Vector3f getAxisKey(KeyInputEvent kie) {
Vector3f result = Vector3f.ZERO;
switch (kie.getKeyCode()) {
case KeyInput.KEY_X:
result = Vector3f.UNIT_X;
break;
case KeyInput.KEY_Y:
result = Vector3f.UNIT_Y;
break;
case KeyInput.KEY_Z:
result = Vector3f.UNIT_Z;
break;
}
return result;
}
} }

Loading…
Cancel
Save