Added alphamap rename tool to the terrain editor. Removing a texture layer now clears all alpha for that layer
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10838 75d07b2b-3a1a-0410-a2c5-0572b91ccdcaexperimental
parent
a2a39bd0d5
commit
d61ac1afe5
@ -0,0 +1,202 @@ |
|||||||
|
/* |
||||||
|
* To change this template, choose Tools | Templates |
||||||
|
* and open the template in the editor. |
||||||
|
*/ |
||||||
|
package com.jme3.gde.terraineditor; |
||||||
|
|
||||||
|
import com.jme3.asset.TextureKey; |
||||||
|
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.JmeTerrainQuad; |
||||||
|
import com.jme3.gde.core.sceneexplorer.nodes.actions.AbstractToolWizardAction; |
||||||
|
import com.jme3.gde.core.sceneexplorer.nodes.actions.ToolAction; |
||||||
|
import com.jme3.material.MatParam; |
||||||
|
import com.jme3.material.Material; |
||||||
|
import com.jme3.terrain.geomipmap.TerrainQuad; |
||||||
|
import com.jme3.texture.Texture; |
||||||
|
import java.awt.Component; |
||||||
|
import java.io.File; |
||||||
|
import java.io.FileInputStream; |
||||||
|
import java.io.FileOutputStream; |
||||||
|
import java.io.IOException; |
||||||
|
import java.nio.channels.FileChannel; |
||||||
|
import java.text.MessageFormat; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import javax.swing.JComponent; |
||||||
|
import org.openide.DialogDisplayer; |
||||||
|
import org.openide.WizardDescriptor; |
||||||
|
import org.openide.nodes.Node; |
||||||
|
import org.openide.util.Exceptions; |
||||||
|
|
||||||
|
/** |
||||||
|
* Rename the alpha-maps. |
||||||
|
* |
||||||
|
* @author bowens |
||||||
|
*/ |
||||||
|
@org.openide.util.lookup.ServiceProvider(service = ToolAction.class) |
||||||
|
public class RenameTerrainAction extends AbstractToolWizardAction { |
||||||
|
|
||||||
|
private String oldName; |
||||||
|
private String newName; |
||||||
|
|
||||||
|
public RenameTerrainAction() { |
||||||
|
name = "Rename Terrain Alphamaps"; |
||||||
|
} |
||||||
|
|
||||||
|
public Class<?> getNodeClass() { |
||||||
|
return JmeTerrainQuad.class; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected Object showWizard(Node node) { |
||||||
|
AbstractSceneExplorerNode rootNode = (AbstractSceneExplorerNode) node; |
||||||
|
TerrainQuad quad = rootNode.getLookup().lookup(TerrainQuad.class); |
||||||
|
MatParam param = quad.getMaterial().getParam("AlphaMap"); |
||||||
|
if (param == null) |
||||||
|
oldName = null; |
||||||
|
else { |
||||||
|
String[] splita = param.getValueAsString().split("/"); |
||||||
|
String[] split = splita[splita.length-1].split("-alphablend0.png"); |
||||||
|
String first = split[0]; |
||||||
|
oldName = first; |
||||||
|
} |
||||||
|
List<WizardDescriptor.Panel<WizardDescriptor>> panels = new ArrayList<WizardDescriptor.Panel<WizardDescriptor>>(); |
||||||
|
panels.add(new RenameTerrainWizardPanel1()); |
||||||
|
for (int i = 0; i < panels.size(); i++) { |
||||||
|
Component c = panels.get(i).getComponent(); |
||||||
|
if (c instanceof JComponent) { // assume Swing components
|
||||||
|
JComponent jc = (JComponent) c; |
||||||
|
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i); |
||||||
|
jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, true); |
||||||
|
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, true); |
||||||
|
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, true); |
||||||
|
} |
||||||
|
} |
||||||
|
WizardDescriptor wiz = new WizardDescriptor(new WizardDescriptor.ArrayIterator<WizardDescriptor>(panels)); |
||||||
|
// {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
|
||||||
|
wiz.setTitleFormat(new MessageFormat("{0}")); |
||||||
|
wiz.setTitle("Rename the alphamaps of the terrain"); |
||||||
|
wiz.putProperty("oldName", oldName); |
||||||
|
|
||||||
|
if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) { |
||||||
|
return wiz; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected Object doApplyTool(AbstractSceneExplorerNode rootNode, Object settings) { |
||||||
|
WizardDescriptor wiz = (WizardDescriptor) settings; |
||||||
|
if (wiz == null || wiz.getProperties() == null || wiz.getProperties().get("newName") == null) |
||||||
|
return null; |
||||||
|
newName = cleanFileName( wiz.getProperties().get("newName").toString() ); |
||||||
|
if (newName == null) |
||||||
|
return null; |
||||||
|
|
||||||
|
TerrainQuad quad = rootNode.getLookup().lookup(TerrainQuad.class); |
||||||
|
rename(quad, oldName, newName); |
||||||
|
|
||||||
|
return quad; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void doUndoTool(AbstractSceneExplorerNode rootNode, Object undoObject) { |
||||||
|
TerrainQuad quad = rootNode.getLookup().lookup(TerrainQuad.class); |
||||||
|
rename(quad, newName, oldName); |
||||||
|
} |
||||||
|
|
||||||
|
private void rename(TerrainQuad quad, String prevName, String newName) { |
||||||
|
|
||||||
|
ProjectAssetManager manager = (ProjectAssetManager) SceneApplication.getApplication().getAssetManager(); |
||||||
|
String texFolder = "Textures/terrain-alpha/"; |
||||||
|
|
||||||
|
|
||||||
|
// rename the files
|
||||||
|
String texFolderFilePath = manager.getAssetFolderName() +"/"+ texFolder; |
||||||
|
String prevPath0 = texFolderFilePath+prevName+"-alphablend0.png"; |
||||||
|
String prevPath1 = texFolderFilePath+prevName+"-alphablend1.png"; |
||||||
|
String prevPath2 = texFolderFilePath+prevName+"-alphablend2.png"; |
||||||
|
String newPath0 = texFolderFilePath+newName+"-alphablend0.png"; |
||||||
|
String newPath1 = texFolderFilePath+newName+"-alphablend1.png"; |
||||||
|
String newPath2 = texFolderFilePath+newName+"-alphablend2.png"; |
||||||
|
try { |
||||||
|
File f0_a = new File(prevPath0); |
||||||
|
File f0_b = new File(newPath0); |
||||||
|
copyFile(f0_a, f0_b); |
||||||
|
//f0_a.delete();
|
||||||
|
|
||||||
|
File f1_a = new File(prevPath1); |
||||||
|
File f1_b = new File(newPath1); |
||||||
|
copyFile(f1_a, f1_b); |
||||||
|
//f1_a.delete();
|
||||||
|
|
||||||
|
File f2_a = new File(prevPath2); |
||||||
|
File f2_b = new File(newPath2); |
||||||
|
copyFile(f2_a, f2_b); |
||||||
|
//f2_a.delete();
|
||||||
|
} catch (IOException ex) { |
||||||
|
Exceptions.printStackTrace(ex); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
// set the new mat params
|
||||||
|
String alphaPath0 = texFolder+newName+"-alphablend0.png"; |
||||||
|
String alphaPath1 = texFolder+newName+"-alphablend1.png"; |
||||||
|
String alphaPath2 = texFolder+newName+"-alphablend2.png"; |
||||||
|
|
||||||
|
TextureKey tk0 = (TextureKey) manager.loadTexture(texFolder+prevName+"-alphablend0.png").getKey(); |
||||||
|
TextureKey tk1 = (TextureKey) manager.loadTexture(texFolder+prevName+"-alphablend1.png").getKey(); |
||||||
|
TextureKey tk2 = (TextureKey) manager.loadTexture(texFolder+prevName+"-alphablend2.png").getKey(); |
||||||
|
|
||||||
|
Texture tex0 = manager.loadTexture(cloneKeyParams(tk0, alphaPath0) ); |
||||||
|
Texture tex1 = manager.loadTexture(cloneKeyParams(tk1, alphaPath1) ); |
||||||
|
Texture tex2 = manager.loadTexture(cloneKeyParams(tk2, alphaPath2) ); |
||||||
|
|
||||||
|
Material material = quad.getMaterial(); |
||||||
|
material.setTexture("AlphaMap", tex0); |
||||||
|
material.setTexture("AlphaMap_1", tex1); |
||||||
|
material.setTexture("AlphaMap_2", tex2); |
||||||
|
} |
||||||
|
|
||||||
|
private void copyFile(File sourceFile, File destFile) throws IOException { |
||||||
|
if(!destFile.exists()) { |
||||||
|
destFile.createNewFile(); |
||||||
|
} |
||||||
|
|
||||||
|
FileChannel source = null; |
||||||
|
FileChannel destination = null; |
||||||
|
|
||||||
|
try { |
||||||
|
source = new FileInputStream(sourceFile).getChannel(); |
||||||
|
destination = new FileOutputStream(destFile).getChannel(); |
||||||
|
destination.transferFrom(source, 0, source.size()); |
||||||
|
} |
||||||
|
finally { |
||||||
|
if(source != null) { |
||||||
|
source.close(); |
||||||
|
} |
||||||
|
if(destination != null) { |
||||||
|
destination.close(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private String cleanFileName(String name) { |
||||||
|
if (name == null) |
||||||
|
return null; |
||||||
|
|
||||||
|
return name.replaceAll("[\\W]|_", ""); |
||||||
|
} |
||||||
|
|
||||||
|
private TextureKey cloneKeyParams(TextureKey tkOrig, String path) { |
||||||
|
TextureKey tk = new TextureKey(path, false); |
||||||
|
tk.setAnisotropy(tkOrig.getAnisotropy()); |
||||||
|
tk.setAsCube(tkOrig.isAsCube()); |
||||||
|
tk.setAsTexture3D(tkOrig.isAsTexture3D()); |
||||||
|
tk.setGenerateMips(tkOrig.isGenerateMips()); |
||||||
|
tk.setTextureTypeHint(tkOrig.getTextureTypeHint()); |
||||||
|
return tk; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,74 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?> |
||||||
|
|
||||||
|
<Form version="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> |
||||||
|
<AuxValues> |
||||||
|
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/> |
||||||
|
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> |
||||||
|
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> |
||||||
|
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/> |
||||||
|
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/> |
||||||
|
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> |
||||||
|
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> |
||||||
|
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> |
||||||
|
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> |
||||||
|
</AuxValues> |
||||||
|
|
||||||
|
<Layout> |
||||||
|
<DimensionLayout dim="0"> |
||||||
|
<Group type="103" groupAlignment="0" attributes="0"> |
||||||
|
<Group type="102" alignment="0" attributes="0"> |
||||||
|
<EmptySpace max="-2" attributes="0"/> |
||||||
|
<Group type="103" groupAlignment="0" attributes="0"> |
||||||
|
<Component id="jLabel1" max="32767" attributes="0"/> |
||||||
|
<Group type="102" attributes="0"> |
||||||
|
<Component id="ranemeLabel" min="-2" pref="139" max="-2" attributes="0"/> |
||||||
|
<EmptySpace max="-2" attributes="0"/> |
||||||
|
<Component id="renameField" min="-2" pref="193" max="-2" attributes="0"/> |
||||||
|
<EmptySpace min="0" pref="0" max="32767" attributes="0"/> |
||||||
|
</Group> |
||||||
|
</Group> |
||||||
|
<EmptySpace max="-2" attributes="0"/> |
||||||
|
</Group> |
||||||
|
</Group> |
||||||
|
</DimensionLayout> |
||||||
|
<DimensionLayout dim="1"> |
||||||
|
<Group type="103" groupAlignment="0" attributes="0"> |
||||||
|
<Group type="102" alignment="0" attributes="0"> |
||||||
|
<EmptySpace max="-2" attributes="0"/> |
||||||
|
<Group type="103" groupAlignment="3" attributes="0"> |
||||||
|
<Component id="ranemeLabel" alignment="3" min="-2" max="-2" attributes="0"/> |
||||||
|
<Component id="renameField" alignment="3" min="-2" max="-2" attributes="0"/> |
||||||
|
</Group> |
||||||
|
<EmptySpace pref="26" max="32767" attributes="0"/> |
||||||
|
<Component id="jLabel1" min="-2" pref="14" max="-2" attributes="0"/> |
||||||
|
</Group> |
||||||
|
</Group> |
||||||
|
</DimensionLayout> |
||||||
|
</Layout> |
||||||
|
<SubComponents> |
||||||
|
<Component class="javax.swing.JLabel" name="ranemeLabel"> |
||||||
|
<Properties> |
||||||
|
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> |
||||||
|
<ResourceString bundle="com/jme3/gde/terraineditor/Bundle.properties" key="RenameTerrainVisualPanel1.ranemeLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> |
||||||
|
</Property> |
||||||
|
</Properties> |
||||||
|
</Component> |
||||||
|
<Component class="javax.swing.JTextField" name="renameField"> |
||||||
|
<Properties> |
||||||
|
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> |
||||||
|
<ResourceString bundle="com/jme3/gde/terraineditor/Bundle.properties" key="RenameTerrainVisualPanel1.renameField.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> |
||||||
|
</Property> |
||||||
|
</Properties> |
||||||
|
<Events> |
||||||
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="renameFieldActionPerformed"/> |
||||||
|
</Events> |
||||||
|
</Component> |
||||||
|
<Component class="javax.swing.JLabel" name="jLabel1"> |
||||||
|
<Properties> |
||||||
|
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> |
||||||
|
<ResourceString bundle="com/jme3/gde/terraineditor/Bundle.properties" key="RenameTerrainVisualPanel1.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> |
||||||
|
</Property> |
||||||
|
</Properties> |
||||||
|
</Component> |
||||||
|
</SubComponents> |
||||||
|
</Form> |
@ -0,0 +1,92 @@ |
|||||||
|
/* |
||||||
|
* To change this template, choose Tools | Templates |
||||||
|
* and open the template in the editor. |
||||||
|
*/ |
||||||
|
package com.jme3.gde.terraineditor; |
||||||
|
|
||||||
|
import javax.swing.JPanel; |
||||||
|
|
||||||
|
public final class RenameTerrainVisualPanel1 extends JPanel { |
||||||
|
|
||||||
|
/** |
||||||
|
* Creates new form RenameTerrainVisualPanel1 |
||||||
|
*/ |
||||||
|
public RenameTerrainVisualPanel1() { |
||||||
|
initComponents(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getName() { |
||||||
|
return "Rename Alphamaps"; |
||||||
|
} |
||||||
|
|
||||||
|
public String getRenamed() { |
||||||
|
return renameField.getText(); |
||||||
|
} |
||||||
|
|
||||||
|
void setOriginalName(String name) { |
||||||
|
renameField.setText(name); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* This method is called from within the constructor to initialize the form. |
||||||
|
* WARNING: Do NOT modify this code. The content of this method is always |
||||||
|
* regenerated by the Form Editor. |
||||||
|
*/ |
||||||
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||||
|
private void initComponents() { |
||||||
|
|
||||||
|
ranemeLabel = new javax.swing.JLabel(); |
||||||
|
renameField = new javax.swing.JTextField(); |
||||||
|
jLabel1 = new javax.swing.JLabel(); |
||||||
|
|
||||||
|
org.openide.awt.Mnemonics.setLocalizedText(ranemeLabel, org.openide.util.NbBundle.getMessage(RenameTerrainVisualPanel1.class, "RenameTerrainVisualPanel1.ranemeLabel.text")); // NOI18N
|
||||||
|
|
||||||
|
renameField.setText(org.openide.util.NbBundle.getMessage(RenameTerrainVisualPanel1.class, "RenameTerrainVisualPanel1.renameField.text")); // NOI18N
|
||||||
|
renameField.addActionListener(new java.awt.event.ActionListener() { |
||||||
|
public void actionPerformed(java.awt.event.ActionEvent evt) { |
||||||
|
renameFieldActionPerformed(evt); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(RenameTerrainVisualPanel1.class, "RenameTerrainVisualPanel1.jLabel1.text")); // NOI18N
|
||||||
|
|
||||||
|
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); |
||||||
|
this.setLayout(layout); |
||||||
|
layout.setHorizontalGroup( |
||||||
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
||||||
|
.addGroup(layout.createSequentialGroup() |
||||||
|
.addContainerGap() |
||||||
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
||||||
|
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) |
||||||
|
.addGroup(layout.createSequentialGroup() |
||||||
|
.addComponent(ranemeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE) |
||||||
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
||||||
|
.addComponent(renameField, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE) |
||||||
|
.addGap(0, 0, Short.MAX_VALUE))) |
||||||
|
.addContainerGap()) |
||||||
|
); |
||||||
|
layout.setVerticalGroup( |
||||||
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
||||||
|
.addGroup(layout.createSequentialGroup() |
||||||
|
.addContainerGap() |
||||||
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) |
||||||
|
.addComponent(ranemeLabel) |
||||||
|
.addComponent(renameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) |
||||||
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE) |
||||||
|
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)) |
||||||
|
); |
||||||
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
|
|
||||||
|
private void renameFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_renameFieldActionPerformed
|
||||||
|
// TODO add your handling code here:
|
||||||
|
}//GEN-LAST:event_renameFieldActionPerformed
|
||||||
|
|
||||||
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
|
private javax.swing.JLabel jLabel1; |
||||||
|
private javax.swing.JLabel ranemeLabel; |
||||||
|
private javax.swing.JTextField renameField; |
||||||
|
// End of variables declaration//GEN-END:variables
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
/* |
||||||
|
* To change this template, choose Tools | Templates |
||||||
|
* and open the template in the editor. |
||||||
|
*/ |
||||||
|
package com.jme3.gde.terraineditor; |
||||||
|
|
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
import java.awt.event.ActionListener; |
||||||
|
import java.text.MessageFormat; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import javax.swing.JComponent; |
||||||
|
import org.openide.DialogDisplayer; |
||||||
|
import org.openide.WizardDescriptor; |
||||||
|
|
||||||
|
// An example action demonstrating how the wizard could be called from within
|
||||||
|
// your code. You can move the code below wherever you need, or register an action:
|
||||||
|
// @ActionID(category="...", id="com.jme3.gde.terraineditor.RenameTerrainWizardAction")
|
||||||
|
// @ActionRegistration(displayName="Open RenameTerrain Wizard")
|
||||||
|
// @ActionReference(path="Menu/Tools", position=...)
|
||||||
|
public final class RenameTerrainWizardAction implements ActionListener { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
List<WizardDescriptor.Panel<WizardDescriptor>> panels = new ArrayList<WizardDescriptor.Panel<WizardDescriptor>>(); |
||||||
|
panels.add(new RenameTerrainWizardPanel1()); |
||||||
|
String[] steps = new String[panels.size()]; |
||||||
|
for (int i = 0; i < panels.size(); i++) { |
||||||
|
Component c = panels.get(i).getComponent(); |
||||||
|
// Default step name to component name of panel.
|
||||||
|
steps[i] = c.getName(); |
||||||
|
if (c instanceof JComponent) { // assume Swing components
|
||||||
|
JComponent jc = (JComponent) c; |
||||||
|
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i); |
||||||
|
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps); |
||||||
|
jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, true); |
||||||
|
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, true); |
||||||
|
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, true); |
||||||
|
} |
||||||
|
} |
||||||
|
WizardDescriptor wiz = new WizardDescriptor(new WizardDescriptor.ArrayIterator<WizardDescriptor>(panels)); |
||||||
|
// {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
|
||||||
|
wiz.setTitleFormat(new MessageFormat("{0}")); |
||||||
|
wiz.setTitle("...dialog title..."); |
||||||
|
if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) { |
||||||
|
// do something
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,70 @@ |
|||||||
|
/* |
||||||
|
* To change this template, choose Tools | Templates |
||||||
|
* and open the template in the editor. |
||||||
|
*/ |
||||||
|
package com.jme3.gde.terraineditor; |
||||||
|
|
||||||
|
import javax.swing.event.ChangeListener; |
||||||
|
import org.openide.WizardDescriptor; |
||||||
|
import org.openide.util.HelpCtx; |
||||||
|
|
||||||
|
public class RenameTerrainWizardPanel1 implements WizardDescriptor.Panel<WizardDescriptor> { |
||||||
|
|
||||||
|
/** |
||||||
|
* The visual component that displays this panel. If you need to access the |
||||||
|
* component from this class, just use getComponent(). |
||||||
|
*/ |
||||||
|
private RenameTerrainVisualPanel1 component; |
||||||
|
|
||||||
|
// Get the visual component for the panel. In this template, the component
|
||||||
|
// is kept separate. This can be more efficient: if the wizard is created
|
||||||
|
// but never displayed, or not all panels are displayed, it is better to
|
||||||
|
// create only those which really need to be visible.
|
||||||
|
@Override |
||||||
|
public RenameTerrainVisualPanel1 getComponent() { |
||||||
|
if (component == null) { |
||||||
|
component = new RenameTerrainVisualPanel1(); |
||||||
|
} |
||||||
|
return component; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public HelpCtx getHelp() { |
||||||
|
// Show no Help button for this panel:
|
||||||
|
return HelpCtx.DEFAULT_HELP; |
||||||
|
// If you have context help:
|
||||||
|
// return new HelpCtx("help.key.here");
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isValid() { |
||||||
|
// If it is always OK to press Next or Finish, then:
|
||||||
|
return true; |
||||||
|
// If it depends on some condition (form filled out...) and
|
||||||
|
// this condition changes (last form field filled in...) then
|
||||||
|
// use ChangeSupport to implement add/removeChangeListener below.
|
||||||
|
// WizardDescriptor.ERROR/WARNING/INFORMATION_MESSAGE will also be useful.
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void addChangeListener(ChangeListener l) { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void removeChangeListener(ChangeListener l) { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void readSettings(WizardDescriptor wiz) { |
||||||
|
RenameTerrainVisualPanel1 comp = (RenameTerrainVisualPanel1) getComponent(); |
||||||
|
String name = wiz.getProperty("oldName").toString(); |
||||||
|
comp.setOriginalName(name); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void storeSettings(WizardDescriptor wiz) { |
||||||
|
RenameTerrainVisualPanel1 comp = (RenameTerrainVisualPanel1) getComponent(); |
||||||
|
String name = comp.getRenamed(); |
||||||
|
wiz.putProperty("newName", name ); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue