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