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 javax.accessibility.AccessibleState; 27 import javax.accessibility.AccessibleStateSet; 28 import javax.swing.SwingConstants; 29 30 import com.sun.star.uno.*; 31 import com.sun.star.accessibility.*; 32 33 /** 34 */ 35 public class ScrollBar extends Component implements SwingConstants, javax.accessibility.Accessible { 36 ScrollBar(XAccessible xAccessible, XAccessibleContext xAccessibleContext)37 public ScrollBar(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { 38 super(xAccessible, xAccessibleContext); 39 } 40 41 /** Creates the AccessibleContext associated with this object */ createAccessibleContext()42 public javax.accessibility.AccessibleContext createAccessibleContext() { 43 return new AccessibleScrollBar(); 44 } 45 46 protected class AccessibleScrollBar extends AccessibleUNOComponent implements 47 javax.accessibility.AccessibleAction { 48 49 protected XAccessibleAction unoAccessibleAction; 50 protected int actionCount = 0; 51 52 /** 53 * Though the class is abstract, this should be called by all sub-classes 54 */ AccessibleScrollBar()55 protected AccessibleScrollBar() { 56 super(); 57 unoAccessibleAction = (XAccessibleAction) UnoRuntime.queryInterface( 58 XAccessibleAction.class, unoAccessibleContext); 59 if (unoAccessibleAction != null) { 60 actionCount = unoAccessibleAction.getAccessibleActionCount(); 61 } 62 } 63 64 /* 65 * AccessibleContext 66 */ 67 68 /** Gets the role of this object */ getAccessibleRole()69 public javax.accessibility.AccessibleRole getAccessibleRole() { 70 return javax.accessibility.AccessibleRole.SCROLL_BAR; 71 } 72 73 /** Gets the AccessibleValue associated with this object that has a graphical representation */ getAccessibleValue()74 public javax.accessibility.AccessibleValue getAccessibleValue() { 75 try { 76 XAccessibleValue unoAccessibleValue = (XAccessibleValue) 77 UnoRuntime.queryInterface(XAccessibleValue.class, unoAccessibleContext); 78 return (unoAccessibleValue != null) ? 79 new AccessibleValueImpl(unoAccessibleValue) : null; 80 } catch (com.sun.star.uno.RuntimeException e) { 81 return null; 82 } 83 } 84 85 /** Gets the AccessibleAction associated with this object that supports one or more actions */ getAccessibleAction()86 public javax.accessibility.AccessibleAction getAccessibleAction() { 87 return this; 88 } 89 90 /* 91 * AccessibleAction 92 */ 93 94 /** Performs the specified Action on the object */ doAccessibleAction(int param)95 public boolean doAccessibleAction(int param) { 96 if (param < actionCount) { 97 try { 98 return unoAccessibleAction.doAccessibleAction(param); 99 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 100 } 101 } 102 return false; 103 } 104 105 /** Returns a description of the specified action of the object */ getAccessibleActionDescription(int param)106 public java.lang.String getAccessibleActionDescription(int param) { 107 if(param < actionCount) { 108 try { 109 return unoAccessibleAction.getAccessibleActionDescription(param); 110 } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 111 } 112 } 113 return null; 114 } 115 116 /** Returns the number of accessible actions available in this object */ getAccessibleActionCount()117 public int getAccessibleActionCount() { 118 return actionCount; 119 } 120 } 121 } 122 123