///* 
// * The MIT License
// *
// * Copyright 2015 Neil McAlister.
// *
// * Permission is hereby granted, free of charge, to any person obtaining a copy
// * of this software and associated documentation files (the "Software"), to deal
// * in the Software without restriction, including without limitation the rights
// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// * copies of the Software, and to permit persons to whom the Software is
// * furnished to do so, subject to the following conditions:
// *
// * The above copyright notice and this permission notice shall be included in
// * all copies or substantial portions of the Software.
// *
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// * THE SOFTWARE.
// */
package sonicScream.models;

import java.io.File;
import java.io.IOException;
import javafx.scene.control.TreeItem;
import sonicScream.utilities.ScriptParser;
import sonicScream.utilities.StringParsing;

public class Script
{

    private final String _internalScriptName;
    private final String _friendlyScriptName;
    private final String _rawScriptName;
    private TreeItem<String> _rootNode;
    private String _treeAsString = null;

    public Script(File scriptFile)
    {
        _rawScriptName = scriptFile.getName();
        _internalScriptName = StringParsing.GetScriptNameFromFileName(_rawScriptName);
        _friendlyScriptName = StringParsing.PrettyFormatScriptName(_internalScriptName);
        try
        {
            _rootNode = ScriptParser.parseScript(scriptFile);
        }
        catch (IOException ex)
        {
            ex.printStackTrace();
        }

    }

    public String getScriptName() { return _internalScriptName; }

    public String getRawScriptName() { return _rawScriptName; }
    
    public TreeItem<String> getRoodNode() { return _rootNode; }
    
    public void setRootNode(TreeItem<String> value) { _rootNode = value; }
    
    public String getScriptAsString() 
    {
        if(_treeAsString == null)
        {
            _treeAsString = ScriptParser.parseScriptTreeToString(_rootNode);             
        }        
        return _treeAsString;
    }
    
    @Override
    public String toString()
    {
        return _friendlyScriptName;
    }
}

@@ -1567,32 +1567,69 @@
 rawScriptName;%0D%0A
+    private final File _scriptFile;%0D%0A
     private Tree
@@ -1978,73 +1978,22 @@
     
-try%0D%0A        %7B%0D%0A            _rootNode = ScriptParser.parseScript(
+_scriptFile = 
 scri
@@ -2002,59 +2002,55 @@
 File
-)
 ;%0D%0A    
-  
-  %7D
+%7D%0D%0A
 %0D%0A    
-    catch (IOException ex
+public String getScriptName(
 )%0D%0A
-    
     
@@ -2064,39 +2064,37 @@
     
-    ex.printStackTrace();%0D%0A    
+return _internalScriptName;%0D%0A
     
@@ -2098,25 +2098,16 @@
    %7D%0D%0A%0D%0A
-    %7D%0D%0A%0D%0A
     publ
@@ -2111,32 +2111,35 @@
 ublic String get
+Raw
 ScriptName() %7B r
@@ -2126,34 +2126,48 @@
 tRawScriptName()
+%0D%0A    %7B%0D%0A      
  
-%7B
  return _interna
@@ -2155,32 +2155,27 @@
     return _
-internal
+raw
 ScriptName; 
@@ -2169,24 +2169,29 @@
 wScriptName;
+%0D%0A   
  %7D%0D%0A%0D%0A    pu
@@ -2199,111 +2199,328 @@
 lic 
+TreeItem%3C
 String
+%3E
  getR
-awScriptName() %7B return _rawScriptName; %7D%0D%0A    %0D%0A    public TreeItem%3CString%3E getRoodNode() %7B
+oodNode()%0D%0A    %7B%0D%0A        if (_rootNode == null)%0D%0A        %7B%0D%0A            try%0D%0A            %7B%0D%0A                _rootNode = ScriptParser.parseScript(_scriptFile);%0D%0A            %7D%0D%0A            catch (IOException ex)%0D%0A            %7B%0D%0A                ex.printStackTrace();%0D%0A            %7D%0D%0A        %7D%0D%0A       
  ret
@@ -2533,24 +2533,25 @@
 ootNode;
- %7D
 %0D%0A    
+%7D%0D%0A
 %0D%0A    pu
@@ -2595,18 +2595,32 @@
 %3E value)
+%0D%0A    %7B%0D%0A      
  
-%7B
  _rootNo
@@ -2630,24 +2630,25 @@
 = value;
- %7D
 %0D%0A    
+%7D%0D%0A
 %0D%0A    pu
@@ -2678,17 +2678,16 @@
 String()
- 
 %0D%0A    %7B%0D
@@ -2697,16 +2697,17 @@
       if
+ 
 (_treeAs
@@ -2810,29 +2810,16 @@
 otNode);
-             
 %0D%0A      
@@ -2821,24 +2821,16 @@
        %7D
-        
 %0D%0A      
@@ -2861,20 +2861,16 @@
 %0A    %7D%0D%0A
-    
 %0D%0A    @O

Make loading lazy