1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10ef39d40dSAndrew Rist * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ef39d40dSAndrew Rist * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19ef39d40dSAndrew Rist * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir package mod._sw; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import java.io.PrintWriter; 26cdf0e10cSrcweir 27cdf0e10cSrcweir import lib.StatusException; 28cdf0e10cSrcweir import lib.TestCase; 29cdf0e10cSrcweir import lib.TestEnvironment; 30cdf0e10cSrcweir import lib.TestParameters; 31cdf0e10cSrcweir import util.AccessibilityTools; 32cdf0e10cSrcweir import util.WriterTools; 33cdf0e10cSrcweir import util.utils; 34cdf0e10cSrcweir 35cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleRole; 36cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible; 37cdf0e10cSrcweir import com.sun.star.awt.XWindow; 38cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 39cdf0e10cSrcweir import com.sun.star.frame.XController; 40cdf0e10cSrcweir import com.sun.star.frame.XModel; 41cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 42cdf0e10cSrcweir import com.sun.star.text.XFootnote; 43cdf0e10cSrcweir import com.sun.star.text.XText; 44cdf0e10cSrcweir import com.sun.star.text.XTextCursor; 45cdf0e10cSrcweir import com.sun.star.text.XTextDocument; 46cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 47cdf0e10cSrcweir import com.sun.star.uno.XInterface; 48cdf0e10cSrcweir import com.sun.star.view.XViewSettingsSupplier; 49cdf0e10cSrcweir 50cdf0e10cSrcweir public class SwAccessibleFootnoteView extends TestCase { 51cdf0e10cSrcweir 52cdf0e10cSrcweir XTextDocument xTextDoc = null; 53cdf0e10cSrcweir 54cdf0e10cSrcweir /** 55cdf0e10cSrcweir * Called to create an instance of <code>TestEnvironment</code> 56cdf0e10cSrcweir * with an object to test and related objects. 57cdf0e10cSrcweir * Inserts the created footnote to the document. 58*e6b649b5SPedro Giffuni * Changes zoom value to 10%(endnote must be in visible area of the document). 59cdf0e10cSrcweir * Obtains accessible object for the inserted footnote. 60cdf0e10cSrcweir * 61*e6b649b5SPedro Giffuni * @param Param test parameters 62cdf0e10cSrcweir * @param log writer to log information while testing 63cdf0e10cSrcweir * 64cdf0e10cSrcweir * @see TestEnvironment 655496b966SPedro Giffuni * @see #getTestEnvironment 66cdf0e10cSrcweir */ createTestEnvironment( TestParameters Param, PrintWriter log)67cdf0e10cSrcweir protected TestEnvironment createTestEnvironment( 68cdf0e10cSrcweir TestParameters Param, PrintWriter log) { 69cdf0e10cSrcweir 70cdf0e10cSrcweir XInterface oObj = null; 71cdf0e10cSrcweir XFootnote oFootnote = null; 72cdf0e10cSrcweir 73cdf0e10cSrcweir log.println( "Creating a test environment" ); 74cdf0e10cSrcweir // get a soffice factory object 75cdf0e10cSrcweir XMultiServiceFactory msf = (XMultiServiceFactory) 76cdf0e10cSrcweir UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc); 77cdf0e10cSrcweir log.println("creating a footnote"); 78cdf0e10cSrcweir 79cdf0e10cSrcweir try { 80cdf0e10cSrcweir oFootnote = (XFootnote) UnoRuntime.queryInterface(XFootnote.class, 81cdf0e10cSrcweir msf.createInstance("com.sun.star.text.Footnote")); 82cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 83cdf0e10cSrcweir e.printStackTrace(log); 84cdf0e10cSrcweir throw new StatusException("Couldn't create footnote", e); 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir XText oText = xTextDoc.getText(); 88cdf0e10cSrcweir XTextCursor oCursor = oText.createTextCursor(); 89cdf0e10cSrcweir 90cdf0e10cSrcweir log.println("inserting the footnote into text document"); 91cdf0e10cSrcweir try { 92cdf0e10cSrcweir oText.insertTextContent(oCursor, oFootnote, false); 93cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 94cdf0e10cSrcweir e.printStackTrace(log); 95cdf0e10cSrcweir throw new StatusException("Couldn't insert the footnote", e); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir XController xController = xTextDoc.getCurrentController(); 99cdf0e10cSrcweir XViewSettingsSupplier xViewSetSup = (XViewSettingsSupplier) 100cdf0e10cSrcweir UnoRuntime.queryInterface(XViewSettingsSupplier.class, 101cdf0e10cSrcweir xController); 102cdf0e10cSrcweir XPropertySet xPropSet = xViewSetSup.getViewSettings(); 103cdf0e10cSrcweir 104cdf0e10cSrcweir try { 105cdf0e10cSrcweir //change zoom value to 10% 106cdf0e10cSrcweir //footer should be in the vissible area of the document 107cdf0e10cSrcweir xPropSet.setPropertyValue("ZoomValue", new Short("10")); 108cdf0e10cSrcweir } catch ( com.sun.star.lang.WrappedTargetException e ) { 109cdf0e10cSrcweir e.printStackTrace(log); 110cdf0e10cSrcweir throw new StatusException("Couldn't set propertyValue...", e); 111cdf0e10cSrcweir } catch ( com.sun.star.lang.IllegalArgumentException e ) { 112cdf0e10cSrcweir e.printStackTrace(log); 113cdf0e10cSrcweir throw new StatusException("Couldn't set propertyValue...", e); 114cdf0e10cSrcweir } catch ( com.sun.star.beans.PropertyVetoException e ) { 115cdf0e10cSrcweir e.printStackTrace(log); 116cdf0e10cSrcweir throw new StatusException("Couldn't set propertyValue...", e); 117cdf0e10cSrcweir } catch ( com.sun.star.beans.UnknownPropertyException e ) { 118cdf0e10cSrcweir e.printStackTrace(log); 119cdf0e10cSrcweir throw new StatusException("Couldn't set propertyValue...", e); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir XModel aModel = (XModel) 123cdf0e10cSrcweir UnoRuntime.queryInterface(XModel.class, xTextDoc); 124cdf0e10cSrcweir 125cdf0e10cSrcweir AccessibilityTools at = new AccessibilityTools(); 126cdf0e10cSrcweir 127cdf0e10cSrcweir XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel); 128cdf0e10cSrcweir XAccessible xRoot = at.getAccessibleObject(xWindow); 129cdf0e10cSrcweir 130cdf0e10cSrcweir at.getAccessibleObjectForRole(xRoot, AccessibleRole.FOOTNOTE); 131cdf0e10cSrcweir 132cdf0e10cSrcweir oObj = AccessibilityTools.SearchedContext; 133cdf0e10cSrcweir 134cdf0e10cSrcweir log.println("ImplementationName " + utils.getImplName(oObj)); 135cdf0e10cSrcweir at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 136cdf0e10cSrcweir 137cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment(oObj); 138cdf0e10cSrcweir 139cdf0e10cSrcweir final XPropertySet PropSet = xViewSetSup.getViewSettings(); 140cdf0e10cSrcweir 141cdf0e10cSrcweir tEnv.addObjRelation("EventProducer", 142cdf0e10cSrcweir new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 143cdf0e10cSrcweir public void fireEvent() { 144cdf0e10cSrcweir try { 145cdf0e10cSrcweir //change zoom value to 130% 146cdf0e10cSrcweir PropSet.setPropertyValue("ZoomValue", new Short("15")); 147cdf0e10cSrcweir //and back to 10% 148cdf0e10cSrcweir PropSet.setPropertyValue("ZoomValue", new Short("10")); 149cdf0e10cSrcweir } catch ( com.sun.star.lang.WrappedTargetException e ) { 150cdf0e10cSrcweir 151cdf0e10cSrcweir } catch ( com.sun.star.lang.IllegalArgumentException e ) { 152cdf0e10cSrcweir 153cdf0e10cSrcweir } catch ( com.sun.star.beans.PropertyVetoException e ) { 154cdf0e10cSrcweir 155cdf0e10cSrcweir } catch ( com.sun.star.beans.UnknownPropertyException e ) { 156cdf0e10cSrcweir 157cdf0e10cSrcweir } 158cdf0e10cSrcweir } 159cdf0e10cSrcweir }); 160cdf0e10cSrcweir 161cdf0e10cSrcweir return tEnv; 162cdf0e10cSrcweir 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir /** 166cdf0e10cSrcweir * Called while disposing a <code>TestEnvironment</code>. 167cdf0e10cSrcweir * Disposes text document. 168*e6b649b5SPedro Giffuni * @param Param test parameters 169cdf0e10cSrcweir * @param log writer to log information while testing 170cdf0e10cSrcweir */ cleanup( TestParameters Param, PrintWriter log)171cdf0e10cSrcweir protected void cleanup( TestParameters Param, PrintWriter log) { 172cdf0e10cSrcweir log.println("dispose text document"); 173cdf0e10cSrcweir util.DesktopTools.closeDoc(xTextDoc); 174cdf0e10cSrcweir } 175cdf0e10cSrcweir 176cdf0e10cSrcweir /** 177cdf0e10cSrcweir * Called while the <code>TestCase</code> initialization. In the 178cdf0e10cSrcweir * implementation does nothing. Subclasses can override to initialize 179cdf0e10cSrcweir * objects shared among all <code>TestEnvironment</code>s. 180cdf0e10cSrcweir * 181*e6b649b5SPedro Giffuni * @param Param test parameters 182cdf0e10cSrcweir * @param log writer to log information while testing 183cdf0e10cSrcweir * 1845496b966SPedro Giffuni * @see #initializeTestCase 185cdf0e10cSrcweir */ initialize(TestParameters Param, PrintWriter log)186cdf0e10cSrcweir protected void initialize(TestParameters Param, PrintWriter log) { 187cdf0e10cSrcweir log.println( "creating a text document" ); 188cdf0e10cSrcweir xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF()); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir } 191