1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 package mod._sc; 28 29 import com.sun.star.beans.XPropertySet; 30 import com.sun.star.container.XEnumerationAccess; 31 import com.sun.star.container.XIndexAccess; 32 import com.sun.star.lang.XMultiServiceFactory; 33 import com.sun.star.sheet.XSpreadsheet; 34 import com.sun.star.sheet.XSpreadsheetDocument; 35 import com.sun.star.sheet.XUniqueCellFormatRangesSupplier; 36 import com.sun.star.table.XCellRange; 37 import com.sun.star.uno.UnoRuntime; 38 import com.sun.star.uno.XInterface; 39 40 import java.awt.Color; 41 42 import java.io.PrintWriter; 43 44 import lib.StatusException; 45 import lib.TestCase; 46 import lib.TestEnvironment; 47 import lib.TestParameters; 48 49 import util.SOfficeFactory; 50 51 52 public class ScUniqueCellFormatsEnumeration extends TestCase { 53 static XSpreadsheetDocument xSheetDoc = null; 54 static XSpreadsheet oSheet = null; 55 56 /** 57 * Creates Spreadsheet document. 58 */ 59 protected void initialize(TestParameters tParam, PrintWriter log) { 60 // get a soffice factory object 61 SOfficeFactory SOF = SOfficeFactory.getFactory( 62 (XMultiServiceFactory) tParam.getMSF()); 63 64 try { 65 log.println("creating a sheetdocument"); 66 xSheetDoc = SOF.createCalcDoc(null); 67 } catch (com.sun.star.uno.Exception e) { 68 // Some exception occures.FAILED 69 e.printStackTrace(log); 70 throw new StatusException("Couldn't create document", e); 71 } 72 } 73 74 /** 75 * Disposes Spreadsheet document. 76 */ 77 protected void cleanup(TestParameters tParam, PrintWriter log) { 78 //add this lines after synchronisation 79 //log.println(" disposing xSheetDoc "); 80 //DesktopTools.closeDoc(xSheetDoc); 81 } 82 83 protected TestEnvironment createTestEnvironment(TestParameters tParam, 84 PrintWriter log) { 85 log.println("Getting the first sheet"); 86 87 XIndexAccess xIA = (XIndexAccess) UnoRuntime.queryInterface( 88 XIndexAccess.class, xSheetDoc.getSheets()); 89 90 try { 91 oSheet = (XSpreadsheet) UnoRuntime.queryInterface( 92 XSpreadsheet.class, xIA.getByIndex(0)); 93 } catch (com.sun.star.lang.WrappedTargetException e) { 94 e.printStackTrace(log); 95 throw new StatusException("Couldn't get a spreadsheet", e); 96 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 97 e.printStackTrace(log); 98 throw new StatusException("Couldn't get a spreadsheet", e); 99 } 100 101 changeColor("A1:A5", 0, 255, 0); 102 changeColor("A6:B10", 255, 0, 0); 103 changeColor("B1:B6", 0, 0, 255); 104 changeColor("B7", 0, 255, 0); 105 changeColor("B8:B10", 0, 0, 255); 106 changeColor("C1:C10", 0, 0, 255); 107 changeColor("D1:D10", 0, 255, 0); 108 109 XUniqueCellFormatRangesSupplier xUCRS = (XUniqueCellFormatRangesSupplier) UnoRuntime.queryInterface( 110 XUniqueCellFormatRangesSupplier.class, 111 oSheet); 112 113 XEnumerationAccess xEnum = (XEnumerationAccess) UnoRuntime.queryInterface( 114 XEnumerationAccess.class, 115 xUCRS.getUniqueCellFormatRanges()); 116 XInterface oObj = xEnum.createEnumeration(); 117 log.println("Implementationname: " + util.utils.getImplName(oObj)); 118 119 TestEnvironment tEnv = new TestEnvironment(oObj); 120 121 tEnv.addObjRelation("ExpectedCount", new Integer(4)); 122 123 return tEnv; 124 } 125 126 protected void changeColor(String RangeName, int r, int g, int b) { 127 XCellRange xRange = oSheet.getCellRangeByName(RangeName); 128 XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface( 129 XPropertySet.class, xRange); 130 Color c = new Color(r, g, b); 131 int c2int = 16777216 + c.hashCode(); 132 133 try { 134 xPropertySet.setPropertyValue("CellBackColor", new Integer(c2int)); 135 } catch (com.sun.star.beans.UnknownPropertyException e) { 136 log.println("Couldn't change CellFormat"); 137 } catch (com.sun.star.beans.PropertyVetoException e) { 138 log.println("Couldn't change CellFormat"); 139 } catch (com.sun.star.lang.IllegalArgumentException e) { 140 log.println("Couldn't change CellFormat"); 141 } catch (com.sun.star.lang.WrappedTargetException e) { 142 log.println("Couldn't change CellFormat"); 143 } 144 } 145 } 146