/* Copyright 2012 Jan Ove Saltvedt This file is part of KBot. KBot is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. KBot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with KBot. If not, see <http://www.gnu.org/licenses/>. */ /* * Copyright � 2010 Jan Ove Saltvedt. * All rights reserved. */ /* * Created by JFormDesigner on Wed Nov 25 16:59:28 CET 2009 */ package com.kbotpro.ui; import java.awt.*; import java.awt.event.WindowListener; import java.awt.event.WindowEvent; import java.io.PrintStream; import java.io.OutputStream; import java.io.IOException; import javax.swing.*; import org.jdesktop.layout.GroupLayout; import com.kbotpro.various.TextAreaOutputStream; /** * @author Jan Ove */ public class Console extends JFrame { private boolean dumpInput = true; TextAreaOutputStream textAreaOutputStream; public Console() { initComponents(); final PrintStream oldOut = System.out; final PrintStream oldErr = System.err; textAreaOutputStream = new TextAreaOutputStream(textArea1, 500); System.setOut(new PrintStream(new OutputStream() { @Override public void write(int b) throws IOException { oldOut.write(b); if(!dumpInput){ return; } textAreaOutputStream.write(b); } })); System.setErr(new PrintStream(new OutputStream() { @Override public void write(int b) throws IOException { oldErr.write(b); if(!dumpInput){ return; } textAreaOutputStream.write(b); } })); addWindowListener(new WindowListener() { public void windowOpened(WindowEvent e) { //To change body of implemented methods use File | Settings | File Templates. } public void windowClosing(WindowEvent e) { //To change body of implemented methods use File | Settings | File Templates. } public void windowClosed(WindowEvent e) { dumpInput = false; } public void windowIconified(WindowEvent e) { //To change body of implemented methods use File | Settings | File Templates. } public void windowDeiconified(WindowEvent e) { //To change body of implemented methods use File | Settings | File Templates. } public void windowActivated(WindowEvent e) { //To change body of implemented methods use File | Settings | File Templates. } public void windowDeactivated(WindowEvent e) { //To change body of implemented methods use File | Settings | File Templates. } }); } private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents scrollPane1 = new JScrollPane(); textArea1 = new JTextArea(); //======== this ======== setTitle("VM output"); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); Container contentPane = getContentPane(); //======== scrollPane1 ======== { //---- textArea1 ---- textArea1.setEditable(false); scrollPane1.setViewportView(textArea1); } GroupLayout contentPaneLayout = new GroupLayout(contentPane); contentPane.setLayout(contentPaneLayout); contentPaneLayout.setHorizontalGroup( contentPaneLayout.createParallelGroup() .add(contentPaneLayout.createSequentialGroup() .addContainerGap() .add(scrollPane1, GroupLayout.DEFAULT_SIZE, 532, Short.MAX_VALUE) .addContainerGap()) ); contentPaneLayout.setVerticalGroup( contentPaneLayout.createParallelGroup() .add(contentPaneLayout.createSequentialGroup() .addContainerGap() .add(scrollPane1, GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE) .addContainerGap()) ); pack(); setLocationRelativeTo(getOwner()); // JFormDesigner - End of component initialization //GEN-END:initComponents } // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables private JScrollPane scrollPane1; private JTextArea textArea1; // JFormDesigner - End of variables declaration //GEN-END:variables }