Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.modularblocks.common.utils.log;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.io.PrintStream;
- import javax.swing.JFrame;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import net.modularblocks.api.common.Logger;
- import net.modularblocks.client.config.Conf;
- import net.modularblocks.common.utils.ArgsParser;
- import net.modularblocks.common.utils.Config;
- import net.modularblocks.server.main.ServerManager;
- public class ConsoleFrame {
- private static ConsoleFrame instance;
- private JFrame consoleframe;
- public JTextArea console;
- private String line;
- private Logger stdLogger;
- private PrintStream out = new PrintStream(new OutputStream() {
- @Override
- public void write(int arg0) throws IOException {
- line += ((char) arg0);
- if((char) arg0 == '\n'){
- stdLogger.print(line);
- line = "";
- //console.append(line);
- //console.setCaretPosition(console.getDocument().getLength());
- }
- }
- });
- private ConsoleFrame() {
- consoleframe = new JFrame("Dev Console");
- console = new JTextArea(60, 30);
- console.setEditable(false);
- JScrollPane sbrText = new JScrollPane(console);
- sbrText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
- consoleframe.setSize(600, 300);
- consoleframe.add(sbrText);
- consoleframe.setVisible(true);
- consoleframe.setDefaultCloseOperation(ArgsParser.isInList("-server")?JFrame.EXIT_ON_CLOSE:JFrame.DISPOSE_ON_CLOSE);
- stdLogger = new Logger(CoreLogger.getLogger(), "std");
- }
- public void setTitle(String t){
- consoleframe.setTitle(t);
- }
- public PrintStream getOut() {
- return out;
- }
- public void write(String msg)
- {
- console.append(msg);
- console.setCaretPosition(console.getDocument().getLength());
- }
- public static ConsoleFrame getInstance() {
- if(instance==null){
- instance=new ConsoleFrame();
- }
- return instance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement