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 
23 
24 package org.openoffice.java.accessibility;
25 
26 import com.sun.star.accessibility.AccessibleStateType;
27 import com.sun.star.accessibility.XAccessibleContext;
28 import com.sun.star.accessibility.XAccessibleComponent;
29 // import com.sun.star.accessibility.XAccessibleExtendedComponent;
30 import com.sun.star.uno.UnoRuntime;
31 
32 public class AccessibleComponentImpl implements javax.accessibility.AccessibleComponent {
33 
34     protected XAccessibleComponent unoObject;
35 //  protected XAccessibleExtendedComponent unoAccessibleExtendedComponent = null;
36 
37     /** Creates new AccessibleComponentImpl */
AccessibleComponentImpl(XAccessibleComponent xAccessibleComponent)38     public AccessibleComponentImpl(XAccessibleComponent xAccessibleComponent) {
39         unoObject = xAccessibleComponent;
40     }
41 
hasState(short state)42     protected boolean hasState(short state) {
43         try {
44             XAccessibleContext unoAccessibleContext = (XAccessibleContext)
45                 UnoRuntime.queryInterface(XAccessibleContext.class, unoObject);
46             // All UNO accessibility implementations must support XAccessibleContext
47             // and return a valid XAccessibleStateSet ..
48             return unoAccessibleContext.getAccessibleStateSet().contains(state);
49         } catch (com.sun.star.uno.RuntimeException e) {
50             return false;
51         } catch (java.lang.NullPointerException e) {
52             System.err.println("XAccessibleContext unsupported or no XAccessibleStateSet returned.");
53             return false;
54         }
55     }
56 
57     /*
58      * XAccessibleComponent
59      */
60 
61     /** Returns the background color of the object */
getBackground()62     public java.awt.Color getBackground() {
63         try {
64             return new java.awt.Color(unoObject.getBackground());
65         } catch (com.sun.star.uno.RuntimeException e) {
66             return null;
67         }
68     }
69 
setBackground(java.awt.Color c)70     public void setBackground(java.awt.Color c) {
71         // Not supported by UNO accessibility API
72     }
73 
74     /** Returns the foreground color of the object */
getForeground()75     public java.awt.Color getForeground() {
76         try {
77             return new java.awt.Color(unoObject.getForeground());
78         } catch (com.sun.star.uno.RuntimeException e) {
79             return null;
80         }
81     }
82 
setForeground(java.awt.Color c)83     public void setForeground(java.awt.Color c) {
84         // Not supported by UNO accessibility API
85     }
86 
getCursor()87     public java.awt.Cursor getCursor() {
88         // Not supported by UNO accessibility API
89         return null;
90     }
91 
setCursor(java.awt.Cursor cursor)92     public void setCursor(java.awt.Cursor cursor) {
93         // Not supported by UNO accessibility API
94     }
95 
getFont()96     public java.awt.Font getFont() {
97         // FIXME
98         return null;
99     }
100 
setFont(java.awt.Font f)101     public void setFont(java.awt.Font f) {
102         // Not supported by UNO accessibility API
103     }
104 
getFontMetrics(java.awt.Font f)105     public java.awt.FontMetrics getFontMetrics(java.awt.Font f) {
106         // FIXME
107         return null;
108     }
109 
isEnabled()110     public boolean isEnabled() {
111         return hasState(AccessibleStateType.ENABLED);
112         }
113 
setEnabled(boolean b)114     public void setEnabled(boolean b) {
115         // Not supported by UNO accessibility API
116     }
117 
isVisible()118     public boolean isVisible() {
119         return hasState(AccessibleStateType.VISIBLE);
120     }
121 
setVisible(boolean b)122     public void setVisible(boolean b) {
123         // Not supported by UNO accessibility API
124     }
125 
isShowing()126     public boolean isShowing() {
127         return hasState(AccessibleStateType.SHOWING);
128     }
129 
contains(java.awt.Point p)130     public boolean contains(java.awt.Point p) {
131         try {
132             return unoObject.containsPoint(new com.sun.star.awt.Point(p.x, p.y));
133         } catch (com.sun.star.uno.RuntimeException e) {
134             return false;
135         }
136     }
137 
138     /** Returns the location of the object on the screen. */
getLocationOnScreen()139     public java.awt.Point getLocationOnScreen() {
140         try {
141             com.sun.star.awt.Point unoPoint = unoObject.getLocationOnScreen();
142             return new java.awt.Point(unoPoint.X, unoPoint.Y);
143         } catch (com.sun.star.uno.RuntimeException e) {
144             return null;
145         }
146     }
147 
148     /** Gets the location of this component in the form of a point specifying the component's top-left corner */
getLocation()149     public java.awt.Point getLocation() {
150         try {
151             com.sun.star.awt.Point unoPoint = unoObject.getLocation();
152             return new java.awt.Point( unoPoint.X, unoPoint.Y );
153         } catch (com.sun.star.uno.RuntimeException e) {
154             return null;
155         }
156     }
157 
158     /** Moves this component to a new location */
setLocation(java.awt.Point p)159     public void setLocation(java.awt.Point p) {
160         // Not supported by UNO accessibility API
161     }
162 
163     /** Gets the bounds of this component in the form of a Rectangle object */
getBounds()164     public java.awt.Rectangle getBounds() {
165         try {
166             com.sun.star.awt.Rectangle unoRect = unoObject.getBounds();
167             return new java.awt.Rectangle(unoRect.X, unoRect.Y, unoRect.Width, unoRect.Height);
168             } catch (com.sun.star.uno.RuntimeException e) {
169             return null;
170         }
171     }
172 
173     /** Moves and resizes this component to conform to the new bounding rectangle r */
setBounds(java.awt.Rectangle r)174     public void setBounds(java.awt.Rectangle r) {
175         // Not supported by UNO accessibility API
176     }
177 
178     /** Returns the size of this component in the form of a Dimension object */
getSize()179     public java.awt.Dimension getSize() {
180         try {
181             com.sun.star.awt.Size unoSize = unoObject.getSize();
182             return new java.awt.Dimension(unoSize.Width, unoSize.Height);
183         } catch (com.sun.star.uno.RuntimeException e) {
184             return null;
185         }
186     }
187 
188     /** Resizes this component so that it has width d.width and height d.height */
setSize(java.awt.Dimension d)189     public void setSize(java.awt.Dimension d) {
190         // Not supported by UNO accessibility API
191     }
192 
getAccessibleAt(java.awt.Point p)193     public javax.accessibility.Accessible getAccessibleAt(java.awt.Point p) {
194         // Not supported by this implementation
195         return null;
196     }
197 
isFocusTraversable()198     public boolean isFocusTraversable() {
199         return hasState(AccessibleStateType.FOCUSABLE);
200         }
201 
requestFocus()202     public void requestFocus() {
203         unoObject.grabFocus();
204     }
205 
206     /**
207     * Adds the specified focus listener to receive focus events from
208     * this component when this component gains input focus.
209     * If listener <code>l</code> is <code>null</code>,
210     * no exception is thrown and no action is performed.
211     */
212 
addFocusListener(java.awt.event.FocusListener l)213     public void addFocusListener(java.awt.event.FocusListener l) {
214         // Not supported by this implementation
215     }
216 
217     /**
218     * Removes the specified focus listener so that it no longer
219     * receives focus events from this component. This method performs
220     * no function, nor does it throw an exception, if the listener
221     * specified by the argument was not previously added to this component.
222     * If listener <code>l</code> is <code>null</code>,
223     * no exception is thrown and no action is performed.
224     */
225 
removeFocusListener(java.awt.event.FocusListener l)226     public void removeFocusListener(java.awt.event.FocusListener l) {
227         // Not supported by this implementation
228     }
229 }
230