|
@@ -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 {
|
|
|
[email protected](service = SceneExplorerPropertyEditor.class)
|
|
|
+public class MaterialPropertyEditor implements PropertyEditor, SceneExplorerPropertyEditor {
|
|
|
|
|
|
private LinkedList<PropertyChangeListener> listeners = new LinkedList<PropertyChangeListener>();
|
|
|
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<Void>() {
|
|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|