summaryrefslogtreecommitdiffstats
path: root/khtml/java/org/kde/kjas/server/KJASConsole.java
blob: 51498b59b29f4527d78b0d2edd98f8920fb6810e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package org.kde.kjas.server;

import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class KJASConsole
    extends Frame
    implements Console
{
    private TextArea txt;

    public KJASConsole()
    {
        super("Konqueror Java Console");

        txt = new TextArea();
        txt.setEditable(false);
        txt.setBackground(Color.white);
        txt.setForeground(Color.black);

        Panel main = new Panel(new BorderLayout());
        Panel btns = new Panel(new BorderLayout());

        Button clear = new Button("Clear");
        Button close = new Button("Close");
        
        btns.add(clear, "West");
        btns.add(close, "East");

        main.add(txt, "Center");
        main.add(btns, "South");
        
        add( main );

        clear.addActionListener
        (
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    txt.setText("");
                }
            }
        );

        close.addActionListener
        (
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    setVisible(false);
                }
            }
        );
        
        addWindowListener
        (
            new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    setVisible(false);
                }
            }
        );

        setSize(500, 300);

        PrintStream st = new PrintStream( new KJASConsoleStream(this) );
        System.setOut(st);
        System.setErr(st);
        
        System.out.println( "Java VM version: " +
                            System.getProperty("java.version") );
        System.out.println( "Java VM vendor:  " +
                            System.getProperty("java.vendor") );
    }
    
    public void clear() {
      txt.setText("");
    }

    public void append(String msg) {
        if (msg == null) {
            return;
        }
        int length = msg.length();
        synchronized(txt) {
            //get the caret position, and then get the new position
            int old_pos = txt.getCaretPosition();
            txt.append(msg);
            txt.setCaretPosition( old_pos + length );
        }
    }   
}