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 package org.openoffice.java.accessibility; 24 25 import com.sun.star.accessibility.*; 26 import com.sun.star.uno.*; 27 28 import javax.accessibility.AccessibleContext; 29 import javax.accessibility.AccessibleState; 30 import javax.accessibility.AccessibleStateSet; 31 32 import javax.swing.SwingConstants; 33 34 35 /** 36 */ 37 public class ComboBox extends Container { 38 private XAccessibleAction unoAccessibleAction = null; 39 ComboBox(XAccessible xAccessible, XAccessibleContext xAccessibleContext)40 public ComboBox(XAccessible xAccessible, XAccessibleContext xAccessibleContext) { 41 super(javax.accessibility.AccessibleRole.COMBO_BOX, xAccessible, 42 xAccessibleContext); 43 } 44 45 /** Appends the specified component to the end of this container */ add(java.awt.Component c)46 public java.awt.Component add(java.awt.Component c) { 47 // List should be always the first child 48 if (c instanceof List) { 49 return super.add(c, 0); 50 } else { 51 return super.add(c); 52 } 53 } 54 55 /** Creates the AccessibleContext associated with this object */ createAccessibleContext()56 public javax.accessibility.AccessibleContext createAccessibleContext() { 57 return new AccessibleComboBox(); 58 } 59 60 protected class AccessibleComboBox extends AccessibleContainer 61 implements javax.accessibility.AccessibleAction { 62 /** 63 * Though the class is abstract, this should be called by all sub-classes 64 */ AccessibleComboBox()65 protected AccessibleComboBox() { 66 super(); 67 } 68 69 /* 70 * AccessibleContext 71 */ 72 73 /** Gets the AccessibleAction associated with this object that supports one or more actions */ getAccessibleAction()74 public javax.accessibility.AccessibleAction getAccessibleAction() { 75 if (unoAccessibleAction == null) { 76 unoAccessibleAction = (XAccessibleAction) UnoRuntime.queryInterface(XAccessibleAction.class, 77 unoAccessibleContext); 78 79 if (unoAccessibleAction == null) { 80 return null; 81 } 82 } 83 84 return this; 85 } 86 87 /* 88 * AccessibleAction 89 */ 90 91 /** Performs the specified Action on the object */ doAccessibleAction(int param)92 public boolean doAccessibleAction(int param) { 93 if (param == 0) { 94 try { 95 return unoAccessibleAction.doAccessibleAction(0); 96 } catch (com.sun.star.uno.Exception e) { 97 } 98 } 99 100 return false; 101 } 102 103 /** Returns a description of the specified action of the object */ getAccessibleActionDescription(int param)104 public java.lang.String getAccessibleActionDescription(int param) { 105 return javax.swing.UIManager.getString("ComboBox.togglePopupText"); 106 } 107 108 /** Returns the number of accessible actions available in this object */ getAccessibleActionCount()109 public int getAccessibleActionCount() { 110 return 1; 111 } 112 } 113 114 /** 115 * Returns whether this Component can be focused. 116 * 117 * @return <code>true</code> if this Component is focusable; 118 * <code>false</code> otherwise. 119 * @see #setFocusable 120 * @since 1.4 121 */ isFocusable()122 public boolean isFocusable() { 123 return true; 124 } 125 } 126