OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 20 | Rev 65 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.openoffice.spreadsheet;
15
 
20 ilm 16
import org.openconcerto.openoffice.LengthUnit;
17 ilm 17
import org.openconcerto.openoffice.ODPackage;
20 ilm 18
import org.openconcerto.openoffice.StyleProperties;
17 ilm 19
import org.openconcerto.openoffice.StyleStyle;
20
import org.openconcerto.openoffice.StyleStyleDesc;
21
import org.openconcerto.openoffice.XMLVersion;
22
 
20 ilm 23
import java.math.BigDecimal;
24
 
17 ilm 25
import org.jdom.Element;
26
 
27
public class ColumnStyle extends StyleStyle {
28
 
29
    // from section 18.728 in v1.2-part1
30
    public static final StyleStyleDesc<ColumnStyle> DESC = new StyleStyleDesc<ColumnStyle>(ColumnStyle.class, XMLVersion.OD, "table-column", "co", "table") {
31
        @Override
32
        public ColumnStyle create(ODPackage pkg, Element e) {
33
            return new ColumnStyle(pkg, e);
34
        }
35
    };
36
 
20 ilm 37
    private StyleTableColumnProperties colProps;
38
 
17 ilm 39
    public ColumnStyle(final ODPackage pkg, Element tableColElem) {
40
        super(pkg, tableColElem);
41
    }
42
 
20 ilm 43
    public final StyleTableColumnProperties getTableColumnProperties() {
44
        if (this.colProps == null)
45
            this.colProps = new StyleTableColumnProperties(this);
46
        return this.colProps;
17 ilm 47
    }
48
 
20 ilm 49
    public final Float getWidth() {
50
        final BigDecimal res = this.getTableColumnProperties().getWidth(TableStyle.DEFAULT_UNIT);
51
        return res == null ? null : res.floatValue();
17 ilm 52
    }
53
 
54
    void setWidth(float f) {
55
        getFormattingProperties().setAttribute("column-width", f + TableStyle.DEFAULT_UNIT.getSymbol(), this.getSTYLE());
56
        // optional, so no need to recompute it
57
        rmRelWidth();
58
    }
59
 
60
    void rmRelWidth() {
61
        getFormattingProperties().removeAttribute("rel-column-width", this.getSTYLE());
62
    }
20 ilm 63
 
64
    // see 17.16 of v1.2-cs01-part1
65
    public static class StyleTableColumnProperties extends StyleProperties {
66
 
67
        public StyleTableColumnProperties(StyleStyle style) {
68
            super(style, style.getFamily());
69
        }
70
 
71
        public final BigDecimal getWidth(final LengthUnit in) {
72
            return LengthUnit.parseLength(getAttributeValue("column-width", this.getNS("style")), in);
73
        }
74
 
75
        public final String getBreakBefore() {
76
            return getAttributeValue("break-before", this.getNS("fo"));
77
        }
78
 
79
        public final String getBreakAfter() {
80
            return getAttributeValue("break-after", this.getNS("fo"));
81
        }
82
    }
17 ilm 83
}