1 Clazz.declarePackage ("jalview.util");
\r
2 Clazz.load (["java.awt.event.ActionListener", "$.WindowAdapter", "$.WindowListener", "java.io.PipedInputStream"], "jalview.util.AWTConsole", ["jalview.util.MessageManager", "java.awt.BorderLayout", "$.Button", "$.Dimension", "$.Frame", "$.GraphicsEnvironment", "$.Panel", "$.TextArea", "$.Toolkit", "java.io.PipedOutputStream", "java.lang.NullPointerException", "$.Thread"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
5 this.textArea = null;
\r
11 this.errorThrower = null;
\r
12 Clazz.instantialize (this, arguments);
\r
13 }, jalview.util, "AWTConsole", java.awt.event.WindowAdapter, [java.awt.event.WindowListener, java.awt.event.ActionListener, Runnable]);
\r
14 Clazz.prepareFields (c$, function () {
\r
15 this.pin = new java.io.PipedInputStream ();
\r
16 this.pin2 = new java.io.PipedInputStream ();
\r
18 Clazz.makeConstructor (c$,
\r
20 Clazz.superConstructor (this, jalview.util.AWTConsole, []);
\r
21 this.frame = new java.awt.Frame ("Java Console");
\r
22 var screenSize = java.awt.Toolkit.getDefaultToolkit ().getScreenSize ();
\r
23 var frameSize = new java.awt.Dimension ((Clazz.doubleToInt (screenSize.width / 2)), (Clazz.doubleToInt (screenSize.height / 2)));
\r
24 var x = (Clazz.doubleToInt (frameSize.width / 2));
\r
25 var y = (Clazz.doubleToInt (frameSize.height / 2));
\r
26 this.frame.setBounds (x, y, frameSize.width, frameSize.height);
\r
27 this.textArea = new java.awt.TextArea ();
\r
28 this.textArea.setEditable (false);
\r
29 var button = new java.awt.Button ("clear");
\r
30 var panel = new java.awt.Panel ();
\r
31 panel.setLayout ( new java.awt.BorderLayout ());
\r
32 panel.add (this.textArea, "Center");
\r
33 panel.add (button, "South");
\r
34 this.frame.add (panel);
\r
35 this.frame.setVisible (true);
\r
36 this.frame.addWindowListener (this);
\r
37 button.addActionListener (this);
\r
39 var pout = new java.io.PipedOutputStream (this.pin);
\r
40 System.setOut ( new java.io.PrintStream (pout, true));
\r
42 if (Clazz.exceptionOf (e$$, java.io.IOException)) {
\r
45 this.textArea.append ("Couldn't redirect STDOUT to this console\n" + io.getMessage ());
\r
47 } else if (Clazz.exceptionOf (e$$, SecurityException)) {
\r
50 this.textArea.append ("Couldn't redirect STDOUT to this console\n" + se.getMessage ());
\r
57 var pout2 = new java.io.PipedOutputStream (this.pin2);
\r
58 System.setErr ( new java.io.PrintStream (pout2, true));
\r
60 if (Clazz.exceptionOf (e$$, java.io.IOException)) {
\r
63 this.textArea.append ("Couldn't redirect STDERR to this console\n" + io.getMessage ());
\r
65 } else if (Clazz.exceptionOf (e$$, SecurityException)) {
\r
68 this.textArea.append ("Couldn't redirect STDERR to this console\n" + se.getMessage ());
\r
75 this.reader = new Thread (this);
\r
76 this.reader.setDaemon (true);
\r
77 this.reader.start ();
\r
78 this.reader2 = new Thread (this);
\r
79 this.reader2.setDaemon (true);
\r
80 this.reader2.start ();
\r
81 System.out.println ("Hello World 2");
\r
82 System.out.println ("All fonts available to Graphic2D:\n");
\r
83 var ge = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment ();
\r
84 var fontNames = ge.getAvailableFontFamilyNames ();
\r
85 for (var n = 0; n < fontNames.length; n++) System.out.println (fontNames[n]);
\r
87 System.out.println ("\nLets throw an error on this console");
\r
88 this.errorThrower = new Thread (this);
\r
89 this.errorThrower.setDaemon (true);
\r
90 this.errorThrower.start ();
\r
92 Clazz.overrideMethod (c$, "windowClosed",
\r
97 this.reader.join (1000);
\r
100 if (Clazz.exceptionOf (e, Exception)) {
\r
106 this.reader2.join (1000);
\r
107 this.pin2.close ();
\r
109 if (Clazz.exceptionOf (e, Exception)) {
\r
115 }, "java.awt.event.WindowEvent");
\r
116 Clazz.overrideMethod (c$, "windowClosing",
\r
118 this.frame.setVisible (false);
\r
119 this.frame.dispose ();
\r
120 }, "java.awt.event.WindowEvent");
\r
121 Clazz.overrideMethod (c$, "actionPerformed",
\r
123 this.textArea.setText ("");
\r
124 }, "java.awt.event.ActionEvent");
\r
125 Clazz.overrideMethod (c$, "run",
\r
128 while (Thread.currentThread () === this.reader) {
\r
132 if (Clazz.exceptionOf (ie, InterruptedException)) {
\r
137 if (this.pin.available () != 0) {
\r
138 var input = this.readLine (this.pin);
\r
139 this.textArea.append (input);
\r
140 }if (this.quit) return;
\r
142 while (Thread.currentThread () === this.reader2) {
\r
146 if (Clazz.exceptionOf (ie, InterruptedException)) {
\r
151 if (this.pin2.available () != 0) {
\r
152 var input = this.readLine (this.pin2);
\r
153 this.textArea.append (input);
\r
154 }if (this.quit) return;
\r
157 if (Clazz.exceptionOf (e, Exception)) {
\r
158 this.textArea.append ("\nConsole reports an Internal error.");
\r
159 this.textArea.append ("The error is: " + e);
\r
164 if (Thread.currentThread () === this.errorThrower) {
\r
168 if (Clazz.exceptionOf (ie, InterruptedException)) {
\r
173 throw new NullPointerException (jalview.util.MessageManager.getString ("exception.application_test_npe"));
\r
175 Clazz.defineMethod (c$, "readLine",
\r
179 var available = $in.available ();
\r
180 if (available == 0) break;
\r
181 var b = Clazz.newByteArray (available, 0);
\r
183 input = input + String.instantialize (b, 0, b.length);
\r
184 } while (!input.endsWith ("\n") && !input.endsWith ("\r\n") && !this.quit);
\r
186 }, "java.io.PipedInputStream");
\r