Advertisement
magik6000

Untitled

Aug 22nd, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1.  
  2.  
  3. package net.modularblocks.common.utils.log;
  4.  
  5. import java.io.IOException;
  6. import java.io.OutputStream;
  7. import java.io.PrintStream;
  8.  
  9. import javax.swing.JFrame;
  10. import javax.swing.JScrollPane;
  11. import javax.swing.JTextArea;
  12.  
  13. import net.modularblocks.api.common.Logger;
  14. import net.modularblocks.client.config.Conf;
  15. import net.modularblocks.common.utils.ArgsParser;
  16. import net.modularblocks.common.utils.Config;
  17. import net.modularblocks.server.main.ServerManager;
  18.  
  19. public class ConsoleFrame {
  20.     private static ConsoleFrame instance;
  21.     private JFrame consoleframe;
  22.     public JTextArea console;
  23.     private String line;
  24.     private Logger stdLogger;
  25.    
  26.     private PrintStream out = new PrintStream(new OutputStream() {
  27.         @Override
  28.         public void write(int arg0) throws IOException {
  29.             line += ((char) arg0);
  30.            
  31.             if((char) arg0 == '\n'){
  32.                 stdLogger.print(line);
  33.                 line = "";
  34.                
  35.                 //console.append(line);            
  36.                 //console.setCaretPosition(console.getDocument().getLength());
  37.             }
  38.         }
  39.     });
  40.  
  41.     private ConsoleFrame() {
  42.         consoleframe = new JFrame("Dev Console");
  43.         console = new JTextArea(60, 30);
  44.         console.setEditable(false);
  45.         JScrollPane sbrText = new JScrollPane(console);
  46.         sbrText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  47.         consoleframe.setSize(600, 300);
  48.         consoleframe.add(sbrText);
  49.         consoleframe.setVisible(true);
  50.         consoleframe.setDefaultCloseOperation(ArgsParser.isInList("-server")?JFrame.EXIT_ON_CLOSE:JFrame.DISPOSE_ON_CLOSE);
  51.         stdLogger = new Logger(CoreLogger.getLogger(), "std");
  52.     }
  53.  
  54.     public void setTitle(String t){
  55.         consoleframe.setTitle(t);
  56.     }
  57.    
  58.     public PrintStream getOut() {
  59.         return out;
  60.     }
  61.  
  62.     public void write(String msg)
  63.     {
  64.         console.append(msg);
  65.         console.setCaretPosition(console.getDocument().getLength());
  66.     }
  67.    
  68.     public static ConsoleFrame getInstance() {
  69.         if(instance==null){
  70.             instance=new ConsoleFrame();
  71.         }
  72.         return instance;
  73.     }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement