LibreOffice Module xmerge (master) 1
SheetSettings.java
Go to the documentation of this file.
1/*
2 * This file is part of the LibreOffice project.
3 *
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/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
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 .
17 */
18
19package org.openoffice.xmerge.converter.xml.sxc;
20
21import org.w3c.dom.NamedNodeMap;
22import org.w3c.dom.NodeList;
23import org.w3c.dom.Node;
24import org.w3c.dom.Element;
25import java.awt.Point;
26
28
33public class SheetSettings implements OfficeConstants {
34
36 private org.w3c.dom.Document settings = null;
37
39 private int cursorX = 0;
40 private int cursorY = 0;
41 private int splitTypeX;
42 private int splitTypeY;
43 private int splitPointX = 0;
44 private int splitPointY = 0;
45 private int posLeft = 0;
46 private int posTop = 0;
47 private int paneNumber = 2;
48
49 final private static int SPLIT = 0x01;
50 final private static int FREEZE = 0x02;
51
55 public SheetSettings() {
56 }
57
63 public SheetSettings(Node root) {
64 readNode(root);
65 }
66
72 public SheetSettings(String name) {
74 }
75
81 public void setCursor(Point activeCell) {
82 cursorX = (int) activeCell.getX();
83 cursorY = (int) activeCell.getY();
84 }
85
91 public Point getCursor() {
92 return new Point(cursorX, cursorY);
93 }
94
100 public void setFreeze(Point splitPoint) {
103 splitPointX = (int) splitPoint.getX();
104 splitPointY = (int) splitPoint.getY();
105 }
106
112 public void setSplit(Point splitPoint) {
113
116 splitPointX = (int) splitPoint.getX();
117 splitPointY = (int) splitPoint.getY();
118 }
119
125 public Point getSplit() {
126
127 return new Point(splitPointX, splitPointY);
128 }
129
136
137 return new Point(splitTypeX, splitTypeY);
138 }
139
145 public int getLeft() {
146 return posLeft;
147 }
148
154 public int getTop() {
155 return posTop;
156 }
157
172 public int getPaneNumber() {
173 return paneNumber;
174 }
175
181 public void setSheetName(String sheetName) {
182 this.sheetName = sheetName;
183 }
184
199 public void setPaneNumber(int paneNumber) {
200 this.paneNumber = paneNumber;
201 }
202
209 return sheetName;
210 }
211
220 private void addConfigItem(Node root, String attribute, String type, String value) {
221
222 Element configItem = settings.createElement(TAG_CONFIG_ITEM);
223 configItem.setAttribute(ATTRIBUTE_CONFIG_NAME, attribute);
224 configItem.setAttribute(ATTRIBUTE_CONFIG_TYPE, type);
225
226 configItem.appendChild(settings.createTextNode(value));
227
228 root.appendChild(configItem);
229 }
230
237 public void writeNode(org.w3c.dom.Document settings, Node root) {
238
239 this.settings = settings;
240 Element configItemMapEntry = settings.createElement(TAG_CONFIG_ITEM_MAP_ENTRY);
241 configItemMapEntry.setAttribute(ATTRIBUTE_CONFIG_NAME, getSheetName());
242 addConfigItem(configItemMapEntry, "CursorPositionX", "int", Integer.toString(cursorX));
243 addConfigItem(configItemMapEntry, "CursorPositionY", "int", Integer.toString(cursorY));
244
245 String splitMode = Integer.toString(splitTypeX);
246 if(splitPointX==0) {
247 splitMode = "0";
248 }
249 addConfigItem(configItemMapEntry, "HorizontalSplitMode", "short", splitMode);
250
251 splitMode = Integer.toString(splitTypeY);
252 if(splitPointY==0) {
253 splitMode = "0";
254 }
255 addConfigItem(configItemMapEntry, "VerticalSplitMode", "short", splitMode);
256
257 addConfigItem(configItemMapEntry, "HorizontalSplitPosition", "int", Integer.toString(splitPointX));
258 addConfigItem(configItemMapEntry, "VerticalSplitPosition", "int", Integer.toString(splitPointY));
259 addConfigItem(configItemMapEntry, "ActiveSplitRange", "short", Integer.toString(paneNumber));
260
261 addConfigItem(configItemMapEntry, "PositionLeft", "int", "0");
262 addConfigItem(configItemMapEntry, "PositionRight", "int", Integer.toString(posLeft));
263 addConfigItem(configItemMapEntry, "PositionTop", "int", "0");
264 addConfigItem(configItemMapEntry, "PositionBottom", "int", Integer.toString(posTop));
265 root.appendChild(configItemMapEntry);
266 }
267
274 private void addAttribute(String name, String value) {
275
276 if(name.equals("CursorPositionX")) {
277 cursorX = Integer.parseInt(value);
278 } else if(name.equals("CursorPositionY")) {
279 cursorY = Integer.parseInt(value);
280
281 } else if(name.equals("HorizontalSplitPosition")) {
282 splitPointX = Integer.parseInt(value);
283 } else if(name.equals("VerticalSplitPosition")) {
284 splitPointY = Integer.parseInt(value);
285 } else if(name.equals("ActiveSplitRange")) {
286 paneNumber = Integer.parseInt(value);
287
288 } else if(name.equals("PositionRight")) {
289 posLeft = Integer.parseInt(value);
290 } else if(name.equals("PositionBottom")) {
291 posTop = Integer.parseInt(value);
292
293 } else if(name.equals("HorizontalSplitMode")) {
294 splitTypeX = Integer.parseInt(value);
295 } else if(name.equals("VerticalSplitMode")) {
296 splitTypeY = Integer.parseInt(value);
297 }
298 }
299
305 private void readNode(Node root) {
306
307 NamedNodeMap sheetAtt = root.getAttributes();
308
309 Node sheetNameNode = sheetAtt.getNamedItem(ATTRIBUTE_CONFIG_NAME);
310
311 sheetName = sheetNameNode.getNodeValue();
312
313 if (root.hasChildNodes()) {
314
315 NodeList nodeList = root.getChildNodes();
316 int len = nodeList.getLength();
317 for (int i = 0; i < len; i++) {
318 Node child = nodeList.item(i);
319
320 if (child.getNodeType() == Node.ELEMENT_NODE) {
321 String nodeName = child.getNodeName();
322
323 if (nodeName.equals(TAG_CONFIG_ITEM)) {
324
325 NamedNodeMap cellAtt = child.getAttributes();
326
327 Node configNameNode =
328 cellAtt.getNamedItem(ATTRIBUTE_CONFIG_NAME);
329
330 String name = configNameNode.getNodeValue();
331 NodeList nodeList2 = child.getChildNodes();
332 int len2 = nodeList2.getLength();
333 String s = "";
334 for (int j = 0; j < len2; j++) {
335 Node child2 = nodeList2.item(j);
336 if (child2.getNodeType() == Node.TEXT_NODE) {
337 s = child2.getNodeValue();
338 }
339 }
340 addAttribute(name, s);
341 }
342 }
343 }
344 }
345 }
346}
This is a class representing the different attributes for a worksheet contained in settings....
String getSheetName()
Gets the name of the worksheet these Settings apply to.
org.w3c.dom.Document settings
A w3c Document.
SheetSettings(Node root)
Constructor that takes a Node to build a SheetSettings.
void addAttribute(String name, String value)
Sets a variable based on a String value read from XML.
int getLeft()
Gets the leftmost column visible in the right pane.
void setCursor(Point activeCell)
Sets the position of the active cell.
void readNode(Node root)
Reads document settings from xml and inits SheetSettings variables.
SheetSettings()
Default Constructor for a SheetSettings.
int getTop()
Gets the top row visible in the lower pane.
Point getCursor()
Gets the position of the active cell.
void setSheetName(String sheetName)
Sets the sheetName this settings object applies to.
void setPaneNumber(int paneNumber)
Sets the active pane number.
void writeNode(org.w3c.dom.Document settings, Node root)
Writes out a settings.xml entry for this SheetSettings object.
void setFreeze(Point splitPoint)
Sets the position of the freeze.
void addConfigItem(Node root, String attribute, String type, String value)
Adds an XML entry for a particular setting.
void setSplit(Point splitPoint)
Sets the position of the split.
Point getSplit()
Gets the position of the split.
SheetSettings(String name)
Constructor for a SheetSettings.
Any value
const char * name
This interface contains constants for StarOffice XML tags, attributes (StarCalc cell types,...
String ATTRIBUTE_CONFIG_NAME
Attribute tag for config:name of element config:config-item.
String TAG_CONFIG_ITEM
Element tag for config:config-item.
String TAG_CONFIG_ITEM_MAP_ENTRY
Element tag for config:config-item-map-entry.
String ATTRIBUTE_CONFIG_TYPE
Attribute tag for config:type of element config:config-item.
int i
Document and PluginFactory implementations for XML based formats.
Provides interfaces for converting between two Document formats, and supports a "merge" interface for...
Definition: Convert.java:19
sal_Int32 attribute
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int
ResultType type