OSDN Git Service

- add project selection in AssetPack "add to project" for unclear situations
authornormen667 <normen667@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Sat, 2 Jul 2011 13:31:28 +0000 (13:31 +0000)
committernormen667 <normen667@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Sat, 2 Jul 2011 13:31:28 +0000 (13:31 +0000)
git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@7808 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

sdk/jme3-assetpack-support/src/com/jme3/gde/assetpack/AssetPackLoader.java
sdk/jme3-assetpack-support/src/com/jme3/gde/assetpack/actions/AddAssetAction.java
sdk/jme3-assetpack-support/src/com/jme3/gde/assetpack/actions/AddToProjectAction.java
sdk/jme3-assetpack-support/src/com/jme3/gde/assetpack/actions/Bundle.properties
sdk/jme3-assetpack-support/src/com/jme3/gde/assetpack/actions/ProjectSelection.form [new file with mode: 0644]
sdk/jme3-assetpack-support/src/com/jme3/gde/assetpack/actions/ProjectSelection.java [new file with mode: 0644]

index 604623b..eab3900 100644 (file)
@@ -310,14 +310,11 @@ public class AssetPackLoader {
         return description;
     }
 
-    public static void addAllFiles(ProjectAssetManager pm, AssetConfiguration config) {
+    public static void addAllFiles(ProjectAssetManager source, ProjectAssetManager dest, AssetConfiguration config) {
         Element assetElement = config.getAssetElement();
         NodeList list = assetElement.getElementsByTagName("file");
-        ProjectAssetManager proman = null;
         try {
-            //TODO:not good
-            proman = SceneApplication.getApplication().getCurrentSceneRequest().getManager();
-            if (proman == null) {
+            if (dest == null) {
                 Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not get project asset manager!");
                 return;
             }
@@ -328,13 +325,13 @@ public class AssetPackLoader {
         for (int i = 0; i < list.getLength(); i++) {
             Element fileElem = (Element) list.item(i);
             try {
-                String src = pm.getAbsoluteAssetPath(fileElem.getAttribute("path"));
+                String src = source.getAbsoluteAssetPath(fileElem.getAttribute("path"));
                 if (src == null) {
                     Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not find texture with manager!");
                     return;
                 }
                 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("\\", "/");
                 destFolder = destFolder.substring(0, destFolder.lastIndexOf("/"));
                 FileObject folder = FileUtil.createFolder(new File(destFolder));
@@ -346,14 +343,11 @@ public class AssetPackLoader {
         return;
     }
 
-    public static void addModelFiles(ProjectAssetManager pm, AssetConfiguration config) {
+    public static void addModelFiles(ProjectAssetManager source, ProjectAssetManager dest, AssetConfiguration config) {
         Element assetElement = config.getAssetElement();
         NodeList fileNodeList = assetElement.getElementsByTagName("file");
-        ProjectAssetManager currentProjectAssetManager = null;
         try {
-            //TODO:not good
-            currentProjectAssetManager = SceneApplication.getApplication().getCurrentSceneRequest().getManager();
-            if (currentProjectAssetManager == null) {
+            if (dest == null) {
                 Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not get project asset manager!");
                 return;
             }
@@ -366,13 +360,13 @@ public class AssetPackLoader {
             String type = fileElem.getAttribute("type");
             if ("texture".equals(type) || "sound".equals(type) || "materialdef".equals(type) || "shader".equals(type) || "other".equals(type)) {
                 try {
-                    String src = pm.getAbsoluteAssetPath(fileElem.getAttribute("path"));
+                    String src = source.getAbsoluteAssetPath(fileElem.getAttribute("path"));
                     if (src == null) {
                         Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not find texture with manager!");
                         return;
                     }
                     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("\\", "/");
                     destFolder = destFolder.substring(0, destFolder.lastIndexOf("/"));
                     FileObject folder = FileUtil.createFolder(new File(destFolder));
@@ -385,17 +379,14 @@ public class AssetPackLoader {
         List<NodeList> varAssets = config.getVariationAssets();
         if (varAssets != null) {
             for (NodeList nodeList : varAssets) {
-                addVariationFiles(nodeList, pm);
+                addVariationFiles(nodeList, source, dest);
             }
         }
         return;
     }
 
-    private static void addVariationFiles(NodeList fileNodeList, ProjectAssetManager pm) {
-        ProjectAssetManager currentProjectAssetManager = null;
+    private static void addVariationFiles(NodeList fileNodeList, ProjectAssetManager pm, ProjectAssetManager currentProjectAssetManager) {
         try {
-            //TODO:not good
-            currentProjectAssetManager = SceneApplication.getApplication().getCurrentSceneRequest().getManager();
             if (currentProjectAssetManager == null) {
                 Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not get project asset manager!");
                 return;
index dce4f4d..a48c811 100644 (file)
@@ -7,6 +7,7 @@ package com.jme3.gde.assetpack.actions;
 import com.jme3.gde.assetpack.AssetConfiguration;
 import com.jme3.gde.assetpack.AssetPackLoader;
 import com.jme3.gde.core.assets.ProjectAssetManager;
+import com.jme3.gde.core.scene.SceneApplication;
 import com.jme3.scene.Spatial;
 import java.awt.event.ActionEvent;
 import java.beans.PropertyChangeListener;
@@ -40,13 +41,13 @@ public final class AddAssetAction implements Action {
             Spatial model = AssetPackLoader.loadAssetPackModel(pm, conf);
             if (model != null) {
                 SceneComposerTopComponent.findInstance().addModel(model);
-                AssetPackLoader.addModelFiles(pm, conf);
+                AssetPackLoader.addModelFiles(pm, SceneApplication.getApplication().getCurrentSceneRequest().getManager(),conf);
             } else {
                 Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Error loading model");
             }
         } else {
             AssetConfiguration conf = new AssetConfiguration(assetElement);
-            AssetPackLoader.addAllFiles(pm, conf);
+            AssetPackLoader.addAllFiles(pm, SceneApplication.getApplication().getCurrentSceneRequest().getManager(), conf);
         }
     }
 
index 9285b0a..444b1c3 100644 (file)
@@ -8,7 +8,6 @@ import com.jme3.export.binary.BinaryExporter;
 import com.jme3.gde.assetpack.AssetConfiguration;
 import com.jme3.gde.assetpack.AssetPackLoader;
 import com.jme3.gde.core.assets.ProjectAssetManager;
-import com.jme3.gde.core.scene.SceneApplication;
 import com.jme3.scene.Spatial;
 import java.awt.event.ActionEvent;
 import java.beans.PropertyChangeListener;
@@ -47,14 +46,14 @@ public final class AddToProjectAction implements Action {
                 AssetConfiguration conf = new AssetConfiguration(assetElement);
                 Spatial model = AssetPackLoader.loadAssetPackModel(pm, conf);
                 if (model != null) {
-                    ProjectAssetManager mgr = SceneApplication.getApplication().getCurrentSceneRequest().getManager();
+                    ProjectAssetManager mgr = ProjectSelection.getProjectAssetManager();
                     if (mgr != null && mgr != pm) {
                         FileObject modelFolder = mgr.getAssetFolder().getFileObject("Models");
                         if (modelFolder == null) {
                             modelFolder = mgr.getAssetFolder().createFolder("Models");
                         }
                         if (modelFolder.isFolder()) {
-                            AssetPackLoader.addModelFiles(pm, conf);
+                            AssetPackLoader.addModelFiles(pm, mgr, conf);
                             SceneComposerTopComponent.findInstance().addModel(model);
                             OutputStream out = modelFolder.createAndOpen(conf.getAssetElement().getAttribute("name") + ".j3o");
                             BinaryExporter.getInstance().save(model, out);
@@ -77,7 +76,8 @@ public final class AddToProjectAction implements Action {
                 }
             } else {
                 AssetConfiguration conf = new AssetConfiguration(assetElement);
-                AssetPackLoader.addAllFiles(pm, conf);
+                ProjectAssetManager mgr = ProjectSelection.getProjectAssetManager();
+                AssetPackLoader.addAllFiles(pm, mgr, conf);
             }
         } catch (IOException ex) {
             Exceptions.printStackTrace(ex);
diff --git a/sdk/jme3-assetpack-support/src/com/jme3/gde/assetpack/actions/ProjectSelection.form b/sdk/jme3-assetpack-support/src/com/jme3/gde/assetpack/actions/ProjectSelection.form
new file mode 100644 (file)
index 0000000..c08bc48
--- /dev/null
@@ -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>
diff --git a/sdk/jme3-assetpack-support/src/com/jme3/gde/assetpack/actions/ProjectSelection.java b/sdk/jme3-assetpack-support/src/com/jme3/gde/assetpack/actions/ProjectSelection.java
new file mode 100644 (file)
index 0000000..531eab7
--- /dev/null
@@ -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
+}