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