SDK : One can now rename or delete an animation in the Scene Explorer

experimental
Nehon 11 years ago
parent 65aad55b10
commit 4d861ce90d
  1. 90
      sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeAnimation.java

@ -46,16 +46,21 @@ import com.jme3.gde.core.sceneexplorer.nodes.actions.impl.tracks.EffectTrackWiza
import java.awt.Image; import java.awt.Image;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import org.openide.actions.DeleteAction;
import org.openide.actions.RenameAction;
import org.openide.awt.Actions; import org.openide.awt.Actions;
import org.openide.loaders.DataObject; import org.openide.loaders.DataObject;
import org.openide.nodes.Node; import org.openide.nodes.Node;
import org.openide.nodes.NodeAdapter;
import org.openide.nodes.Sheet; import org.openide.nodes.Sheet;
import org.openide.util.Exceptions; import org.openide.util.Exceptions;
import org.openide.util.actions.SystemAction;
/** /**
* *
@ -88,8 +93,18 @@ public class JmeAnimation extends AbstractSceneExplorerNode {
children.setAnimControl(jmeControl); children.setAnimControl(jmeControl);
icon = IconList.animation.getImage(); icon = IconList.animation.getImage();
addNodeListener(new NodeAdapter(){
@Override
public void propertyChange(PropertyChangeEvent evt) {
if(evt.getPropertyName().equalsIgnoreCase("name")){
doRenameAnimation((String) evt.getOldValue(),(String)evt.getNewValue());
}
}
});
} }
@Override @Override
public Image getIcon(int type) { public Image getIcon(int type) {
return icon; return icon;
@ -151,6 +166,8 @@ public class JmeAnimation extends AbstractSceneExplorerNode {
return new Action[]{Actions.alwaysEnabled(new PlayAction(), playing ? "Stop" : "Play", "", false), return new Action[]{Actions.alwaysEnabled(new PlayAction(), playing ? "Stop" : "Play", "", false),
Actions.alwaysEnabled(new PlayBackParamsAction(), "Playback parameters", "", false), Actions.alwaysEnabled(new PlayBackParamsAction(), "Playback parameters", "", false),
SystemAction.get(RenameAction.class),
SystemAction.get(DeleteAction.class),
Actions.alwaysEnabled(new EffectTrackWizardAction(jmeControl.getLookup().lookup(AnimControl.class).getSpatial(), this), "Add Effect Track", "", false), Actions.alwaysEnabled(new EffectTrackWizardAction(jmeControl.getLookup().lookup(AnimControl.class).getSpatial(), this), "Add Effect Track", "", false),
Actions.alwaysEnabled(new AudioTrackWizardAction(jmeControl.getLookup().lookup(AnimControl.class).getSpatial(), this), "Add Audio Track", "", false), Actions.alwaysEnabled(new AudioTrackWizardAction(jmeControl.getLookup().lookup(AnimControl.class).getSpatial(), this), "Add Audio Track", "", false),
Actions.alwaysEnabled(new ExtractAnimationAction(), "Extract sub-animation", "", true) Actions.alwaysEnabled(new ExtractAnimationAction(), "Extract sub-animation", "", true)
@ -159,7 +176,7 @@ public class JmeAnimation extends AbstractSceneExplorerNode {
@Override @Override
public boolean canDestroy() { public boolean canDestroy() {
return false; return !jmeControl.readOnly;
} }
public void stop() { public void stop() {
@ -169,22 +186,25 @@ public class JmeAnimation extends AbstractSceneExplorerNode {
@Override @Override
public void destroy() throws IOException { public void destroy() throws IOException {
// super.destroy(); super.destroy();
// final Spatial spat = getParentNode().getLookup().lookup(Spatial.class); final AnimControl control = jmeControl.getLookup().lookup(AnimControl.class);
// try { try {
// SceneApplication.getApplication().enqueue(new Callable<Void>() { lookupContents.remove(JmeAnimation.this.animation);
// lookupContents.remove(this);
// public Void call() throws Exception { SceneApplication.getApplication().enqueue(new Callable<Void>() {
// spat.removeControl(skeletonControl); public Void call() throws Exception {
// return null; control.removeAnim(JmeAnimation.this.animation);
// } return null;
// }).get(); }
// ((AbstractSceneExplorerNode) getParentNode()).refresh(true); }).get();
// } catch (InterruptedException ex) { jmeControl.refreshChildren();
// Exceptions.printStackTrace(ex); setChanged();
// } catch (ExecutionException ex) { } catch (InterruptedException ex) {
// Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
// } } catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
} }
@Override @Override
@ -405,4 +425,40 @@ public class JmeAnimation extends AbstractSceneExplorerNode {
// ((JmeTrackChildren) getChildren()).refreshChildren(false); // ((JmeTrackChildren) getChildren()).refreshChildren(false);
// } // }
// } // }
@Override
public boolean canRename() {
return !jmeControl.readOnly;
}
/**
* renames the animation in the opengl thread.
* Note that renaming an animation mean to delete the old one and create a
* new anim with the new name and the old data
* @param evt
*/
protected void doRenameAnimation(final String oldName,final String newName) {
final AnimControl control = jmeControl.getLookup().lookup(AnimControl.class);
try {
lookupContents.remove(JmeAnimation.this.animation);
JmeAnimation.this.animation = SceneApplication.getApplication().enqueue(new Callable<Animation>() {
public Animation call() throws Exception {
Animation anim = control.getAnim(oldName);
Animation newAnim = new Animation(newName, anim.getLength());
newAnim.setTracks(anim.getTracks());
control.removeAnim(anim);
control.addAnim(newAnim);
return newAnim;
}
}).get();
lookupContents.add(JmeAnimation.this.animation);
setChanged();
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
}
} }

Loading…
Cancel
Save