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
.XIndexAccess
;
22 import com
.sun
.star
.lang
.XMultiServiceFactory
;
23 import com
.sun
.star
.sheet
.XSpreadsheet
;
24 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
25 import com
.sun
.star
.sheet
.XUniqueCellFormatRangesSupplier
;
26 import com
.sun
.star
.table
.XCellRange
;
27 import com
.sun
.star
.uno
.UnoRuntime
;
28 import com
.sun
.star
.uno
.XInterface
;
30 import java
.awt
.Color
;
32 import java
.io
.PrintWriter
;
34 import lib
.StatusException
;
36 import lib
.TestEnvironment
;
37 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
42 public class ScUniqueCellFormatsObj
extends TestCase
{
43 private XSpreadsheetDocument xSheetDoc
= null;
44 static XSpreadsheet oSheet
= null;
47 * Creates Spreadsheet document.
49 protected void initialize(TestParameters tParam
, PrintWriter log
) {
50 // get a soffice factory object
51 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
52 (XMultiServiceFactory
) tParam
.getMSF());
55 log
.println("creating a sheetdocument");
56 xSheetDoc
= SOF
.createCalcDoc(null);
57 } catch (com
.sun
.star
.uno
.Exception e
) {
58 // Some exception occurs.FAILED
59 e
.printStackTrace(log
);
60 throw new StatusException("Couldn't create document", e
);
65 * Disposes Spreadsheet document.
67 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
68 util
.DesktopTools
.closeDoc(xSheetDoc
);
71 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
73 log
.println("Getting the first sheet");
75 XIndexAccess xIA
= UnoRuntime
.queryInterface(
76 XIndexAccess
.class, xSheetDoc
.getSheets());
79 oSheet
= UnoRuntime
.queryInterface(
80 XSpreadsheet
.class, xIA
.getByIndex(0));
81 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
82 e
.printStackTrace(log
);
83 throw new StatusException("Couldn't get a spreadsheet", e
);
84 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
85 e
.printStackTrace(log
);
86 throw new StatusException("Couldn't get a spreadsheet", e
);
89 changeColor("A1:A5", 0, 255, 0);
90 changeColor("A6:B10", 255, 0, 0);
91 changeColor("B1:B6", 0, 0, 255);
92 changeColor("B7", 0, 255, 0);
93 changeColor("B8:B10", 0, 0, 255);
94 changeColor("C1:C10", 0, 0, 255);
95 changeColor("D1:D10", 0, 255, 0);
97 XUniqueCellFormatRangesSupplier xUCRS
= UnoRuntime
.queryInterface(
98 XUniqueCellFormatRangesSupplier
.class,
101 XInterface oObj
= xUCRS
.getUniqueCellFormatRanges();
102 log
.println("Implementationname: " + util
.utils
.getImplName(oObj
));
104 TestEnvironment tEnv
= new TestEnvironment(oObj
);
109 protected void changeColor(String RangeName
, int r
, int g
, int b
) {
110 XCellRange xRange
= oSheet
.getCellRangeByName(RangeName
);
111 XPropertySet xPropertySet
= UnoRuntime
.queryInterface(
112 XPropertySet
.class, xRange
);
113 Color c
= new Color(r
, g
, b
);
114 int c2int
= 16777216 + c
.hashCode();
117 xPropertySet
.setPropertyValue("CellBackColor", new Integer(c2int
));
118 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
119 log
.println("Couldn't change CellFormat");
120 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
121 log
.println("Couldn't change CellFormat");
122 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
123 log
.println("Couldn't change CellFormat");
124 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
125 log
.println("Couldn't change CellFormat");