- Add way to store packed textures to png files when creating j3m files git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10122 75d07b2b-3a1a-0410-a2c5-0572b91ccdca3.0
parent
9b1e2819a9
commit
7b46639a4c
@ -0,0 +1,2 @@ |
||||
StoreTextureWizardVisualPanel1.jTextField1.text= |
||||
StoreTextureWizardVisualPanel1.jLabel1.text=Save asset to: |
@ -0,0 +1,57 @@ |
||||
<?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" attributes="0"> |
||||
<EmptySpace max="-2" attributes="0"/> |
||||
<Group type="103" groupAlignment="0" attributes="0"> |
||||
<Component id="jLabel1" pref="388" max="32767" attributes="0"/> |
||||
<Component id="jTextField1" max="32767" attributes="0"/> |
||||
</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"/> |
||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/> |
||||
<EmptySpace max="-2" attributes="0"/> |
||||
<Component id="jTextField1" min="-2" max="-2" attributes="0"/> |
||||
<EmptySpace pref="244" max="32767" attributes="0"/> |
||||
</Group> |
||||
</Group> |
||||
</DimensionLayout> |
||||
</Layout> |
||||
<SubComponents> |
||||
<Component class="javax.swing.JTextField" name="jTextField1"> |
||||
<Properties> |
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> |
||||
<ResourceString bundle="com/jme3/gde/materials/wizards/Bundle.properties" key="StoreTextureWizardVisualPanel1.jTextField1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> |
||||
</Property> |
||||
</Properties> |
||||
</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/materials/wizards/Bundle.properties" key="StoreTextureWizardVisualPanel1.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> |
||||
</Property> |
||||
</Properties> |
||||
</Component> |
||||
</SubComponents> |
||||
</Form> |
@ -0,0 +1,71 @@ |
||||
/* |
||||
* To change this template, choose Tools | Templates |
||||
* and open the template in the editor. |
||||
*/ |
||||
package com.jme3.gde.materials.wizards; |
||||
|
||||
import javax.swing.JPanel; |
||||
|
||||
public final class StoreTextureWizardVisualPanel1 extends JPanel { |
||||
|
||||
/** |
||||
* Creates new form StoreTextureWizardVisualPanel1 |
||||
*/ |
||||
public StoreTextureWizardVisualPanel1() { |
||||
initComponents(); |
||||
} |
||||
|
||||
@Override |
||||
public String getName() { |
||||
return "Set storage path"; |
||||
} |
||||
|
||||
public void setPath(String path){ |
||||
jTextField1.setText(path); |
||||
} |
||||
|
||||
public String getPath(){ |
||||
return jTextField1.getText(); |
||||
} |
||||
|
||||
/** |
||||
* 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() { |
||||
|
||||
jTextField1 = new javax.swing.JTextField(); |
||||
jLabel1 = new javax.swing.JLabel(); |
||||
|
||||
jTextField1.setText(org.openide.util.NbBundle.getMessage(StoreTextureWizardVisualPanel1.class, "StoreTextureWizardVisualPanel1.jTextField1.text")); // NOI18N
|
||||
|
||||
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(StoreTextureWizardVisualPanel1.class, "StoreTextureWizardVisualPanel1.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, 388, Short.MAX_VALUE) |
||||
.addComponent(jTextField1)) |
||||
.addContainerGap()) |
||||
); |
||||
layout.setVerticalGroup( |
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
||||
.addGroup(layout.createSequentialGroup() |
||||
.addContainerGap() |
||||
.addComponent(jLabel1) |
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
||||
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) |
||||
.addContainerGap(244, Short.MAX_VALUE)) |
||||
); |
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JLabel jLabel1; |
||||
private javax.swing.JTextField jTextField1; |
||||
// End of variables declaration//GEN-END:variables
|
||||
} |
@ -0,0 +1,119 @@ |
||||
/* |
||||
* To change this template, choose Tools | Templates |
||||
* and open the template in the editor. |
||||
*/ |
||||
package com.jme3.gde.materials.wizards; |
||||
|
||||
import com.jme3.gde.core.assets.ProjectAssetManager; |
||||
import java.awt.Component; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.io.BufferedOutputStream; |
||||
import java.io.IOException; |
||||
import java.io.OutputStream; |
||||
import java.text.MessageFormat; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import javax.swing.JComponent; |
||||
import org.openide.DialogDisplayer; |
||||
import org.openide.NotifyDescriptor; |
||||
import org.openide.WizardDescriptor; |
||||
import org.openide.filesystems.FileObject; |
||||
import org.openide.filesystems.FileUtil; |
||||
import org.openide.util.Exceptions; |
||||
|
||||
// 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.materials.wizards.StoreTextureWizardWizardAction")
|
||||
// @ActionRegistration(displayName="Open StoreTextureWizard Wizard")
|
||||
// @ActionReference(path="Menu/Tools", position=...)
|
||||
public final class StoreTextureWizardWizardAction implements ActionListener { |
||||
|
||||
private final ProjectAssetManager mgr; |
||||
private byte[] data; |
||||
private String name; |
||||
|
||||
public StoreTextureWizardWizardAction(ProjectAssetManager mgr, byte[] data, String name) { |
||||
this.mgr = mgr; |
||||
this.data = data; |
||||
this.name = name; |
||||
} |
||||
|
||||
public StoreTextureWizardWizardAction(ProjectAssetManager mgr, byte[] data) { |
||||
this.mgr = mgr; |
||||
this.data = data; |
||||
} |
||||
|
||||
public StoreTextureWizardWizardAction(ProjectAssetManager mgr) { |
||||
this.mgr = mgr; |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
if (mgr == null) { |
||||
return; |
||||
} |
||||
List<WizardDescriptor.Panel<WizardDescriptor>> panels = new ArrayList<WizardDescriptor.Panel<WizardDescriptor>>(); |
||||
panels.add(new StoreTextureWizardWizardPanel1()); |
||||
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)); |
||||
if (name != null) { |
||||
wiz.putProperty("path", name); |
||||
} else { |
||||
wiz.putProperty("path", "Textures/MyTexture.png"); |
||||
} |
||||
// {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
|
||||
wiz.setTitleFormat(new MessageFormat("{0}")); |
||||
wiz.setTitle("Save texture as.."); |
||||
if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) { |
||||
String path = (String) wiz.getProperties().get("path"); |
||||
if (path != null) { |
||||
name = path; |
||||
OutputStream out = null; |
||||
try { |
||||
FileObject file = mgr.getAssetFolder().getFileObject(path); |
||||
if (file != null) { |
||||
NotifyDescriptor.Confirmation mesg = new NotifyDescriptor.Confirmation("File exists, overwrite?", |
||||
"File Exists", |
||||
NotifyDescriptor.YES_NO_OPTION); |
||||
DialogDisplayer.getDefault().notify(mesg); |
||||
if (mesg.getValue() != NotifyDescriptor.Confirmation.YES_OPTION) { |
||||
return; |
||||
} |
||||
} |
||||
file = FileUtil.createData(mgr.getAssetFolder(), path); |
||||
out = new BufferedOutputStream(file.getOutputStream()); |
||||
out.write(data); |
||||
} catch (IOException ex) { |
||||
DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message("Failed to create data!\n" + ex)); |
||||
Exceptions.printStackTrace(ex); |
||||
} finally { |
||||
if (out != null) { |
||||
try { |
||||
out.close(); |
||||
} catch (IOException ex) { |
||||
Exceptions.printStackTrace(ex); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
} |
@ -0,0 +1,66 @@ |
||||
/* |
||||
* To change this template, choose Tools | Templates |
||||
* and open the template in the editor. |
||||
*/ |
||||
package com.jme3.gde.materials.wizards; |
||||
|
||||
import javax.swing.event.ChangeListener; |
||||
import org.openide.WizardDescriptor; |
||||
import org.openide.util.HelpCtx; |
||||
|
||||
public class StoreTextureWizardWizardPanel1 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 StoreTextureWizardVisualPanel1 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 StoreTextureWizardVisualPanel1 getComponent() { |
||||
if (component == null) { |
||||
component = new StoreTextureWizardVisualPanel1(); |
||||
} |
||||
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) { |
||||
component.setPath((String)wiz.getProperty("path")); |
||||
} |
||||
|
||||
@Override |
||||
public void storeSettings(WizardDescriptor wiz) { |
||||
wiz.putProperty("path", component.getPath()); |
||||
} |
||||
} |
Loading…
Reference in new issue