!747 !awt { !actionListener { !pcall { m { static S vmName = "This is a JavaX VM."; // Use any vM p { new Console(new String[0]); } !include #1000943 // DelayedUpdate static class Console extends WindowAdapter implements WindowListener, ActionListener { PipedInputStream pin=new PipedInputStream(); PipedInputStream pin2=new PipedInputStream(); PipedInputStream pin3=new PipedInputStream(); Thread reader, reader2; boolean quit; JFrame frame; JTextArea textArea; JTextField tfInput; StringBuffer buf = new StringBuffer(); JButton buttonclear, buttonkill, buttonrestart, buttonduplicate, buttonstacktrace; String[] args; final DelayedUpdate du = new DelayedUpdate(new Runnable() { public void run() { try { textArea.append(buf.substring(textArea.getText().length())); } catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}}); public Console(final String[] args) ctex { this.args = args; // create all components and add them frame=new JFrame(args.length == 0 ? "Console Bot Console" : "Console Bot Console - " + join(" ", args)); /*Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize=new Dimension((int)(screenSize.width/2),(int)(screenSize.height/2)); int x=(int)(frameSize.width/2); int y=(int)(frameSize.height/2); frame.setBounds(x,y,frameSize.width,frameSize.height);*/ // put in right-bottom corner Rectangle r = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); int w = 550, h = 200; frame.setBounds(r.x+r.width-w, r.y+r.height-h, w, h); textArea=new JTextArea(); textArea.setEditable(false); buttonclear = new JButton("clear"); buttonkill = new JButton("kill"); buttonrestart = new JButton("restart"); buttonduplicate = new JButton("duplicate"); buttonstacktrace = new JButton("status"); buttonstacktrace.setToolTipText("Show threads & stack traces."); JPanel buttons = new JPanel(new GridLayout(1, 5)); buttons.add(buttonclear); buttons.add(buttonkill); buttons.add(buttonrestart); buttons.add(buttonduplicate); buttons.add(buttonstacktrace); tfInput = new JTextField(); tfInput.addActionListener(actionListener { S line = tfInput.getText(); sendToLocalBot(vmName, "send line * to system.in", line); tfInput.setText(""); }); JPanel panel = new JPanel(new BorderLayout()); panel.add(new JScrollPane(textArea), BorderLayout.CENTER); panel.add(tfInput, BorderLayout.SOUTH); frame.addWindowListener(new WindowAdapter() { public void windowActivated(WindowEvent e) { tfInput.requestFocus(); } }); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(panel, BorderLayout.CENTER); frame.getContentPane().add(buttons, BorderLayout.SOUTH); frame.setVisible(true); //frame.addWindowListener(this); // disabled for now buttonclear.addActionListener(this); buttonkill.addActionListener(this); buttonrestart.addActionListener(this); buttonduplicate.addActionListener(this); buttonstacktrace.addActionListener(this); quit=false; // signals the Threads that they should exit if (args.length != 0) { print("Starting title updater"); new Thread("Console Title Updater :)") { public void run() { if (args.length != 0) { int i = 0; while (i < args.length && !isSnippetID(args[i])) ++i; print("Getting title for " + args[i]); String title = getSnippetTitle(args[i]); print("Title: " + title); if (title != null && title.length() != 0) frame.setTitle(title + " [Output]"); } } }.start(); } System.setIn(pin3); } public synchronized void windowClosed(WindowEvent evt) { /*quit=true; this.notifyAll(); // stop all threads try { reader.join(1000);pin.close(); } catch (Exception e){} try { reader2.join(1000);pin2.close(); } catch (Exception e){} System.exit(0);*/ } public synchronized void windowClosing(WindowEvent evt) { frame.setVisible(false); // default behaviour of JFrame frame.dispose(); } public synchronized void actionPerformed(ActionEvent evt) { /*if (evt.getSource() == buttonkill) { print("Console: Kill button pressed!"); // TODO: give threads time to finish, e.g. reportToChat? System.exit(0); } else if (evt.getSource() == buttonrestart) { print("Console: Restart button pressed."); nohupJavax(smartJoin(args)); System.exit(0); } else if (evt.getSource() == buttonduplicate) { print("Console: Duplicate button pressed."); nohupJavax(smartJoin(args)); } else if (evt.getSource() == buttonstacktrace) { listUserThreadsWithStackTraces(); } else { textArea.setText(""); buf = new StringBuffer(); }*/ } public void appendText(String s, boolean outNotErr) { //if (verbose) oldOut.println("Console appendText " + outNotErr + " " + quote(s)); buf.append(s); du.trigger(); } } // Console }