diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/AbstractSceneExplorerNode.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/AbstractSceneExplorerNode.java index 0f0c45009..952eae669 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/AbstractSceneExplorerNode.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/AbstractSceneExplorerNode.java @@ -41,6 +41,8 @@ import org.openide.loaders.DataObject; import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Node; +import org.openide.nodes.NodeAdapter; +import org.openide.nodes.NodeListener; import org.openide.nodes.Sheet; import org.openide.util.Exceptions; import org.openide.util.Lookup; @@ -67,7 +69,7 @@ public abstract class AbstractSceneExplorerNode extends AbstractNode implements public AbstractSceneExplorerNode(Children children, DataObject dataObject) { super(children, new ProxyLookup(dataObject.getLookup(), new DynamicLookup(new InstanceContent()))); this.dataObject = dataObject; - lookupContents = getLookup().lookup(DynamicLookup.class).getInstanceContent(); + lookupContents = getLookup().lookup(DynamicLookup.class).getInstanceContent(); } public AbstractSceneExplorerNode(DataObject dataObject) { @@ -165,6 +167,23 @@ public abstract class AbstractSceneExplorerNode extends AbstractNode implements } return prop; } + + protected Property makeEmbedProperty(Object obj,Class objectClass, Class returntype, String method, String setter, String name) { + Property prop = null; + try { + if (readOnly) { + prop = new SceneExplorerProperty(objectClass.cast(obj), returntype, method, null); + } else { + prop = new SceneExplorerProperty(objectClass.cast(obj), returntype, method, setter, this); + } + prop.setName(name); + + } catch (NoSuchMethodException ex) { + Exceptions.printStackTrace(ex); + } + return prop; + } + protected void createFields(Class c, Sheet.Set set, Object obj) throws SecurityException { for (Field field : c.getDeclaredFields()) { @@ -189,4 +208,5 @@ public abstract class AbstractSceneExplorerNode extends AbstractNode implements public Node[] createNodes(Object key, DataObject dataObject, boolean readOnly) { return new Node[]{Node.EMPTY}; } + } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeParticleEmitter.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeParticleEmitter.java index 869c0b3d2..853505794 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeParticleEmitter.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeParticleEmitter.java @@ -33,12 +33,16 @@ package com.jme3.gde.core.sceneexplorer.nodes; import com.jme3.effect.shapes.EmitterShape; import com.jme3.effect.ParticleEmitter; -import com.jme3.gde.core.sceneexplorer.nodes.SceneExplorerNode; +import com.jme3.effect.ParticleMesh; +import com.jme3.effect.influencers.ParticleInfluencer; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; import java.awt.Image; +import java.beans.PropertyEditor; +import java.lang.reflect.InvocationTargetException; import org.openide.loaders.DataObject; import org.openide.nodes.Node; +import org.openide.nodes.PropertySupport; import org.openide.nodes.Sheet; import org.openide.util.ImageUtilities; @@ -46,12 +50,11 @@ import org.openide.util.ImageUtilities; * * @author normenhansen */ -@org.openide.util.lookup.ServiceProvider(service=SceneExplorerNode.class) -public class JmeParticleEmitter extends JmeGeometry{ +@org.openide.util.lookup.ServiceProvider(service = SceneExplorerNode.class) +public class JmeParticleEmitter extends JmeGeometry { public JmeParticleEmitter() { } - private static Image smallImage = ImageUtilities.loadImage("com/jme3/gde/core/sceneexplorer/nodes/icons/particleemitter.gif"); private ParticleEmitter geom; @@ -84,51 +87,89 @@ public class JmeParticleEmitter extends JmeGeometry{ return sheet; } - createFields(geom.getClass(), set, obj); -// set.put(makeProperty(obj, boolean.class, "isEnabled", "setEnabled", "Enabled")); -// set.put(makeProperty(obj, EmitterShape.class, "getShape", "setShape", "Emitter Shape")); -// set.put(makeProperty(obj, int.class, "getNumVisibleParticles", "setNumParticles", "Num Particles")); -// set.put(makeProperty(obj, float.class, "getParticlesPerSec", "setParticlesPerSec", "Particles Per Sec")); -// set.put(makeProperty(obj, ColorRGBA.class, "getStartColor", "setStartColor", "Start Color")); -// set.put(makeProperty(obj, ColorRGBA.class, "getEndColor", "setEndColor", "End Color")); -// set.put(makeProperty(obj, float.class, "getStartSize", "setStartSize", "Start Size")); -// set.put(makeProperty(obj, float.class, "getEndSize", "setEndSize", "End Size")); -// set.put(makeProperty(obj, float.class, "getHighLife", "setHighLife", "High Life")); -// set.put(makeProperty(obj, float.class, "getLowLife", "setLowLife", "Low Life")); -// set.put(makeProperty(obj, float.class, "getGravity", "setGravity", "Gravity")); -// set.put(makeProperty(obj, Vector3f.class, "getInitialVelocity", "setInitialVelocity", "Initial Velocity")); -// set.put(makeProperty(obj, Vector3f.class, "getFaceNormal", "setFaceNormal", "Face Normal")); -// set.put(makeProperty(obj, float.class, "getVelocityVariation", "setVelocityVariation", "Velocity Variation")); -// set.put(makeProperty(obj, boolean.class, "isFacingVelocity", "setFacingVelocity", "Facing Velocity")); -// set.put(makeProperty(obj, boolean.class, "isRandomAngle", "setRandomAngle", "Random Angle")); -// set.put(makeProperty(obj, boolean.class, "isInWorldSpace", "setInWorldSpace", "World Space")); -// set.put(makeProperty(obj, float.class, "getRotateSpeed", "setRotateSpeed", "Rotate Speed")); -// set.put(makeProperty(obj, boolean.class, "isSelectRandomImage", "setSelectRandomImage", "Select Random Image")); -// set.put(makeProperty(obj, int.class, "getImagesX", "setImagesX", "Images X")); -// set.put(makeProperty(obj, int.class, "getImagesY", "setImagesY", "Images Y")); - -// set.put(makeProperty(obj, EmitterShape.class, "getShape", "setShape", "shape")); - - + set.put(createButtonProperty()); + set.put(makeProperty(obj, boolean.class, "isEnabled", "setEnabled", "Enabled")); + set.put(makeProperty(obj, ParticleMesh.Type.class, "getMeshType", "setMeshType", "Mesh Type")); + set.put(makeProperty(obj, EmitterShape.class, "getShape", "setShape", "Emitter Shape")); + set.put(makeProperty(obj, int.class, "getMaxNumParticles", "setNumParticles", "Num Particles")); + set.put(makeProperty(obj, float.class, "getParticlesPerSec", "setParticlesPerSec", "Particles Per Sec")); + set.put(makeProperty(obj, ColorRGBA.class, "getStartColor", "setStartColor", "Start Color")); + set.put(makeProperty(obj, ColorRGBA.class, "getEndColor", "setEndColor", "End Color")); + set.put(makeProperty(obj, float.class, "getStartSize", "setStartSize", "Start Size")); + set.put(makeProperty(obj, float.class, "getEndSize", "setEndSize", "End Size")); + set.put(makeProperty(obj, float.class, "getHighLife", "setHighLife", "High Life")); + set.put(makeProperty(obj, float.class, "getLowLife", "setLowLife", "Low Life")); + set.put(makeProperty(obj, Vector3f.class, "getGravity", "setGravity", "Gravity")); + set.put(makeEmbedProperty(obj.getParticleInfluencer(), ParticleInfluencer.class, Vector3f.class, "getInitialVelocity", "setInitialVelocity", "Initial Velocity")); + set.put(makeEmbedProperty(obj.getParticleInfluencer(), ParticleInfluencer.class, float.class, "getVelocityVariation", "setVelocityVariation", "Velocity Variation")); + set.put(makeProperty(obj, Vector3f.class, "getFaceNormal", "setFaceNormal", "Face Normal")); + set.put(makeProperty(obj, boolean.class, "isFacingVelocity", "setFacingVelocity", "Facing Velocity")); + set.put(makeProperty(obj, boolean.class, "isRandomAngle", "setRandomAngle", "Random Angle")); + set.put(makeProperty(obj, boolean.class, "isInWorldSpace", "setInWorldSpace", "World Space")); + set.put(makeProperty(obj, float.class, "getRotateSpeed", "setRotateSpeed", "Rotate Speed")); + set.put(makeProperty(obj, boolean.class, "isSelectRandomImage", "setSelectRandomImage", "Select Random Image")); + set.put(makeProperty(obj, int.class, "getImagesX", "setImagesX", "Images X")); + set.put(makeProperty(obj, int.class, "getImagesY", "setImagesY", "Images Y")); sheet.put(set); + return sheet; } + @Override + public void propertyChange(String name, Object before, Object after) { + if (!name.equals("Emitt all particles")) { + fireSave(true); + firePropertyChange(name, before, after); + } + + } + + @Override public Class getExplorerObjectClass() { return ParticleEmitter.class; } + @Override public Class getExplorerNodeClass() { return JmeParticleEmitter.class; } + @Override public Node[] createNodes(Object key, DataObject key2, boolean cookie) { - JmeSpatialChildren children=new JmeSpatialChildren((com.jme3.scene.Spatial)key); + JmeSpatialChildren children = new JmeSpatialChildren((com.jme3.scene.Spatial) key); children.setReadOnly(cookie); children.setDataObject(key2); return new Node[]{new JmeParticleEmitter((ParticleEmitter) key, children).setReadOnly(cookie)}; } + public ParticleEmitter getEmitter() { + return geom; + } + + private Property createButtonProperty() { + return new PropertySupport.ReadWrite("emitt", Object.class, "Emitt all particles", "Click here to emitt all particles of this emitter ") { + + JmeParticleEmitterButtonProperty pe; + + @Override + public Object getValue() throws IllegalAccessException, InvocationTargetException { + return ""; + } + + @Override + public PropertyEditor getPropertyEditor() { + if (pe == null) { + pe = new JmeParticleEmitterButtonProperty(JmeParticleEmitter.this); + pe.attachEnv(pe.env); + } + return pe; + } + + @Override + public void setValue(Object t) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + } + }; + } } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeParticleEmitterButtonProperty.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeParticleEmitterButtonProperty.java new file mode 100644 index 000000000..ec33ddf18 --- /dev/null +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeParticleEmitterButtonProperty.java @@ -0,0 +1,79 @@ +package com.jme3.gde.core.sceneexplorer.nodes; + +import com.jme3.effect.ParticleEmitter; +import com.jme3.gde.core.scene.SceneApplication; +import com.jme3.gde.core.util.ButtonInplaceEditor; +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyEditorSupport; +import java.util.concurrent.Callable; +import org.openide.explorer.propertysheet.ExPropertyEditor; +import org.openide.explorer.propertysheet.InplaceEditor; +import org.openide.explorer.propertysheet.PropertyEnv; + +/** + * + * @author Nehon + */ +public class JmeParticleEmitterButtonProperty extends PropertyEditorSupport implements ExPropertyEditor, InplaceEditor.Factory { + + JmeParticleEmitter pe; + + public JmeParticleEmitterButtonProperty(JmeParticleEmitter pe) { + super(); + + this.pe = pe; + } + PropertyEnv env; + + public void attachEnv(PropertyEnv env) { + this.env = env; + env.registerInplaceEditorFactory(this); + } + private ButtonInplaceEditor ed = null; + + public InplaceEditor getInplaceEditor() { + if (ed == null) { + ed = new ButtonInplaceEditor("Emitt!"); + ed.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + + SceneApplication.getApplication().enqueue(new Callable() { + + public Object call() throws Exception { + + pe.getEmitter().killAllParticles(); + pe.getEmitter().emitAllParticles(); + return null; + } + }); + } + }); + } + return ed; + } + + @Override + public boolean isPaintable() { + return true; + } + + @Override + public void paintValue(Graphics gfx, Rectangle box) { + if (ed == null) { + getInplaceEditor(); + } + ed.setSize(box.width, box.height); + ed.doLayout(); + Graphics g = gfx.create(box.x, box.y, box.width, box.height); + ed.setOpaque(false); + ed.paint(g); + g.dispose(); + pe.refresh(false); + } +} diff --git a/sdk/jme3-core/src/com/jme3/gde/core/util/ButtonInplaceEditor.java b/sdk/jme3-core/src/com/jme3/gde/core/util/ButtonInplaceEditor.java new file mode 100644 index 000000000..a3e0fd9af --- /dev/null +++ b/sdk/jme3-core/src/com/jme3/gde/core/util/ButtonInplaceEditor.java @@ -0,0 +1,103 @@ +package com.jme3.gde.core.util; + +import java.awt.Color; +import java.awt.Component; +import java.beans.PropertyEditor; +import javax.swing.DefaultButtonModel; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.KeyStroke; +import org.openide.explorer.propertysheet.InplaceEditor; +import org.openide.explorer.propertysheet.PropertyEnv; +import org.openide.explorer.propertysheet.PropertyModel; + +/** + * + * @author Nehon + */ +public class ButtonInplaceEditor extends JButton implements InplaceEditor { + + private PropertyEditor editor = null; + private PropertyModel model; + private PropertyEnv env; + + public ButtonInplaceEditor() { + this("Click"); + setActionCommand(COMMAND_SUCCESS); + setForeground(Color.BLACK); + } + + public ButtonInplaceEditor(String text) { + super(text); + setActionCommand(COMMAND_SUCCESS); + setForeground(Color.BLACK); + } + + public ButtonInplaceEditor(Icon icon) { + super(icon); + setActionCommand(COMMAND_SUCCESS); + setForeground(Color.BLACK); + + } + + public ButtonInplaceEditor(String text, Icon icon) { + super(text, icon); + setActionCommand(COMMAND_SUCCESS); + setForeground(Color.BLACK); + } + + public void connect(PropertyEditor pe, PropertyEnv pe1) { + editor = pe; + env = pe1; + reset(); + } + + public JComponent getComponent() { + return this; + } + + public void clear() { + editor = null; + model = null; + } + + public Object getValue() { + repaint(); + updateUI(); + return ""; + } + + public void setValue(Object o) { + repaint(); + updateUI(); + } + + public boolean supportsTextEntry() { + return false; + } + + public void reset() { + } + + public KeyStroke[] getKeyStrokes() { + return new KeyStroke[0]; + } + + public PropertyEditor getPropertyEditor() { + return editor; + } + + public PropertyModel getPropertyModel() { + return model; + } + + public void setPropertyModel(PropertyModel pm) { + + this.model = pm; + } + + public boolean isKnownComponent(Component cmpnt) { + return false; + } +} \ No newline at end of file