X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=site%2Fj2s%2Fjalview%2Futil%2FAWTConsole.js;h=7e1b5ee2a8b57271b6d2c7064137a5aa23cc93d5;hp=d03b9fa6a69ed6aaf683738ba51491d34bfe211a;hb=b9b7a352eee79b7764c3b09c9d19663075061d8c;hpb=7301a2415adab88038b291fc54caeeb3a5a47a44 diff --git a/site/j2s/jalview/util/AWTConsole.js b/site/j2s/jalview/util/AWTConsole.js index d03b9fa..7e1b5ee 100644 --- a/site/j2s/jalview/util/AWTConsole.js +++ b/site/j2s/jalview/util/AWTConsole.js @@ -1,187 +1,187 @@ -Clazz.declarePackage ("jalview.util"); -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 () { -c$ = Clazz.decorateAsClass (function () { -this.frame = null; -this.textArea = null; -this.reader = null; -this.reader2 = null; -this.quit = false; -this.pin = null; -this.pin2 = null; -this.errorThrower = null; -Clazz.instantialize (this, arguments); -}, jalview.util, "AWTConsole", java.awt.event.WindowAdapter, [java.awt.event.WindowListener, java.awt.event.ActionListener, Runnable]); -Clazz.prepareFields (c$, function () { -this.pin = new java.io.PipedInputStream (); -this.pin2 = new java.io.PipedInputStream (); -}); -Clazz.makeConstructor (c$, -function () { -Clazz.superConstructor (this, jalview.util.AWTConsole, []); -this.frame = new java.awt.Frame ("Java Console"); -var screenSize = java.awt.Toolkit.getDefaultToolkit ().getScreenSize (); -var frameSize = new java.awt.Dimension ((Clazz.doubleToInt (screenSize.width / 2)), (Clazz.doubleToInt (screenSize.height / 2))); -var x = (Clazz.doubleToInt (frameSize.width / 2)); -var y = (Clazz.doubleToInt (frameSize.height / 2)); -this.frame.setBounds (x, y, frameSize.width, frameSize.height); -this.textArea = new java.awt.TextArea (); -this.textArea.setEditable (false); -var button = new java.awt.Button ("clear"); -var panel = new java.awt.Panel (); -panel.setLayout ( new java.awt.BorderLayout ()); -panel.add (this.textArea, "Center"); -panel.add (button, "South"); -this.frame.add (panel); -this.frame.setVisible (true); -this.frame.addWindowListener (this); -button.addActionListener (this); -try { -var pout = new java.io.PipedOutputStream (this.pin); -System.setOut ( new java.io.PrintStream (pout, true)); -} catch (e$$) { -if (Clazz.exceptionOf (e$$, java.io.IOException)) { -var io = e$$; -{ -this.textArea.append ("Couldn't redirect STDOUT to this console\n" + io.getMessage ()); -} -} else if (Clazz.exceptionOf (e$$, SecurityException)) { -var se = e$$; -{ -this.textArea.append ("Couldn't redirect STDOUT to this console\n" + se.getMessage ()); -} -} else { -throw e$$; -} -} -try { -var pout2 = new java.io.PipedOutputStream (this.pin2); -System.setErr ( new java.io.PrintStream (pout2, true)); -} catch (e$$) { -if (Clazz.exceptionOf (e$$, java.io.IOException)) { -var io = e$$; -{ -this.textArea.append ("Couldn't redirect STDERR to this console\n" + io.getMessage ()); -} -} else if (Clazz.exceptionOf (e$$, SecurityException)) { -var se = e$$; -{ -this.textArea.append ("Couldn't redirect STDERR to this console\n" + se.getMessage ()); -} -} else { -throw e$$; -} -} -this.quit = false; -this.reader = new Thread (this); -this.reader.setDaemon (true); -this.reader.start (); -this.reader2 = new Thread (this); -this.reader2.setDaemon (true); -this.reader2.start (); -System.out.println ("Hello World 2"); -System.out.println ("All fonts available to Graphic2D:\n"); -var ge = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment (); -var fontNames = ge.getAvailableFontFamilyNames (); -for (var n = 0; n < fontNames.length; n++) System.out.println (fontNames[n]); - -System.out.println ("\nLets throw an error on this console"); -this.errorThrower = new Thread (this); -this.errorThrower.setDaemon (true); -this.errorThrower.start (); -}); -Clazz.overrideMethod (c$, "windowClosed", -function (evt) { -this.quit = true; -this.notifyAll (); -try { -this.reader.join (1000); -this.pin.close (); -} catch (e) { -if (Clazz.exceptionOf (e, Exception)) { -} else { -throw e; -} -} -try { -this.reader2.join (1000); -this.pin2.close (); -} catch (e) { -if (Clazz.exceptionOf (e, Exception)) { -} else { -throw e; -} -} -System.exit (0); -}, "java.awt.event.WindowEvent"); -Clazz.overrideMethod (c$, "windowClosing", -function (evt) { -this.frame.setVisible (false); -this.frame.dispose (); -}, "java.awt.event.WindowEvent"); -Clazz.overrideMethod (c$, "actionPerformed", -function (evt) { -this.textArea.setText (""); -}, "java.awt.event.ActionEvent"); -Clazz.overrideMethod (c$, "run", -function () { -try { -while (Thread.currentThread () === this.reader) { -try { -this.wait (100); -} catch (ie) { -if (Clazz.exceptionOf (ie, InterruptedException)) { -} else { -throw ie; -} -} -if (this.pin.available () != 0) { -var input = this.readLine (this.pin); -this.textArea.append (input); -}if (this.quit) return; -} -while (Thread.currentThread () === this.reader2) { -try { -this.wait (100); -} catch (ie) { -if (Clazz.exceptionOf (ie, InterruptedException)) { -} else { -throw ie; -} -} -if (this.pin2.available () != 0) { -var input = this.readLine (this.pin2); -this.textArea.append (input); -}if (this.quit) return; -} -} catch (e) { -if (Clazz.exceptionOf (e, Exception)) { -this.textArea.append ("\nConsole reports an Internal error."); -this.textArea.append ("The error is: " + e); -} else { -throw e; -} -} -if (Thread.currentThread () === this.errorThrower) { -try { -this.wait (1000); -} catch (ie) { -if (Clazz.exceptionOf (ie, InterruptedException)) { -} else { -throw ie; -} -} -throw new NullPointerException (jalview.util.MessageManager.getString ("exception.application_test_npe")); -}}); -Clazz.defineMethod (c$, "readLine", -function ($in) { -var input = ""; -do { -var available = $in.available (); -if (available == 0) break; -var b = Clazz.newByteArray (available, 0); -$in.read (b); -input = input + String.instantialize (b, 0, b.length); -} while (!input.endsWith ("\n") && !input.endsWith ("\r\n") && !this.quit); -return input; -}, "java.io.PipedInputStream"); -}); +Clazz.declarePackage ("jalview.util"); +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 () { +c$ = Clazz.decorateAsClass (function () { +this.frame = null; +this.textArea = null; +this.reader = null; +this.reader2 = null; +this.quit = false; +this.pin = null; +this.pin2 = null; +this.errorThrower = null; +Clazz.instantialize (this, arguments); +}, jalview.util, "AWTConsole", java.awt.event.WindowAdapter, [java.awt.event.WindowListener, java.awt.event.ActionListener, Runnable]); +Clazz.prepareFields (c$, function () { +this.pin = new java.io.PipedInputStream (); +this.pin2 = new java.io.PipedInputStream (); +}); +Clazz.makeConstructor (c$, +function () { +Clazz.superConstructor (this, jalview.util.AWTConsole, []); +this.frame = new java.awt.Frame ("Java Console"); +var screenSize = java.awt.Toolkit.getDefaultToolkit ().getScreenSize (); +var frameSize = new java.awt.Dimension ((Clazz.doubleToInt (screenSize.width / 2)), (Clazz.doubleToInt (screenSize.height / 2))); +var x = (Clazz.doubleToInt (frameSize.width / 2)); +var y = (Clazz.doubleToInt (frameSize.height / 2)); +this.frame.setBounds (x, y, frameSize.width, frameSize.height); +this.textArea = new java.awt.TextArea (); +this.textArea.setEditable (false); +var button = new java.awt.Button ("clear"); +var panel = new java.awt.Panel (); +panel.setLayout ( new java.awt.BorderLayout ()); +panel.add (this.textArea, "Center"); +panel.add (button, "South"); +this.frame.add (panel); +this.frame.setVisible (true); +this.frame.addWindowListener (this); +button.addActionListener (this); +try { +var pout = new java.io.PipedOutputStream (this.pin); +System.setOut ( new java.io.PrintStream (pout, true)); +} catch (e$$) { +if (Clazz.exceptionOf (e$$, java.io.IOException)) { +var io = e$$; +{ +this.textArea.append ("Couldn't redirect STDOUT to this console\n" + io.getMessage ()); +} +} else if (Clazz.exceptionOf (e$$, SecurityException)) { +var se = e$$; +{ +this.textArea.append ("Couldn't redirect STDOUT to this console\n" + se.getMessage ()); +} +} else { +throw e$$; +} +} +try { +var pout2 = new java.io.PipedOutputStream (this.pin2); +System.setErr ( new java.io.PrintStream (pout2, true)); +} catch (e$$) { +if (Clazz.exceptionOf (e$$, java.io.IOException)) { +var io = e$$; +{ +this.textArea.append ("Couldn't redirect STDERR to this console\n" + io.getMessage ()); +} +} else if (Clazz.exceptionOf (e$$, SecurityException)) { +var se = e$$; +{ +this.textArea.append ("Couldn't redirect STDERR to this console\n" + se.getMessage ()); +} +} else { +throw e$$; +} +} +this.quit = false; +this.reader = new Thread (this); +this.reader.setDaemon (true); +this.reader.start (); +this.reader2 = new Thread (this); +this.reader2.setDaemon (true); +this.reader2.start (); +System.out.println ("Hello World 2"); +System.out.println ("All fonts available to Graphic2D:\n"); +var ge = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment (); +var fontNames = ge.getAvailableFontFamilyNames (); +for (var n = 0; n < fontNames.length; n++) System.out.println (fontNames[n]); + +System.out.println ("\nLets throw an error on this console"); +this.errorThrower = new Thread (this); +this.errorThrower.setDaemon (true); +this.errorThrower.start (); +}); +Clazz.overrideMethod (c$, "windowClosed", +function (evt) { +this.quit = true; +this.notifyAll (); +try { +this.reader.join (1000); +this.pin.close (); +} catch (e) { +if (Clazz.exceptionOf (e, Exception)) { +} else { +throw e; +} +} +try { +this.reader2.join (1000); +this.pin2.close (); +} catch (e) { +if (Clazz.exceptionOf (e, Exception)) { +} else { +throw e; +} +} +System.exit (0); +}, "java.awt.event.WindowEvent"); +Clazz.overrideMethod (c$, "windowClosing", +function (evt) { +this.frame.setVisible (false); +this.frame.dispose (); +}, "java.awt.event.WindowEvent"); +Clazz.overrideMethod (c$, "actionPerformed", +function (evt) { +this.textArea.setText (""); +}, "java.awt.event.ActionEvent"); +Clazz.overrideMethod (c$, "run", +function () { +try { +while (Thread.currentThread () === this.reader) { +try { +this.wait (100); +} catch (ie) { +if (Clazz.exceptionOf (ie, InterruptedException)) { +} else { +throw ie; +} +} +if (this.pin.available () != 0) { +var input = this.readLine (this.pin); +this.textArea.append (input); +}if (this.quit) return; +} +while (Thread.currentThread () === this.reader2) { +try { +this.wait (100); +} catch (ie) { +if (Clazz.exceptionOf (ie, InterruptedException)) { +} else { +throw ie; +} +} +if (this.pin2.available () != 0) { +var input = this.readLine (this.pin2); +this.textArea.append (input); +}if (this.quit) return; +} +} catch (e) { +if (Clazz.exceptionOf (e, Exception)) { +this.textArea.append ("\nConsole reports an Internal error."); +this.textArea.append ("The error is: " + e); +} else { +throw e; +} +} +if (Thread.currentThread () === this.errorThrower) { +try { +this.wait (1000); +} catch (ie) { +if (Clazz.exceptionOf (ie, InterruptedException)) { +} else { +throw ie; +} +} +throw new NullPointerException (jalview.util.MessageManager.getString ("exception.application_test_npe")); +}}); +Clazz.defineMethod (c$, "readLine", +function ($in) { +var input = ""; +do { +var available = $in.available (); +if (available == 0) break; +var b = Clazz.newByteArray (available, 0); +$in.read (b); +input = input + String.instantialize (b, 0, b.length); +} while (!input.endsWith ("\n") && !input.endsWith ("\r\n") && !this.quit); +return input; +}, "java.io.PipedInputStream"); +});