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.XAccessibleValue; 27 import com.sun.star.uno.AnyConverter; 28 29 /** The AccessibleValueImpl mappes the calls to the java AccessibleValue 30 * interface to the corresponding methods of the UNO XAccessibleValue interface 31 */ 32 public class AccessibleValueImpl implements javax.accessibility.AccessibleValue { 33 protected XAccessibleValue unoObject; 34 35 /** Creates new AccessibleValueImpl */ AccessibleValueImpl(XAccessibleValue xAccessibleValue)36 public AccessibleValueImpl(XAccessibleValue xAccessibleValue) { 37 unoObject = xAccessibleValue; 38 } 39 toNumber(java.lang.Object any)40 public static java.lang.Number toNumber(java.lang.Object any) { 41 try { 42 if(AnyConverter.isByte(any)) { 43 return new Byte(AnyConverter.toByte(any)); 44 } else if (AnyConverter.isShort(any)) { 45 return new Short(AnyConverter.toShort(any)); 46 } else if (AnyConverter.isInt(any)) { 47 return new Integer(AnyConverter.toInt(any)); 48 } else if (AnyConverter.isLong(any)) { 49 return new Long(AnyConverter.toLong(any)); 50 } else if (AnyConverter.isFloat(any)) { 51 return new Float(AnyConverter.toFloat(any)); 52 } else if (AnyConverter.isDouble(any)) { 53 return new Double(AnyConverter.toDouble(any)); 54 } 55 } catch (com.sun.star.lang.IllegalArgumentException e) { 56 } 57 58 return null; 59 } 60 getMinimumAccessibleValue()61 public java.lang.Number getMinimumAccessibleValue() { 62 try { 63 return toNumber(unoObject.getMinimumValue()); 64 } catch (com.sun.star.uno.RuntimeException e) { 65 return null; 66 } 67 } 68 getCurrentAccessibleValue()69 public java.lang.Number getCurrentAccessibleValue() { 70 try { 71 return toNumber(unoObject.getCurrentValue()); 72 } catch (com.sun.star.uno.RuntimeException e) { 73 return null; 74 } 75 } 76 getMaximumAccessibleValue()77 public java.lang.Number getMaximumAccessibleValue() { 78 try { 79 return toNumber(unoObject.getMaximumValue()); 80 } catch (com.sun.star.uno.RuntimeException e) { 81 return null; 82 } 83 } 84 setCurrentAccessibleValue(java.lang.Number number)85 public boolean setCurrentAccessibleValue(java.lang.Number number) { 86 try { 87 return unoObject.setCurrentValue(number); 88 } catch (com.sun.star.uno.RuntimeException e) { 89 return false; 90 } 91 } 92 } 93