Fixed persistence issues when restarting the program, Improved the compile wizard allowing indent settings and comment settings, Fixed end conversations not being generated properly.

This commit is contained in:
Waverunner
2014-09-12 10:10:42 -04:00
parent 0c9b963d86
commit 31a248662b
31 changed files with 1159 additions and 659 deletions
@@ -0,0 +1,187 @@
package com.projectswg.tools.csc.conversationeditor;
import com.projectswg.tools.csc.conversationeditor.ConversationNode;
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.Map;
import javax.swing.JOptionPane;
import org.openide.windows.TopComponent;
public class Compiler {
private final File file;
private boolean comments = true;
private boolean tabs = true;
private String header = "";
public Compiler(File file, boolean comments, String header, boolean tabs) {
this.file = file;
this.comments = comments;
this.header = header;
this.tabs = tabs;
}
public boolean compile() throws IOException {
TopComponent component = TopComponent.getRegistry().getActivated();
if (component == null || !(component instanceof EditorTopComponent))
return false;
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 false;
}
try (BufferedWriter bw = new BufferedWriter(new FileWriter(file.getAbsolutePath()))) {
createBaseFile(bw);
LinkedHashMap<ConversationNode, ArrayList<ConversationNode>> conversationLinks = scene.getConversationLinks();
for (Map.Entry<ConversationNode, ArrayList<ConversationNode>> entry : conversationLinks.entrySet()) {
if (entry.getKey().isStartNode()) {
createOptionsAndHandler(bw, entry.getKey(), entry.getValue(), 1, conversationLinks);
break;
}
}
}
return true;
}
private void createBaseFile(BufferedWriter bw) throws IOException {
if (comments && !header.isEmpty()) bw.write("#" + header + "\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();
String indent4 = getIndent(4);
String indent8 = getIndent(8);
int count = handleNum + 1;
for (ConversationNode selectedOption : options) {
bw.write(indent4 + (options.indexOf(selectedOption) > 0 ? "elif" : "if") + " selection == " + options.indexOf(selectedOption) + ":\n");
if (conversationLinks.containsKey(selectedOption)) {
if (comments) bw.write(indent8 + "# " + (selectedOption.getDisplayText().equals("") ? selectedOption.getStf() : selectedOption.getDisplayText()) + "\n");
for (ConversationNode handleNode : conversationLinks.get(selectedOption)) {
if (!handleNode.isOption() && !handleNode.isEndNode()) {
if (conversationLinks.get(handleNode) == null) {
bw.write(indent8 + "# NULL Error printing out handle for " + handleNode.getStf());
} else {
createOptions(bw, conversationLinks.get(handleNode), count++, indent8);
bw.write(indent8 + "core.conversationService.sendConversationMessage(actor, npc, OutOfBand.ProsePackage('@conversation/"
+ handleNode.getStf() + "')\n");
handleFuncs.put(handleNode, conversationLinks.get(handleNode)); // Put these nodes in list so we can create the handlers later.
}
} else if (handleNode.isEndNode()) {
if (handleNode.getStf().contains(":")) {
String[] split = handleNode.getStf().split(":");
bw.write(indent8 + "core.conversationService.sendStopConversation(actor, npc, 'conversation/" + split[0] + "', '" + split[1] + "')\n");
} else {
bw.write(indent8 + "# Couldn't write end response because of bad format!");
}
}
}
}
bw.write(indent8 + "return\n");
bw.newLine();
}
bw.write(indent4 + "return\n");
bw.newLine();
int currentHandler = handleNum + 1;
for (Map.Entry<ConversationNode, ArrayList<ConversationNode>> handleNode : handleFuncs.entrySet()) {
bw.write("# Handle Response for " + handleNode.getKey().getStf());
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 {
String indent4 = getIndent(4);
bw.write(indent4 + "options = new Vector()\n");
if (options.size() > 1) {
for (ConversationNode option : options) {
bw.write(indent4 + "options.add(ConversationOption(OutOfBand.ProsePackage('@conversation/" + option.getStf() +"'), "
+ String.valueOf(option.getOptionId()) + ")\n");
}
} else {
for (ConversationNode option : options) {
bw.write(indent4 + "options.add(ConversationOption(OutOfBand.ProsePackage('@conversation/" + option.getStf() +"'), " + options.indexOf(option) + ")\n");
}
}
bw.write(indent4 + "core.conversationService.sendConversationOptions(actor, npc, handleOptionScreen" + String.valueOf(handleScreenNum) + ")\n");
bw.write(indent4 + "core.conversationService.sendConversationMessage(actor, npc, OutOfBand.ProsePackage('@conversation/" + response.getStf() + "'))\n");
bw.write(indent4 + "return\n");
bw.newLine();
bw.write("# Handle Response for " + response.getStf());
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('@conversation/" + option.getStf() +"'), " + options.indexOf(option) + ")\n");
}
} else {
for (ConversationNode option : options) {
bw.write(space + "options.add(ConversationOption(OutOfBand.ProsePackage('@conversation/" + option.getStf() +"'), " + options.indexOf(option) + ")\n");
}
}
bw.write(space + "core.conversationService.sendConversationOptions(actor, npc, handleOptionScreen" + String.valueOf(handleScreenNum) + ")\n");
}
private String getIndent(int length) {
String rtn = "";
if (!tabs) {
int i = 0;
while (i < length) {
rtn = rtn + " ";
}
} else {
switch(length) {
case 4:
rtn = "\t";
break;
case 8:
rtn = "\t\t";
break;
}
}
return rtn;
}
}
@@ -38,7 +38,6 @@ public final class EditorTopComponent extends TopComponent implements ExplorerMa
private final SceneView scene;
private String activePath = "";
// New Conversation
public EditorTopComponent() {
initComponents();
@@ -47,8 +46,9 @@ public final class EditorTopComponent extends TopComponent implements ExplorerMa
this.scene = new SceneView(mgr);
scrollPane.setViewportView(scene.createView());
associateLookup(ExplorerUtils.createLookup(mgr, getActionMap()));
associateLookup(ExplorerUtils.createLookup(mgr, getActionMap()));
//SystemAction.get(CompileWizardAction.class).setEnabled(true);
}
/**
@@ -79,21 +79,22 @@ public final class EditorTopComponent extends TopComponent implements ExplorerMa
@Override
public void componentOpened() {
if (activePath.equals("")) {
// blankSlate();
// scene.validate();
if (activePath.isEmpty() && scene.getScenePath().isEmpty()) {
blankSlate();
return;
}
File file = new File(activePath);
if (!scene.isLoaded()) {
File file = new File(activePath);
if (!file.exists()) {
JOptionPane.showMessageDialog(null, "Couldn't open conversation file " + file.getAbsolutePath()
+ " because it no longer exists.", "Conversation Script Editor", JOptionPane.INFORMATION_MESSAGE);
blankSlate();
scene.validate();
} else {
OpenConversation.open(file, this);
if (!file.exists()) {
JOptionPane.showMessageDialog(null, "Couldn't open conversation file " + file.getAbsolutePath()
+ " because it no longer exists.", "Conversation Script Editor", JOptionPane.INFORMATION_MESSAGE);
blankSlate();
scene.validate();
} else {
OpenConversation.open(file, this);
}
}
}
@@ -103,12 +104,10 @@ public final class EditorTopComponent extends TopComponent implements ExplorerMa
}
void writeProperties(java.util.Properties p) {
//p.setProperty("version", "1.0");
p.setProperty("activePath", scene.getScenePath());
}
void readProperties(java.util.Properties p) {
//String version = p.getProperty("version");
this.activePath = p.getProperty("activePath");
}
@@ -105,7 +105,6 @@ public class SceneSaver {
@Override
public void run() {
deserializeNodeDataVersion1(scene, sceneXMLNode);
scene.validate ();
}
});
@@ -23,6 +23,7 @@ public class SceneView extends GraphScene<ConversationNode, String>{
private String name = "";
private String scenePath = "";
private boolean loaded = false;
private int id = 1;
@@ -35,11 +36,11 @@ public class SceneView extends GraphScene<ConversationNode, String>{
mainLayer = new LayerWidget(this);
addChild(mainLayer);
getActions().addAction(ActionFactory.createZoomAction());
getActions().addAction(ActionFactory.createWheelPanAction());
connectionLayer = new LayerWidget(this);
addChild(connectionLayer);
getActions().addAction(ActionFactory.createZoomAction());
getActions().addAction(ActionFactory.createWheelPanAction());
this.mgr = mgr;
}
@@ -130,6 +131,14 @@ public class SceneView extends GraphScene<ConversationNode, String>{
this.id = id;
}
public void setLoaded(boolean loaded) {
this.loaded = loaded;
}
public boolean isLoaded() {
return loaded;
}
public LinkedHashMap<ConversationNode, ArrayList<ConversationNode>> getConversationLinks() {
List<Widget> connectedNodes = connectionLayer.getChildren();
LinkedHashMap<ConversationNode, ArrayList<ConversationNode>> conversationLinks = new LinkedHashMap<>();
@@ -23,7 +23,7 @@ import org.openide.util.NbBundle.Messages;
displayName = "New Conversation"
)
@ActionReferences({
@ActionReference(path = "Menu/File", position = -115),
@ActionReference(path = "Menu/File", position = 2),
@ActionReference(path = "Toolbars/File", position = 400),
@ActionReference(path = "Shortcuts", name = "D-N")
})
@@ -33,8 +33,6 @@ public final class NewConversation implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
EditorTopComponent newEditor = new EditorTopComponent();
newEditor.blankSlate();
newEditor.getScene().validate();
newEditor.open();
newEditor.requestActive();
}
@@ -3,6 +3,7 @@ package com.projectswg.tools.csc.conversationeditor.actions;
import com.projectswg.tools.csc.conversationeditor.EditorTopComponent;
import com.projectswg.tools.csc.conversationeditor.SceneSaver;
import com.projectswg.tools.csc.conversationeditor.SceneView;
import com.projectswg.tools.csc.conversationeditor.wizard.CompileWizardAction;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
@@ -17,9 +18,9 @@ import org.openide.awt.ActionRegistration;
import org.openide.filesystems.FileChooserBuilder;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle.Messages;
import org.openide.util.actions.SystemAction;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
@ActionID(category = "File", id = "org.mycore.OpenFileAction")
@@ -44,10 +45,14 @@ public final class OpenConversation implements ActionListener {
open(toAdd, editor);
editor.open();
editor.requestActive();
}
}
public static void open(File openFile, EditorTopComponent editor) {
if (editor.getScene().isLoaded())
return;
try {
if (!openFile.getName().endsWith(".xml")) {
System.out.println("Not a valid Conversation Editor file!");
@@ -78,10 +83,11 @@ public final class OpenConversation implements ActionListener {
}
scene.setSceneName(openFile.getName().split(".xml")[0]);
scene.setScenePath(openFile.getAbsolutePath());
saver.deserializeData(scene, sceneNode);
editor.setName(scene.getSceneName());
scene.setLoaded(true);
} catch (ParserConfigurationException | SAXException | IOException ex) {
Exceptions.printStackTrace(ex);
}
@@ -46,7 +46,7 @@ import org.xml.sax.SAXException;
displayName = "Save"
)
@ActionReferences({
@ActionReference(path = "Menu/File", position = -90, separatorBefore = -140),
@ActionReference(path = "Menu/File", position = 3, separatorBefore = -140),
@ActionReference(path = "Toolbars/File", position = 500),
@ActionReference(path = "Shortcuts", name = "D-S")
})
@@ -9,11 +9,22 @@
<file name="Debug_hidden"/>
<file name="Diff_hidden"/>
<folder name="Edit">
<file name="com-projectswg-tools-csc-conversationeditor-actions-NewConvOption.instance_hidden"/>
<file name="org-netbeans-core-ui-options-filetypes-OpenAsAction.instance_hidden"/>
<file name="org-netbeans-core-ui-sysopen-SystemOpenAction.instance_hidden"/>
<file name="org-netbeans-modules-quicksearch-QuickSearchAction.instance_hidden"/>
<file name="org-netbeans-modules-search-FindInFilesAction.instance_hidden"/>
<file name="org-netbeans-modules-search-ReplaceInFilesAction.instance_hidden"/>
<file name="org-openide-actions-CopyAction.instance_hidden"/>
<file name="org-openide-actions-CutAction.instance_hidden"/>
<file name="org-openide-actions-DeleteAction.instance_hidden"/>
<file name="org-openide-actions-FindAction.instance_hidden"/>
<file name="org-openide-actions-GotoAction.instance_hidden"/>
<file name="org-openide-actions-PasteAction.instance_hidden"/>
<file name="org-openide-actions-RedoAction.instance_hidden"/>
<file name="org-openide-actions-ReplaceAction.instance_hidden"/>
<file name="org-openide-actions-UndoAction.instance_hidden"/>
</folder>
<folder name="File">
<file name="com-projectswg-tools-csc-conversationeditor-actions-CompileConvScript.instance_hidden"/>
<file name="com-projectswg-tools-csc-conversationeditor-actions-NewConvEnd.instance_hidden"/>
<file name="org-netbeans-modules-print-action-PageSetupAction.instance_hidden"/>
<file name="org-netbeans-modules-print-action-PrintAction.instance_hidden"/>
<file name="org-netbeans-modules-project-ui-actions-CloseAllProjectsAction.instance_hidden"/>
@@ -0,0 +1,15 @@
CompileVisualPanel1.jLabel1.text=Select the directory to export to. If this is your first time running the wizard, you'll have to select the location of the scripts/conversation folder
CompileVisualPanel1.jLabel2.text=Export Directory:
CompileVisualPanel1.tbExportDirectory.text=None Selected
CompileVisualPanel1.btnChngScriptsLoc.text=Change Scripts Location
CompileVisualPanel1.btnChngScriptsLoc.toolTipText=
CompileVisualPanel2.jLabel1.text=Select any additional options for compiling the script.
CompileVisualPanel2.jLabel2.text=Indentation type:
CompileVisualPanel2.radioSpaces.text=Spaces
CompileVisualPanel2.radioTabs.text=Tabs
CompileVisualPanel2.chkbxComments.text=Generate Comments
CompileVisualPanel2.jLabel4.text=Script name
CompileVisualPanel2.tbScriptName.text=
CompileVisualPanel2.jLabel3.text=Header:
CompileVisualPanel2.txtAreaHeader.text=Base file generated using Conversation Script Creator for ProjectSWG
CompileVisualPanel2.jLabel5.text=Note: Must end in .py!
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.7" 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">
<Component id="jScrollPane1" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="tbExportDirectory" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<Component id="btnChngScriptsLoc" 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="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="tbExportDirectory" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="286" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnChngScriptsLoc" min="-2" max="-2" attributes="0"/>
<EmptySpace 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/conversationeditor/wizard/Bundle.properties" key="CompileVisualPanel1.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTree" name="scriptsTree">
<Properties>
<Property name="model" type="javax.swing.tree.TreeModel" editor="org.netbeans.modules.form.editors2.TreeModelEditor">
<TreeModel code="scripts/conversation&#xa;&#xa; "/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="btnChngScriptsLoc">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/conversationeditor/wizard/Bundle.properties" key="CompileVisualPanel1.btnChngScriptsLoc.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/conversationeditor/wizard/Bundle.properties" key="CompileVisualPanel1.btnChngScriptsLoc.toolTipText" 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="btnChngScriptsLocActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/conversationeditor/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.JTextField" name="tbExportDirectory">
<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/conversationeditor/wizard/Bundle.properties" key="CompileVisualPanel1.tbExportDirectory.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Form>
@@ -0,0 +1,152 @@
/*
* 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.conversationeditor.wizard;
import java.io.File;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import org.openide.filesystems.FileChooserBuilder;
public final class CompileVisualPanel1 extends JPanel {
public CompileVisualPanel1() {
initComponents();
}
@Override
public String getName() {
return "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();
jScrollPane1 = new javax.swing.JScrollPane();
scriptsTree = new javax.swing.JTree();
btnChngScriptsLoc = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
tbExportDirectory = new javax.swing.JTextField();
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(CompileVisualPanel1.class, "CompileVisualPanel1.jLabel1.text")); // NOI18N
javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("scripts/conversation");
scriptsTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
jScrollPane1.setViewportView(scriptsTree);
org.openide.awt.Mnemonics.setLocalizedText(btnChngScriptsLoc, org.openide.util.NbBundle.getMessage(CompileVisualPanel1.class, "CompileVisualPanel1.btnChngScriptsLoc.text")); // NOI18N
btnChngScriptsLoc.setToolTipText(org.openide.util.NbBundle.getMessage(CompileVisualPanel1.class, "CompileVisualPanel1.btnChngScriptsLoc.toolTipText")); // NOI18N
btnChngScriptsLoc.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnChngScriptsLocActionPerformed(evt);
}
});
org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(CompileVisualPanel1.class, "CompileVisualPanel1.jLabel2.text")); // NOI18N
tbExportDirectory.setEditable(false);
tbExportDirectory.setText(org.openide.util.NbBundle.getMessage(CompileVisualPanel1.class, "CompileVisualPanel1.tbExportDirectory.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)
.addComponent(jScrollPane1)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tbExportDirectory))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(btnChngScriptsLoc))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(tbExportDirectory, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 286, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnChngScriptsLoc)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void btnChngScriptsLocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChngScriptsLocActionPerformed
File home = new File(System.getProperty("user.home"));
File selection = new FileChooserBuilder("user-dir").setTitle("Select Directory").
setDefaultWorkingDirectory(home).setApproveText("Select").setDirectoriesOnly(true).showOpenDialog();
if (selection != null) {
String path = selection.getAbsolutePath();
if (!path.endsWith("scripts\\conversation")) {
JOptionPane.showConfirmDialog(null, path + " is not a valid scripts/conversation directory", "Error", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE);
return;
}
populateScriptsTree(selection);
}
}//GEN-LAST:event_btnChngScriptsLocActionPerformed
public void populateScriptsTree(File base) {
DefaultMutableTreeNode root = new DefaultMutableTreeNode("scripts/conversation");
populateTree(root, base);
scriptsTree.setModel(new DefaultTreeModel(root));
tbExportDirectory.setText(base.getAbsolutePath());
}
private void populateTree(DefaultMutableTreeNode root, File dir) {
for (File f : dir.listFiles()) {
if (f.isDirectory()) {
DefaultMutableTreeNode dirNode = new DefaultMutableTreeNode(f.getName());
populateTree(dirNode, f);
root.add(dirNode);
}
}
}
public javax.swing.JTextField getExportDirectory() {
return tbExportDirectory;
}
public javax.swing.JTree getScriptFolderTree() {
return scriptsTree;
}
public void setScriptsTree(JTree scriptsTree) {
this.scriptsTree = scriptsTree;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnChngScriptsLoc;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTree scriptsTree;
private javax.swing.JTextField tbExportDirectory;
// End of variables declaration//GEN-END:variables
}
@@ -0,0 +1,188 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.4" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents>
<Component class="javax.swing.ButtonGroup" name="radialIndentation">
</Component>
</NonVisualComponents>
<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">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel1" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jLabel2" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="36" max="-2" attributes="0"/>
<Component id="radioSpaces" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="radioTabs" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="chkbxComments" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" alignment="1" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel4" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="tbScriptName" min="-2" pref="164" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jLabel5" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="144" max="32767" attributes="0"/>
</Group>
</Group>
</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="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="31" max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="radioSpaces" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="radioTabs" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="chkbxComments" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel4" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="tbScriptName" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel5" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="118" max="-2" attributes="0"/>
<EmptySpace max="-2" 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/conversationeditor/wizard/Bundle.properties" key="CompileVisualPanel2.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/conversationeditor/wizard/Bundle.properties" key="CompileVisualPanel2.jLabel2.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JRadioButton" name="radioSpaces">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="radialIndentation"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/conversationeditor/wizard/Bundle.properties" key="CompileVisualPanel2.radioSpaces.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JRadioButton" name="radioTabs">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="radialIndentation"/>
</Property>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/conversationeditor/wizard/Bundle.properties" key="CompileVisualPanel2.radioTabs.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="chkbxComments">
<Properties>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/conversationeditor/wizard/Bundle.properties" key="CompileVisualPanel2.chkbxComments.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="chkbxCommentsItemStateChanged"/>
</Events>
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTextArea" name="txtAreaHeader">
<Properties>
<Property name="columns" type="int" value="20"/>
<Property name="rows" type="int" value="5"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/conversationeditor/wizard/Bundle.properties" key="CompileVisualPanel2.txtAreaHeader.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
<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/conversationeditor/wizard/Bundle.properties" key="CompileVisualPanel2.jLabel3.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel4">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/conversationeditor/wizard/Bundle.properties" key="CompileVisualPanel2.jLabel4.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="tbScriptName">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/projectswg/tools/csc/conversationeditor/wizard/Bundle.properties" key="CompileVisualPanel2.tbScriptName.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/conversationeditor/wizard/Bundle.properties" key="CompileVisualPanel2.jLabel5.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Form>
@@ -0,0 +1,193 @@
/*
* 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.conversationeditor.wizard;
import java.awt.event.ItemEvent;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public final class CompileVisualPanel2 extends JPanel {
/**
* Creates new form CompileVisualPanel2
*/
public CompileVisualPanel2() {
initComponents();
}
@Override
public String getName() {
return "Set Options";
}
/**
* 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() {
radialIndentation = new javax.swing.ButtonGroup();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
radioSpaces = new javax.swing.JRadioButton();
radioTabs = new javax.swing.JRadioButton();
chkbxComments = new javax.swing.JCheckBox();
jScrollPane1 = new javax.swing.JScrollPane();
txtAreaHeader = new javax.swing.JTextArea();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
tbScriptName = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(CompileVisualPanel2.class, "CompileVisualPanel2.jLabel1.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(CompileVisualPanel2.class, "CompileVisualPanel2.jLabel2.text")); // NOI18N
radialIndentation.add(radioSpaces);
org.openide.awt.Mnemonics.setLocalizedText(radioSpaces, org.openide.util.NbBundle.getMessage(CompileVisualPanel2.class, "CompileVisualPanel2.radioSpaces.text")); // NOI18N
radialIndentation.add(radioTabs);
radioTabs.setSelected(true);
org.openide.awt.Mnemonics.setLocalizedText(radioTabs, org.openide.util.NbBundle.getMessage(CompileVisualPanel2.class, "CompileVisualPanel2.radioTabs.text")); // NOI18N
chkbxComments.setSelected(true);
org.openide.awt.Mnemonics.setLocalizedText(chkbxComments, org.openide.util.NbBundle.getMessage(CompileVisualPanel2.class, "CompileVisualPanel2.chkbxComments.text")); // NOI18N
chkbxComments.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
chkbxCommentsItemStateChanged(evt);
}
});
txtAreaHeader.setColumns(20);
txtAreaHeader.setRows(5);
txtAreaHeader.setText(org.openide.util.NbBundle.getMessage(CompileVisualPanel2.class, "CompileVisualPanel2.txtAreaHeader.text")); // NOI18N
jScrollPane1.setViewportView(txtAreaHeader);
org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(CompileVisualPanel2.class, "CompileVisualPanel2.jLabel3.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(CompileVisualPanel2.class, "CompileVisualPanel2.jLabel4.text")); // NOI18N
tbScriptName.setText(org.openide.util.NbBundle.getMessage(CompileVisualPanel2.class, "CompileVisualPanel2.tbScriptName.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(CompileVisualPanel2.class, "CompileVisualPanel2.jLabel5.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()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)))
.addGroup(layout.createSequentialGroup()
.addGap(36, 36, 36)
.addComponent(radioSpaces)
.addGap(18, 18, 18)
.addComponent(radioTabs))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(chkbxComments))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel3)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tbScriptName, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel5)
.addGap(0, 144, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(31, 31, 31)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(radioSpaces)
.addComponent(radioTabs))
.addGap(18, 18, 18)
.addComponent(chkbxComments)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(tbScriptName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
private void chkbxCommentsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkbxCommentsItemStateChanged
switch(evt.getStateChange()) {
case ItemEvent.DESELECTED:
txtAreaHeader.setEditable(false);
txtAreaHeader.setEnabled(false);
break;
case ItemEvent.SELECTED:
txtAreaHeader.setEditable(true);
txtAreaHeader.setEnabled(true);
break;
}
}//GEN-LAST:event_chkbxCommentsItemStateChanged
public JRadioButton getRadioSpaces() {
return radioSpaces;
}
public JRadioButton getRadioTabs() {
return radioTabs;
}
public JCheckBox getChkbxComments() {
return chkbxComments;
}
public ButtonGroup getRadioGroupIndentation() {
return radialIndentation;
}
public JTextArea getTxtAreaHeader() {
return txtAreaHeader;
}
public JTextField getTbScriptName() {
return tbScriptName;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JCheckBox chkbxComments;
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.JScrollPane jScrollPane1;
private javax.swing.ButtonGroup radialIndentation;
private javax.swing.JRadioButton radioSpaces;
private javax.swing.JRadioButton radioTabs;
private javax.swing.JTextField tbScriptName;
private javax.swing.JTextArea txtAreaHeader;
// End of variables declaration//GEN-END:variables
}
@@ -0,0 +1,98 @@
/*
* 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.conversationeditor.wizard;
import com.projectswg.tools.csc.conversationeditor.Compiler;
import com.projectswg.tools.csc.conversationeditor.EditorTopComponent;
import java.awt.Component;
import java.awt.Desktop;
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 javax.swing.JOptionPane;
import org.openide.DialogDisplayer;
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.windows.TopComponent;
// An example action demonstrating how the wizard could be called from within
// your code. You can move the code below wherever you need, or register an action:
@ActionID(category="File", id="com.projectswg.tools.csc.conversationeditor.wizard.CompileWizardAction")
@ActionRegistration(displayName="Compile Script")
@ActionReference(path="Menu/File", position=0, separatorAfter=1)
public final class CompileWizardAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
TopComponent component = TopComponent.getRegistry().getActivated();
if (component == null || !(component instanceof EditorTopComponent)) {
JOptionPane.showConfirmDialog(component, "No active scene to compile!", "Conversation Script Creator", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
return;
}
List<WizardDescriptor.Panel<WizardDescriptor>> panels = new ArrayList<>();
panels.add(new CompileWizardPanel1());
panels.add(new CompileWizardPanel2());
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 Wizard");
if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) {
String directory = (String) wiz.getProperty("directory");
boolean comments = (Boolean) wiz.getProperty("comments");
String header = (String) wiz.getProperty("header");
boolean tabs = (((String) wiz.getProperty("indent")).equals("tabs"));
String script = (String) wiz.getProperty("script");
File file = new File(directory + "\\" + script);
if (file.exists()) {
JOptionPane.showConfirmDialog(null, "The directory " + file.getAbsolutePath() +
" already exists!", "Conversation Script Creator", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
return;
}
Compiler compiler = new Compiler(file, comments, header, tabs);
try {
if (compiler.compile()) {
if (JOptionPane.showConfirmDialog(null, "Script created at " + file.getAbsolutePath() + " successfully. Would you like to open it?",
"Conversation Script Creator", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) {
Desktop dt = Desktop.getDesktop();
if (dt != null)
dt.open(file);
}
} else {
JOptionPane.showConfirmDialog(null, "Failed to create script at " + file.getAbsolutePath()
+ " !", "Conversation Script Creator", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
@@ -0,0 +1,132 @@
/*
* 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.conversationeditor.wizard;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
import javax.swing.JTree;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import org.openide.WizardDescriptor;
import org.openide.util.HelpCtx;
import org.openide.util.NbPreferences;
public class CompileWizardPanel1 implements WizardDescriptor.Panel<WizardDescriptor>, TreeSelectionListener {
private CompileVisualPanel1 component;
private boolean valid = true;
private final Set<ChangeListener> listeners = new HashSet<>(1);
public CompileWizardPanel1() {
valid = false;
}
@Override
public CompileVisualPanel1 getComponent() {
if (component == null) {
component = new CompileVisualPanel1();
component.getScriptFolderTree().addTreeSelectionListener(this);
}
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() {
System.out.println("dafd" + valid);
return valid;
}
private void setValid(boolean val) {
if (val == valid)
return;
valid = val;
fireChangeEvent();
}
@Override
public void addChangeListener(ChangeListener l) {
listeners.add(l);
}
@Override
public void removeChangeListener(ChangeListener l) {
listeners.remove(l);
}
protected final void fireChangeEvent() {
ChangeEvent event = new ChangeEvent(this);
for (ChangeListener l : listeners) {
l.stateChanged(event);
}
}
@Override
public void readSettings(WizardDescriptor wiz) {
Object tree = wiz.getProperty("tree");
if (tree != null) {
component.setScriptsTree((JTree) tree);
} else {
Object scripts = wiz.getProperty("directory");
if (scripts == null) {
scripts = NbPreferences.forModule(CompileWizardPanel1.class).get("directory", "");
if (scripts == "") {
return;
}
}
File dir = new File(scripts.toString().split("conversation")[0] + "\\conversation");
if (!dir.exists()) {
return;
}
component.populateScriptsTree(dir);
}
}
@Override
public void storeSettings(WizardDescriptor wiz) {
wiz.putProperty("directory", component.getExportDirectory().getText());
NbPreferences.forModule(CompileWizardPanel1.class).put("directory", component.getExportDirectory().getText()); // persist across reloads
wiz.putProperty("tree", component.getScriptFolderTree());
}
@Override
public void valueChanged(TreeSelectionEvent e) {
if (e.getNewLeadSelectionPath() == null)
return;
Object[] path = e.getNewLeadSelectionPath().getPath();
String dir = component.getExportDirectory().getText().split("conversation")[0] + "conversation";
for (Object p : path) {
if (!p.toString().equals("scripts/conversation") && !dir.contains(p.toString()))
dir += "\\" +p.toString();
}
component.getExportDirectory().setText(dir);
setValid(true);
}
}
@@ -0,0 +1,154 @@
/*
* 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.conversationeditor.wizard;
import java.util.HashSet;
import java.util.Set;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.openide.WizardDescriptor;
import org.openide.WizardValidationException;
import org.openide.util.HelpCtx;
public class CompileWizardPanel2 implements WizardDescriptor.ValidatingPanel<WizardDescriptor>, DocumentListener {
/**
* The visual component that displays this panel. If you need to access the component from this class, just use getComponent().
*/
private CompileVisualPanel2 component;
private boolean valid = false;
private final Set<ChangeListener> listeners = new HashSet<>(1);
// 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 CompileVisualPanel2 getComponent() {
if (component == null) {
component = new CompileVisualPanel2();
component.getTbScriptName().getDocument().addDocumentListener(this);
}
return component;
}
@Override
public HelpCtx getHelp() {
return HelpCtx.DEFAULT_HELP;
}
@Override
public boolean isValid() {
System.out.println(valid);
return valid;
}
public void setValid(boolean val) {
if (valid == val)
return;
this.valid = val;
fireChangeEvent();
}
protected final void fireChangeEvent() {
ChangeEvent event = new ChangeEvent(this);
for (ChangeListener l : listeners) {
l.stateChanged(event);
}
}
@Override
public void addChangeListener(ChangeListener l) {
listeners.add(l);
}
@Override
public void removeChangeListener(ChangeListener l) {
listeners.remove(l);
}
@Override
public void readSettings(WizardDescriptor wiz) {
Object indents = wiz.getProperty("indent");
if (indents == null || indents.toString().equals("tabs"))
component.getRadioTabs().setSelected(true);
else
component.getRadioSpaces().setSelected(true);
Object comments = wiz.getProperty("comments");
if (comments == null) {
} else {
component.getChkbxComments().setSelected(Boolean.valueOf(comments.toString()));
}
Object header = wiz.getProperty("header");
if (header == null) {
} else {
component.getTxtAreaHeader().setText(header.toString());
}
Object sName = wiz.getProperty("script");
if (sName == null) {
// TODO: Use scene name
} else {
component.getTbScriptName().setText(sName.toString());
valid = true;
}
}
@Override
public void storeSettings(WizardDescriptor wiz) {
if (component.getRadioTabs().isSelected())
wiz.putProperty("indent", "tabs");
else
wiz.putProperty("indent", "spaces");
wiz.putProperty("comments", component.getChkbxComments().isSelected());
wiz.putProperty("header", component.getTxtAreaHeader().getText());
wiz.putProperty("script", component.getTbScriptName().getText());
}
private void checkText() {
if (!component.getTbScriptName().getText().endsWith(".py")) {
setValid(false);
} else {
setValid(true);
}
}
@Override
public void insertUpdate(DocumentEvent e) {
checkText();
}
@Override
public void removeUpdate(DocumentEvent e) {
checkText();
}
@Override
public void changedUpdate(DocumentEvent e) {
checkText();
}
@Override
public void validate() throws WizardValidationException {
if (!component.getTbScriptName().getText().endsWith(".py")) {
valid = false;
throw new WizardValidationException(null, "The script name must end with the .py extension.", null);
}
}
}