Mercurial > hg > jslab
comparison src/samer/core_/util/heavy/Console.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bf79fb79ee13 |
---|---|
1 /* | |
2 * Console.java | |
3 * | |
4 * Copyright (c) 2000, Samer Abdallah, King's College London. | |
5 * All rights reserved. | |
6 * | |
7 * This software is provided AS iS and WITHOUT ANY WARRANTY; | |
8 * without even the implied warranty of MERCHANTABILITY or | |
9 * FITNESS FOR A PARTICULAR PURPOSE. | |
10 */ | |
11 | |
12 package samer.core.util.heavy; | |
13 import samer.core.*; | |
14 import java.awt.*; | |
15 import java.io.*; | |
16 | |
17 /** | |
18 <p> | |
19 A class which can display messages in a scrolling text | |
20 area, which can be put in another container or its own frame. | |
21 There is a static reference to the current Console so | |
22 that anyone can display messages without worrying about | |
23 who created the Console. | |
24 | |
25 <p> | |
26 Associated with the Console are a Writer and an OutputStream | |
27 so that any method which writes to a Java IO stream can be | |
28 redirected to the current console. | |
29 | |
30 */ | |
31 | |
32 public class Console extends TextArea implements Agent | |
33 { | |
34 private Writer writer=null; | |
35 private OutputStream ostream=null; | |
36 | |
37 public Console() | |
38 { | |
39 super("",16,40, | |
40 Shell.getBoolean("awt.output.console.scrollbars", false) | |
41 ? TextArea.SCROLLBARS_VERTICAL_ONLY | |
42 : TextArea.SCROLLBARS_NONE | |
43 ); | |
44 | |
45 // setEditable(false); | |
46 setBackground( Shell.getColor("awt.output.console.background", Color.black)); | |
47 setForeground( Shell.getColor("awt.output.console.foreground", Color.orange)); | |
48 setFont(X.font(Shell.datum("awt.output.console.font"),null)); | |
49 } | |
50 | |
51 public void write( String s) { append(s); } | |
52 public void getCommands(Agent.Registry r) { r.add("clear").add("setfont"); } | |
53 public void execute(String cmd, Environment env) throws Exception | |
54 { | |
55 if (cmd.equals("clear")) setText(""); | |
56 else if (cmd.equals("setfont")) | |
57 setFont(X.font(env.datum("font"),null)); | |
58 } | |
59 | |
60 public String toString() { return "Console"; } | |
61 | |
62 public Writer getWriter() { | |
63 if (writer==null) writer = new Writer(); | |
64 return writer; | |
65 } | |
66 | |
67 public OutputStream getStream() { | |
68 if (ostream==null) ostream = new OutputStream(); | |
69 return ostream; | |
70 } | |
71 | |
72 class Writer extends java.io.Writer | |
73 { | |
74 StringBuffer str; | |
75 | |
76 Writer() { str = new StringBuffer(); } | |
77 | |
78 public void write( char buf[], int off, int len) { | |
79 str.append( buf, off, len); // indentation | |
80 } | |
81 | |
82 public void flush() { | |
83 // append( str.toString()); | |
84 try { append( str.toString()); | |
85 } catch(IOException ex) { /* eh? */} | |
86 str.setLength(0); | |
87 } | |
88 public void close() { } | |
89 } | |
90 | |
91 class OutputStream extends java.io.OutputStream | |
92 { | |
93 StringBuffer str; | |
94 | |
95 OutputStream() { str = new StringBuffer(); } | |
96 | |
97 public void write( int b) { str.append( (char)b); } | |
98 public void flush() { append( str.toString()); str.setLength(0); } | |
99 public void close() { } | |
100 } | |
101 } | |
102 |