1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScUniqueCellFormatsEnumeration.java,v $
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 ************************************************************************/
32 import com
.sun
.star
.beans
.XPropertySet
;
33 import com
.sun
.star
.container
.XEnumerationAccess
;
34 import com
.sun
.star
.container
.XIndexAccess
;
35 import com
.sun
.star
.lang
.XMultiServiceFactory
;
36 import com
.sun
.star
.sheet
.XSpreadsheet
;
37 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
38 import com
.sun
.star
.sheet
.XUniqueCellFormatRangesSupplier
;
39 import com
.sun
.star
.table
.XCellRange
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
43 import java
.awt
.Color
;
45 import java
.io
.PrintWriter
;
47 import lib
.StatusException
;
49 import lib
.TestEnvironment
;
50 import lib
.TestParameters
;
52 import util
.SOfficeFactory
;
55 public class ScUniqueCellFormatsEnumeration
extends TestCase
{
56 static XSpreadsheetDocument xSheetDoc
= null;
57 static XSpreadsheet oSheet
= null;
60 * Creates Spreadsheet document.
62 protected void initialize(TestParameters tParam
, PrintWriter log
) {
63 // get a soffice factory object
64 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
65 (XMultiServiceFactory
) tParam
.getMSF());
68 log
.println("creating a sheetdocument");
69 xSheetDoc
= SOF
.createCalcDoc(null);
70 } catch (com
.sun
.star
.uno
.Exception e
) {
71 // Some exception occures.FAILED
72 e
.printStackTrace(log
);
73 throw new StatusException("Couldn't create document", e
);
78 * Disposes Spreadsheet document.
80 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
81 //add this lines after synchronisation
82 //log.println(" disposing xSheetDoc ");
83 //DesktopTools.closeDoc(xSheetDoc);
86 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
88 log
.println("Getting the first sheet");
90 XIndexAccess xIA
= (XIndexAccess
) UnoRuntime
.queryInterface(
91 XIndexAccess
.class, xSheetDoc
.getSheets());
94 oSheet
= (XSpreadsheet
) UnoRuntime
.queryInterface(
95 XSpreadsheet
.class, xIA
.getByIndex(0));
96 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
97 e
.printStackTrace(log
);
98 throw new StatusException("Couldn't get a spreadsheet", e
);
99 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
100 e
.printStackTrace(log
);
101 throw new StatusException("Couldn't get a spreadsheet", e
);
104 changeColor("A1:A5", 0, 255, 0);
105 changeColor("A6:B10", 255, 0, 0);
106 changeColor("B1:B6", 0, 0, 255);
107 changeColor("B7", 0, 255, 0);
108 changeColor("B8:B10", 0, 0, 255);
109 changeColor("C1:C10", 0, 0, 255);
110 changeColor("D1:D10", 0, 255, 0);
112 XUniqueCellFormatRangesSupplier xUCRS
= (XUniqueCellFormatRangesSupplier
) UnoRuntime
.queryInterface(
113 XUniqueCellFormatRangesSupplier
.class,
116 XEnumerationAccess xEnum
= (XEnumerationAccess
) UnoRuntime
.queryInterface(
117 XEnumerationAccess
.class,
118 xUCRS
.getUniqueCellFormatRanges());
119 XInterface oObj
= xEnum
.createEnumeration();
120 log
.println("Implementationname: " + util
.utils
.getImplName(oObj
));
122 TestEnvironment tEnv
= new TestEnvironment(oObj
);
124 tEnv
.addObjRelation("ExpectedCount", new Integer(4));
129 protected void changeColor(String RangeName
, int r
, int g
, int b
) {
130 XCellRange xRange
= oSheet
.getCellRangeByName(RangeName
);
131 XPropertySet xPropertySet
= (XPropertySet
) UnoRuntime
.queryInterface(
132 XPropertySet
.class, xRange
);
133 Color c
= new Color(r
, g
, b
);
134 int c2int
= 16777216 + c
.hashCode();
137 xPropertySet
.setPropertyValue("CellBackColor", new Integer(c2int
));
138 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
139 log
.println("Couldn't change CellFormat");
140 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
141 log
.println("Couldn't change CellFormat");
142 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
143 log
.println("Couldn't change CellFormat");
144 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
145 log
.println("Couldn't change CellFormat");