Merge branch 'master' into PBRisComing

define_list_fix
Nehon 10 years ago
commit 4b1c61dec1
  1. 4
      jme3-core/src/main/java/com/jme3/cinematic/Cinematic.java
  2. 20
      jme3-core/src/main/java/com/jme3/cinematic/events/AnimationEvent.java
  3. 69
      jme3-core/src/test/java/com/jme3/cinematic/CinematicTest.java
  4. 6
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/DeleteShortcut.java
  5. 14
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/MoveShortcut.java
  6. 14
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/RotateShortcut.java
  7. 14
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/ScaleShortcut.java
  8. 216
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/ShortcutManager.java

@ -702,7 +702,9 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
dispose(); dispose();
cinematicEvents.clear(); cinematicEvents.clear();
timeLine.clear(); timeLine.clear();
eventsData.clear(); if (eventsData != null) {
eventsData.clear();
}
} }
/** /**

@ -43,7 +43,7 @@ import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule; import com.jme3.export.OutputCapsule;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -431,15 +431,17 @@ public class AnimationEvent extends AbstractCinematicEvent {
@Override @Override
public void dispose() { public void dispose() {
super.dispose(); super.dispose();
Object o = cinematic.getEventData(MODEL_CHANNELS, model); if (cinematic != null) {
if (o != null) { Object o = cinematic.getEventData(MODEL_CHANNELS, model);
ArrayList<AnimChannel> list = (ArrayList<AnimChannel>) o; if (o != null) {
list.remove(channel); Collection<AnimChannel> values = ((HashMap<Integer, AnimChannel>) o).values();
if (list.isEmpty()) { while (values.remove(channel));
cinematic.removeEventData(MODEL_CHANNELS, model); if (values.isEmpty()) {
cinematic.removeEventData(MODEL_CHANNELS, model);
}
} }
cinematic = null;
channel = null;
} }
cinematic = null;
channel = null;
} }
} }

@ -0,0 +1,69 @@
/*
* Copyright (c) 2009-2015 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.cinematic;
import com.jme3.animation.AnimControl;
import com.jme3.animation.Animation;
import com.jme3.cinematic.events.AnimationEvent;
import com.jme3.scene.Node;
import org.junit.Test;
/**
*
* @author davidB
*/
public class CinematicTest {
/**
* No NPE or any exception when clear() a new Cinematic
*/
@Test
public void clearEmpty() {
Cinematic sut = new Cinematic();
sut.clear();
}
/**
* No ClassCastException when clear() a Cinematic with AnimationEvent
*/
@Test
public void clearAnimationEvent() {
Cinematic sut = new Cinematic();
Node model = new Node("model");
AnimControl ac = new AnimControl();
ac.addAnim(new Animation("animName", 1.0f));
model.addControl(ac);
sut.enqueueCinematicEvent(new AnimationEvent(model, "animName"));
sut.initialize(null, null);
sut.clear();
}
}

@ -29,7 +29,9 @@ public class DeleteShortcut extends ShortcutTool {
@Override @Override
public boolean isActivableBy(KeyInputEvent kie) { public boolean isActivableBy(KeyInputEvent kie) {
if (kie.getKeyCode() == KeyInput.KEY_X && kie.isPressed()) { if (kie.getKeyCode() == KeyInput.KEY_X && kie.isPressed()) {
if (Lookup.getDefault().lookup(ShortcutManager.class).isShiftDown()) { ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
if (!scm.isActive() && scm.isShiftDown()) {
// ^ can't be enable if an other shortcut is allready active
return true; return true;
} }
} }
@ -99,7 +101,7 @@ public class DeleteShortcut extends ShortcutTool {
@Override @Override
public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) {
} }
private class DeleteUndo extends AbstractUndoableSceneEdit { private class DeleteUndo extends AbstractUndoableSceneEdit {
private Spatial spatial; private Spatial spatial;

@ -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