2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import com
.sun
.star
.beans
.XPropertySet
;
21 import com
.sun
.star
.container
.XEnumerationAccess
;
22 import com
.sun
.star
.container
.XIndexAccess
;
23 import com
.sun
.star
.lang
.XMultiServiceFactory
;
24 import com
.sun
.star
.sheet
.XSpreadsheet
;
25 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
26 import com
.sun
.star
.sheet
.XUniqueCellFormatRangesSupplier
;
27 import com
.sun
.star
.table
.XCellRange
;
28 import com
.sun
.star
.uno
.UnoRuntime
;
29 import com
.sun
.star
.uno
.XInterface
;
31 import java
.awt
.Color
;
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
40 import util
.SOfficeFactory
;
43 public class ScUniqueCellFormatsEnumeration
extends TestCase
{
44 private XSpreadsheetDocument xSheetDoc
= null;
45 static XSpreadsheet oSheet
= null;
48 * Creates Spreadsheet document.
50 protected void initialize(TestParameters tParam
, PrintWriter log
) {
51 // get a soffice factory object
52 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
53 (XMultiServiceFactory
) tParam
.getMSF());
56 log
.println("creating a sheetdocument");
57 xSheetDoc
= SOF
.createCalcDoc(null);
58 } catch (com
.sun
.star
.uno
.Exception e
) {
59 // Some exception occurs.FAILED
60 e
.printStackTrace(log
);
61 throw new StatusException("Couldn't create document", e
);
66 * Disposes Spreadsheet document.
68 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
69 util
.DesktopTools
.closeDoc(xSheetDoc
);
72 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
74 log
.println("Getting the first sheet");
76 XIndexAccess xIA
= UnoRuntime
.queryInterface(
77 XIndexAccess
.class, xSheetDoc
.getSheets());
80 oSheet
= UnoRuntime
.queryInterface(
81 XSpreadsheet
.class, xIA
.getByIndex(0));
82 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
83 e
.printStackTrace(log
);
84 throw new StatusException("Couldn't get a spreadsheet", e
);
85 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
86 e
.printStackTrace(log
);
87 throw new StatusException("Couldn't get a spreadsheet", e
);
90 changeColor("A1:A5", 0, 255, 0);
91 changeColor("A6:B10", 255, 0, 0);
92 changeColor("B1:B6", 0, 0, 255);
93 changeColor("B7", 0, 255, 0);
94 changeColor("B8:B10", 0, 0, 255);
95 changeColor("C1:C10", 0, 0, 255);
96 changeColor("D1:D10", 0, 255, 0);
98 XUniqueCellFormatRangesSupplier xUCRS
= UnoRuntime
.queryInterface(
99 XUniqueCellFormatRangesSupplier
.class,
102 XEnumerationAccess xEnum
= UnoRuntime
.queryInterface(
103 XEnumerationAccess
.class,
104 xUCRS
.getUniqueCellFormatRanges());
105 XInterface oObj
= xEnum
.createEnumeration();
106 log
.println("Implementationname: " + util
.utils
.getImplName(oObj
));
108 TestEnvironment tEnv
= new TestEnvironment(oObj
);
110 tEnv
.addObjRelation("ExpectedCount", new Integer(4));
115 protected void changeColor(String RangeName
, int r
, int g
, int b
) {
116 XCellRange xRange
= oSheet
.getCellRangeByName(RangeName
);
117 XPropertySet xPropertySet
= UnoRuntime
.queryInterface(
118 XPropertySet
.class, xRange
);
119 Color c
= new Color(r
, g
, b
);
120 int c2int
= 16777216 + c
.hashCode();
123 xPropertySet
.setPropertyValue("CellBackColor", new Integer(c2int
));
124 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
125 log
.println("Couldn't change CellFormat");
126 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
127 log
.println("Couldn't change CellFormat");
128 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
129 log
.println("Couldn't change CellFormat");
130 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
131 log
.println("Couldn't change CellFormat");