- add swing to nifty converter git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8730 75d07b2b-3a1a-0410-a2c5-0572b91ccdca3.0
parent
96c6fa5944
commit
984f2e3af7
@ -0,0 +1,32 @@ |
||||
# Copyright (c) 2009-2010 jMonkeyEngine |
||||
# All rights reserved. |
||||
# |
||||
# Redistribution and use in source and binary forms, with or without |
||||
# modification, are permitted provided that the following conditions are |
||||
# met: |
||||
# |
||||
# * Redistributions of source code must retain the above copyright |
||||
# notice, this list of conditions and the following disclaimer. |
||||
# |
||||
# * Redistributions in binary form must reproduce the above copyright |
||||
# notice, this list of conditions and the following disclaimer in the |
||||
# documentation and/or other materials provided with the distribution. |
||||
# |
||||
# * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||
# may be used to endorse or promote products derived from this software |
||||
# without specific prior written permission. |
||||
# |
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
ProjectSelection.jButton1.text=OK |
||||
ProjectSelection.jButton2.text=Cancel |
@ -0,0 +1,85 @@ |
||||
<?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="310" max="32767" attributes="0"/> |
||||
<Group type="102" alignment="1" attributes="0"> |
||||
<EmptySpace min="-2" pref="83" max="-2" attributes="0"/> |
||||
<Component id="jButton1" min="-2" max="-2" attributes="0"/> |
||||
<EmptySpace max="-2" attributes="0"/> |
||||
<Component id="jButton2" min="-2" max="-2" attributes="0"/> |
||||
<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"> |
||||
<Component id="jComboBox1" min="-2" max="-2" attributes="0"/> |
||||
<EmptySpace max="32767" attributes="0"/> |
||||
<Group type="103" groupAlignment="3" attributes="0"> |
||||
<Component id="jButton2" alignment="3" min="-2" max="-2" attributes="0"/> |
||||
<Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/> |
||||
</Group> |
||||
</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/core/util/Bundle.properties" key="ProjectSelection.jButton1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> |
||||
</Property> |
||||
</Properties> |
||||
<Events> |
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/> |
||||
</Events> |
||||
</Component> |
||||
<Component class="javax.swing.JButton" name="jButton2"> |
||||
<Properties> |
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> |
||||
<ResourceString bundle="com/jme3/gde/core/util/Bundle.properties" key="ProjectSelection.jButton2.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> |
||||
</Property> |
||||
</Properties> |
||||
<Events> |
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/> |
||||
</Events> |
||||
</Component> |
||||
</SubComponents> |
||||
</Form> |
@ -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
|
||||
} |
@ -1,8 +1,8 @@ |
||||
build.xml.data.CRC32=9c8dd190 |
||||
build.xml.data.CRC32=05e55fdc |
||||
build.xml.script.CRC32=a0136781 |
||||
build.xml.stylesheet.CRC32=a56c6a5b@1.46.1 |
||||
build.xml.stylesheet.CRC32=a56c6a5b@1.46.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=9c8dd190 |
||||
nbproject/build-impl.xml.data.CRC32=05e55fdc |
||||
nbproject/build-impl.xml.script.CRC32=55a34aaf |
||||
nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.46.1 |
||||
nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.46.2 |
||||
|
Binary file not shown.
@ -0,0 +1,5 @@ |
||||
# To change this template, choose Tools | Templates |
||||
# and open the template in the editor. |
||||
|
||||
ProjectSelection.jButton1.text=OK |
||||
ProjectSelection.jButton2.text=Cancel |
@ -0,0 +1,123 @@ |
||||
/* |
||||
* To change this template, choose Tools | Templates |
||||
* and open the template in the editor. |
||||
*/ |
||||
package com.jme3.gde.gui.swing; |
||||
|
||||
import com.jme3.gde.core.assets.ProjectAssetManager; |
||||
import com.jme3.gde.core.util.ProjectSelection; |
||||
import java.awt.event.ActionListener; |
||||
import java.awt.event.ActionEvent; |
||||
import java.io.IOException; |
||||
import java.net.URL; |
||||
import java.net.URLClassLoader; |
||||
import java.util.Iterator; |
||||
import java.util.LinkedList; |
||||
import java.util.List; |
||||
import org.netbeans.api.java.classpath.ClassPath; |
||||
import org.netbeans.api.java.project.JavaProjectConstants; |
||||
import org.netbeans.api.project.Project; |
||||
|
||||
import org.netbeans.api.project.SourceGroup; |
||||
|
||||
import org.netbeans.api.project.Sources; |
||||
import org.openide.awt.ActionRegistration; |
||||
import org.openide.awt.ActionReference; |
||||
import org.openide.awt.ActionReferences; |
||||
import org.openide.awt.ActionID; |
||||
import org.openide.filesystems.FileObject; |
||||
import org.openide.util.Exceptions; |
||||
import org.openide.util.NbBundle.Messages; |
||||
|
||||
@ActionID(category = "NiftyGUI", |
||||
id = "com.jme3.gde.gui.swing.ConvertToNifty") |
||||
@ActionRegistration(displayName = "#CTL_ConvertToNifty") |
||||
@ActionReferences({ |
||||
@ActionReference(path = "Menu/Tools/NiftyGUI", position = 0) |
||||
}) |
||||
@Messages("CTL_ConvertToNifty=Convert Project Swing classes to NiftyGUI") |
||||
public final class ConvertToNifty implements ActionListener { |
||||
|
||||
private final Project context; |
||||
|
||||
public ConvertToNifty(Project context) { |
||||
this.context = context; |
||||
} |
||||
|
||||
public void actionPerformed(ActionEvent ev) { |
||||
ProjectAssetManager pm = context.getLookup().lookup(ProjectAssetManager.class); |
||||
if (pm == null) { |
||||
pm = ProjectSelection.getProjectAssetManager("Select target project"); |
||||
} |
||||
FileObject folder; |
||||
folder = context.getProjectDirectory(); |
||||
if (pm != null) { |
||||
folder = pm.getAssetFolder().getFileObject("Interface/Converted"); |
||||
if (folder == null) { |
||||
try { |
||||
folder = pm.getAssetFolder().getFileObject("Interface"); |
||||
if (folder == null) { |
||||
folder = pm.getAssetFolder().createFolder("Interface"); |
||||
} |
||||
folder = folder.createFolder("Converted"); |
||||
} catch (IOException ex) { |
||||
Exceptions.printStackTrace(ex); |
||||
folder = context.getProjectDirectory(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
Sources sources = context.getLookup().lookup(Sources.class); |
||||
if (sources != null) { |
||||
List<URL> urls = new LinkedList<URL>(); |
||||
SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); |
||||
for (SourceGroup sourceGroup : groups) { |
||||
try { |
||||
ClassPath path = ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.COMPILE); |
||||
for (Iterator<ClassPath.Entry> it = path.entries().iterator(); it.hasNext();) { |
||||
ClassPath.Entry entry = it.next(); |
||||
urls.add(entry.getURL()); |
||||
} |
||||
} catch (Exception ex) { |
||||
Exceptions.printStackTrace(ex); |
||||
} |
||||
} |
||||
for (SourceGroup sourceGroup : groups) { |
||||
ClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), this.getClass().getClassLoader()); |
||||
Class clazzFactory; |
||||
try { |
||||
clazzFactory = loader.loadClass("nl.tygron.niftyconverter.NiftyFactory"); |
||||
Class clazzFile = loader.loadClass("java.io.File"); |
||||
Class clazzString = loader.loadClass("java.lang.String"); |
||||
Class clazzConfig = loader.loadClass("nl.tygron.niftyconverter.util.NiftyConverterConfig"); |
||||
clazzConfig.getDeclaredMethod("setOutputDir", clazzString).invoke(null, folder.getPath()); |
||||
Object string = clazzString.getDeclaredConstructor(clazzString).newInstance(sourceGroup.getRootFolder().getPath());//context.getProjectDirectory().getFileObject("build/classes").getPath());
|
||||
Object file = clazzFile.getDeclaredConstructor(clazzString).newInstance(string); |
||||
Object factory = clazzFactory.newInstance(); |
||||
clazzFactory.getMethod("loadComponents", clazzFile).invoke(factory, file); |
||||
} catch (Exception ex) { |
||||
Exceptions.printStackTrace(ex); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
// SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
|
||||
// for (SourceGroup sourceGroup : groups) {
|
||||
// try {
|
||||
// ClassPath path = ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.COMPILE);
|
||||
// ClassLoader loader = new URLClassLoader(new URL[]{new URL("jar:file:/Users/normenhansen/Documents/Code/swingtonifty/dist/swingtonifty.jar!/")}, path.getClassLoader(true));
|
||||
// Class clazzFactory = loader.loadClass("nl.tygron.niftyconverter.NiftyFactory");
|
||||
// Class clazzFile = loader.loadClass("java.io.File");
|
||||
// Class clazzString = loader.loadClass("java.lang.String");
|
||||
// Class clazzConfig = loader.loadClass("nl.tygron.niftyconverter.util.NiftyConverterConfig");
|
||||
// clazzConfig.getDeclaredMethod("setOutputDir", clazzString).invoke(null, folder.getPath());
|
||||
// Object string = clazzString.getDeclaredConstructor(clazzString).newInstance(sourceGroup.getRootFolder().getPath());//context.getProjectDirectory().getFileObject("build/classes").getPath());
|
||||
// Object file = clazzFile.getDeclaredConstructor(clazzString).newInstance(string);
|
||||
// Object factory = clazzFactory.newInstance();
|
||||
// clazzFactory.getMethod("loadComponents", clazzFile).invoke(factory, file);
|
||||
// } catch (Exception ex) {
|
||||
// Exceptions.printStackTrace(ex);
|
||||
// }
|
||||
// }
|
Loading…
Reference in new issue