/** * Check BackColor and IsLandscape properties, wait for an exception: test is ok if no exception * happened. */ public void checkChangeColor() { try { XMultiServiceFactory m_xMSF_ = (XMultiServiceFactory) param.getMSF(); XComponentLoader aLoader = (XComponentLoader) UnoRuntime.queryInterface( XComponentLoader.class, m_xMSF_.createInstance("com.sun.star.frame.Desktop")); XComponent xDocument = (XComponent) UnoRuntime.queryInterface( XComponent.class, aLoader.loadComponentFromURL( "private:factory/swriter", "_blank", 0, new PropertyValue[0])); // xDocument.addEventListener( this ); XTextDocument oDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, xDocument); XMultiServiceFactory oDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc); // XInterface xInterface = (XInterface) oDocMSF.createInstance( "com.sun.star.style.PageStyle" // ); // create a supplier to get the Style family collection XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier) UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, oDoc); // get the NameAccess interface from the Style family collection XNameAccess xNameAccess = xSupplier.getStyleFamilies(); XNameContainer xPageStyleCollection = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, xNameAccess.getByName("PageStyles")); // create a PropertySet to set the properties for the new Pagestyle XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xPageStyleCollection.getByName("Standard")); log.println("BackColor @ " + xPropertySet.getPropertyValue("BackColor").toString()); log.println("IsLandscape @ " + xPropertySet.getPropertyValue("IsLandscape").toString()); log.println( "Size @ H:" + ((Size) xPropertySet.getPropertyValue("Size")).Height + " W:" + ((Size) xPropertySet.getPropertyValue("Size")).Width); log.println("Set Landscape"); xPropertySet.setPropertyValue("IsLandscape", new Boolean(true)); log.println("Set BackColor"); xPropertySet.setPropertyValue("BackColor", new Integer((int) 255000000)); } catch (Exception e) { e.printStackTrace(); failed("Exception."); } }
/** * Creating a Testenvironment for the interfaces to be tested. Retrieves the collection of style * families available in the document using the interface <code>XStyleFamiliesSupplier</code>. * Obtains default style from the style family <code>'PageStyles'</code>. Retrieves value of the * property <code>'RightPageHeaderContent'</code>. Sets some string for the text which is printed * in the center part of the header or footer using the interface <code>XHeaderFooterContent * </code> and sets new value of the property <code>'RightPageHeaderContent'</code>. Creates text * cursor for the text which is printed in the center part of the header or footer. This text * cursor is the instance of the service <code>com.sun.star.text.TextCursor</code>. * </ul> */ protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { XInterface oObj = null; XPropertySet PropSet; XNameAccess PageStyles = null; XStyle StdStyle = null; XStyleFamiliesSupplier StyleFam = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xSpreadsheetDoc); XNameAccess StyleFamNames = StyleFam.getStyleFamilies(); try { PageStyles = (XNameAccess) AnyConverter.toObject( new Type(XNameAccess.class), StyleFamNames.getByName("PageStyles")); StdStyle = (XStyle) AnyConverter.toObject(new Type(XStyle.class), PageStyles.getByName("Default")); } catch (com.sun.star.lang.WrappedTargetException e) { e.printStackTrace(log); throw new StatusException("Couldn't get by name", e); } catch (com.sun.star.container.NoSuchElementException e) { e.printStackTrace(log); throw new StatusException("Couldn't get by name", e); } catch (com.sun.star.lang.IllegalArgumentException e) { e.printStackTrace(log); throw new StatusException("Couldn't get by name", e); } // get the property-set PropSet = UnoRuntime.queryInterface(XPropertySet.class, StdStyle); XHeaderFooterContent RPHC = null; // creation of testobject here // first we write what we are intend to do to log file log.println("creating a test environment"); try { RPHC = (XHeaderFooterContent) AnyConverter.toObject( new Type(XHeaderFooterContent.class), PropSet.getPropertyValue("RightPageHeaderContent")); } catch (com.sun.star.lang.WrappedTargetException e) { e.printStackTrace(log); throw new StatusException("Couldn't get HeaderContent", e); } catch (com.sun.star.beans.UnknownPropertyException e) { e.printStackTrace(log); throw new StatusException("Couldn't get HeaderContent", e); } catch (com.sun.star.lang.IllegalArgumentException e) { e.printStackTrace(log); throw new StatusException("Couldn't get HeaderContent", e); } XText center = RPHC.getCenterText(); center.setString("CENTER"); try { PropSet.setPropertyValue("RightPageHeaderContent", RPHC); } catch (com.sun.star.lang.WrappedTargetException e) { e.printStackTrace(log); throw new StatusException("Couldn't set HeaderContent", e); } catch (com.sun.star.lang.IllegalArgumentException e) { e.printStackTrace(log); throw new StatusException("Couldn't set HeaderContent", e); } catch (com.sun.star.beans.PropertyVetoException e) { e.printStackTrace(log); throw new StatusException("Couldn't set HeaderContent", e); } catch (com.sun.star.beans.UnknownPropertyException e) { e.printStackTrace(log); throw new StatusException("Couldn't set HeaderContent", e); } // create testobject here oObj = center.createTextCursor(); TestEnvironment tEnv = new TestEnvironment(oObj); // add relation for XTextRange tEnv.addObjRelation("XTEXT", UnoRuntime.queryInterface(XText.class, center)); return tEnv; } // finish method getTestEnvironment