01: /*
02: * SwingPnutsConsole.java
03: *
04: */
05: package org.pnuts.tools;
06:
07: import java.awt.Container;
08: import javax.swing.JComponent;
09: import javax.swing.JTextArea;
10: import pnuts.tools.*;
11:
12: /**
13: * Utility class for Swing-based PnutsConsole
14: * This class is used by NetBeans Pnuts module.
15: */
16: public class SwingPnutsConsole extends PnutsConsole {
17: final static String DEFAULT_TITLE = "Pnuts Console";
18:
19: /**
20: * Creates a new PnutsConsole specifying a container
21: *
22: * @param container the Container object into which the console UI is embedded
23: * @param modules the initial modules to be used
24: * @param cl the class loader
25: * @param inputlog the input log
26: * @param terminationCallback the command object that is called when the console session terminates
27: * @param priority the priority of the interpreter thread
28: */
29: public static PnutsConsole getInstance(Container container,
30: String[] modules, ClassLoader cl, String inputlog,
31: boolean greeting, Runnable terminationCallback, int priority) {
32: PnutsConsoleUI ui = new PnutsConsoleUI() {
33: protected PnutsConsole createConsole() {
34: return new SwingPnutsConsole();
35: }
36: };
37: ui.setTitle(DEFAULT_TITLE);
38: PnutsConsole c = ui.createConsole(modules, null, cl, inputlog,
39: greeting, terminationCallback, priority);
40: if (container != null) {
41: container.add(ui.getComponent());
42: }
43: c.start();
44: ui.getTextArea().requestFocus();
45: return c;
46: }
47:
48: public JComponent getComponent() {
49: PnutsConsoleUI ui = (PnutsConsoleUI) getConsoleUI();
50: return ui.getComponent();
51: }
52:
53: public JTextArea getTextArea() {
54: PnutsConsoleUI ui = (PnutsConsoleUI) getConsoleUI();
55: return ui.getTextArea();
56: }
57:
58: public void requestFocus() {
59: PnutsConsoleUI ui = (PnutsConsoleUI) getConsoleUI();
60: ui.getTextArea().requestFocus();
61: }
62: }
|