1 /*-
2  * Copyright (C) 2007 Erik Larsson
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 package org.catacombae.hfsexplorer;
19 
20 import java.awt.BorderLayout;
21 import java.io.OutputStream;
22 import java.io.PrintStream;
23 import javax.swing.JScrollPane;
24 import javax.swing.JTextArea;
25 import org.catacombae.hfsexplorer.gui.HFSExplorerJFrame;
26 import org.catacombae.hfsexplorer.io.JTextAreaOutputStream;
27 
28 public class DebugConsoleWindow extends HFSExplorerJFrame {
29     private static final int WINDOW_NUMBER_OF_COLUMNS = 80;
30     private static final int WINDOW_NUMBER_OF_LINES = 25;
31 
32     private final JScrollPane debugAreaScroller;
33     private final JTextArea debugArea;
34 
35     private final Object syncObject = new Object();
36     private final OutputStream debugStream;
37 
DebugConsoleWindow(PrintStream stdErr)38     public DebugConsoleWindow(PrintStream stdErr) {
39         super("Debug Console");
40 
41         setLayout(new BorderLayout());
42         this.debugArea = new JTextArea(WINDOW_NUMBER_OF_LINES, WINDOW_NUMBER_OF_COLUMNS);
43         this.debugAreaScroller = new JScrollPane(debugArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
44                 JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
45         this.debugArea.setLineWrap(true);
46         this.debugArea.setEditable(false);
47 
48         add(debugAreaScroller, BorderLayout.CENTER);
49 
50         pack();
51         setLocationRelativeTo(null);
52         setDefaultCloseOperation(DISPOSE_ON_CLOSE);
53 
54         this.debugStream = new JTextAreaOutputStream(stdErr, debugArea, debugAreaScroller, syncObject, null);
55     }
56 
57     /**
58      * Returns an OutputStream which sends its output to the DebugConsoleWindow's JTextArea.
59      * @return an OutputStream which sends its output to the DebugConsoleWindow's JTextArea.
60      */
getDebugStream()61     public OutputStream getDebugStream() {
62         return debugStream;
63     }
64 }
65