Skip to content

Commit 06c2447

Browse files
committed
Added open option, Added delete option for nodes, General functionality changes
1 parent 54a0fd6 commit 06c2447

17 files changed

+495
-117
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ hs_err_pid*
1515
/build/
1616
/ConversationEditor/build/
1717
/dist/
18-
/nbproject/private/
18+
/nbproject/private/
19+
/ConversationEditor/nbproject/private/
20+
/ConversationCompiler/nbproject/private/

ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/ConversationConnectProvider.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,51 @@ public void createConnection(Widget source, Widget target) {
4545
JOptionPane.showMessageDialog(null, "Cannot attach end conversation node to responses/options!", "Conversation Script Creator", JOptionPane.INFORMATION_MESSAGE);
4646
return;
4747
}
48+
ConversationNode cSource = ((ConversationWidget) source).getAttachedNode();
49+
ConversationNode cTarget = ((ConversationWidget) target).getAttachedNode();
50+
51+
if (cSource.isOption()) {
52+
if (cTarget.isOption())
53+
return;
54+
55+
else if (cTarget.isStartNode())
56+
return;
57+
58+
} else if (cSource.isStartNode()) {
59+
if (cTarget.isEndNode())
60+
return;
61+
} else if (cSource.isEndNode()) {
62+
return;
63+
64+
} else { // Response nodes
65+
if (cTarget.isEndNode())
66+
return;
67+
68+
else if (cTarget.isStartNode())
69+
return;
70+
}
71+
72+
/* This won't work for preventing linking to same node 2x's. Need to find another way :(
73+
if (scene.getConnectionLayer().getChildren().size() > 0) {
74+
for (Widget widget : scene.getConnectionLayer().getChildren()) {
75+
System.out.println("CHILD: " + widget.toString());
76+
if (!(widget instanceof ConnectionWidget)) {
77+
continue;
78+
}
79+
80+
ConnectionWidget existingConn = (ConnectionWidget) widget;
81+
if (existingConn.getTargetAnchor().getRelatedWidget() == target) {
82+
System.out.println("SAME");
83+
return;
84+
}
85+
}
86+
}*/
87+
4888
ConnectionWidget conn = new ConnectionWidget(scene);
4989
conn.setTargetAnchorShape(AnchorShape.TRIANGLE_FILLED);
5090
conn.setTargetAnchor(AnchorFactory.createRectangularAnchor(target));
5191
conn.setSourceAnchor(AnchorFactory.createRectangularAnchor(source));
5292
scene.getConnectionLayer().addChild(conn);
53-
54-
((ConversationWidget)source).getAttachedNode().setCompiled(false);
55-
((ConversationWidget)target).getAttachedNode().setCompiled(false);
5693
}
5794
}
5895
}

ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/ConversationNode.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.openide.util.Lookup;
99

1010
public class ConversationNode extends AbstractNode implements Lookup.Provider {
11-
private final int id;
11+
private int id;
1212
private int optionId;
1313
private String displayText;
1414
private String stf;
@@ -24,10 +24,10 @@ public ConversationNode(String stf, boolean isOption, int id, boolean isEndNode,
2424
this.stf = stf;
2525
this.option = isOption;
2626
this.displayText = "";
27-
this.id = id;
2827
this.endNode = isEndNode;
2928
this.startNode = isStartNode;
3029
this.optionId = optionId;
30+
this.id = id;
3131

3232
// Properties Window
3333
if (!isStartNode)
@@ -76,6 +76,10 @@ public int getId() {
7676
return id;
7777
}
7878

79+
public void setId(int id) {
80+
this.id = id;
81+
}
82+
7983
public boolean isCompiled() {
8084
return compiled;
8185
}

ConversationEditor/src/com/projectswg/tools/csc/conversationeditor/ConversationWidget.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
public class ConversationWidget extends IconNodeWidget implements LookupListener {
1919
private final ConversationNode attachedNode;
2020
private final ExplorerManager mgr;
21+
private boolean selected;
2122

2223
public ConversationWidget(SceneView scene, final ExplorerManager mgr, final ConversationNode node, boolean endConversation) {
2324
super(scene.getScene());
2425

2526
this.attachedNode = node;
2627
this.mgr = mgr;
27-
28+
2829
if (node.isEndNode()) {
2930
setLabel(node.getStf());
3031
setImage(ImageUtilities.loadImage("com/projectswg/tools/csc/conversationeditor/conversation_end.png"));
@@ -50,10 +51,24 @@ public ConversationWidget(SceneView scene, final ExplorerManager mgr, final Conv
5051
public Point locationSuggested(Widget widget, Point originalLocation, Point suggestedLocation) {
5152
if (!(widget instanceof ConversationWidget))
5253
return suggestedLocation;
54+
ConversationWidget cWidget = (ConversationWidget) widget;
55+
ConversationNode node = cWidget.getAttachedNode();
5356

54-
if (((ConversationWidget) widget).getAttachedNode().isLocked())
57+
if (node.isLocked())
5558
return originalLocation;
5659

60+
if (cWidget.getExpManager().getRootContext() != node) {
61+
cWidget.getExpManager().setRootContext(node);
62+
63+
ConversationNode[] nodes = new ConversationNode[1];
64+
nodes[0] = node;
65+
try {
66+
cWidget.getExpManager().setSelectedNodes(nodes);
67+
} catch (PropertyVetoException ex) {
68+
Exceptions.printStackTrace(ex);
69+
}
70+
}
71+
5772
return suggestedLocation;
5873
}
5974
}, ActionFactory.createDefaultMoveProvider()));
@@ -98,6 +113,14 @@ public ExplorerManager getExpManager() {
98113
return mgr;
99114
}
100115

116+
public boolean isSelected() {
117+
return selected;
118+
}
119+
120+
public void setSelected(boolean selected) {
121+
this.selected = selected;
122+
}
123+
101124
@Override
102125
public void resultChanged(LookupEvent ev) {
103126
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
package com.projectswg.tools.csc.conversationeditor;
22

3-
import com.projectswg.tools.csc.conversationeditor.actions.SaveConversation;
4-
import java.awt.Point;
5-
import java.io.IOException;
6-
import javax.xml.parsers.ParserConfigurationException;
7-
import javax.xml.transform.TransformerException;
3+
import com.projectswg.tools.csc.conversationeditor.actions.OpenConversation;
4+
import java.io.File;
5+
import javax.swing.JOptionPane;
86
import org.netbeans.api.settings.ConvertAsProperties;
97
import org.openide.awt.ActionID;
108
import org.openide.awt.ActionReference;
119
import org.openide.explorer.ExplorerManager;
1210
import org.openide.explorer.ExplorerUtils;
13-
import org.openide.util.Exceptions;
1411
import org.openide.util.NbBundle.Messages;
1512
import org.openide.windows.TopComponent;
16-
import org.xml.sax.SAXException;
1713

1814
@ConvertAsProperties(
1915
dtd = "-//com.projectswg.tools.csc.conversationeditor//Editor//EN",
20-
autostore = false
16+
autostore = true
2117
)
2218
@TopComponent.Description(
2319
preferredID = "EditorTopComponent",
2420
//iconBase="SET/PATH/TO/ICON/HERE",
2521
persistenceType = TopComponent.PERSISTENCE_ALWAYS
2622
)
27-
@TopComponent.Registration(mode = "editor", openAtStartup = true)
23+
@TopComponent.Registration(mode = "editor", openAtStartup = false)
2824
@ActionID(category = "Window", id = "com.projectswg.tools.csc.conversationeditor.EditorTopComponent")
2925
@ActionReference(path = "Menu/Window" /*, position = 333 */)
3026
@TopComponent.OpenActionRegistration(
@@ -40,41 +36,21 @@ public final class EditorTopComponent extends TopComponent implements ExplorerMa
4036

4137
private final ExplorerManager mgr = new ExplorerManager();
4238
private final SceneView scene;
39+
private String activePath = "";
4340

4441
// New Conversation
4542
public EditorTopComponent() {
4643
initComponents();
4744

4845
setToolTipText(Bundle.HINT_EditorTopComponent());
49-
50-
SceneView scene = new SceneView(mgr);
51-
scrollPane.setViewportView(scene.createView());
52-
53-
setName(Bundle.CTL_EditorTopComponent() + " - *New Conversation*");
54-
55-
scene.addNode(new ConversationNode("Begin Conversation", false, 0, false, true, 0));
56-
scene.addNode(new ConversationNode("End Conversation", false, 1, true, false, 0));
57-
58-
associateLookup(ExplorerUtils.createLookup(mgr, getActionMap()));
59-
this.scene = scene;
60-
}
61-
62-
// Open Conversation
63-
public EditorTopComponent(String convName) {
64-
initComponents();
65-
66-
setToolTipText(Bundle.HINT_EditorTopComponent());
67-
68-
SceneView scene = new SceneView(mgr);
69-
scene.setSceneName(convName);
46+
setName("*New Conversation*");
7047

48+
this.scene = new SceneView(mgr);
7149
scrollPane.setViewportView(scene.createView());
72-
73-
setName(Bundle.CTL_EditorTopComponent() + " - " + (scene.getSceneName().equals("") ? "*New Conversation*" : scene.getSceneName()));
74-
7550
associateLookup(ExplorerUtils.createLookup(mgr, getActionMap()));
76-
this.scene = scene;
51+
7752
}
53+
7854
/**
7955
* This method is called from within the constructor to initialize the form.
8056
* WARNING: Do NOT modify this code. The content of this method is always
@@ -100,30 +76,40 @@ private void initComponents() {
10076
// Variables declaration - do not modify//GEN-BEGIN:variables
10177
private javax.swing.JScrollPane scrollPane;
10278
// End of variables declaration//GEN-END:variables
79+
10380
@Override
10481
public void componentOpened() {
105-
// TODO add custom code on component opening
82+
if (activePath.equals("")) {
83+
// blankSlate();
84+
// scene.validate();
85+
return;
86+
}
87+
88+
File file = new File(activePath);
89+
90+
if (!file.exists()) {
91+
JOptionPane.showMessageDialog(null, "Couldn't open conversation file " + file.getAbsolutePath()
92+
+ " because it no longer exists.", "Conversation Script Editor", JOptionPane.INFORMATION_MESSAGE);
93+
blankSlate();
94+
scene.validate();
95+
} else {
96+
OpenConversation.open(file, this);
97+
}
10698
}
10799

108100
@Override
109101
public void componentClosed() {
110-
/*try {
111-
SaveConversation.save(scene);
112-
} catch (ParserConfigurationException | IOException | SAXException | TransformerException ex) {
113-
Exceptions.printStackTrace(ex);
114-
}*/
102+
// TODO: save msg
115103
}
116104

117105
void writeProperties(java.util.Properties p) {
118-
// better to version settings since initial version as advocated at
119-
// http://wiki.apidesign.org/wiki/PropertyFiles
120-
p.setProperty("version", "1.0");
121-
// TODO store your settings
106+
//p.setProperty("version", "1.0");
107+
p.setProperty("activePath", scene.getScenePath());
122108
}
123109

124110
void readProperties(java.util.Properties p) {
125-
String version = p.getProperty("version");
126-
// TODO read your settings according to their version
111+
//String version = p.getProperty("version");
112+
this.activePath = p.getProperty("activePath");
127113
}
128114

129115
@Override
@@ -134,4 +120,9 @@ public ExplorerManager getExplorerManager() {
134120
public SceneView getScene() {
135121
return scene;
136122
}
123+
124+
public void blankSlate() {
125+
scene.addNode(new ConversationNode("Begin Conversation", false, 0, false, true, 0));
126+
scene.addNode(new ConversationNode("End Conversation", false, 1, true, false, 0));
127+
}
137128
}

0 commit comments

Comments
 (0)