merged tag ooo/DEV300_m102
[LibreOffice.git] / toolkit / test / accessibility / ov / ContextView.java
blob4204c5de7bac0498c3681a2364d8205512231695
1 package ov;
3 import java.awt.Color;
4 import java.awt.Dimension;
5 import java.awt.GridBagLayout;
6 import java.awt.GridBagConstraints;
8 import java.awt.event.ActionListener;
9 import java.awt.event.ActionEvent;
11 import javax.swing.JLabel;
12 import javax.swing.JTextField;
14 import com.sun.star.accessibility.AccessibleEventId;
15 import com.sun.star.accessibility.AccessibleEventObject;
16 import com.sun.star.accessibility.XAccessibleContext;
18 import tools.NameProvider;
20 public class ContextView
21 extends ListeningObjectView
22 implements ActionListener
24 static public ObjectView Create (
25 ObjectViewContainer aContainer,
26 XAccessibleContext xContext)
28 System.out.println ("ContextView.CreateView");
29 if (xContext != null)
30 return new ContextView (aContainer);
31 else
32 return null;
35 public ContextView (ObjectViewContainer aContainer)
37 super (aContainer);
38 maNameLabel = new JLabel ("Name: ");
39 maName = new JLabel ("");
40 maDescriptionLabel = new JLabel ("Description: ");
41 maDescription = new JLabel ("");
42 maRoleLabel = new JLabel ("Role: ");
43 maRole = new JLabel ("");
45 // Make the background of name and description white and opaque so
46 // that leading and trailing spaces become visible.
47 maName.setOpaque (true);
48 maName.setBackground (Color.WHITE);
49 maDescription.setOpaque (true);
50 maDescription.setBackground (Color.WHITE);
51 maRole.setOpaque (true);
52 maRole.setBackground (Color.WHITE);
54 GridBagLayout aLayout = new GridBagLayout();
55 setLayout (aLayout);
56 GridBagConstraints constraints = new GridBagConstraints ();
57 constraints.gridx = 0;
58 constraints.gridy = 0;
59 constraints.gridwidth = 1;
60 constraints.gridheight = 1;
61 constraints.weightx = 0;
62 constraints.weighty = 1;
63 constraints.anchor = GridBagConstraints.WEST;
64 constraints.fill = GridBagConstraints.NONE;
65 add (maNameLabel, constraints);
66 constraints.gridy = 1;
67 add (maDescriptionLabel, constraints);
68 constraints.gridy = 2;
69 add (maRoleLabel, constraints);
70 constraints.gridy = 0;
71 constraints.gridx = 1;
72 constraints.weightx = 2;
73 add (maName, constraints);
74 constraints.gridy = 1;
75 add (maDescription, constraints);
76 constraints.gridy = 2;
77 add (maRole, constraints);
80 public void Update ()
82 if (mxContext == null)
84 maName.setText ("<null object>");
85 maDescription.setText ("<null object>");
86 maRole.setText ("<null object>");
88 else
90 maName.setText (mxContext.getAccessibleName());
91 maDescription.setText (mxContext.getAccessibleDescription());
92 maRole.setText (NameProvider.getRoleName (mxContext.getAccessibleRole()));
96 public String GetTitle ()
98 return ("Context");
101 /** Listen for changes regarding displayed values.
103 public void notifyEvent (AccessibleEventObject aEvent)
105 switch (aEvent.EventId)
107 case AccessibleEventId.NAME_CHANGED :
108 case AccessibleEventId.DESCRIPTION_CHANGED :
109 Update ();
113 public void actionPerformed (ActionEvent aEvent)
118 private JLabel
119 maNameLabel,
120 maName,
121 maDescriptionLabel,
122 maDescription,
123 maRoleLabel,
124 maRole;