merged tag ooo/DEV300_m102
[LibreOffice.git] / toolkit / test / accessibility / MessageArea.java
blobc9d95995e0665822d146a25501f72298e4583f6a
1 import java.awt.Font;
2 import java.awt.Rectangle;
3 import java.awt.Color;
4 import java.awt.Graphics;
5 import javax.swing.JScrollPane;
6 import javax.swing.JTextArea;
7 import javax.swing.JScrollBar;
11 /** A message area displays text in a scrollable text widget. It is a
12 singleton. Other objects can access it directly to display messages.
14 public class MessageArea
15 extends JScrollPane
17 public static synchronized MessageArea Instance ()
19 if (saInstance == null)
20 saInstance = new MessageArea ();
21 return saInstance;
27 /** Create a new message area. This method is private because the class is
28 a singleton and may therefore not be instanciated from the outside.
30 private MessageArea ()
32 maText = new JTextArea();
33 maText.setBackground (new Color (255,250,240));
34 maText.setFont (new Font ("Helvetica", Font.PLAIN, 9));
35 setViewportView (maText);
36 setVerticalScrollBarPolicy (JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
37 setHorizontalScrollBarPolicy (JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
39 printMessage (
40 "class path is " + System.getProperty ("java.class.path") + "\n");
46 /** Show the given string at the end of the message area and scroll to make
47 it visible.
49 public static synchronized void print (String aMessage)
51 print (0, aMessage);
57 /** Show the given string at the end of the message area and scroll to make
58 it visible. Indent the string as requested.
60 public static synchronized void print (int nIndentation, String aMessage)
62 while (nIndentation-- > 0)
63 aMessage = " " + aMessage;
64 Instance().printMessage(aMessage);
70 /** Show the given string at the end of the message area and scroll to make
71 it visible.
73 public static void println (String aMessage)
75 println (0, aMessage);
81 /** Show the given string at the end of the message area and scroll to make
82 it visible.
84 public static void println (int nIndentation, String aMessage)
86 print (nIndentation, aMessage+"\n");
92 public void paintComponent (Graphics g)
94 synchronized (g)
96 JScrollBar sb = getVerticalScrollBar();
97 if (sb != null)
99 int nScrollBarValue = sb.getMaximum() - sb.getVisibleAmount() - 1;
100 sb.setValue (nScrollBarValue);
102 super.paintComponent (g);
109 /** Append the given string to the end of the text and scroll so that it
110 becomes visible. This is an internal method. Use one of the static
111 and public ones.
113 private synchronized void printMessage (String aMessage)
115 maText.append (aMessage);
121 private static MessageArea saInstance = null;
122 private JTextArea maText;