2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import java
.awt
.Color
;
21 import java
.awt
.Graphics
;
22 import javax
.swing
.JScrollPane
;
23 import javax
.swing
.JTextArea
;
24 import javax
.swing
.JScrollBar
;
28 /** A message area displays text in a scrollable text widget. It is a
29 singleton. Other objects can access it directly to display messages.
31 public class MessageArea
34 public static synchronized MessageArea
Instance ()
36 if (saInstance
== null)
37 saInstance
= new MessageArea ();
44 /** Create a new message area. This method is private because the class is
45 a singleton and may therefore not be instanciated from the outside.
47 private MessageArea ()
49 maText
= new JTextArea();
50 maText
.setBackground (new Color (255,250,240));
51 maText
.setFont (new Font ("Helvetica", Font
.PLAIN
, 9));
52 setViewportView (maText
);
53 setVerticalScrollBarPolicy (JScrollPane
.VERTICAL_SCROLLBAR_ALWAYS
);
54 setHorizontalScrollBarPolicy (JScrollPane
.HORIZONTAL_SCROLLBAR_ALWAYS
);
57 "class path is " + System
.getProperty ("java.class.path") + "\n");
63 /** Show the given string at the end of the message area and scroll to make
66 public static synchronized void print (String aMessage
)
74 /** Show the given string at the end of the message area and scroll to make
75 it visible. Indent the string as requested.
77 public static synchronized void print (int nIndentation
, String aMessage
)
79 while (nIndentation
-- > 0)
80 aMessage
= " " + aMessage
;
81 Instance().printMessage(aMessage
);
87 /** Show the given string at the end of the message area and scroll to make
90 public static void println (String aMessage
)
92 println (0, aMessage
);
98 /** Show the given string at the end of the message area and scroll to make
101 public static void println (int nIndentation
, String aMessage
)
103 print (nIndentation
, aMessage
+"\n");
109 public void paintComponent (Graphics g
)
113 JScrollBar sb
= getVerticalScrollBar();
116 int nScrollBarValue
= sb
.getMaximum() - sb
.getVisibleAmount() - 1;
117 sb
.setValue (nScrollBarValue
);
119 super.paintComponent (g
);
126 /** Append the given string to the end of the text and scroll so that it
127 becomes visible. This is an internal method. Use one of the static
130 private synchronized void printMessage (String aMessage
)
132 maText
.append (aMessage
);
138 private static MessageArea saInstance
= null;
139 private JTextArea maText
;