OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 144 Rev 156
Line 14... Line 14...
14
 package org.openconcerto.ui.light;
14
 package org.openconcerto.ui.light;
15
 
15
 
16
import org.openconcerto.utils.io.JSONConverter;
16
import org.openconcerto.utils.io.JSONConverter;
17
import org.openconcerto.utils.io.Transferable;
17
import org.openconcerto.utils.io.Transferable;
18
 
18
 
-
 
19
import java.io.Externalizable;
-
 
20
import java.io.IOException;
-
 
21
import java.io.ObjectInput;
-
 
22
import java.io.ObjectOutput;
-
 
23
 
19
import net.minidev.json.JSONObject;
24
import net.minidev.json.JSONObject;
20
 
25
 
21
public class LightUILine extends LightUIContainer implements Transferable {
26
public class LightUILine extends LightUIContainer implements Transferable, Externalizable {
22
    private static final long serialVersionUID = 4132718509484530435L;
27
    private static final long serialVersionUID = 4132718509484530435L;
23
 
28
 
24
    public static final int ALIGN_GRID = 0;
29
    public static final int ALIGN_GRID = 0;
25
    public static final int ALIGN_LEFT = 1;
30
    public static final int ALIGN_LEFT = 1;
26
    public static final int ALIGN_RIGHT = 2;
31
    public static final int ALIGN_RIGHT = 2;
27
 
32
 
28
    private int gridAlignment = ALIGN_GRID;
33
    private int gridAlignment = ALIGN_GRID;
29
 
34
 
30
    private Integer elementPadding;
35
    private int elementPadding = 0;
31
    private Integer elementMargin;
36
    private int elementMargin = 0;
32
 
37
 
33
    public LightUILine() {
38
    public LightUILine() {
34
        // Id will be set when this line will be added into a panel, or set manually.
39
        // Id will be set when this line will be added into a panel, or set manually.
35
        super("");
40
        super("");
36
        this.setType(TYPE_PANEL_LINE);
41
        this.setType(TYPE_PANEL_LINE);
Line 106... Line 111...
106
 
111
 
107
    @Override
112
    @Override
108
    public JSONObject toJSON() {
113
    public JSONObject toJSON() {
109
        final JSONObject result = super.toJSON();
114
        final JSONObject result = super.toJSON();
110
        result.put("class", "LightUILine");
115
        result.put("class", "LightUILine");
111
        if (this.elementPadding != null) {
116
        if (this.elementPadding != 0) {
112
            result.put("element-padding", this.elementPadding);
117
            result.put("element-padding", this.elementPadding);
113
        }
118
        }
114
        if (this.elementMargin != null) {
119
        if (this.elementMargin != 0) {
115
            result.put("element-margin", this.elementMargin);
120
            result.put("element-margin", this.elementMargin);
116
        }
121
        }
117
        if (this.gridAlignment != ALIGN_GRID) {
122
        if (this.gridAlignment != ALIGN_GRID) {
118
            result.put("grid-alignment", this.gridAlignment);
123
            result.put("grid-alignment", this.gridAlignment);
119
        }
124
        }
Line 121... Line 126...
121
    }
126
    }
122
 
127
 
123
    @Override
128
    @Override
124
    public void fromJSON(final JSONObject json) {
129
    public void fromJSON(final JSONObject json) {
125
        super.fromJSON(json);
130
        super.fromJSON(json);
126
        this.elementPadding = JSONConverter.getParameterFromJSON(json, "element-padding", Integer.class);
131
        this.elementPadding = JSONConverter.getParameterFromJSON(json, "element-padding", Integer.class, 0);
127
        this.elementMargin = JSONConverter.getParameterFromJSON(json, "element-margin", Integer.class);
132
        this.elementMargin = JSONConverter.getParameterFromJSON(json, "element-margin", Integer.class, 0);
128
        this.gridAlignment = JSONConverter.getParameterFromJSON(json, "grid-alignment", Integer.class, ALIGN_GRID);
133
        this.gridAlignment = JSONConverter.getParameterFromJSON(json, "grid-alignment", Integer.class, ALIGN_GRID);
129
    }
134
    }
-
 
135
 
-
 
136
    @Override
-
 
137
    public void writeExternal(ObjectOutput out) throws IOException {
-
 
138
        super.writeExternal(out);
-
 
139
        out.writeInt(this.elementMargin);
-
 
140
        out.writeInt(this.elementPadding);
-
 
141
        out.writeByte(this.gridAlignment);
-
 
142
    }
-
 
143
 
-
 
144
    @Override
-
 
145
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-
 
146
        super.readExternal(in);
-
 
147
        this.elementMargin = in.readInt();
-
 
148
        this.elementPadding = in.readInt();
-
 
149
        this.gridAlignment = in.readByte();
-
 
150
    }
-
 
151
 
-
 
152
    @Override
-
 
153
    public void addChild(LightUIElement child) {
-
 
154
        if (child instanceof LightUILine) {
-
 
155
            throw new IllegalArgumentException("child is a LightUILine");
-
 
156
        }
-
 
157
        super.addChild(child);
-
 
158
    }
130
}
159
}