Branch libreoffice-5-0-4
[LibreOffice.git] / toolkit / test / accessibility / MessageArea.java
blob512cfaf73397eecd7c9cf07e2c7b3e9447e2714c
1 /*
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 .
19 import java.awt.Font;
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
32 extends JScrollPane
34 public static synchronized MessageArea Instance ()
36 if (saInstance == null)
37 saInstance = new MessageArea ();
38 return saInstance;
44 /** Create a new message area. This method is private because the class is
45 a singleton and may therefore not be instantiated 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);
56 printMessage (
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
64 it visible. Indent the string as requested.
66 private static synchronized void print (int nIndentation, String aMessage)
68 while (nIndentation-- > 0) {
69 aMessage = " " + aMessage;
71 Instance().printMessage(aMessage);
77 /** Show the given string at the end of the message area and scroll to make
78 it visible.
80 public static void println (String aMessage)
82 println (0, aMessage);
88 /** Show the given string at the end of the message area and scroll to make
89 it visible.
91 private static void println (int nIndentation, String aMessage)
93 print (nIndentation, aMessage+"\n");
99 @Override
100 public void paintComponent (Graphics g)
102 synchronized (g)
104 JScrollBar sb = getVerticalScrollBar();
105 if (sb != null)
107 int nScrollBarValue = sb.getMaximum() - sb.getVisibleAmount() - 1;
108 sb.setValue (nScrollBarValue);
110 super.paintComponent (g);
117 /** Append the given string to the end of the text and scroll so that it
118 becomes visible. This is an internal method. Use one of the static
119 and public ones.
121 private synchronized void printMessage (String aMessage)
123 maText.append (aMessage);
129 private static MessageArea saInstance = null;
130 private final JTextArea maText;