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