/*     */ package org.ui.debug;
/*     */ 
/*     */ import java.awt.BorderLayout;
/*     */ import java.awt.Color;
/*     */ import java.awt.FlowLayout;
/*     */ import java.awt.Font;
/*     */ import java.awt.event.ActionEvent;
/*     */ import java.io.PrintStream;
/*     */ import javax.swing.BorderFactory;
/*     */ import javax.swing.BoxLayout;
/*     */ import javax.swing.JButton;
/*     */ import javax.swing.JLabel;
/*     */ import javax.swing.JPanel;
/*     */ import javax.swing.JScrollPane;
/*     */ import javax.swing.JTextArea;
/*     */ import org.ui.UICreator;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Console
/*     */   extends JPanel
/*     */ {
/*     */   private static final long serialVersionUID = -1800165403047521827L;
/*     */   private JPanel consoleLogger;
/*     */   private JScrollPane scrollPane;
/*     */   private JPanel toolBar;
/*     */   private JButton clear;
/*     */   private JLabel queueSize;
/*     */   private JLabel info;
/*     */   private ConsoleWriteStream stdout;
/*     */   private ConsoleWriteStream stderr;
/*  50 */   private Entry lastEntry = Entry.NORMAL;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public Console() {
/*  59 */     setLayout(new BorderLayout());
/*     */     
/*  61 */     createUI();
/*     */     
/*  63 */     setupUI();
/*     */     
/*  65 */     createListener();
/*     */     
/*  67 */     createWriteStreams();
/*     */ 
/*     */     
/*  70 */     add(this.scrollPane, "Center");
/*  71 */     add(this.toolBar, "North");
/*     */ 
/*     */     
/*  74 */     createLog("Console was created successfully\n", Entry.INFORMATION);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void createListener() {
/*  81 */     this.clear.addActionListener(e -> {
/*     */           this.consoleLogger.removeAll();
/*     */           this.consoleLogger.revalidate();
/*     */           this.consoleLogger.repaint();
/*     */           this.queueSize.setText("| Elements: (none)");
/*     */           this.info.setText((String)null);
/*     */         });
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void setupUI() {
/*  97 */     this.consoleLogger.setLayout(new BoxLayout(this.consoleLogger, 1));
/*  98 */     this.info.setForeground(Color.YELLOW);
/*     */ 
/*     */     
/* 101 */     this.clear.setToolTipText("Clear the console logger's buffer.\nThis means deleting all current log entries in the console.");
/*     */     
/* 103 */     this.scrollPane.setVerticalScrollBarPolicy(22);
/* 104 */     this.scrollPane.setHorizontalScrollBarPolicy(30);
/* 105 */     this.scrollPane.setAutoscrolls(true);
/*     */ 
/*     */     
/* 108 */     this.toolBar.add(new JLabel("Console"));
/* 109 */     this.toolBar.add(this.clear);
/* 110 */     this.toolBar.add(this.queueSize);
/* 111 */     this.toolBar.add(this.info);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void createUI() {
/* 118 */     this.toolBar = new JPanel(new FlowLayout(0, 4, 0));
/*     */     
/* 120 */     this.consoleLogger = new JPanel();
/*     */     
/* 122 */     this.scrollPane = new JScrollPane(this.consoleLogger);
/*     */     
/* 124 */     this.clear = UICreator.createIconifiedButton('c');
/* 125 */     this.queueSize = new JLabel();
/* 126 */     this.info = new JLabel();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void createWriteStreams() {
/* 133 */     this.stdout = new ConsoleWriteStream(this, Entry.NORMAL);
/* 134 */     this.stderr = new ConsoleWriteStream(this, Entry.ERROR);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public final synchronized void createLog(String message, Entry entryType) {
/* 148 */     JTextArea lastLog = getLastEntryLog();
/*     */ 
/*     */ 
/*     */     
/* 152 */     if (this.lastEntry == entryType && lastLog != null && (int)lastLog.getText().lines().count() < 48) {
/*     */ 
/*     */       
/* 155 */       lastLog.setText(String.format("%s%s", new Object[] { lastLog.getText(), message }));
/*     */ 
/*     */       
/* 158 */       this.scrollPane.getVerticalScrollBar().setValue(this.scrollPane.getVerticalScrollBar().getMaximum());
/* 159 */       this.scrollPane.repaint();
/*     */     
/*     */     }
/*     */     else {
/*     */       
/* 164 */       boolean isQueueFull = ((this.consoleLogger.getComponents()).length > 36);
/*     */ 
/*     */       
/* 167 */       this.info.setText(isQueueFull ? "Elements were deleted form Console buffer due to limited queue size" : null);
/*     */ 
/*     */       
/* 170 */       if (isQueueFull)
/*     */       {
/*     */         
/* 173 */         this.consoleLogger.remove(this.consoleLogger.getComponents()[0]);
/*     */       }
/*     */ 
/*     */       
/* 177 */       createBasicConsoleLog(message, Entry.getColorByEnum(entryType));
/*     */     } 
/*     */     
/* 180 */     this.lastEntry = entryType;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private JTextArea getLastEntryLog() {
/* 190 */     int elementIndex = (this.consoleLogger.getComponents()).length - 1;
/*     */     
/* 192 */     if (elementIndex < 0)
/*     */     {
/* 194 */       return null;
/*     */     }
/*     */ 
/*     */     
/* 198 */     return (JTextArea)this.consoleLogger.getComponents()[elementIndex];
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void createBasicConsoleLog(String message, Color color) {
/* 211 */     JTextArea messageBlock = new JTextArea(message);
/*     */ 
/*     */ 
/*     */ 
/*     */     
/* 216 */     messageBlock.setBorder(BorderFactory.createEmptyBorder());
/*     */     
/* 218 */     messageBlock.setFont(new Font("Consolas", 0, 14));
/*     */     
/* 220 */     messageBlock.setEditable(false);
/*     */     
/* 222 */     messageBlock.setBackground(new Color(1579032));
/*     */     
/* 224 */     messageBlock.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.DARK_GRAY));
/* 225 */     messageBlock.setForeground(color);
/*     */ 
/*     */ 
/*     */     
/* 229 */     this.consoleLogger.add(messageBlock);
/* 230 */     this.scrollPane.getVerticalScrollBar().setValue(this.scrollPane.getVerticalScrollBar().getMaximum());
/*     */     
/* 232 */     this.queueSize.setText(String.format("Elements: (%d)", new Object[] { Integer.valueOf((this.consoleLogger.getComponents()).length) }));
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public PrintStream getStdOut() {
/* 241 */     return new PrintStream(this.stdout);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public PrintStream getStdErr() {
/* 250 */     return new PrintStream(this.stderr);
/*     */   }
/*     */ }


/* Location:              /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/ui/debug/Console.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */