terrain height tool remembers undo history as an entire mouseDown event now. RMB now erases

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10474 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
bre..om 12 years ago
parent ef700eff19
commit 3079ca689f
  1. 5
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/Bundle.properties
  2. 22
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.form
  3. 25
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.java
  4. 95
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/tools/RaiseTerrainTool.java
  5. 4
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/tools/RaiseTerrainToolAction.java

@ -9,7 +9,6 @@ OpenIDE-Module-Name=Terrain Editor
OpenIDE-Module-Short-Description=Terrain Editor OpenIDE-Module-Short-Description=Terrain Editor
TerrainEditorTopComponent.createTerrainButton.text= TerrainEditorTopComponent.createTerrainButton.text=
TerrainEditorTopComponent.raiseTerrainButton.text= TerrainEditorTopComponent.raiseTerrainButton.text=
TerrainEditorTopComponent.lowerTerrainButton.text=
TerrainEditorTopComponent.smoothTerrainButton.text= TerrainEditorTopComponent.smoothTerrainButton.text=
TerrainEditorTopComponent.roughTerrainButton.text= TerrainEditorTopComponent.roughTerrainButton.text=
TerrainEditorTopComponent.radiusLabel.text=Radius: TerrainEditorTopComponent.radiusLabel.text=Radius:
@ -52,9 +51,7 @@ CreateTerrainVisualPanel2.imageFileChooser.approveButtonToolTipText=Use this hei
CreateTerrainVisualPanel2.imageFileChooser.dialogTitle=Load a heightmap image CreateTerrainVisualPanel2.imageFileChooser.dialogTitle=Load a heightmap image
TerrainEditorTopComponent.heightLabel.text=Height/Weight: TerrainEditorTopComponent.heightLabel.text=Height/Weight:
TerrainEditorTopComponent.raiseTerrainButton.actionCommand=Raise TerrainEditorTopComponent.raiseTerrainButton.actionCommand=Raise
TerrainEditorTopComponent.raiseTerrainButton.toolTipText=Raise terrain TerrainEditorTopComponent.raiseTerrainButton.toolTipText=Raise terrain. RMB to lower
TerrainEditorTopComponent.lowerTerrainButton.toolTipText=Lower terrain
TerrainEditorTopComponent.lowerTerrainButton.actionCommand=Lower
TerrainEditorTopComponent.smoothTerrainButton.toolTipText=Smooth terrain TerrainEditorTopComponent.smoothTerrainButton.toolTipText=Smooth terrain
TerrainEditorTopComponent.smoothTerrainButton.actionCommand=Smooth TerrainEditorTopComponent.smoothTerrainButton.actionCommand=Smooth
TerrainEditorTopComponent.roughTerrainButton.toolTipText=Rough terrain (not implemented) TerrainEditorTopComponent.roughTerrainButton.toolTipText=Rough terrain (not implemented)

@ -314,28 +314,6 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="raiseTerrainButtonActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="raiseTerrainButtonActionPerformed"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JToggleButton" name="lowerTerrainButton">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="terrainModButtonGroup"/>
</Property>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/com/jme3/gde/terraineditor/icon_terrain-down.png"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/terraineditor/Bundle.properties" key="TerrainEditorTopComponent.lowerTerrainButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/terraineditor/Bundle.properties" key="TerrainEditorTopComponent.lowerTerrainButton.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="actionCommand" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/terraineditor/Bundle.properties" key="TerrainEditorTopComponent.lowerTerrainButton.actionCommand" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="lowerTerrainButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JToggleButton" name="smoothTerrainButton"> <Component class="javax.swing.JToggleButton" name="smoothTerrainButton">
<Properties> <Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor"> <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">

@ -244,7 +244,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
createTerrainButton = new javax.swing.JButton(); createTerrainButton = new javax.swing.JButton();
jSeparator1 = new javax.swing.JToolBar.Separator(); jSeparator1 = new javax.swing.JToolBar.Separator();
raiseTerrainButton = new javax.swing.JToggleButton(); raiseTerrainButton = new javax.swing.JToggleButton();
lowerTerrainButton = new javax.swing.JToggleButton();
smoothTerrainButton = new javax.swing.JToggleButton(); smoothTerrainButton = new javax.swing.JToggleButton();
roughTerrainButton = new javax.swing.JToggleButton(); roughTerrainButton = new javax.swing.JToggleButton();
levelTerrainButton = new javax.swing.JToggleButton(); levelTerrainButton = new javax.swing.JToggleButton();
@ -422,18 +421,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
}); });
jToolBar1.add(raiseTerrainButton); 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); terrainModButtonGroup.add(smoothTerrainButton);
smoothTerrainButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jme3/gde/terraineditor/icon_terrain-smooth.png"))); // NOI18N 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 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 }//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 private void addTextureButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTextureButtonActionPerformed
if (editorController == null || editorController.getTerrain(null) == null) { if (editorController == null || editorController.getTerrain(null) == null) {
return; return;
@ -949,7 +925,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
private javax.swing.JPanel levelBrushPanel; private javax.swing.JPanel levelBrushPanel;
private javax.swing.JCheckBox levelPrecisionCheckbox; private javax.swing.JCheckBox levelPrecisionCheckbox;
private javax.swing.JToggleButton levelTerrainButton; private javax.swing.JToggleButton levelTerrainButton;
private javax.swing.JToggleButton lowerTerrainButton;
private javax.swing.JTextField octavesField; private javax.swing.JTextField octavesField;
private javax.swing.JPanel paintingPanel; private javax.swing.JPanel paintingPanel;
private javax.swing.JLabel radiusLabel; private javax.swing.JLabel radiusLabel;

@ -33,10 +33,18 @@ package com.jme3.gde.terraineditor.tools;
import com.jme3.asset.AssetManager; import com.jme3.asset.AssetManager;
import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode; 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.ColorRGBA;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.Node; 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.loaders.DataObject;
import org.openide.util.Lookup;
/** /**
* Raise the terrain * Raise the terrain
@ -45,20 +53,54 @@ import org.openide.loaders.DataObject;
*/ */
public class RaiseTerrainTool extends TerrainTool { public class RaiseTerrainTool extends TerrainTool {
private boolean modifying = false; // to check when undo actions need to be set
List<RaiseTerrainToolAction> actions = new ArrayList<RaiseTerrainToolAction>();
@Override @Override
public void actionPrimary(Vector3f point, int textureIndex, AbstractSceneExplorerNode rootNode, DataObject dataObject) { public void actionPrimary(Vector3f point, int textureIndex, AbstractSceneExplorerNode rootNode, DataObject dataObject) {
if (radius == 0 || weight == 0) setPrimary(true);
return; action(point, textureIndex, rootNode, dataObject);
RaiseTerrainToolAction action = new RaiseTerrainToolAction(point, radius, weight, getMesh());
action.doActionPerformed(rootNode, dataObject);
} }
@Override @Override
public void actionSecondary(Vector3f point, int textureIndex, AbstractSceneExplorerNode rootNode, DataObject dataObject) { 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<RaiseTerrainToolAction> cloned = new ArrayList<RaiseTerrainToolAction>();
cloned.addAll(actions);
recordUndo(cloned, rootNode, dataObject);
actions.clear();
}
}
@Override @Override
public void addMarkerPrimary(Node parent) { public void addMarkerPrimary(Node parent) {
@ -66,4 +108,47 @@ public class RaiseTerrainTool extends TerrainTool {
markerPrimary.getMaterial().setColor("Color", ColorRGBA.Green); markerPrimary.getMaterial().setColor("Color", ColorRGBA.Green);
} }
private void recordUndo(final List<RaiseTerrainToolAction> 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<actions.size(); i++) {
RaiseTerrainToolAction a = actions.get(i);
a.applyTool(rootNode);
}
setModified(rootNode, dataObject);
}
};
if (manager != null) // this is a temporary check, it should never be null but occasionally is
manager.addEdit(this, undoer);
}
protected void setModified(final AbstractSceneExplorerNode rootNode, final DataObject dataObject) {
if (dataObject.isModified())
return;
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
dataObject.setModified(true);
rootNode.refresh(true);
}
});
}
} }

@ -61,6 +61,10 @@ public class RaiseTerrainToolAction extends AbstractTerrainToolAction {
name = "Raise terrain"; name = "Raise terrain";
} }
public Object applyTool(AbstractSceneExplorerNode rootNode) {
return doApplyTool(rootNode);
}
@Override @Override
protected Object doApplyTool(AbstractSceneExplorerNode rootNode) { protected Object doApplyTool(AbstractSceneExplorerNode rootNode) {
Terrain terrain = getTerrain(rootNode.getLookup().lookup(Node.class)); Terrain terrain = getTerrain(rootNode.getLookup().lookup(Node.class));

Loading…
Cancel
Save