- add project selection in AssetPack "add to project" for unclear situations

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7808 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 14 years ago
parent 324750e4aa
commit a4f1eb8b2c
  1. 29
      sdk/jme3-assetpack-support/src/com/jme3/gde/assetpack/AssetPackLoader.java
  2. 5
      sdk/jme3-assetpack-support/src/com/jme3/gde/assetpack/actions/AddAssetAction.java
  3. 8
      sdk/jme3-assetpack-support/src/com/jme3/gde/assetpack/actions/AddToProjectAction.java
  4. 1
      sdk/jme3-assetpack-support/src/com/jme3/gde/assetpack/actions/Bundle.properties
  5. 69
      sdk/jme3-assetpack-support/src/com/jme3/gde/assetpack/actions/ProjectSelection.form
  6. 135
      sdk/jme3-assetpack-support/src/com/jme3/gde/assetpack/actions/ProjectSelection.java

@ -310,14 +310,11 @@ public class AssetPackLoader {
return description; return description;
} }
public static void addAllFiles(ProjectAssetManager pm, AssetConfiguration config) { public static void addAllFiles(ProjectAssetManager source, ProjectAssetManager dest, AssetConfiguration config) {
Element assetElement = config.getAssetElement(); Element assetElement = config.getAssetElement();
NodeList list = assetElement.getElementsByTagName("file"); NodeList list = assetElement.getElementsByTagName("file");
ProjectAssetManager proman = null;
try { try {
//TODO:not good if (dest == null) {
proman = SceneApplication.getApplication().getCurrentSceneRequest().getManager();
if (proman == null) {
Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not get project asset manager!"); Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not get project asset manager!");
return; return;
} }
@ -328,13 +325,13 @@ public class AssetPackLoader {
for (int i = 0; i < list.getLength(); i++) { for (int i = 0; i < list.getLength(); i++) {
Element fileElem = (Element) list.item(i); Element fileElem = (Element) list.item(i);
try { try {
String src = pm.getAbsoluteAssetPath(fileElem.getAttribute("path")); String src = source.getAbsoluteAssetPath(fileElem.getAttribute("path"));
if (src == null) { if (src == null) {
Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not find texture with manager!"); Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not find texture with manager!");
return; return;
} }
FileObject srcFile = FileUtil.toFileObject(new File(src)); FileObject srcFile = FileUtil.toFileObject(new File(src));
String destName = proman.getAssetFolderName() + "/" + fileElem.getAttribute("path"); String destName = dest.getAssetFolderName() + "/" + fileElem.getAttribute("path");
String destFolder = destName.replace("\\", "/"); String destFolder = destName.replace("\\", "/");
destFolder = destFolder.substring(0, destFolder.lastIndexOf("/")); destFolder = destFolder.substring(0, destFolder.lastIndexOf("/"));
FileObject folder = FileUtil.createFolder(new File(destFolder)); FileObject folder = FileUtil.createFolder(new File(destFolder));
@ -346,14 +343,11 @@ public class AssetPackLoader {
return; return;
} }
public static void addModelFiles(ProjectAssetManager pm, AssetConfiguration config) { public static void addModelFiles(ProjectAssetManager source, ProjectAssetManager dest, AssetConfiguration config) {
Element assetElement = config.getAssetElement(); Element assetElement = config.getAssetElement();
NodeList fileNodeList = assetElement.getElementsByTagName("file"); NodeList fileNodeList = assetElement.getElementsByTagName("file");
ProjectAssetManager currentProjectAssetManager = null;
try { try {
//TODO:not good if (dest == null) {
currentProjectAssetManager = SceneApplication.getApplication().getCurrentSceneRequest().getManager();
if (currentProjectAssetManager == null) {
Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not get project asset manager!"); Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not get project asset manager!");
return; return;
} }
@ -366,13 +360,13 @@ public class AssetPackLoader {
String type = fileElem.getAttribute("type"); String type = fileElem.getAttribute("type");
if ("texture".equals(type) || "sound".equals(type) || "materialdef".equals(type) || "shader".equals(type) || "other".equals(type)) { if ("texture".equals(type) || "sound".equals(type) || "materialdef".equals(type) || "shader".equals(type) || "other".equals(type)) {
try { try {
String src = pm.getAbsoluteAssetPath(fileElem.getAttribute("path")); String src = source.getAbsoluteAssetPath(fileElem.getAttribute("path"));
if (src == null) { if (src == null) {
Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not find texture with manager!"); Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not find texture with manager!");
return; return;
} }
FileObject srcFile = FileUtil.toFileObject(new File(src)); FileObject srcFile = FileUtil.toFileObject(new File(src));
String destName = currentProjectAssetManager.getAssetFolderName() + "/" + fileElem.getAttribute("path"); String destName = dest.getAssetFolderName() + "/" + fileElem.getAttribute("path");
String destFolder = destName.replace("\\", "/"); String destFolder = destName.replace("\\", "/");
destFolder = destFolder.substring(0, destFolder.lastIndexOf("/")); destFolder = destFolder.substring(0, destFolder.lastIndexOf("/"));
FileObject folder = FileUtil.createFolder(new File(destFolder)); FileObject folder = FileUtil.createFolder(new File(destFolder));
@ -385,17 +379,14 @@ public class AssetPackLoader {
List<NodeList> varAssets = config.getVariationAssets(); List<NodeList> varAssets = config.getVariationAssets();
if (varAssets != null) { if (varAssets != null) {
for (NodeList nodeList : varAssets) { for (NodeList nodeList : varAssets) {
addVariationFiles(nodeList, pm); addVariationFiles(nodeList, source, dest);
} }
} }
return; return;
} }
private static void addVariationFiles(NodeList fileNodeList, ProjectAssetManager pm) { private static void addVariationFiles(NodeList fileNodeList, ProjectAssetManager pm, ProjectAssetManager currentProjectAssetManager) {
ProjectAssetManager currentProjectAssetManager = null;
try { try {
//TODO:not good
currentProjectAssetManager = SceneApplication.getApplication().getCurrentSceneRequest().getManager();
if (currentProjectAssetManager == null) { if (currentProjectAssetManager == null) {
Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not get project asset manager!"); Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not get project asset manager!");
return; return;

@ -7,6 +7,7 @@ package com.jme3.gde.assetpack.actions;
import com.jme3.gde.assetpack.AssetConfiguration; import com.jme3.gde.assetpack.AssetConfiguration;
import com.jme3.gde.assetpack.AssetPackLoader; import com.jme3.gde.assetpack.AssetPackLoader;
import com.jme3.gde.core.assets.ProjectAssetManager; import com.jme3.gde.core.assets.ProjectAssetManager;
import com.jme3.gde.core.scene.SceneApplication;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
@ -40,13 +41,13 @@ public final class AddAssetAction implements Action {
Spatial model = AssetPackLoader.loadAssetPackModel(pm, conf); Spatial model = AssetPackLoader.loadAssetPackModel(pm, conf);
if (model != null) { if (model != null) {
SceneComposerTopComponent.findInstance().addModel(model); SceneComposerTopComponent.findInstance().addModel(model);
AssetPackLoader.addModelFiles(pm, conf); AssetPackLoader.addModelFiles(pm, SceneApplication.getApplication().getCurrentSceneRequest().getManager(),conf);
} else { } else {
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Error loading model"); Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Error loading model");
} }
} else { } else {
AssetConfiguration conf = new AssetConfiguration(assetElement); AssetConfiguration conf = new AssetConfiguration(assetElement);
AssetPackLoader.addAllFiles(pm, conf); AssetPackLoader.addAllFiles(pm, SceneApplication.getApplication().getCurrentSceneRequest().getManager(), conf);
} }
} }

@ -8,7 +8,6 @@ import com.jme3.export.binary.BinaryExporter;
import com.jme3.gde.assetpack.AssetConfiguration; import com.jme3.gde.assetpack.AssetConfiguration;
import com.jme3.gde.assetpack.AssetPackLoader; import com.jme3.gde.assetpack.AssetPackLoader;
import com.jme3.gde.core.assets.ProjectAssetManager; import com.jme3.gde.core.assets.ProjectAssetManager;
import com.jme3.gde.core.scene.SceneApplication;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
@ -47,14 +46,14 @@ public final class AddToProjectAction implements Action {
AssetConfiguration conf = new AssetConfiguration(assetElement); AssetConfiguration conf = new AssetConfiguration(assetElement);
Spatial model = AssetPackLoader.loadAssetPackModel(pm, conf); Spatial model = AssetPackLoader.loadAssetPackModel(pm, conf);
if (model != null) { if (model != null) {
ProjectAssetManager mgr = SceneApplication.getApplication().getCurrentSceneRequest().getManager(); ProjectAssetManager mgr = ProjectSelection.getProjectAssetManager();
if (mgr != null && mgr != pm) { if (mgr != null && mgr != pm) {
FileObject modelFolder = mgr.getAssetFolder().getFileObject("Models"); FileObject modelFolder = mgr.getAssetFolder().getFileObject("Models");
if (modelFolder == null) { if (modelFolder == null) {
modelFolder = mgr.getAssetFolder().createFolder("Models"); modelFolder = mgr.getAssetFolder().createFolder("Models");
} }
if (modelFolder.isFolder()) { if (modelFolder.isFolder()) {
AssetPackLoader.addModelFiles(pm, conf); AssetPackLoader.addModelFiles(pm, mgr, conf);
SceneComposerTopComponent.findInstance().addModel(model); SceneComposerTopComponent.findInstance().addModel(model);
OutputStream out = modelFolder.createAndOpen(conf.getAssetElement().getAttribute("name") + ".j3o"); OutputStream out = modelFolder.createAndOpen(conf.getAssetElement().getAttribute("name") + ".j3o");
BinaryExporter.getInstance().save(model, out); BinaryExporter.getInstance().save(model, out);
@ -77,7 +76,8 @@ public final class AddToProjectAction implements Action {
} }
} else { } else {
AssetConfiguration conf = new AssetConfiguration(assetElement); AssetConfiguration conf = new AssetConfiguration(assetElement);
AssetPackLoader.addAllFiles(pm, conf); ProjectAssetManager mgr = ProjectSelection.getProjectAssetManager();
AssetPackLoader.addAllFiles(pm, mgr, conf);
} }
} catch (IOException ex) { } catch (IOException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);

@ -1 +1,2 @@
CTL_PreviewAssetPackItem=Preview CTL_PreviewAssetPackItem=Preview
ProjectSelection.jButton1.text=Select Project

@ -0,0 +1,69 @@
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<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="false"/>
<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">
<Component id="jComboBox1" alignment="0" pref="227" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jComboBox1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JComboBox" name="jComboBox1">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4">
<StringItem index="0" value="Item 1"/>
<StringItem index="1" value="Item 2"/>
<StringItem index="2" value="Item 3"/>
<StringItem index="3" value="Item 4"/>
</StringArray>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jComboBox1ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="jButton1">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/assetpack/actions/Bundle.properties" key="ProjectSelection.jButton1.text" 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="jButton1ActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

@ -0,0 +1,135 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* ProjectSelection.java
*
* Created on 02.07.2011, 15:08:08
*/
package com.jme3.gde.assetpack.actions;
import com.jme3.gde.assetpack.project.AssetPackProject;
import com.jme3.gde.core.assets.ProjectAssetManager;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.JFrame;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectInformation;
import org.netbeans.api.project.ui.OpenProjects;
/**
*
* @author normenhansen
*/
public class ProjectSelection extends javax.swing.JDialog {
private List<Project> projects;
private int selected = 0;
/** Creates new form ProjectSelection */
public ProjectSelection(List<Project> projects) {
super(new JFrame(), true);
initComponents();
setLocationRelativeTo(null);
this.projects = projects;
jComboBox1.removeAllItems();
for (Iterator<Project> it = projects.iterator(); it.hasNext();) {
Project project = it.next();
ProjectInformation info = project.getLookup().lookup(ProjectInformation.class);
jComboBox1.addItem(info.getName());
}
}
public Project getSelected() {
return projects.get(selected);
}
public static Project showProjectSelection() {
List<Project> validProjects = new ArrayList<Project>();
Project[] projects = OpenProjects.getDefault().getOpenProjects();
for (Project project : projects) {
if (!(project instanceof AssetPackProject) && project.getLookup().lookup(ProjectAssetManager.class) != null) {
validProjects.add(project);
}
}
if (validProjects.size() == 1) {
return validProjects.get(0);
}
ProjectSelection sel = new ProjectSelection(validProjects);
sel.setVisible(true);
return sel.getSelected();
}
public static ProjectAssetManager getProjectAssetManager() {
Project proj = showProjectSelection();
if (proj == null) {
return null;
} else {
return proj.getLookup().lookup(ProjectAssetManager.class);
}
}
/** 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jComboBox1 = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jComboBox1ActionPerformed(evt);
}
});
jButton1.setText(org.openide.util.NbBundle.getMessage(ProjectSelection.class, "ProjectSelection.jButton1.text")); // NOI18N
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jComboBox1, 0, 227, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
selected = jComboBox1.getSelectedIndex();
}//GEN-LAST:event_jComboBox1ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
setVisible(false);
}//GEN-LAST:event_jButton1ActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JComboBox jComboBox1;
// End of variables declaration//GEN-END:variables
}
Loading…
Cancel
Save