|
@@ -0,0 +1,147 @@
|
|
|
+/*
|
|
|
+ * 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.core.util;
|
|
|
+
|
|
|
+import com.jme3.gde.core.assets.ProjectAssetManager;
|
|
|
+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 Project[] projects;
|
|
|
+ private int selected = 0;
|
|
|
+
|
|
|
+ /** Creates new form ProjectSelection */
|
|
|
+ public ProjectSelection(Project[] projects, boolean assetOnly) {
|
|
|
+ super(new JFrame(), true);
|
|
|
+ initComponents();
|
|
|
+ setLocationRelativeTo(null);
|
|
|
+ this.projects = projects;
|
|
|
+ jComboBox1.removeAllItems();
|
|
|
+ for (int i = 0; i < projects.length; i++) {
|
|
|
+ Project project = projects[i];
|
|
|
+ ProjectAssetManager manager = project.getLookup().lookup(ProjectAssetManager.class);
|
|
|
+ if (assetOnly == false || manager != null) {
|
|
|
+ ProjectInformation info = project.getLookup().lookup(ProjectInformation.class);
|
|
|
+ jComboBox1.addItem(info.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Project getSelected() {
|
|
|
+ if (selected == -1) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return projects[selected];
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Project showProjectSelection(String title, boolean assetOnly) {
|
|
|
+ Project[] projects = OpenProjects.getDefault().getOpenProjects();
|
|
|
+ ProjectSelection sel = new ProjectSelection(projects, assetOnly);
|
|
|
+ sel.setTitle(title);
|
|
|
+ sel.setVisible(true);
|
|
|
+ return sel.getSelected();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ProjectAssetManager getProjectAssetManager(String title) {
|
|
|
+ Project proj = showProjectSelection(title, true);
|
|
|
+ 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();
|
|
|
+ jButton2 = 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);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ jButton2.setText(org.openide.util.NbBundle.getMessage(ProjectSelection.class, "ProjectSelection.jButton2.text")); // NOI18N
|
|
|
+ jButton2.addActionListener(new java.awt.event.ActionListener() {
|
|
|
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
+ jButton2ActionPerformed(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, 310, Short.MAX_VALUE)
|
|
|
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
|
|
+ .addGap(83, 83, 83)
|
|
|
+ .addComponent(jButton1)
|
|
|
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
|
+ .addComponent(jButton2)
|
|
|
+ .addContainerGap())
|
|
|
+ );
|
|
|
+ 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)
|
|
|
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
|
|
+ .addComponent(jButton2)
|
|
|
+ .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
|
|
|
+
|
|
|
+ private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
|
|
|
+ selected = -1;
|
|
|
+ setVisible(false);
|
|
|
+ }//GEN-LAST:event_jButton2ActionPerformed
|
|
|
+ // Variables declaration - do not modify//GEN-BEGIN:variables
|
|
|
+ private javax.swing.JButton jButton1;
|
|
|
+ private javax.swing.JButton jButton2;
|
|
|
+ private javax.swing.JComboBox jComboBox1;
|
|
|
+ // End of variables declaration//GEN-END:variables
|
|
|
+}
|