11package 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 ;
86import org .netbeans .api .settings .ConvertAsProperties ;
97import org .openide .awt .ActionID ;
108import org .openide .awt .ActionReference ;
119import org .openide .explorer .ExplorerManager ;
1210import org .openide .explorer .ExplorerUtils ;
13- import org .openide .util .Exceptions ;
1411import org .openide .util .NbBundle .Messages ;
1512import 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