From b9870753fcb7178de889cc5da5d6b7c275d96793 Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Tue, 5 Apr 2011 01:00:20 +0000 Subject: [PATCH] - add "last selected" available via SceneExplorer - add API for external variable type editors - first version of "create j3m" function for materials (WIP - parameter values are only toString() versions atm) git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7187 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- sdk/jme3-core/nbproject/project.properties | 2 +- .../SceneExplorerTopComponent.java | 9 +++ .../properties/SceneExplorerProperty.java | 5 +- .../SceneExplorerPropertyEditor.java | 41 ++++++++++++ .../nbproject/genfiles.properties | 4 +- sdk/jme3-materialeditor/nbproject/project.xml | 2 +- .../gde/materials/MaterialProperties.java | 41 ++++++++++++ .../jme3/gde/materials/MaterialProperty.java | 13 +++- .../materials}/MaterialPropertyEditor.java | 65 +++++++++++++++++-- 9 files changed, 167 insertions(+), 15 deletions(-) create mode 100644 sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/properties/SceneExplorerPropertyEditor.java rename sdk/{jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/properties => jme3-materialeditor/src/com/jme3/gde/materials}/MaterialPropertyEditor.java (63%) diff --git a/sdk/jme3-core/nbproject/project.properties b/sdk/jme3-core/nbproject/project.properties index 78700583a..b010f823c 100644 --- a/sdk/jme3-core/nbproject/project.properties +++ b/sdk/jme3-core/nbproject/project.properties @@ -6,4 +6,4 @@ nbm.homepage=http://www.jmonkeyengine.com nbm.module.author=Normen Hansen nbm.needs.restart=true project.license=jme -spec.version.base=0.12.0 +spec.version.base=0.12.1 diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/SceneExplorerTopComponent.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/SceneExplorerTopComponent.java index 8d9a619ab..b0f13252e 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/SceneExplorerTopComponent.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/SceneExplorerTopComponent.java @@ -76,6 +76,7 @@ public final class SceneExplorerTopComponent extends TopComponent implements Exp private SceneRequest request; private final Result nodeSelectionResult; private AbstractSceneExplorerNode selectedSpatial; + private AbstractSceneExplorerNode lastSelected; public SceneExplorerTopComponent() { initComponents(); @@ -250,6 +251,7 @@ public final class SceneExplorerTopComponent extends TopComponent implements Exp Object object = it.next(); if (object instanceof AbstractSceneExplorerNode) { selectedSpatial = (AbstractSceneExplorerNode) object; + lastSelected = (AbstractSceneExplorerNode) object; return; } } @@ -273,4 +275,11 @@ public final class SceneExplorerTopComponent extends TopComponent implements Exp public void previewRequested(PreviewRequest request) { } + + /** + * @return the selectedSpatial + */ + public AbstractSceneExplorerNode getLastSelected() { + return lastSelected; + } } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/properties/SceneExplorerProperty.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/properties/SceneExplorerProperty.java index d2a55635a..7c52fdc5f 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/properties/SceneExplorerProperty.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/properties/SceneExplorerProperty.java @@ -75,11 +75,12 @@ public class SceneExplorerProperty extends PropertySupport.Reflection { setPropertyEditorClass(Matrix3fPropertyEditor.class); } else if (valueType == ColorRGBA.class) { setPropertyEditorClass(ColorRGBAPropertyEditor.class); - } else if (valueType == Material.class) { - setPropertyEditorClass(MaterialPropertyEditor.class); } else if (valueType == EmitterShape.class) { setPropertyEditorClass(EmitterShapePropertyEditor.class); } + for (SceneExplorerPropertyEditor di : Lookup.getDefault().lookupAll(SceneExplorerPropertyEditor.class)) { + di.setEditor(valueType, this); + } } @Override diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/properties/SceneExplorerPropertyEditor.java b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/properties/SceneExplorerPropertyEditor.java new file mode 100644 index 000000000..6c0f9cf02 --- /dev/null +++ b/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/properties/SceneExplorerPropertyEditor.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2009-2010 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.gde.core.sceneexplorer.nodes.properties; + +/** + * + * @author normenhansen + */ +public interface SceneExplorerPropertyEditor { + public void setEditor(Class valueType, SceneExplorerProperty prop); +} diff --git a/sdk/jme3-materialeditor/nbproject/genfiles.properties b/sdk/jme3-materialeditor/nbproject/genfiles.properties index 6dac79da7..e60ea2516 100644 --- a/sdk/jme3-materialeditor/nbproject/genfiles.properties +++ b/sdk/jme3-materialeditor/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=3a4f0982 +build.xml.data.CRC32=6e7dc984 build.xml.script.CRC32=f284e28d build.xml.stylesheet.CRC32=a56c6a5b@1.42.2 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=3a4f0982 +nbproject/build-impl.xml.data.CRC32=6e7dc984 nbproject/build-impl.xml.script.CRC32=56cee44d nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.42.2 diff --git a/sdk/jme3-materialeditor/nbproject/project.xml b/sdk/jme3-materialeditor/nbproject/project.xml index f9fd6dd7c..162fc8622 100644 --- a/sdk/jme3-materialeditor/nbproject/project.xml +++ b/sdk/jme3-materialeditor/nbproject/project.xml @@ -12,7 +12,7 @@ 1 - 0.12 + 0.12.1 diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialProperties.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialProperties.java index 7098c721e..ed497f167 100644 --- a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialProperties.java +++ b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialProperties.java @@ -5,6 +5,8 @@ package com.jme3.gde.materials; import com.jme3.gde.core.assets.ProjectAssetManager; +import com.jme3.material.MatParam; +import com.jme3.material.Material; import com.jme3.system.JmeSystem; import java.io.IOException; import java.io.InputStream; @@ -12,6 +14,7 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.StringWriter; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; @@ -389,6 +392,15 @@ public class MaterialProperties { return ""; } + private void createBaseMaterialFile() throws IOException { + OutputStreamWriter out = new OutputStreamWriter(material.getOutputStream()); + out.write("Material MyMaterial : " + matDefName + " {\n"); + out.write(" MaterialParameters {\n"); + out.write(" }\n"); + out.write("}\n"); + out.close(); + } + /** * trims a line and removes comments * @param line @@ -444,6 +456,34 @@ public class MaterialProperties { out.close(); } + /** + * Creates the data from a material + * @param mat + */ + public void setAsMaterial(Material mat) throws IOException { + assert (mat.getMaterialDef().getAssetName() != null); + setName("MyMaterial"); + setMatDefName(mat.getMaterialDef().getAssetName()); + createBaseMaterialFile(); + materialParameters.clear(); + Collection params=mat.getParams(); + for (Iterator it = params.iterator(); it.hasNext();) { + MatParam matParam = it.next(); + materialParameters.put(matParam.getName(), new MaterialProperty(matParam)); + } + additionalRenderStates.put("Wireframe", new MaterialProperty("OnOff", "Wireframe", mat.getAdditionalRenderState().isWireframe() ? "On" : "Off")); + additionalRenderStates.put("DepthWrite", new MaterialProperty("OnOff", "DepthWrite", mat.getAdditionalRenderState().isDepthWrite() ? "On" : "Off")); + additionalRenderStates.put("DepthTest", new MaterialProperty("OnOff", "DepthTest", mat.getAdditionalRenderState().isDepthTest() ? "On" : "Off")); + additionalRenderStates.put("ColorWrite", new MaterialProperty("OnOff", "ColorWrite", mat.getAdditionalRenderState().isColorWrite() ? "On" : "Off")); + additionalRenderStates.put("PointSprite", new MaterialProperty("OnOff", "PointSprite", mat.getAdditionalRenderState().isPointSprite() ? "On" : "Off")); + additionalRenderStates.put("FaceCull", new MaterialProperty("FaceCullMode", "FaceCull", mat.getAdditionalRenderState().getFaceCullMode().name())); + additionalRenderStates.put("Blend", new MaterialProperty("BlendMode", "Blend", mat.getAdditionalRenderState().getBlendMode().name())); + additionalRenderStates.put("AlphaTestFalloff", new MaterialProperty("Float", "AlphaTestFalloff", mat.getAdditionalRenderState().getAlphaFallOff() + "")); + additionalRenderStates.put("PolyOffset", new MaterialProperty("Float,Float", "PolyOffset", mat.getAdditionalRenderState().getPolyOffsetUnits() + ", " + mat.getAdditionalRenderState().getPolyOffsetFactor())); + parseMatDef(); + setAsText(getUpdatedContent()); + } + /** * @return the matDefName */ @@ -456,6 +496,7 @@ public class MaterialProperties { */ public void setMatDefName(String matDefName) { this.matDefName = matDefName; + assert (matDefName != null); initMatDef(); parseMatDef(); } diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialProperty.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialProperty.java index 51cf37fdd..bc59d57ee 100644 --- a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialProperty.java +++ b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialProperty.java @@ -2,14 +2,16 @@ * To change this template, choose Tools | Templates * and open the template in the editor. */ - package com.jme3.gde.materials; +import com.jme3.material.MatParam; + /** * * @author normenhansen */ public class MaterialProperty { + private String type; private String name; private String value; @@ -17,13 +19,19 @@ public class MaterialProperty { public MaterialProperty() { } - public MaterialProperty(String type, String name, String value) { this.type = type; this.name = name; this.value = value; } + public MaterialProperty(MatParam param) { + this.type = param.getVarType().name(); + this.name = param.getName(); +// param.getVarType(). + //TODO: change to correct string + this.value = param.getValue().toString(); + } /** * @return the type @@ -66,5 +74,4 @@ public class MaterialProperty { public void setValue(String value) { this.value = value; } - } diff --git a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/properties/MaterialPropertyEditor.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialPropertyEditor.java similarity index 63% rename from sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/properties/MaterialPropertyEditor.java rename to sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialPropertyEditor.java index cc19bba1e..fbb19897e 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/properties/MaterialPropertyEditor.java +++ b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialPropertyEditor.java @@ -29,31 +29,39 @@ * 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.gde.core.sceneexplorer.nodes.properties; +package com.jme3.gde.materials; import com.jme3.asset.AssetKey; import com.jme3.asset.DesktopAssetManager; +import com.jme3.gde.core.assets.ProjectAssetManager; import com.jme3.gde.core.scene.SceneApplication; import com.jme3.gde.core.scene.SceneRequest; +import com.jme3.gde.core.sceneexplorer.SceneExplorerTopComponent; +import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode; +import com.jme3.gde.core.sceneexplorer.nodes.properties.SceneExplorerProperty; +import com.jme3.gde.core.sceneexplorer.nodes.properties.SceneExplorerPropertyEditor; import com.jme3.material.Material; -import com.jme3.math.Quaternion; import java.awt.Component; import java.awt.Graphics; import java.awt.Rectangle; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyEditor; +import java.io.IOException; import java.util.Iterator; import java.util.LinkedList; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; +import org.openide.filesystems.FileObject; +import org.openide.loaders.DataObject; import org.openide.util.Exceptions; /** * * @author normenhansen */ -public class MaterialPropertyEditor implements PropertyEditor { +@org.openide.util.lookup.ServiceProvider(service = SceneExplorerPropertyEditor.class) +public class MaterialPropertyEditor implements PropertyEditor, SceneExplorerPropertyEditor { private LinkedList listeners = new LinkedList(); private Material material = new Material(); @@ -83,12 +91,41 @@ public class MaterialPropertyEditor implements PropertyEditor { public String getAsText() { String name = material.getAssetName(); if (name == null) { - name = "stored in file"; + name = "create j3m file"; } return name; } public void setAsText(final String text) throws IllegalArgumentException { + if ("create j3m file".equals(text)) { + AbstractSceneExplorerNode geom = SceneExplorerTopComponent.findInstance().getLastSelected(); + assert (geom != null); + ProjectAssetManager pm = geom.getLookup().lookup(ProjectAssetManager.class); + assert (pm != null); + DataObject obj = geom.getLookup().lookup(DataObject.class); + assert (obj != null); + FileObject currentFile = obj.getPrimaryFile(); + FileObject currentFolder = currentFile.getParent(); + try { + Material old = material.clone(); + int i = 1; + FileObject newFile = currentFolder.getFileObject(currentFile.getName() + "_" + i, "j3m"); + while (newFile != null) { + i++; + newFile = currentFolder.getFileObject(currentFile.getName() + "_" + i, "j3m"); + } + newFile = currentFolder.createData(currentFile.getName() + "_" + i, "j3m"); + MaterialProperties properties = new MaterialProperties(newFile, pm); + material.setAssetName(pm.getRelativeAssetPath(newFile.getPath())); + properties.setAsMaterial(material); + notifyListeners(old, material); + currentFolder.refresh(); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + return; + } + return; + } try { Material old = material; SceneApplication.getApplication().enqueue(new Callable() { @@ -116,8 +153,18 @@ public class MaterialPropertyEditor implements PropertyEditor { if (request == null) { return new String[]{}; } - String[] mats = request.getManager().getMaterials(); - return mats; + if (material.getAssetName() == null) { + String[] materials = request.getManager().getMaterials(); + String[] mats = new String[materials.length + 1]; + mats[0] = ("create j3m file"); + for (int i = 0; i < materials.length; i++) { + String string = materials[i]; + mats[i + 1] = string; + } + return mats; + } else { + return request.getManager().getMaterials(); + } } public Component getCustomEditor() { @@ -143,4 +190,10 @@ public class MaterialPropertyEditor implements PropertyEditor { propertyChangeListener.propertyChange(new PropertyChangeEvent(this, null, before, after)); } } + + public void setEditor(Class valueType, SceneExplorerProperty prop) { + if (valueType == Material.class) { + prop.setPropertyEditorClass(MaterialPropertyEditor.class); + } + } }