merged tag ooo/DEV300_m102
[LibreOffice.git] / toolkit / test / accessibility / ov / TextView.java
blob094647986e4fbc66ed72500cbd00ad67aca22587
1 package ov;
3 import java.awt.Color;
4 import java.awt.GridBagConstraints;
5 import java.awt.GridBagLayout;
6 import java.awt.event.ActionListener;
7 import java.awt.event.ActionEvent;
9 import javax.swing.JButton;
10 import javax.swing.JLabel;
12 import com.sun.star.accessibility.AccessibleEventId;
13 import com.sun.star.accessibility.AccessibleEventObject;
14 import com.sun.star.accessibility.AccessibleStateType;
15 import com.sun.star.accessibility.XAccessibleText;
16 import com.sun.star.accessibility.XAccessibleContext;
17 import com.sun.star.accessibility.XAccessibleStateSet;
18 import com.sun.star.uno.UnoRuntime;
20 public class TextView
21 extends ListeningObjectView
23 /** Create a TextView when the given object supports the
24 XAccessibleText interface.
26 static public ObjectView Create (
27 ObjectViewContainer aContainer,
28 XAccessibleContext xContext)
30 XAccessibleText xText = (XAccessibleText)UnoRuntime.queryInterface(
31 XAccessibleText.class, xContext);
32 if (xText != null)
33 return new TextView (aContainer);
34 else
35 return null;
39 public TextView (ObjectViewContainer aContainer)
41 super (aContainer);
43 setLayout (new GridBagLayout());
44 GridBagConstraints aConstraints = new GridBagConstraints ();
46 JLabel aLabel = new JLabel ("Text:");
47 aConstraints.gridy = 0;
48 aConstraints.weightx = 1;
49 aConstraints.fill = GridBagConstraints.HORIZONTAL;
50 add (aLabel, aConstraints);
52 maTextLabel = new JLabel ("");
53 aConstraints.gridx = 1;
54 aConstraints.fill = GridBagConstraints.NONE;
55 aConstraints.anchor = GridBagConstraints.WEST;
56 add (maTextLabel, aConstraints);
58 aLabel = new JLabel ("Caret position:");
59 aConstraints.gridx = 0;
60 aConstraints.gridy = 1;
61 aConstraints.weightx = 1;
62 aConstraints.fill = GridBagConstraints.HORIZONTAL;
63 add (aLabel, aConstraints);
65 maCaretPositionLabel = new JLabel ("");
66 aConstraints.gridx = 1;
67 aConstraints.fill = GridBagConstraints.NONE;
68 aConstraints.anchor = GridBagConstraints.WEST;
69 add (maCaretPositionLabel, aConstraints);
73 /** Additionally to the context store a reference to the
74 XAccessibleText interface.
76 public void SetObject (XAccessibleContext xObject)
78 mxText = (XAccessibleText)UnoRuntime.queryInterface(
79 XAccessibleText.class, xObject);
80 super.SetObject (xObject);
83 synchronized public void Destroy ()
85 super.Destroy();
88 synchronized public void Update ()
90 if (mxText == null)
92 maTextLabel.setText ("<null object>");
93 maCaretPositionLabel.setText ("<null object>");
95 else
97 maTextLabel.setText (mxText.getText());
98 maCaretPositionLabel.setText (Integer.toString(mxText.getCaretPosition()));
102 public String GetTitle ()
104 return ("Text");
107 public void notifyEvent (AccessibleEventObject aEvent)
109 System.out.println (aEvent);
110 switch (aEvent.EventId)
112 case AccessibleEventId.TEXT_CHANGED :
113 case AccessibleEventId.CARET_CHANGED :
114 Update ();
115 break;
119 private JLabel
120 maTextLabel,
121 maCaretPositionLabel;
122 private XAccessibleText mxText;