Modified terrain node listeners to handle removed terrain. Fixed an issue with actions spamming the save cookie with modified changes.
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8310 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
e4d8bee22f
commit
d63fcf3e23
@ -91,6 +91,8 @@ public abstract class AbstractStatefulGLToolAction {
|
||||
}
|
||||
|
||||
protected void setModified(final AbstractSceneExplorerNode rootNode, final DataObject dataObject) {
|
||||
if (dataObject.isModified())
|
||||
return;
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
|
@ -33,13 +33,13 @@
|
||||
package com.jme3.gde.terraineditor;
|
||||
|
||||
import com.jme3.asset.AssetManager;
|
||||
import com.jme3.asset.TextureKey;
|
||||
import com.jme3.bounding.BoundingBox;
|
||||
import com.jme3.gde.core.assets.AssetDataObject;
|
||||
import com.jme3.gde.core.assets.ProjectAssetManager;
|
||||
import com.jme3.gde.core.scene.SceneApplication;
|
||||
import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode;
|
||||
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.undoredo.AbstractUndoableSceneEdit;
|
||||
import com.jme3.gde.core.undoredo.SceneUndoRedoManager;
|
||||
import com.jme3.gde.core.util.TerrainUtils;
|
||||
@ -51,8 +51,6 @@ import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.terrain.ProgressMonitor;
|
||||
import com.jme3.terrain.Terrain;
|
||||
import com.jme3.terrain.geomipmap.TerrainLodControl;
|
||||
import com.jme3.terrain.geomipmap.TerrainQuad;
|
||||
import com.jme3.texture.Texture;
|
||||
import com.jme3.texture.Texture.WrapMode;
|
||||
import com.jme3.util.SkyFactory;
|
||||
@ -86,6 +84,7 @@ import org.openide.util.Lookup;
|
||||
@SuppressWarnings("unchecked")
|
||||
public class TerrainEditorController implements NodeListener {
|
||||
private JmeSpatial jmeRootNode;
|
||||
private JmeSpatial selectedSpat;
|
||||
private Node terrainNode;
|
||||
private Node rootNode;
|
||||
private AssetDataObject currentFileObject;
|
||||
@ -143,7 +142,26 @@ public class TerrainEditorController implements NodeListener {
|
||||
}
|
||||
|
||||
public void setNeedsSave(boolean state) {
|
||||
currentFileObject.setModified(state);
|
||||
if (state && !currentFileObject.isModified())
|
||||
currentFileObject.setModified(state);
|
||||
else if (!state && currentFileObject.isModified())
|
||||
currentFileObject.setModified(state);
|
||||
}
|
||||
|
||||
protected void setSelectedSpat(JmeSpatial selectedSpat) {
|
||||
|
||||
if (this.selectedSpat == selectedSpat) {
|
||||
return;
|
||||
}
|
||||
if (this.selectedSpat != null) {
|
||||
this.selectedSpat.removePropertyChangeListener(this);
|
||||
this.selectedSpat.removeNodeListener(this);
|
||||
}
|
||||
this.selectedSpat = selectedSpat;
|
||||
if (selectedSpat != null) {
|
||||
selectedSpat.addPropertyChangeListener(this);
|
||||
selectedSpat.addNodeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
public Node getTerrain(Spatial root) {
|
||||
@ -172,6 +190,30 @@ public class TerrainEditorController implements NodeListener {
|
||||
|
||||
return terrainNode;
|
||||
}
|
||||
|
||||
public JmeNode findJmeTerrain(JmeNode root) {
|
||||
if (root == null)
|
||||
root = (JmeNode) jmeRootNode;
|
||||
|
||||
Node node = root.getLookup().lookup(Node.class);
|
||||
if (node != null && node instanceof Terrain && node instanceof Node) {
|
||||
return root;
|
||||
}
|
||||
|
||||
if (node != null) {
|
||||
if (root.getChildren() != null) {
|
||||
for (org.openide.nodes.Node child : root.getChildren().getNodes() ) {
|
||||
if (child instanceof JmeNode) {
|
||||
JmeNode res = findJmeTerrain((JmeNode)child);
|
||||
if (res != null)
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the actual height modification on the terrain.
|
||||
@ -1066,18 +1108,28 @@ public class TerrainEditorController implements NodeListener {
|
||||
setNeedsSave(true);
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
public void propertyChange(PropertyChangeEvent ev) {
|
||||
if (ev.getNewValue() == null && ev.getOldValue() != null) {
|
||||
topComponent.clearTextureTable(); // terrain deleted
|
||||
terrainNode = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void childrenAdded(NodeMemberEvent ev) {
|
||||
//topComponent.reinitTextureTable();
|
||||
boolean isTerrain = false;
|
||||
for(org.openide.nodes.Node n : ev.getSnapshot()) {
|
||||
Node node = n.getLookup().lookup(Node.class);
|
||||
if (node instanceof Terrain) {
|
||||
isTerrain = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isTerrain)
|
||||
topComponent.reinitTextureTable();
|
||||
}
|
||||
|
||||
public void childrenRemoved(NodeMemberEvent ev) {
|
||||
//terrainNode = null;
|
||||
//Node t = getTerrain(rootNode);
|
||||
//if (t == null)
|
||||
// topComponent.reinitTextureTable();
|
||||
|
||||
}
|
||||
|
||||
public void childrenReordered(NodeReorderEvent ev) {
|
||||
|
@ -869,10 +869,11 @@ 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
|
||||
editorController.setSelectedSpat(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
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1150,6 +1151,21 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
|
||||
*/
|
||||
protected void reinitTextureTable() {
|
||||
|
||||
clearTextureTable();
|
||||
|
||||
getTableModel().initModel();
|
||||
|
||||
if (textureTable.getRowCount() > 0) {
|
||||
toolController.setSelectedTextureIndex(0); // select the first row by default
|
||||
} else {
|
||||
toolController.setSelectedTextureIndex(-1);
|
||||
}
|
||||
|
||||
editorController.enableTextureButtons();
|
||||
triPlanarCheckBox.setSelected(editorController.isTriPlanarEnabled());
|
||||
}
|
||||
|
||||
protected void clearTextureTable() {
|
||||
TextureCellRendererEditor rendererTexturer = new TextureCellRendererEditor();
|
||||
textureTable.getColumnModel().getColumn(1).setCellRenderer(rendererTexturer); // diffuse
|
||||
textureTable.getColumnModel().getColumn(1).setCellEditor(rendererTexturer);
|
||||
@ -1165,19 +1181,8 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
|
||||
if (editorController.getTerrain(null) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
getTableModel().initModel();
|
||||
|
||||
if (textureTable.getRowCount() > 0) {
|
||||
toolController.setSelectedTextureIndex(0); // select the first row by default
|
||||
} else {
|
||||
toolController.setSelectedTextureIndex(-1);
|
||||
}
|
||||
|
||||
editorController.enableTextureButtons();
|
||||
triPlanarCheckBox.setSelected(editorController.isTriPlanarEnabled());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds another texture layer to the material, sets a default texture for it.
|
||||
* Assumes that the new index is in the range of the amount of available textures
|
||||
|
Loading…
x
Reference in New Issue
Block a user