From a49c4068de283b1f91733dfa6f049f037578c2e6 Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Wed, 3 Oct 2012 01:20:52 +0000 Subject: [PATCH] SDK: - make Model Import Tool work without selecting a project explicitly git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9811 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../nbproject/genfiles.properties | 2 +- .../nbproject/project.xml | 4 +- .../assetpack/actions/ProjectSelection.form | 2 +- .../assetpack/actions/ProjectSelection.java | 8 +- .../nbproject/genfiles.properties | 8 +- sdk/jme3-model-importer/nbproject/project.xml | 17 +++ .../jme3/gde/modelimporter/Bundle.properties | 3 +- .../jme3/gde/modelimporter/ImportModel.java | 35 ++++- .../gde/modelimporter/ProjectSelection.form | 69 +++++++++ .../gde/modelimporter/ProjectSelection.java | 142 ++++++++++++++++++ .../src/com/jme3/gde/modelimporter/layer.xml | 4 +- 11 files changed, 280 insertions(+), 14 deletions(-) create mode 100644 sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/ProjectSelection.form create mode 100644 sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/ProjectSelection.java diff --git a/sdk/jme3-assetpack-support/nbproject/genfiles.properties b/sdk/jme3-assetpack-support/nbproject/genfiles.properties index f2b2d2f65..605a2a346 100644 --- a/sdk/jme3-assetpack-support/nbproject/genfiles.properties +++ b/sdk/jme3-assetpack-support/nbproject/genfiles.properties @@ -3,6 +3,6 @@ build.xml.script.CRC32=c0969383 build.xml.stylesheet.CRC32=a56c6a5b@1.42.2 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=9f2b8f14 +nbproject/build-impl.xml.data.CRC32=b5dd9827 nbproject/build-impl.xml.script.CRC32=4d376df0 nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.50.1 diff --git a/sdk/jme3-assetpack-support/nbproject/project.xml b/sdk/jme3-assetpack-support/nbproject/project.xml index 460ebebc9..32d6907ea 100644 --- a/sdk/jme3-assetpack-support/nbproject/project.xml +++ b/sdk/jme3-assetpack-support/nbproject/project.xml @@ -185,7 +185,9 @@ - + + com.jme3.gde.assetpack.project + 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 index c08bc48d7..764d77b8f 100644 --- 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 @@ -1,4 +1,4 @@ - +
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 index 531eab76d..860f6c9f1 100644 --- 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 @@ -44,7 +44,13 @@ public class ProjectSelection extends javax.swing.JDialog { } public Project getSelected() { - return projects.get(selected); + if (selected < 0) { + return null; + } + if (projects.size() > selected) { + return projects.get(selected); + } + return null; } public static Project showProjectSelection() { diff --git a/sdk/jme3-model-importer/nbproject/genfiles.properties b/sdk/jme3-model-importer/nbproject/genfiles.properties index fb87f45c1..19a2ee3ec 100644 --- a/sdk/jme3-model-importer/nbproject/genfiles.properties +++ b/sdk/jme3-model-importer/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=2db6ec0e +build.xml.data.CRC32=ae2392d0 build.xml.script.CRC32=b6310686 -build.xml.stylesheet.CRC32=a56c6a5b@2.49.1 +build.xml.stylesheet.CRC32=a56c6a5b@2.50.1 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=2db6ec0e +nbproject/build-impl.xml.data.CRC32=ae2392d0 nbproject/build-impl.xml.script.CRC32=4db64ed5 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.49.1 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.50.1 diff --git a/sdk/jme3-model-importer/nbproject/project.xml b/sdk/jme3-model-importer/nbproject/project.xml index 6cb05bb57..7e350abbf 100644 --- a/sdk/jme3-model-importer/nbproject/project.xml +++ b/sdk/jme3-model-importer/nbproject/project.xml @@ -6,6 +6,14 @@ com.jme3.gde.modelimporter + + com.jme3.gde.assetpack + + + + 3.0 + + com.jme3.gde.core @@ -42,6 +50,15 @@ 1.30 + + org.netbeans.modules.projectuiapi + + + + 1 + 1.57.1.8 + + org.openide.awt diff --git a/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/Bundle.properties b/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/Bundle.properties index 2ef525d7a..6fd0e2564 100644 --- a/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/Bundle.properties +++ b/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/Bundle.properties @@ -1,4 +1,5 @@ -CTL_ImportModel=Import Model (Select Project) +CTL_ImportModel=Import Model +ProjectSelection.jButton1.text=Select Project OpenIDE-Module-Display-Category=jMonkeyEngine OpenIDE-Module-Long-Description=\ This plugin allows importing models to a project using a Wizard. diff --git a/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/ImportModel.java b/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/ImportModel.java index a5b6bd292..f28a3c1ab 100644 --- a/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/ImportModel.java +++ b/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/ImportModel.java @@ -14,7 +14,6 @@ import java.awt.Component; import java.awt.Dialog; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; -import java.io.File; import java.io.IOException; import java.text.MessageFormat; import java.util.Iterator; @@ -24,29 +23,59 @@ import javax.swing.JComponent; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectInformation; +import org.netbeans.api.project.ui.OpenProjects; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; import org.openide.WizardDescriptor; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.loaders.DataObject; import org.openide.util.Exceptions; +import org.openide.util.NbBundle; +@ActionID( + category = "File", +id = "com.jme3.gde.modelimporter.ImportModel") +@ActionRegistration( + iconBase = "com/jme3/gde/modelimporter/103_.png", +displayName = "#CTL_ImportModel") +@ActionReferences({ + @ActionReference(path = "Menu/File", position = 1413), + @ActionReference(path = "Toolbars/File", position = 310) +}) +@NbBundle.Messages("CTL_SomeAction=test") @SuppressWarnings("unchecked") public final class ImportModel implements ActionListener { - private final Project context; + private Project context; private WizardDescriptor.Panel[] panels; + public ImportModel() { + } + public ImportModel(Project context) { this.context = context; } public void actionPerformed(ActionEvent ev) { + if (context == null) { + this.context = OpenProjects.getDefault().getMainProject(); + if (context == null) { + context = ProjectSelection.showProjectSelection(); + } + if (context == null) { + return; + } + } final WizardDescriptor wiz = new WizardDescriptor(getPanels()); // {0} will be replaced by WizardDesriptor.Panel.getComponent().getName() wiz.setTitleFormat(new MessageFormat("{0}")); - wiz.setTitle("Import Model to Project"); + wiz.setTitle("Import Model to Project " + context.getLookup().lookup(ProjectInformation.class).getDisplayName()); wiz.putProperty("project", context); Dialog dialog = DialogDisplayer.getDefault().createDialog(wiz); dialog.setVisible(true); diff --git a/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/ProjectSelection.form b/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/ProjectSelection.form new file mode 100644 index 000000000..c165ae652 --- /dev/null +++ b/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/ProjectSelection.form @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/ProjectSelection.java b/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/ProjectSelection.java new file mode 100644 index 000000000..ff0ca178b --- /dev/null +++ b/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/ProjectSelection.java @@ -0,0 +1,142 @@ +/* + * 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.modelimporter; + +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 projects; + private int selected = 0; + + /** + * Creates new form ProjectSelection + */ + public ProjectSelection(List projects) { + super(new JFrame(), true); + initComponents(); + setLocationRelativeTo(null); + this.projects = projects; + jComboBox1.removeAllItems(); + for (Iterator it = projects.iterator(); it.hasNext();) { + Project project = it.next(); + ProjectInformation info = project.getLookup().lookup(ProjectInformation.class); + jComboBox1.addItem(info.getName()); + } + } + + public Project getSelected() { + if (selected < 0) { + return null; + } + if (projects.size() > selected) { + return projects.get(selected); + } + return null; + } + + public static Project showProjectSelection() { + List validProjects = new ArrayList(); + 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") + // //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(); + }// //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 +} diff --git a/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/layer.xml b/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/layer.xml index f7bdd7f02..5ac8c423f 100644 --- a/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/layer.xml +++ b/sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/layer.xml @@ -1,7 +1,7 @@ - +