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();
cinematicEvents.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.scene.Spatial;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
@ -431,15 +431,17 @@ public class AnimationEvent extends AbstractCinematicEvent {
@Override
public void dispose() {
super.dispose();
Object o = cinematic.getEventData(MODEL_CHANNELS, model);
if (o != null) {
ArrayList<AnimChannel> list = (ArrayList<AnimChannel>) o;
list.remove(channel);
if (list.isEmpty()) {
cinematic.removeEventData(MODEL_CHANNELS, model);
if (cinematic != null) {
Object o = cinematic.getEventData(MODEL_CHANNELS, model);
if (o != null) {
Collection<AnimChannel> values = ((HashMap<Integer, AnimChannel>) o).values();
while (values.remove(channel));
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
public boolean isActivableBy(KeyInputEvent kie) {
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;
}
}
@ -99,7 +101,7 @@ public class DeleteShortcut extends ShortcutTool {
@Override
public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) {
}
private class DeleteUndo extends AbstractUndoableSceneEdit {
private Spatial spatial;

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

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

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

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