Added creator files

This commit is contained in:
Waverunner
2014-09-08 13:25:39 -04:00
parent 996e45e8e5
commit 3637c5abc1
59 changed files with 2150 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
<!-- for some information on what you could do (e.g. targets to override). -->
<!-- If you delete this file and reopen the project it will be recreated. -->
<project name="com.projectswg.tools.csc.compiler" default="netbeans" basedir=".">
<description>Builds, tests, and runs the project com.projectswg.tools.csc.compiler.</description>
<import file="nbproject/build-impl.xml"/>
</project>
+5
View File
@@ -0,0 +1,5 @@
Manifest-Version: 1.0
OpenIDE-Module: com.projectswg.tools.csc.compiler
OpenIDE-Module-Localizing-Bundle: com/projectswg/tools/csc/compiler/Bundle.properties
OpenIDE-Module-Specification-Version: 1.0
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
*** GENERATED FROM project.xml - DO NOT EDIT ***
*** EDIT ../build.xml INSTEAD ***
-->
<project name="com.projectswg.tools.csc.compiler-impl" basedir="..">
<fail message="Please build using Ant 1.7.1 or higher.">
<condition>
<not>
<antversion atleast="1.7.1"/>
</not>
</condition>
</fail>
<property file="nbproject/private/suite-private.properties"/>
<property file="nbproject/suite.properties"/>
<fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail>
<property file="${suite.dir}/nbproject/private/platform-private.properties"/>
<property file="${suite.dir}/nbproject/platform.properties"/>
<macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
<attribute name="name"/>
<attribute name="value"/>
<sequential>
<property name="@{name}" value="${@{value}}"/>
</sequential>
</macrodef>
<macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
<attribute name="property"/>
<attribute name="value"/>
<sequential>
<property name="@{property}" value="@{value}"/>
</sequential>
</macrodef>
<property file="${user.properties.file}"/>
<nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
<condition>
<not>
<contains string="${cluster.path.evaluated}" substring="platform"/>
</not>
</condition>
</fail>
<import file="${harness.dir}/build.xml"/>
</project>
@@ -0,0 +1,8 @@
build.xml.data.CRC32=beb6af21
build.xml.script.CRC32=16594606
build.xml.stylesheet.CRC32=[email protected]
# 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=beb6af21
nbproject/build-impl.xml.script.CRC32=bd99f65f
nbproject/build-impl.xml.stylesheet.CRC32=[email protected]
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Users/Wave/Documents/NetBeansProjects/ConversationScriptCreator/ConversationCompiler/src/com/projectswg/tools/csc/compiler/Compiler.java</file>
</group>
</open-files>
</project-private>
@@ -0,0 +1,2 @@
javac.source=1.7
javac.compilerargs=-Xlint -Xlint:-serial
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.apisupport.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
<code-name-base>com.projectswg.tools.csc.compiler</code-name-base>
<suite-component/>
<module-dependencies>
<dependency>
<code-name-base>com.projectswg.tools.csc.conversationeditor</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>1.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.api.visual</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>2.42.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.awt</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.61.2</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.dialogs</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.36.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.nodes</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.38.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>8.37.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.windows</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>6.70.1</specification-version>
</run-dependency>
</dependency>
</module-dependencies>
<public-packages/>
</data>
</configuration>
</project>
@@ -0,0 +1 @@
suite.dir=${basedir}/..
@@ -0,0 +1 @@
OpenIDE-Module-Name=Conversation Compiler
@@ -0,0 +1,179 @@
package com.projectswg.tools.csc.compiler;
import com.projectswg.tools.csc.conversationeditor.ConversationNode;
import com.projectswg.tools.csc.conversationeditor.ConversationWidget;
import com.projectswg.tools.csc.conversationeditor.EditorTopComponent;
import com.projectswg.tools.csc.conversationeditor.SceneView;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.swing.JOptionPane;
import org.netbeans.api.visual.widget.ConnectionWidget;
import org.netbeans.api.visual.widget.Widget;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
public class Compiler {
private final File file;
public Compiler(File file) {
this.file = file;
}
public void compile() throws IOException {
TopComponent component = WindowManager.getDefault().findTopComponent("EditorTopComponent");
if (component == null || !(component instanceof EditorTopComponent))
return;
EditorTopComponent editor = (EditorTopComponent) component;
SceneView scene = editor.getScene();
if (scene == null) {
JOptionPane.showMessageDialog(null, "The scene was null! You must restart the editor in order to compile :(",
"Conversation Script Creator", JOptionPane.ERROR_MESSAGE);
return;
}
try (BufferedWriter bw = new BufferedWriter(new FileWriter(file.getAbsolutePath()))) {
createBaseFile(bw);
List<Widget> connectedNodes = scene.getConnectionLayer().getChildren();
LinkedHashMap<ConversationNode, ArrayList<ConversationNode>> conversationLinks = new LinkedHashMap<>();
for (Widget widget : connectedNodes) {
ConnectionWidget connection = (ConnectionWidget) widget;
ConversationWidget source = (ConversationWidget) connection.getSourceAnchor().getRelatedWidget();
ConversationNode sNode = source.getAttachedNode();
if (!conversationLinks.containsKey(sNode)) {
conversationLinks.put(sNode, new ArrayList<ConversationNode>());
}
ConversationWidget target = (ConversationWidget) connection.getTargetAnchor().getRelatedWidget();
ConversationNode tNode = target.getAttachedNode();
if (conversationLinks.containsKey(sNode))
conversationLinks.get(sNode).add(tNode);
else
System.out.println("No key for node " + sNode.getStf());
//System.out.println("This connection widget came from " + sNode.getStf() + " and is pointing to " + tNode.getStf());
//compiler.compileTarget(tNode);
}
for (Map.Entry<ConversationNode, ArrayList<ConversationNode>> entry : conversationLinks.entrySet()) {
/*System.out.println("Handling for node " + entry.getKey().getStf());
for (ConversationNode node : entry.getValue()) {
System.out.println("Node: " + node.getStf());
}*/
if (entry.getKey().isStartNode()) {
createOptionsAndHandler(bw, entry.getKey(), entry.getValue(), 1, conversationLinks);
break;
}
}
}
}
private void createBaseFile(BufferedWriter bw) throws IOException {
bw.write("# Base file generated using Conversation Script Creator for ProjectSWG\n");
bw.write("from resources.common import ConversationOption\n" +
"from resources.common import OutOfBand\n" +
"from resources.common import ProsePackage\n" +
"from java.util import Vector\n");
bw.newLine();
bw.write("import sys\n");
bw.newLine();
bw.write("def startConversation(core, actor, npc):\n");
}
private void createResponseHandler(BufferedWriter bw, ArrayList<ConversationNode> options, int handleNum,
LinkedHashMap<ConversationNode, ArrayList<ConversationNode>> conversationLinks) throws IOException {
LinkedHashMap<ConversationNode, ArrayList<ConversationNode>> handleFuncs = new LinkedHashMap<>();
bw.write("def handleOptionScreen" + handleNum + "(core, actor, npc, selection):\n");
bw.newLine();
int count = handleNum + 1;
for (ConversationNode selectedOption : options) {
bw.write(" " + (options.indexOf(selectedOption) > 0 ? "elif" : "if") + " selection == " + options.indexOf(selectedOption) + ":\n");
if (conversationLinks.containsKey(selectedOption)) {
bw.write(" #Handler for Option " + selectedOption.getStf() + "\n");
for (ConversationNode handleNode : conversationLinks.get(selectedOption)) {
if (!handleNode.isOption()) {
if (conversationLinks.get(handleNode) == null) {
bw.write(" core.conversationService.sendStopConversation(actor, npc, 'conversation/c_newbie_secondchance', 's_136')\n");
} else {
createOptions(bw, conversationLinks.get(handleNode), count++, " ");
bw.write(" core.conversationService.sendConversationMessage(actor, npc, OutOfBand.ProsePackage('@" + handleNode.getStf() + "')\n");
handleFuncs.put(handleNode, conversationLinks.get(handleNode)); // Put these nodes in list so we can create the handlers later.
}
}
}
}
bw.write(" return\n");
bw.newLine();
}
bw.write(" return\n");
bw.newLine();
int currentHandler = handleNum + 1;
for (Map.Entry<ConversationNode, ArrayList<ConversationNode>> handleNode : handleFuncs.entrySet()) {
createResponseHandler(bw, handleNode.getValue(), currentHandler++, conversationLinks);
}
}
private void createOptionsAndHandler(BufferedWriter bw, ConversationNode response, ArrayList<ConversationNode> options, int handleScreenNum,
LinkedHashMap<ConversationNode, ArrayList<ConversationNode>> conversationLinks) throws IOException {
bw.write(" options = new Vector()\n");
if (options.size() > 1) {
ArrayList<ConversationNode> orderedOptions = new ArrayList<>();
for (ConversationNode unOrdered : options) {
orderedOptions.add(unOrdered.getOptionId(), unOrdered);
}
for (ConversationNode option : orderedOptions) {
bw.write(" options.add(ConversationOption(OutOfBand.ProsePackage('@" + option.getStf() +"'), " + options.indexOf(option) + ")\n");
}
} else {
for (ConversationNode option : options) {
bw.write(" options.add(ConversationOption(OutOfBand.ProsePackage('@" + option.getStf() +"'), " + options.indexOf(option) + ")\n");
}
}
bw.write(" core.conversationService.sendConversationOptions(actor, npc, handleOptionScreen" + String.valueOf(handleScreenNum) + ")\n");
bw.write(" core.conversationService.sendConversationMessage(actor, npc, OutOfBand.ProsePackage('@" + response.getStf() + "'))\n");
bw.write(" return\n");
bw.newLine();
createResponseHandler(bw, options, handleScreenNum, conversationLinks);
}
private void createOptions(BufferedWriter bw, ArrayList<ConversationNode> options, int handleScreenNum, String space) throws IOException {
bw.write(space + "options = new Vector()\n");
if (options.size() > 1) {
ArrayList<ConversationNode> orderedOptions = new ArrayList<>();
for (ConversationNode unOrdered : options) {
orderedOptions.add(unOrdered.getOptionId(), unOrdered);
}
for (ConversationNode option : orderedOptions) {
bw.write(space + "options.add(ConversationOption(OutOfBand.ProsePackage('@" + option.getStf() +"'), " + options.indexOf(option) + ")\n");
}
} else {
for (ConversationNode option : options) {
bw.write(space + "options.add(ConversationOption(OutOfBand.ProsePackage('@" + option.getStf() +"'), " + options.indexOf(option) + ")\n");
}
}
bw.write(space + "core.conversationService.sendConversationOptions(actor, npc, handleOptionScreen" + String.valueOf(handleScreenNum) + ")\n");
}
}
@@ -0,0 +1,9 @@
CompileVisualPanel1.jLabel1.text=Location
CompileVisualPanel1.jLabel2.text=Please select the location where you wish to build the script to.
CompileVisualPanel1.btnBrowse.text=Browse
CompileVisualPanel1.txtLocation.text=
CompileVisualPanel1.jLabel3.text=Script Name
CompileVisualPanel1.txtName.text=conversation_script
CompileVisualPanel1.jLabel4.text=Enter a name for the compiled script. This should not include any extensions (ex: .py)
CompileVisualPanel1.jLabel5.text=Script will be built to:
CompileVisualPanel1.txtBuildLoc.text=
@@ -0,0 +1,158 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.4" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<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="true"/>
<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">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="txtName" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel5" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtBuildLoc" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="txtLocation" min="-2" pref="266" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnBrowse" min="-2" pref="75" max="-2" attributes="0"/>
</Group>
<Component id="jLabel2" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jLabel4" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<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">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnBrowse" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtLocation" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="14" max="-2" attributes="0"/>
<Component id="jLabel4" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtName" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="48" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel5" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtBuildLoc" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="124" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/compiler/wizard/Bundle.properties" key="CompileVisualPanel1.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtLocation">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/compiler/wizard/Bundle.properties" key="CompileVisualPanel1.txtLocation.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnBrowse">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/compiler/wizard/Bundle.properties" key="CompileVisualPanel1.btnBrowse.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="btnBrowseActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="txtLocation"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/compiler/wizard/Bundle.properties" key="CompileVisualPanel1.jLabel2.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel3">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/compiler/wizard/Bundle.properties" key="CompileVisualPanel1.jLabel3.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtName">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/compiler/wizard/Bundle.properties" key="CompileVisualPanel1.txtName.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="keyTyped" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtNameKeyTyped"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel4">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="txtName"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/compiler/wizard/Bundle.properties" key="CompileVisualPanel1.jLabel4.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel5">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/compiler/wizard/Bundle.properties" key="CompileVisualPanel1.jLabel5.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtBuildLoc">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/compiler/wizard/Bundle.properties" key="CompileVisualPanel1.txtBuildLoc.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Form>
@@ -0,0 +1,155 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.projectswg.tools.csc.compiler.wizard;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
public final class CompileVisualPanel1 extends JPanel {
/**
* Creates new form CompileVisualPanel1
*/
public CompileVisualPanel1() {
initComponents();
}
@Override
public String getName() {
return "Select Location";
}
/**
* 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
txtLocation = new javax.swing.JTextField();
btnBrowse = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
txtName = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
txtBuildLoc = new javax.swing.JTextField();
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(CompileVisualPanel1.class, "CompileVisualPanel1.jLabel1.text")); // NOI18N
txtLocation.setEditable(false);
txtLocation.setText(org.openide.util.NbBundle.getMessage(CompileVisualPanel1.class, "CompileVisualPanel1.txtLocation.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(btnBrowse, org.openide.util.NbBundle.getMessage(CompileVisualPanel1.class, "CompileVisualPanel1.btnBrowse.text")); // NOI18N
btnBrowse.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBrowseActionPerformed(evt);
}
});
jLabel2.setLabelFor(txtLocation);
org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(CompileVisualPanel1.class, "CompileVisualPanel1.jLabel2.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(CompileVisualPanel1.class, "CompileVisualPanel1.jLabel3.text")); // NOI18N
txtName.setText(org.openide.util.NbBundle.getMessage(CompileVisualPanel1.class, "CompileVisualPanel1.txtName.text")); // NOI18N
txtName.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
txtNameKeyTyped(evt);
}
});
jLabel4.setLabelFor(txtName);
org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(CompileVisualPanel1.class, "CompileVisualPanel1.jLabel4.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(CompileVisualPanel1.class, "CompileVisualPanel1.jLabel5.text")); // NOI18N
txtBuildLoc.setEditable(false);
txtBuildLoc.setText(org.openide.util.NbBundle.getMessage(CompileVisualPanel1.class, "CompileVisualPanel1.txtBuildLoc.text")); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtName))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtBuildLoc))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtLocation, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnBrowse, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel2)
.addComponent(jLabel4))
.addGap(0, 0, Short.MAX_VALUE))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnBrowse)
.addComponent(txtLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(14, 14, 14)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(48, 48, 48)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(txtBuildLoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(124, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseActionPerformed
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Select Location");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = chooser.showDialog(this, "Select");
if (returnVal == JFileChooser.APPROVE_OPTION) {
txtLocation.setText(chooser.getSelectedFile().getPath());
txtBuildLoc.setText(txtLocation.getText() + "\\" + txtName.getText() + ".py");
}
}//GEN-LAST:event_btnBrowseActionPerformed
private void txtNameKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNameKeyTyped
txtBuildLoc.setText(txtLocation.getText() + "\\" + txtName.getText() + ".py");
}//GEN-LAST:event_txtNameKeyTyped
public String getBuildLocation() {
return txtBuildLoc.getText();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnBrowse;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JTextField txtBuildLoc;
private javax.swing.JTextField txtLocation;
private javax.swing.JTextField txtName;
// End of variables declaration//GEN-END:variables
}
@@ -0,0 +1,72 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.projectswg.tools.csc.compiler.wizard;
import com.projectswg.tools.csc.compiler.Compiler;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JComponent;
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.ActionRegistration;
import org.openide.util.Exceptions;
import org.openide.util.ImageUtilities;
@ActionID(category="...", id="com.projectswg.tools.csc.compiler.wizard.CompileWizardAction")
@ActionRegistration(displayName="Create Script")
@ActionReference(path="Menu/File")
public final class CompileWizardAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
List<WizardDescriptor.Panel<WizardDescriptor>> panels = new ArrayList<>();
CompileWizardPanel1 compilePanel = new CompileWizardPanel1();
panels.add(compilePanel);
String[] steps = new String[panels.size()];
for (int i = 0; i < panels.size(); i++) {
Component c = panels.get(i).getComponent();
// Default step name to component name of panel.
steps[i] = c.getName();
if (c instanceof JComponent) { // assume Swing components
JComponent jc = (JComponent) c;
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i);
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps);
jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, true);
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, true);
jc.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, true);
}
}
WizardDescriptor wiz = new WizardDescriptor(new WizardDescriptor.ArrayIterator<>(panels));
// {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
wiz.setTitleFormat(new MessageFormat("{0}"));
wiz.setTitle("Compile Conversation Script");
wiz.putProperty(WizardDescriptor.PROP_IMAGE, ImageUtilities.loadImage("com/projectswg/tools/csc/compiler/wizard/csc_wizard_bg.png"));
if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) {
File file = new File(compilePanel.getComponent().getBuildLocation());
if (file.exists()) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message("Script already exists: " + file.getAbsolutePath(), NotifyDescriptor.ERROR_MESSAGE));
} else {
Compiler compiler = new Compiler(file);
try {
compiler.compile();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
}
@@ -0,0 +1,63 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.projectswg.tools.csc.compiler.wizard;
import javax.swing.event.ChangeListener;
import org.openide.WizardDescriptor;
import org.openide.util.HelpCtx;
public class CompileWizardPanel1 implements WizardDescriptor.Panel<WizardDescriptor> {
private CompileVisualPanel1 component;
// Get the visual component for the panel. In this template, the component
// is kept separate. This can be more efficient: if the wizard is created
// but never displayed, or not all panels are displayed, it is better to
// create only those which really need to be visible.
@Override
public CompileVisualPanel1 getComponent() {
if (component == null) {
component = new CompileVisualPanel1();
}
return component;
}
@Override
public HelpCtx getHelp() {
// Show no Help button for this panel:
return HelpCtx.DEFAULT_HELP;
// If you have context help:
// return new HelpCtx("help.key.here");
}
@Override
public boolean isValid() {
// If it is always OK to press Next or Finish, then:
return true;
// If it depends on some condition (form filled out...) and
// this condition changes (last form field filled in...) then
// use ChangeSupport to implement add/removeChangeListener below.
// WizardDescriptor.ERROR/WARNING/INFORMATION_MESSAGE will also be useful.
}
@Override
public void addChangeListener(ChangeListener l) {
}
@Override
public void removeChangeListener(ChangeListener l) {
}
@Override
public void readSettings(WizardDescriptor wiz) {
// use wiz.getProperty to retrieve previous panel state
}
@Override
public void storeSettings(WizardDescriptor wiz) {
// use wiz.putProperty to remember current panel state
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB