diff --git a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/Bundle.properties b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/Bundle.properties
index 5ac2494c0..cc457bbe9 100644
--- a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/Bundle.properties
+++ b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/Bundle.properties
@@ -9,7 +9,6 @@ OpenIDE-Module-Name=Terrain Editor
OpenIDE-Module-Short-Description=Terrain Editor
TerrainEditorTopComponent.createTerrainButton.text=
TerrainEditorTopComponent.raiseTerrainButton.text=
-TerrainEditorTopComponent.lowerTerrainButton.text=
TerrainEditorTopComponent.smoothTerrainButton.text=
TerrainEditorTopComponent.roughTerrainButton.text=
TerrainEditorTopComponent.radiusLabel.text=Radius:
@@ -52,9 +51,7 @@ CreateTerrainVisualPanel2.imageFileChooser.approveButtonToolTipText=Use this hei
CreateTerrainVisualPanel2.imageFileChooser.dialogTitle=Load a heightmap image
TerrainEditorTopComponent.heightLabel.text=Height/Weight:
TerrainEditorTopComponent.raiseTerrainButton.actionCommand=Raise
-TerrainEditorTopComponent.raiseTerrainButton.toolTipText=Raise terrain
-TerrainEditorTopComponent.lowerTerrainButton.toolTipText=Lower terrain
-TerrainEditorTopComponent.lowerTerrainButton.actionCommand=Lower
+TerrainEditorTopComponent.raiseTerrainButton.toolTipText=Raise terrain. RMB to lower
TerrainEditorTopComponent.smoothTerrainButton.toolTipText=Smooth terrain
TerrainEditorTopComponent.smoothTerrainButton.actionCommand=Smooth
TerrainEditorTopComponent.roughTerrainButton.toolTipText=Rough terrain (not implemented)
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 b07ee78a3..a4808ee4f 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
@@ -314,28 +314,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
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 a13000398..b71ece8ec 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
@@ -244,7 +244,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
createTerrainButton = new javax.swing.JButton();
jSeparator1 = new javax.swing.JToolBar.Separator();
raiseTerrainButton = new javax.swing.JToggleButton();
- lowerTerrainButton = new javax.swing.JToggleButton();
smoothTerrainButton = new javax.swing.JToggleButton();
roughTerrainButton = new javax.swing.JToggleButton();
levelTerrainButton = new javax.swing.JToggleButton();
@@ -422,18 +421,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
});
jToolBar1.add(raiseTerrainButton);
- terrainModButtonGroup.add(lowerTerrainButton);
- lowerTerrainButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jme3/gde/terraineditor/icon_terrain-down.png"))); // NOI18N
- org.openide.awt.Mnemonics.setLocalizedText(lowerTerrainButton, org.openide.util.NbBundle.getMessage(TerrainEditorTopComponent.class, "TerrainEditorTopComponent.lowerTerrainButton.text")); // NOI18N
- lowerTerrainButton.setToolTipText(org.openide.util.NbBundle.getMessage(TerrainEditorTopComponent.class, "TerrainEditorTopComponent.lowerTerrainButton.toolTipText")); // NOI18N
- lowerTerrainButton.setActionCommand(org.openide.util.NbBundle.getMessage(TerrainEditorTopComponent.class, "TerrainEditorTopComponent.lowerTerrainButton.actionCommand")); // NOI18N
- lowerTerrainButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- lowerTerrainButtonActionPerformed(evt);
- }
- });
- jToolBar1.add(lowerTerrainButton);
-
terrainModButtonGroup.add(smoothTerrainButton);
smoothTerrainButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jme3/gde/terraineditor/icon_terrain-smooth.png"))); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(smoothTerrainButton, org.openide.util.NbBundle.getMessage(TerrainEditorTopComponent.class, "TerrainEditorTopComponent.smoothTerrainButton.text")); // NOI18N
@@ -729,17 +716,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
}
}//GEN-LAST:event_raiseTerrainButtonActionPerformed
- private void lowerTerrainButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lowerTerrainButtonActionPerformed
- if (lowerTerrainButton.isSelected()) {
- LowerTerrainTool tool = new LowerTerrainTool();
- toolController.setTerrainEditButtonState(tool);
- setHintText(tool);
- } else {
- toolController.setTerrainEditButtonState(null);
- setHintText((TerrainTool) null);
- }
- }//GEN-LAST:event_lowerTerrainButtonActionPerformed
-
private void addTextureButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTextureButtonActionPerformed
if (editorController == null || editorController.getTerrain(null) == null) {
return;
@@ -949,7 +925,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
private javax.swing.JPanel levelBrushPanel;
private javax.swing.JCheckBox levelPrecisionCheckbox;
private javax.swing.JToggleButton levelTerrainButton;
- private javax.swing.JToggleButton lowerTerrainButton;
private javax.swing.JTextField octavesField;
private javax.swing.JPanel paintingPanel;
private javax.swing.JLabel radiusLabel;
diff --git a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/tools/RaiseTerrainTool.java b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/tools/RaiseTerrainTool.java
index 83f897aad..268268b28 100644
--- a/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/tools/RaiseTerrainTool.java
+++ b/sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/tools/RaiseTerrainTool.java
@@ -33,10 +33,18 @@ package com.jme3.gde.terraineditor.tools;
import com.jme3.asset.AssetManager;
import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode;
+import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit;
+import com.jme3.gde.core.undoredo.SceneUndoRedoManager;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
+import com.jme3.terrain.Terrain;
+import java.util.ArrayList;
+import java.util.List;
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
import org.openide.loaders.DataObject;
+import org.openide.util.Lookup;
/**
* Raise the terrain
@@ -45,20 +53,54 @@ import org.openide.loaders.DataObject;
*/
public class RaiseTerrainTool extends TerrainTool {
+ private boolean modifying = false; // to check when undo actions need to be set
+ List actions = new ArrayList();
+
@Override
public void actionPrimary(Vector3f point, int textureIndex, AbstractSceneExplorerNode rootNode, DataObject dataObject) {
- if (radius == 0 || weight == 0)
- return;
- RaiseTerrainToolAction action = new RaiseTerrainToolAction(point, radius, weight, getMesh());
- action.doActionPerformed(rootNode, dataObject);
+ setPrimary(true);
+ action(point, textureIndex, rootNode, dataObject);
}
@Override
public void actionSecondary(Vector3f point, int textureIndex, AbstractSceneExplorerNode rootNode, DataObject dataObject) {
- // no secondary option
+ setPrimary(false);
+ action(point, textureIndex, rootNode, dataObject);
}
+ private void action(Vector3f point, int textureIndex, AbstractSceneExplorerNode rootNode, DataObject dataObject) {
+ if (radius == 0 || weight == 0)
+ return;
+
+ if (!modifying)
+ modifying = true;
+
+ RaiseTerrainToolAction action;
+ if (isPrimary())
+ action = new RaiseTerrainToolAction(point, radius, weight, getMesh());
+ else
+ action = new RaiseTerrainToolAction(point, radius, -weight, getMesh());
+
+ action.doActionPerformed(rootNode, dataObject, false);
+ actions.add(action);
+ }
+
+ @Override
+ public void actionEnded(AbstractSceneExplorerNode rootNode, DataObject dataObject) {
+ if (modifying) {
+ modifying = false;
+
+ if (actions.isEmpty())
+ return;
+
+ // record undo action
+ List cloned = new ArrayList();
+ cloned.addAll(actions);
+ recordUndo(cloned, rootNode, dataObject);
+ actions.clear();
+ }
+ }
@Override
public void addMarkerPrimary(Node parent) {
@@ -66,4 +108,47 @@ public class RaiseTerrainTool extends TerrainTool {
markerPrimary.getMaterial().setColor("Color", ColorRGBA.Green);
}
+ private void recordUndo(final List actions, final AbstractSceneExplorerNode rootNode, final DataObject dataObject) {
+ Lookup lookup = Lookup.getDefault() ;
+ SceneUndoRedoManager manager = lookup.lookup(SceneUndoRedoManager.class);
+
+ AbstractUndoableSceneEdit undoer = new AbstractUndoableSceneEdit() {
+
+ @Override
+ public void sceneUndo() throws CannotUndoException {
+ Terrain terrain = null;
+ for (int i=actions.size()-1; i>=0; i--) {
+ RaiseTerrainToolAction a = actions.get(i);
+ if (terrain == null)
+ terrain = a.getTerrain(rootNode.getLookup().lookup(Node.class));
+ a.doUndoTool(rootNode, terrain);
+ }
+ setModified(rootNode, dataObject);
+ }
+
+ @Override
+ public void sceneRedo() throws CannotRedoException {
+ for (int i=0; i