1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 package ov;
23 
24 import java.awt.Color;
25 import java.awt.Dimension;
26 import java.awt.GridBagLayout;
27 import java.awt.GridBagConstraints;
28 
29 import java.awt.event.ActionListener;
30 import java.awt.event.ActionEvent;
31 
32 import javax.swing.JLabel;
33 import javax.swing.JTextField;
34 
35 import com.sun.star.accessibility.AccessibleEventId;
36 import com.sun.star.accessibility.AccessibleEventObject;
37 import com.sun.star.accessibility.XAccessibleContext;
38 
39 import tools.NameProvider;
40 
41 public class ContextView
42     extends ListeningObjectView
43     implements ActionListener
44 {
Create( ObjectViewContainer aContainer, XAccessibleContext xContext)45     static public ObjectView Create (
46         ObjectViewContainer aContainer,
47         XAccessibleContext xContext)
48     {
49         System.out.println ("ContextView.CreateView");
50         if (xContext != null)
51             return new ContextView (aContainer);
52         else
53             return null;
54     }
55 
ContextView(ObjectViewContainer aContainer)56     public ContextView (ObjectViewContainer aContainer)
57     {
58         super (aContainer);
59         maNameLabel = new JLabel ("Name: ");
60         maName = new JLabel ("");
61         maDescriptionLabel = new JLabel ("Description: ");
62         maDescription = new JLabel ("");
63         maRoleLabel = new JLabel ("Role: ");
64         maRole = new JLabel ("");
65 
66         // Make the background of name and description white and opaque so
67         // that leading and trailing spaces become visible.
68         maName.setOpaque (true);
69         maName.setBackground (Color.WHITE);
70         maDescription.setOpaque (true);
71         maDescription.setBackground (Color.WHITE);
72         maRole.setOpaque (true);
73         maRole.setBackground (Color.WHITE);
74 
75         GridBagLayout aLayout = new GridBagLayout();
76         setLayout (aLayout);
77         GridBagConstraints constraints = new GridBagConstraints ();
78         constraints.gridx = 0;
79         constraints.gridy = 0;
80         constraints.gridwidth = 1;
81         constraints.gridheight = 1;
82         constraints.weightx = 0;
83         constraints.weighty = 1;
84         constraints.anchor = GridBagConstraints.WEST;
85         constraints.fill = GridBagConstraints.NONE;
86         add (maNameLabel, constraints);
87         constraints.gridy = 1;
88         add (maDescriptionLabel, constraints);
89         constraints.gridy = 2;
90         add (maRoleLabel, constraints);
91         constraints.gridy = 0;
92         constraints.gridx = 1;
93         constraints.weightx = 2;
94         add (maName, constraints);
95         constraints.gridy = 1;
96         add (maDescription, constraints);
97         constraints.gridy = 2;
98         add (maRole, constraints);
99     }
100 
Update()101     public void Update ()
102     {
103         if (mxContext == null)
104         {
105             maName.setText ("<null object>");
106             maDescription.setText ("<null object>");
107             maRole.setText ("<null object>");
108         }
109         else
110         {
111             maName.setText (mxContext.getAccessibleName());
112             maDescription.setText (mxContext.getAccessibleDescription());
113             maRole.setText (NameProvider.getRoleName (mxContext.getAccessibleRole()));
114         }
115     }
116 
GetTitle()117     public String GetTitle ()
118     {
119         return ("Context");
120     }
121 
122     /** Listen for changes regarding displayed values.
123     */
notifyEvent(AccessibleEventObject aEvent)124     public void notifyEvent (AccessibleEventObject aEvent)
125     {
126         switch (aEvent.EventId)
127         {
128             case AccessibleEventId.NAME_CHANGED :
129             case AccessibleEventId.DESCRIPTION_CHANGED :
130                 Update ();
131         }
132     }
133 
actionPerformed(ActionEvent aEvent)134     public void actionPerformed (ActionEvent aEvent)
135     {
136     }
137 
138 
139     private JLabel
140         maNameLabel,
141         maName,
142         maDescriptionLabel,
143         maDescription,
144         maRoleLabel,
145         maRole;
146 }
147