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.logging; 24 25 import org.openoffice.java.accessibility.*; 26 27 28 /** 29 * 30 */ 31 public class XAccessibleTextLog 32 implements com.sun.star.accessibility.XAccessibleText { 33 private com.sun.star.accessibility.XAccessibleText unoObject; 34 private String name = "[Unknown] NoName"; 35 36 /** Creates a new instance of XAccessibleTextLog */ XAccessibleTextLog( com.sun.star.accessibility.XAccessibleText xAccessibleText)37 public XAccessibleTextLog( 38 com.sun.star.accessibility.XAccessibleText xAccessibleText) { 39 unoObject = xAccessibleText; 40 setName(xAccessibleText); 41 } 42 setName( com.sun.star.accessibility.XAccessibleText xAccessibleText)43 private void setName( 44 com.sun.star.accessibility.XAccessibleText xAccessibleText) { 45 try { 46 com.sun.star.accessibility.XAccessibleContext unoAccessibleContext = (com.sun.star.accessibility.XAccessibleContext) com.sun.star.uno.UnoRuntime.queryInterface(com.sun.star.accessibility.XAccessibleContext.class, 47 xAccessibleText); 48 49 if (unoAccessibleContext != null) { 50 name = "[" + 51 AccessibleRoleAdapter.getAccessibleRole(unoAccessibleContext.getAccessibleRole()) + 52 "] " + unoAccessibleContext.getAccessibleName() + ": "; 53 } 54 } catch (com.sun.star.uno.RuntimeException e) { 55 } 56 } 57 getPartString(short s)58 private String getPartString(short s) { 59 String part = "INVALID"; 60 61 switch (s) { 62 case com.sun.star.accessibility.AccessibleTextType.CHARACTER: 63 part = "CHARACTER"; 64 65 break; 66 67 case com.sun.star.accessibility.AccessibleTextType.WORD: 68 part = "WORD"; 69 70 break; 71 72 case com.sun.star.accessibility.AccessibleTextType.SENTENCE: 73 part = "SENTENCE"; 74 75 break; 76 77 case com.sun.star.accessibility.AccessibleTextType.LINE: 78 part = "LINE"; 79 80 break; 81 82 case com.sun.star.accessibility.AccessibleTextType.ATTRIBUTE_RUN: 83 part = "ATTRIBUTE_RUN"; 84 85 break; 86 87 default: 88 break; 89 } 90 91 return part; 92 } 93 dumpTextSegment(com.sun.star.accessibility.TextSegment ts)94 private String dumpTextSegment(com.sun.star.accessibility.TextSegment ts) { 95 if (ts != null) { 96 return "(" + ts.SegmentStart + "," + ts.SegmentEnd + "," + 97 ts.SegmentText + ")"; 98 } 99 100 return "NULL"; 101 } 102 copyText(int param, int param1)103 public boolean copyText(int param, int param1) 104 throws com.sun.star.lang.IndexOutOfBoundsException { 105 return unoObject.copyText(param, param1); 106 } 107 getCaretPosition()108 public int getCaretPosition() { 109 int pos = unoObject.getCaretPosition(); 110 System.err.println(name + "getCaretPosition() returns " + pos); 111 112 return pos; 113 } 114 getCharacter(int param)115 public char getCharacter(int param) 116 throws com.sun.star.lang.IndexOutOfBoundsException { 117 return unoObject.getCharacter(param); 118 } 119 getCharacterAttributes( int param, String[] str)120 public com.sun.star.beans.PropertyValue[] getCharacterAttributes( 121 int param, String[] str) 122 throws com.sun.star.lang.IndexOutOfBoundsException { 123 return unoObject.getCharacterAttributes(param, str); 124 } 125 getCharacterBounds(int param)126 public com.sun.star.awt.Rectangle getCharacterBounds(int param) 127 throws com.sun.star.lang.IndexOutOfBoundsException { 128 try { 129 com.sun.star.awt.Rectangle r = unoObject.getCharacterBounds(param); 130 System.err.println(name + "getCharacterBounds(" + param + 131 ") returns (" + r.X + "," + r.Y + "," + r.Width + "," + 132 r.Height + ")"); 133 134 return r; 135 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 136 System.err.println("IndexOutOufBoundsException caught for " + name + 137 "getCharacterBounds(" + param + ")"); 138 throw e; 139 } 140 } 141 getCharacterCount()142 public int getCharacterCount() { 143 return unoObject.getCharacterCount(); 144 } 145 getIndexAtPoint(com.sun.star.awt.Point point)146 public int getIndexAtPoint(com.sun.star.awt.Point point) { 147 try { 148 int index = unoObject.getIndexAtPoint(point); 149 System.err.println(name + "getIndexAtPoint(" + point.X + ", " + 150 point.Y + ") returns " + index); 151 152 return index; 153 } catch (com.sun.star.uno.RuntimeException e) { 154 System.err.println(name + 155 "RuntimeException caught for getIndexAtPoint(" + point.X + 156 ", " + point.Y + ")"); 157 System.err.println(e.getMessage()); 158 throw e; 159 } 160 } 161 getSelectedText()162 public String getSelectedText() { 163 return unoObject.getSelectedText(); 164 } 165 getSelectionEnd()166 public int getSelectionEnd() { 167 return unoObject.getSelectionEnd(); 168 } 169 getSelectionStart()170 public int getSelectionStart() { 171 return unoObject.getSelectionStart(); 172 } 173 getText()174 public String getText() { 175 return unoObject.getText(); 176 } 177 getTextAtIndex(int param, short param1)178 public com.sun.star.accessibility.TextSegment getTextAtIndex(int param, 179 short param1) 180 throws com.sun.star.lang.IndexOutOfBoundsException, 181 com.sun.star.lang.IllegalArgumentException { 182 try { 183 com.sun.star.accessibility.TextSegment ts = unoObject.getTextAtIndex(param, 184 param1); 185 System.err.println(name + "getTextAtIndex(" + 186 getPartString(param1) + "," + param + ") returns " + 187 dumpTextSegment(ts)); 188 189 return ts; 190 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 191 System.err.println("IndexOutOufBoundsException caught for " + name + 192 " getTextAtIndex(" + getPartString(param1) + "," + param1 + 193 ")"); 194 throw e; 195 } catch (com.sun.star.lang.IllegalArgumentException e) { 196 System.err.println("IllegalArgumentException caught for " + name + 197 " getTextAtIndex(" + getPartString(param1) + "," + param + ")"); 198 throw e; 199 } 200 } 201 getTextBeforeIndex( int param, short param1)202 public com.sun.star.accessibility.TextSegment getTextBeforeIndex( 203 int param, short param1) 204 throws com.sun.star.lang.IndexOutOfBoundsException, 205 com.sun.star.lang.IllegalArgumentException { 206 try { 207 com.sun.star.accessibility.TextSegment ts = unoObject.getTextBeforeIndex(param, 208 param1); 209 System.err.println(name + " getTextBeforeIndex(" + 210 getPartString(param1) + "," + param + ") returns " + 211 dumpTextSegment(ts)); 212 213 return ts; 214 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 215 System.err.println("IndexOutOufBoundsException caught for " + name + 216 " getTextBeforeIndex(" + getPartString(param1) + "," + param1 + 217 ")"); 218 throw e; 219 } catch (com.sun.star.lang.IllegalArgumentException e) { 220 System.err.println("IllegalArgumentException caught for " + name + 221 " getTextBeforeIndex(" + getPartString(param1) + "," + param + 222 ")"); 223 throw e; 224 } 225 } 226 getTextBehindIndex( int param, short param1)227 public com.sun.star.accessibility.TextSegment getTextBehindIndex( 228 int param, short param1) 229 throws com.sun.star.lang.IndexOutOfBoundsException, 230 com.sun.star.lang.IllegalArgumentException { 231 try { 232 com.sun.star.accessibility.TextSegment ts = unoObject.getTextBehindIndex(param, 233 param1); 234 System.err.println(name + " getTextBehindIndex(" + 235 getPartString(param1) + "," + param + ") returns " + 236 dumpTextSegment(ts)); 237 238 return ts; 239 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 240 System.err.println("IndexOutOufBoundsException caught for " + name + 241 " getTextBehindIndex(" + getPartString(param1) + "," + param1 + 242 ")"); 243 throw e; 244 } catch (com.sun.star.lang.IllegalArgumentException e) { 245 System.err.println("IllegalArgumentException caught for " + name + 246 " getTextBehindIndex(" + getPartString(param1) + "," + param + 247 ")"); 248 throw e; 249 } 250 } 251 getTextRange(int param, int param1)252 public String getTextRange(int param, int param1) 253 throws com.sun.star.lang.IndexOutOfBoundsException { 254 return unoObject.getTextRange(param, param1); 255 } 256 setCaretPosition(int param)257 public boolean setCaretPosition(int param) 258 throws com.sun.star.lang.IndexOutOfBoundsException { 259 return unoObject.setCaretPosition(param); 260 } 261 setSelection(int param, int param1)262 public boolean setSelection(int param, int param1) 263 throws com.sun.star.lang.IndexOutOfBoundsException { 264 return unoObject.setSelection(param, param1); 265 } 266 } 267