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
.sheet
.XSpreadsheet
;
23 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
24 import com
.sun
.star
.sheet
.XUniqueCellFormatRangesSupplier
;
25 import com
.sun
.star
.table
.XCellRange
;
26 import com
.sun
.star
.uno
.UnoRuntime
;
27 import com
.sun
.star
.uno
.XInterface
;
29 import java
.awt
.Color
;
31 import java
.io
.PrintWriter
;
33 import lib
.StatusException
;
35 import lib
.TestEnvironment
;
36 import lib
.TestParameters
;
38 import util
.SOfficeFactory
;
41 public class ScUniqueCellFormatsObj
extends TestCase
{
42 private XSpreadsheetDocument xSheetDoc
= null;
43 static XSpreadsheet oSheet
= null;
46 * Creates Spreadsheet document.
49 protected void initialize(TestParameters tParam
, PrintWriter log
) {
50 // get a soffice factory object
51 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
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.
68 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
69 util
.DesktopTools
.closeDoc(xSheetDoc
);
73 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
75 log
.println("Getting the first sheet");
77 XIndexAccess xIA
= UnoRuntime
.queryInterface(
78 XIndexAccess
.class, xSheetDoc
.getSheets());
81 oSheet
= UnoRuntime
.queryInterface(
82 XSpreadsheet
.class, xIA
.getByIndex(0));
83 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
84 e
.printStackTrace(log
);
85 throw new StatusException("Couldn't get a spreadsheet", e
);
86 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
87 e
.printStackTrace(log
);
88 throw new StatusException("Couldn't get a spreadsheet", e
);
91 changeColor("A1:A5", 0, 255, 0);
92 changeColor("A6:B10", 255, 0, 0);
93 changeColor("B1:B6", 0, 0, 255);
94 changeColor("B7", 0, 255, 0);
95 changeColor("B8:B10", 0, 0, 255);
96 changeColor("C1:C10", 0, 0, 255);
97 changeColor("D1:D10", 0, 255, 0);
99 XUniqueCellFormatRangesSupplier xUCRS
= UnoRuntime
.queryInterface(
100 XUniqueCellFormatRangesSupplier
.class,
103 XInterface oObj
= xUCRS
.getUniqueCellFormatRanges();
104 log
.println("Implementationname: " + util
.utils
.getImplName(oObj
));
106 TestEnvironment tEnv
= new TestEnvironment(oObj
);
111 protected void changeColor(String RangeName
, int r
, int g
, int b
) {
112 XCellRange xRange
= oSheet
.getCellRangeByName(RangeName
);
113 XPropertySet xPropertySet
= UnoRuntime
.queryInterface(
114 XPropertySet
.class, xRange
);
115 Color c
= new Color(r
, g
, b
);
116 int c2int
= 16777216 + c
.hashCode();
119 xPropertySet
.setPropertyValue("CellBackColor", Integer
.valueOf(c2int
));
120 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
121 log
.println("Couldn't change CellFormat");
122 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
123 log
.println("Couldn't change CellFormat");
124 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
125 log
.println("Couldn't change CellFormat");
126 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
127 log
.println("Couldn't change CellFormat");