OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 80 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 80 Rev 180
Line 11... Line 11...
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.openoffice;
14
 package org.openconcerto.openoffice;
15
 
15
 
-
 
16
import org.openconcerto.openoffice.spreadsheet.BytesProducer;
16
import org.openconcerto.openoffice.text.TextNode;
17
import org.openconcerto.openoffice.text.TextNode;
17
 
18
 
18
import java.math.BigDecimal;
19
import java.math.BigDecimal;
19
 
20
 
20
import org.jdom.Element;
21
import org.jdom.Element;
Line 26... Line 27...
26
 * @author Sylvain
27
 * @author Sylvain
27
 * @param <D> type of table parent
28
 * @param <D> type of table parent
28
 */
29
 */
29
public class ODFrame<D extends ODDocument> extends ImmutableDocStyledNode<GraphicStyle, D> {
30
public class ODFrame<D extends ODDocument> extends ImmutableDocStyledNode<GraphicStyle, D> {
30
 
31
 
-
 
32
    static public Element createEmpty(XMLVersion ns, final Number w, final Number h, final LengthUnit unit) {
-
 
33
        return createEmpty(ns, BigDecimal.ZERO, BigDecimal.ZERO, w, h, unit);
-
 
34
    }
-
 
35
 
-
 
36
    static public Element createEmpty(XMLVersion ns, final Number x, final Number y, final Number w, final Number h, final LengthUnit unit) {
-
 
37
        final Namespace svgNS = ns.getNS("svg");
-
 
38
        final Element res = new Element("frame", ns.getNS("draw"));
-
 
39
        res.setAttribute("x", unit.format(x), svgNS);
-
 
40
        res.setAttribute("y", unit.format(y), svgNS);
-
 
41
        res.setAttribute("width", unit.format(w), svgNS);
-
 
42
        res.setAttribute("height", unit.format(h), svgNS);
-
 
43
        return res;
-
 
44
    }
-
 
45
 
31
    /**
46
    /**
32
     * Parse SVG and OD length.
47
     * Parse SVG and OD length.
33
     * 
48
     * 
34
     * @param l the string to parse, eg "1.53cm".
49
     * @param l the string to parse, eg "1.53cm".
35
     * @param to the unit, eg {@link LengthUnit#MM}.
50
     * @param to the unit, eg {@link LengthUnit#MM}.
Line 118... Line 133...
118
     * @return the unit used, eg "mm".
133
     * @return the unit used, eg "mm".
119
     */
134
     */
120
    public final LengthUnit getUnit() {
135
    public final LengthUnit getUnit() {
121
        return LengthUnit.MM;
136
        return LengthUnit.MM;
122
    }
137
    }
-
 
138
 
-
 
139
    public final void addImage(final String name, final BytesProducer data) {
-
 
140
        final Element imageElem = new Element("image", getElement().getNamespace("draw"));
-
 
141
        this.getElement().addContent(imageElem);
-
 
142
        this.putImage(imageElem, name, data);
-
 
143
    }
-
 
144
 
-
 
145
    private final void putImage(final Element imageElem, final String name, final BytesProducer data) {
-
 
146
        final String imgPath = "Pictures/" + name + (data.getFormat() != null ? "." + data.getFormat() : "");
-
 
147
        imageElem.setAttribute("href", imgPath, this.getODDocument().getVersion().getNS("xlink"));
-
 
148
        this.getODDocument().getPackage().putFile(imgPath, data.getBytes(this));
-
 
149
    }
-
 
150
 
-
 
151
    public final void setImage(final String name, final BytesProducer data, final boolean allowAdd) {
-
 
152
        final Element imageElem = this.getElement().getChild("image", getElement().getNamespace("draw"));
-
 
153
        if (imageElem != null) {
-
 
154
            final String oldPath = imageElem.getAttributeValue("href", this.getODDocument().getVersion().getNS("xlink"));
-
 
155
            this.getODDocument().getPackage().putFile(oldPath, null);
-
 
156
            imageElem.removeChild("binary-data", this.getODDocument().getVersion().getOFFICE());
-
 
157
 
-
 
158
            if (data == null) {
-
 
159
                imageElem.detach();
-
 
160
            } else {
-
 
161
                this.putImage(imageElem, name, data);
-
 
162
            }
-
 
163
        } else if (data != null) {
-
 
164
            if (allowAdd)
-
 
165
                this.addImage(name, data);
-
 
166
            else
-
 
167
                throw new IllegalStateException("No image in " + this);
-
 
168
        }
-
 
169
    }
123
}
170
}