blob: 3bca8ff58665f5b9b8e16a1acf1e6d9d689b0f75 [file] [log] [blame]
Richard S. Hall5c23fb92006-09-28 19:55:37 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
Richard S. Hall54d1e2e2006-04-05 14:19:38 +00009 *
Richard S. Hall5c23fb92006-09-28 19:55:37 +000010 * http://www.apache.org/licenses/LICENSE-2.0
Richard S. Hall54d1e2e2006-04-05 14:19:38 +000011 *
Richard S. Hall5c23fb92006-09-28 19:55:37 +000012 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
Richard S. Hall54d1e2e2006-04-05 14:19:38 +000018 */
19package org.apache.felix.shell.gui.plugin;
20
21import java.awt.Font;
22
23import javax.swing.*;
24
25public class ScrollableOutputArea extends JScrollPane
26{
27 private JTextArea m_textArea = null;
28
29 public ScrollableOutputArea()
30 {
31 super();
32 m_textArea = new JTextArea();
33 initialize();
34 }
35
36 public ScrollableOutputArea(int rows, int columns)
37 {
38 super();
39 m_textArea = new JTextArea(rows, columns);
40 initialize();
41 }
42
43 private void initialize()
44 {
45 setViewportView(m_textArea);
46 m_textArea.setLineWrap(true);
47 m_textArea.setAutoscrolls(true);
48 m_textArea.setEnabled(true);
49 m_textArea.setEditable(false);
50 m_textArea.setFont(new Font("Monospaced", 0, 12));
51 setAutoscrolls(true);
52 }
53
54 public void setText(String s)
55 {
56 m_textArea.setText(s);
57 }
58
59 public void addText(String text)
60 {
61 m_textArea.append(text);
62 if (m_textArea.isDisplayable())
63 {
64 try
65 {
66 m_textArea.setCaretPosition(Integer.MAX_VALUE); // Scroll to end of window
67 }
68 catch (Exception e)
69 {
70 // Just for safety
71 }
72 }
73 validate();
74 JScrollBar sb = getVerticalScrollBar();
75 if ((sb != null) && (sb.isVisible()))
76 {
77 sb.setValue(Integer.MAX_VALUE);
78 }
79 }
80}