01: /*
02: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
07: *
08: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
09: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
10: * the license for the specific language governing your rights and limitations.
11: *
12: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
13: */
14: package org.pentaho.reportdesigner.crm.report.model;
15:
16: import org.gjt.xpp.XmlPullNode;
17: import org.jetbrains.annotations.NotNull;
18: import org.pentaho.reportdesigner.crm.report.PropertyKeys;
19: import org.pentaho.reportdesigner.lib.client.util.MathUtils;
20: import org.pentaho.reportdesigner.lib.common.xml.XMLContext;
21: import org.pentaho.reportdesigner.lib.common.xml.XMLExternalizable;
22: import org.pentaho.reportdesigner.lib.common.xml.XMLWriter;
23:
24: import java.io.IOException;
25:
26: /**
27: * User: Martin
28: * Date: 02.08.2007
29: * Time: 11:20:28
30: */
31: public class ElementPadding implements XMLExternalizable {
32: private double top;
33: private double bottom;
34: private double left;
35: private double right;
36:
37: public ElementPadding() {
38: }
39:
40: public ElementPadding(double top, double bottom, double left,
41: double right) {
42: this .top = top;
43: this .bottom = bottom;
44: this .left = left;
45: this .right = right;
46: }
47:
48: public double getTop() {
49: return top;
50: }
51:
52: public double getBottom() {
53: return bottom;
54: }
55:
56: public double getLeft() {
57: return left;
58: }
59:
60: public double getRight() {
61: return right;
62: }
63:
64: public boolean isDefault() {
65: return MathUtils.approxEquals(top, 0)
66: && MathUtils.approxEquals(bottom, 0)
67: && MathUtils.approxEquals(left, 0)
68: && MathUtils.approxEquals(right, 0);
69: }
70:
71: public void externalizeObject(@NotNull
72: XMLWriter xmlWriter, @NotNull
73: XMLContext xmlContext) throws IOException {
74: xmlWriter.writeAttribute(PropertyKeys.TOP, String.valueOf(top));
75: xmlWriter.writeAttribute(PropertyKeys.BOTTOM, String
76: .valueOf(bottom));
77: xmlWriter.writeAttribute(PropertyKeys.LEFT, String
78: .valueOf(left));
79: xmlWriter.writeAttribute(PropertyKeys.RIGHT, String
80: .valueOf(right));
81: }
82:
83: public void readObject(@NotNull
84: XmlPullNode node, @NotNull
85: XMLContext xmlContext) throws IOException {
86: top = Double.parseDouble(node
87: .getAttributeValueFromRawName(PropertyKeys.TOP));
88: bottom = Double.parseDouble(node
89: .getAttributeValueFromRawName(PropertyKeys.BOTTOM));
90: left = Double.parseDouble(node
91: .getAttributeValueFromRawName(PropertyKeys.LEFT));
92: right = Double.parseDouble(node
93: .getAttributeValueFromRawName(PropertyKeys.RIGHT));
94: }
95:
96: }
|