@@ -30,7 +30,7 @@ public class Recorder extends PlugInFrame implements PlugIn, ActionListener, Ima
3030 private TextField fileName ;
3131 private static Vector <Thread > notRecordingThreads = new Vector <Thread >();
3232 private String fitTypeStr = CurveFitter .fitList [0 ];
33- private static TextArea textArea = new TextArea (); //recorded code goes here (start with dummy to avoid NullPointerException)
33+ private static TextArea textArea ;
3434 private static Recorder instance ;
3535 private static String commandName ;
3636 private static String commandOptions ;
@@ -135,7 +135,8 @@ public static void resumeRecording() {
135135 * whether the Macro Recorder is open and recording is not suspended
136136 * for the current thread.*/
137137 private static boolean recordingEnabled () {
138- if (getInstance () == null ) return false ;
138+ if (getInstance ()==null || textArea ==null )
139+ return false ;
139140 return !notRecordingThreads .contains (Thread .currentThread ());
140141 }
141142
@@ -279,7 +280,8 @@ public static void record(String method, int a1, int a2, int a3) {
279280 }
280281
281282 public static void record (String method , String a1 , int a2 ) {
282- textArea .append (method +"(\" " +a1 +"\" , " +a2 +");\n " );
283+ if (recordingEnabled ())
284+ textArea .append (method +"(\" " +a1 +"\" , " +a2 +");\n " );
283285 }
284286
285287 public static void record (String method , String args , int a1 , int a2 ) {
@@ -786,6 +788,8 @@ public static void resetCommandOptions() {
786788 }
787789
788790 void createMacro () {
791+ if (!recordingEnabled ())
792+ return ;
789793 String text = textArea .getText ();
790794 if (text ==null || text .equals ("" )) {
791795 IJ .showMessage ("Recorder" , "A macro cannot be created until at least\n one command has been recorded." );
@@ -918,7 +922,7 @@ public void imageOpened(ImagePlus imp) { }
918922 public void imageClosed (ImagePlus imp ) { }
919923
920924 void runCode () {
921- if (instance ==null )
925+ if (instance ==null || ! recordingEnabled () )
922926 return ;
923927 String name = fileName .getText ();
924928 if (name ==null )
@@ -991,7 +995,7 @@ record = false;
991995 }
992996
993997 public String getText () {
994- return textArea .getText ();
998+ return recordingEnabled ()? textArea .getText (): "" ;
995999 }
9961000
9971001 public static Recorder getInstance () {
0 commit comments