From d5c2a14602740ef17606cae6ede37dfa530f0fbc Mon Sep 17 00:00:00 2001 From: "bre..ns" Date: Wed, 6 Apr 2011 17:07:12 +0000 Subject: [PATCH] an only add one terrain to the scene now in jmp git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7202 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../TerrainEditorTopComponent.form | 12 ++--- .../TerrainEditorTopComponent.java | 50 +++++++++++++++++-- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.form b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.form index ce8c5f718..59c555ca7 100644 --- a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.form +++ b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.form @@ -13,7 +13,7 @@ - + @@ -96,7 +96,7 @@ - + @@ -169,7 +169,7 @@ - + @@ -245,7 +245,7 @@ - + @@ -262,7 +262,7 @@ - + @@ -395,7 +395,7 @@ - + diff --git a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.java b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.java index b7f15d9fd..68fa17bc5 100644 --- a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.java +++ b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.java @@ -39,6 +39,7 @@ import com.jme3.gde.core.scene.SceneListener; import com.jme3.gde.core.scene.SceneRequest; import com.jme3.gde.core.sceneexplorer.nodes.JmeNode; import com.jme3.gde.core.sceneexplorer.nodes.JmeSpatial; +import com.jme3.gde.core.sceneexplorer.nodes.JmeTerrainQuad; import com.jme3.gde.core.sceneexplorer.nodes.NodeUtility; import com.jme3.gde.core.sceneexplorer.nodes.properties.TexturePropertyEditor; import com.jme3.gde.core.util.DataObjectSaveNode; @@ -53,6 +54,9 @@ import com.jme3.texture.Texture; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeListenerProxy; import java.io.File; import java.io.IOException; import java.util.Arrays; @@ -78,6 +82,9 @@ import jme3tools.converters.ImageToAwt; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; import org.openide.loaders.DataObjectNotFoundException; +import org.openide.nodes.NodeEvent; +import org.openide.nodes.NodeMemberEvent; +import org.openide.nodes.NodeReorderEvent; import org.openide.util.NbBundle; import org.openide.windows.TopComponent; import org.openide.windows.WindowManager; @@ -89,6 +96,7 @@ import org.openide.NotifyDescriptor.Confirmation; import org.openide.WizardDescriptor; import org.openide.cookies.SaveCookie; import org.openide.loaders.DataObject; +import org.openide.nodes.NodeListener; import org.openide.util.Exceptions; import org.openide.util.HelpCtx; import org.openide.util.Lookup.Result; @@ -117,6 +125,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce private CreateTerrainWizardAction terrainWizard; private SkyboxWizardAction skyboxWizard; private JmeSpatial selectedSpat; + private TerrainNodeListener terrainDeletedNodeListener; public enum TerrainEditButton {none, raiseTerrain, lowerTerrain, smoothTerrain, levelTerrain, paintTerrain, eraseTerrain}; @@ -761,7 +770,8 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce reinitTextureTable(); // update the UI refreshSelected(); - + + createTerrainButton.setEnabled(false); // only let the user add one terrain } public void generateSkybox(WizardDescriptor wiz) { @@ -817,9 +827,35 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce private void selectSpatial(JmeSpatial spatial) { selectedSpat = spatial; + if (selectedSpat instanceof JmeTerrainQuad) { //TODO shouldn't be terrainQuad, should be a generic JmeTerrain + selectedSpat.removeNodeListener(terrainDeletedNodeListener); // remove it if it exists, no way to check if it is there already + selectedSpat.addNodeListener(terrainDeletedNodeListener); // add it back + } } + /** + * When the terrain is deleted, enable the 'add terrain' button again + * and reinitialize the texture table + */ + private class TerrainNodeListener implements NodeListener { + public void childrenAdded(NodeMemberEvent nme) { + } + + public void childrenRemoved(NodeMemberEvent nme) { + } + public void childrenReordered(NodeReorderEvent nre) { + } + + public void nodeDestroyed(NodeEvent ne) { + createTerrainButton.setEnabled(true); + reinitTextureTable(); + } + + public void propertyChange(PropertyChangeEvent evt) { + } + + } /* * @@ -923,6 +959,8 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce request.setWindowTitle("TerrainEditor - " + manager.getRelativeAssetPath(file.getPrimaryFile().getPath())); request.setToolNode(new Node("TerrainEditorToolNode")); SceneApplication.getApplication().requestScene(request); + + terrainDeletedNodeListener = new TerrainNodeListener(); } // run on GL thread @@ -955,8 +993,8 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce toolController.cleanup(); } - for (int i=0; i