Source code: org/mitre/cvw/console/Console.java
1 /*
2 * Copyright (c) 1996-2000. The MITRE Corporation (http://www.mitre.org/).
3 * All rights reserved.
4 * CVW comes with ABSOLUTELY NO WARRANTY. See license for details.
5 */
6
7 package org.mitre.cvw.console;
8
9 import javax.swing.*;
10 import javax.swing.event.*;
11 import javax.swing.text.*;
12 import java.awt.*;
13 import java.awt.event.*;
14
15 /** A simple console class.
16 * This class provides a simple console in a scrolled text frame
17 *
18 * @author S.R.Jones
19 * @version 1.1
20 */
21
22 public class Console extends JFrame {
23
24 private JScrollPane scrollPane;
25 private ConsoleArea textArea;
26 private Container contentPane;
27 private JPanel buttonPanel;
28 private JButton clearButton, closeButton;
29
30 /** Constructor
31 *
32 */
33 public Console() {
34
35 // create the parent
36 super("Console");
37
38 // get the current content pane
39 contentPane = getContentPane();
40 contentPane.setLayout(new BorderLayout());
41
42 textArea = new ConsoleArea(20, 60); // rows and columns specified
43
44 textArea.setEditable(false);
45 textArea.setBackground(Color.white);
46 scrollPane = new JScrollPane(textArea,
47 JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
48 JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
49
50 // buttons
51 clearButton = new JButton("Clear");
52 clearButton.addActionListener(new ActionListener() {
53 public void actionPerformed(ActionEvent e) {
54 textArea.setText(" ");
55 }
56 });
57
58 closeButton = new JButton("Close");
59 closeButton.addActionListener(new ActionListener() {
60 public void actionPerformed(ActionEvent e) {
61 setVisible(false);
62 }
63 });
64
65 buttonPanel = new JPanel(new FlowLayout());
66 buttonPanel.add(clearButton);
67 buttonPanel.add(closeButton);
68
69 JCheckBox scrollLock = new JCheckBox("Lock console scroll", true);
70 scrollLock.addActionListener(new ActionListener() {
71 public void actionPerformed(ActionEvent e) {
72 textArea.setScrollLock(((JCheckBox)e.getSource()).isSelected());
73 }
74 });
75 scrollLock.setHorizontalTextPosition(JCheckBox.LEFT);
76 JPanel slPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
77 slPanel.add(scrollLock);
78
79 JPanel southPanel = new JPanel(new BorderLayout(0, 0));
80 southPanel.add(BorderLayout.CENTER, buttonPanel);
81 southPanel.add(BorderLayout.EAST, slPanel);
82
83 // create the final layout
84 contentPane.add("Center", scrollPane);
85 contentPane.add("South", southPanel);
86
87 // create the new out and err streams, then assign them
88 ConsoleStream consoleOut = new ConsoleStream(System.out, textArea);
89 ConsoleStream consoleErr = new ConsoleStream(System.err, textArea);
90
91 System.setOut(consoleOut);
92 System.setErr(consoleErr);
93
94 // add a window listener
95 pack();
96 addWindowListener(new WindowAdapter() {
97 public void windowClosing(WindowEvent e) {
98 setVisible(false);
99 }
100 });
101
102 //setVisible(true);
103 }
104
105 }
106
107