diff --git a/prism/src/prism/PrismFileLog.java b/prism/src/prism/PrismFileLog.java index c1cd3c58..62f29203 100644 --- a/prism/src/prism/PrismFileLog.java +++ b/prism/src/prism/PrismFileLog.java @@ -26,7 +26,7 @@ package prism; -public class PrismFileLog implements PrismLog +public class PrismFileLog extends PrismLog { String filename; long fp; @@ -71,6 +71,23 @@ public class PrismFileLog implements PrismLog return (fp != 0); } + public long getFilePointer() + { + return fp; + } + + public void flush() + { + PrismNative.PN_FlushFile(fp); + } + + public void close() + { + if (!stdout) PrismNative.PN_CloseFile(fp); + } + + // Basic print methods + public void print(boolean b) { printToLog("" + b); @@ -111,83 +128,11 @@ public class PrismFileLog implements PrismLog printToLog(s); } - public void print(double d[]) - { - int i, n; - n = d.length; - for (i = 0; i < n; i++) { - if (i > 0) - printToLog(" "); - printToLog("" + d[i]); - } - } - public void println() { printToLog("\n"); } - public void println(boolean b) - { - printToLog(b + "\n"); - } - - public void println(char c) - { - printToLog(c + "\n"); - } - - public void println(double d) - { - printToLog(d + "\n"); - } - - public void println(float f) - { - printToLog(f + "\n"); - } - - public void println(int i) - { - printToLog(i + "\n"); - } - - public void println(long l) - { - printToLog(l + "\n"); - } - - public void println(Object obj) - { - printToLog(obj + "\n"); - } - - public void println(String s) - { - printToLog(s + "\n"); - } - - public void println(double d[]) - { - print(d); - println(); - } - - public long getFilePointer() - { - return fp; - } - - public void flush() - { - PrismNative.PN_FlushFile(fp); - } - - public void close() - { - if (!stdout) PrismNative.PN_CloseFile(fp); - } - private void printToLog(String s) { PrismNative.PN_PrintToFile(fp, s); diff --git a/prism/src/prism/PrismLog.java b/prism/src/prism/PrismLog.java index 29e14bce..f4a31bc4 100644 --- a/prism/src/prism/PrismLog.java +++ b/prism/src/prism/PrismLog.java @@ -26,31 +26,104 @@ package prism; -public interface PrismLog +public abstract class PrismLog { - boolean ready(); - void print(boolean b); - void print(char c); - void print(double d); - void print(float f); - void print(int i); - void print(long l); - void print(Object obj); - void print(String s); - void print(double d[]); - void println(); - void println(boolean b); - void println(char c); - void println(double d); - void println(float f); - void println(int i); - void println(long l); - void println(Object obj); - void println(String s); - void println(double d[]); - long getFilePointer(); - void flush(); - void close(); + public abstract boolean ready(); + public abstract long getFilePointer(); + public abstract void flush(); + public abstract void close(); + + public abstract void print(boolean b); + public abstract void print(char c); + public abstract void print(double d); + public abstract void print(float f); + public abstract void print(int i); + public abstract void print(long l); + public abstract void print(Object obj); + public abstract void print(String s); + public abstract void println(); + + public void print(Object arr[]) + { + int i, n = arr.length; + print("["); + for (i = 0; i < n; i++) { + print(i > 0 ? ", " : ""); + print(arr[i]); + } + print("]"); + } + + public void print(int arr[]) + { + int i, n = arr.length; + print("["); + for (i = 0; i < n; i++) { + print(i > 0 ? ", " : ""); + print(arr[i]); + } + print("]"); + } + + public void println(boolean b) + { + print(b); + println(); + } + + public void println(char c) + { + print(c); + println(); + } + + public void println(double d) + { + print(d); + println(); + } + + public void println(float f) + { + print(f); + println(); + } + + public void println(int i) + { + print(i); + println(); + } + + public void println(long l) + { + print(l); + println(); + } + + public void println(Object o) + { + print(o); + println(); + } + + public void println(String s) + { + print(s); + println(); + } + + public void println(double arr[]) + { + print(arr); + println(); + } + + public void println(int arr[]) + { + print(arr); + println(); + } } //------------------------------------------------------------------------------ diff --git a/prism/src/prism/PrismPrintStreamLog.java b/prism/src/prism/PrismPrintStreamLog.java index 1e52786e..f840b1ab 100644 --- a/prism/src/prism/PrismPrintStreamLog.java +++ b/prism/src/prism/PrismPrintStreamLog.java @@ -31,7 +31,7 @@ import java.io.*; /** * Implementation of the PrismLog interface that passed all output to a PrintStream object. */ -public class PrismPrintStreamLog implements PrismLog +public class PrismPrintStreamLog extends PrismLog { PrintStream out = null; @@ -55,6 +55,24 @@ public class PrismPrintStreamLog implements PrismLog return out != null; } + public long getFilePointer() + { + // This implementation is Java only so does not return a file pointer. + return -1; + } + + public void flush() + { + out.flush(); + } + + public void close() + { + out.close(); + } + + // Basic print methods + public void print(boolean b) { out.print(b); @@ -95,83 +113,10 @@ public class PrismPrintStreamLog implements PrismLog out.print(s); } - public void print(double d[]) - { - int i, n; - n = d.length; - for (i = 0; i < n; i++) { - if (i > 0) - out.print(" "); - out.print(d[i]); - } - } - public void println() { out.println(); } - - public void println(boolean b) - { - out.println(b); - } - - public void println(char c) - { - out.println(c); - } - - public void println(double d) - { - out.println(d); - } - - public void println(float f) - { - out.println(f); - } - - public void println(int i) - { - out.println(i); - } - - public void println(long l) - { - out.println(l); - } - - public void println(Object obj) - { - out.println(obj); - } - - public void println(String s) - { - out.println(s); - } - - public void println(double d[]) - { - print(d); - println(); - } - - public long getFilePointer() - { - // This implementation is Java only so does not return a file pointer. - return -1; - } - - public void flush() - { - out.flush(); - } - - public void close() - { - out.close(); - } } //------------------------------------------------------------------------------ diff --git a/prism/src/userinterface/log/GUIVisualLogModel.java b/prism/src/userinterface/log/GUIVisualLogModel.java index 43bf986b..2fdd57c0 100644 --- a/prism/src/userinterface/log/GUIVisualLogModel.java +++ b/prism/src/userinterface/log/GUIVisualLogModel.java @@ -66,7 +66,7 @@ import prism.PrismLog; * * */ -public class GUIVisualLogModel implements PrismLog +public class GUIVisualLogModel extends PrismLog { //Attributes @@ -248,12 +248,12 @@ public class GUIVisualLogModel implements PrismLog return theModel; } - /*These methods are so that this can implement the PrismLog interface - */ - public void close() + // Methods required by PrismLog abstract class + + public boolean ready() { + return true; } - public long getFilePointer() { return -1; @@ -263,6 +263,10 @@ public class GUIVisualLogModel implements PrismLog { } + public void close() + { + } + public void print(long l) { print(NORMAL, ""+l); @@ -312,57 +316,7 @@ public class GUIVisualLogModel implements PrismLog { println(NORMAL, ""); } - - public void println(float f) - { - println(NORMAL,""+f); - } - - public void println(double d) - { - println(NORMAL,""+d); - } - - public void println(Object obj) - { - println(NORMAL,""+obj); - } - - public void println(int i) - { - println(NORMAL,""+i); - } - - public void println(char c) - { - println(NORMAL,""+c); - } - - public void println(boolean b) - { - println(NORMAL,""+b); - } - - public void println(String s) - { - println(NORMAL,""+s); - } - - public void println(double d[]) - { - println(NORMAL,""+d); - } - - public void println(long l) - { - println(NORMAL,""+l); - } - - public boolean ready() - { - return true; - } - + /** Because the entries have to be called from Threads, the invokeLater method is * used to add entries using this Thread. */ diff --git a/prism/src/userinterface/log/GUIWindowLog.java b/prism/src/userinterface/log/GUIWindowLog.java index 851d591b..4cde8eb5 100644 --- a/prism/src/userinterface/log/GUIWindowLog.java +++ b/prism/src/userinterface/log/GUIWindowLog.java @@ -33,10 +33,9 @@ import javax.swing.event.CaretListener; import javax.swing.text.BadLocationException; import prism.*; -import userinterface.GUIPlugin; import userinterface.util.GUIEvent; -public class GUIWindowLog implements PrismLog +public class GUIWindowLog extends PrismLog { // text area swing object where all text will be echoed private JTextArea textArea; @@ -83,6 +82,21 @@ public class GUIWindowLog implements PrismLog return (textArea != null); } + public long getFilePointer() + { + return -1; + } + + public void flush() + { + } + + public void close() + { + } + + // Basic print methods + public void print(boolean b) { addToBuffer("" + b); @@ -123,86 +137,16 @@ public class GUIWindowLog implements PrismLog addToBuffer(s); } - public void print(double d[]) - { - int i, n; - n = d.length; - for (i = 0; i < n; i++) { - if (i > 0) - addToBuffer(" "); - addToBuffer("" + d[i]); - } - } - public void println() { addToBuffer("\n"); } - public void println(boolean b) - { - addToBuffer("" + b + "\n"); - } - - public void println(char c) - { - addToBuffer("" + c + "\n"); - } - - public void println(double d) - { - addToBuffer("" + d + "\n"); - } - - public void println(float f) - { - addToBuffer("" + f + "\n"); - } - - public void println(int i) - { - addToBuffer("" + i + "\n"); - } - - public void println(long l) - { - addToBuffer("" + l + "\n"); - } - - public void println(Object obj) - { - addToBuffer("" + obj + "\n"); - } - - public void println(String s) - { - addToBuffer(s + "\n"); - } - - public void println(double d[]) - { - print(d); - println(); - } - - public long getFilePointer() - { - return -1; - } - - public void flush() - { - } - public void clear() { setClearFlag(); } - public void close() - { - } - public int getMaxTextLength() { return updater.getMaxTextLength();