KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > project > ProjectConsole


1 package org.antlr.works.project;
2
3 import org.antlr.works.prefs.AWPrefs;
4
5 import javax.swing.*;
6 import java.awt.*;
7 import java.awt.event.ActionEvent JavaDoc;
8 import java.awt.event.ActionListener JavaDoc;
9 /*
10
11 [The "BSD licence"]
12 Copyright (c) 2005-2006 Jean Bovet
13 All rights reserved.
14
15 Redistribution and use in source and binary forms, with or without
16 modification, are permitted provided that the following conditions
17 are met:
18
19 1. Redistributions of source code must retain the above copyright
20 notice, this list of conditions and the following disclaimer.
21 2. Redistributions in binary form must reproduce the above copyright
22 notice, this list of conditions and the following disclaimer in the
23 documentation and/or other materials provided with the distribution.
24 3. The name of the author may not be used to endorse or promote products
25 derived from this software without specific prior written permission.
26
27 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
31 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
38 */

39
40 public class ProjectConsole {
41
42     protected Container container;
43     protected JTextArea textArea;
44
45     public ProjectConsole() {
46         create();
47     }
48
49     public Container getContainer() {
50         return container;
51     }
52
53     public void create() {
54         JTabbedPane tabbedPane = new JTabbedPane();
55         tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
56
57         JPanel panel = new JPanel(new BorderLayout());
58
59         Box box = Box.createHorizontalBox();
60
61         JButton clear = new JButton("Clear All");
62         clear.addActionListener(new ActionListener JavaDoc() {
63             public void actionPerformed(ActionEvent JavaDoc e) {
64                 clear();
65             }
66         });
67         box.add(clear);
68         box.add(Box.createHorizontalGlue());
69
70         panel.add(createTextArea(), BorderLayout.CENTER);
71         panel.add(box, BorderLayout.SOUTH);
72
73         tabbedPane.add("Project", panel);
74
75         container = tabbedPane;
76     }
77
78     public Container createTextArea() {
79         textArea = new JTextArea();
80         JScrollPane textAreaScrollPane = new JScrollPane(textArea);
81         textAreaScrollPane.setWheelScrollingEnabled(true);
82         applyFont();
83         return textAreaScrollPane;
84     }
85
86     public void applyFont() {
87         textArea.setFont(new Font(AWPrefs.getEditorFont(), Font.PLAIN, AWPrefs.getEditorFontSize()));
88     }
89
90     public void clear() {
91         textArea.setText("");
92     }
93
94     public synchronized void print(String JavaDoc s) {
95         textArea.setText(textArea.getText()+s);
96         textArea.setCaretPosition(textArea.getText().length());
97     }
98 }
99
Popular Tags