OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 144 Rev 156
Line 15... Line 15...
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.awt.Color;
19
import java.awt.Color;
-
 
20
import java.io.IOException;
-
 
21
import java.io.ObjectInput;
-
 
22
import java.io.ObjectOutput;
20
import java.io.PrintStream;
23
import java.io.PrintStream;
21
import java.util.ArrayList;
24
import java.util.ArrayList;
22
import java.util.List;
25
import java.util.List;
23
 
26
 
24
import net.minidev.json.JSONArray;
27
import net.minidev.json.JSONArray;
25
import net.minidev.json.JSONObject;
28
import net.minidev.json.JSONObject;
26
 
29
 
27
public class LightUIPanel extends LightUserControlContainer implements Transferable {
30
public class LightUIPanel extends LightUserControlContainer implements Transferable {
-
 
31
 
28
    private static final long serialVersionUID = -3399395824294128572L;
32
    private static final long serialVersionUID = -3399395824294128572L;
29
 
33
 
30
    private String title;
34
    private String title;
31
 
-
 
32
    private Color titleColor;
35
    private Color titleColor;
33
    private Color titleBackgroundColor;
36
    private Color titleBackgroundColor;
-
 
37
    private List<LightController> controlers = new ArrayList<>();
34
 
38
 
35
    private final List<LightControler> controlers = new ArrayList<LightControler>();
39
    public LightUIPanel() {
-
 
40
        // Serialization
-
 
41
    }
36
 
42
 
37
    public LightUIPanel(final JSONObject json) {
43
    public LightUIPanel(final JSONObject json) {
38
        super(json);
44
        super(json);
39
    }
45
    }
40
 
46
 
Line 49... Line 55...
49
        this.setWeightX(1);
55
        this.setWeightX(1);
50
        this.setFillWidth(true);
56
        this.setFillWidth(true);
51
        this.setFillHeight(true);
57
        this.setFillHeight(true);
52
    }
58
    }
53
 
59
 
-
 
60
    @Override
-
 
61
    public void destroy() {
-
 
62
        super.destroy();
-
 
63
        this.controlers = null;
-
 
64
    }
-
 
65
 
54
    public final LightUILine getLastLine() {
66
    public final LightUILine getLastLine() {
55
        final int childCount = this.getChildrenCount();
67
        final int childCount = this.getChildrenCount();
56
        if (childCount == 0) {
68
        if (childCount == 0) {
57
            final LightUILine l = new LightUILine();
69
            final LightUILine l = new LightUILine();
58
            this.addChild(l);
70
            this.addChild(l);
Line 76... Line 88...
76
 
88
 
77
    public void setTitleBackgoundColor(final Color c) {
89
    public void setTitleBackgoundColor(final Color c) {
78
        this.titleBackgroundColor = c;
90
        this.titleBackgroundColor = c;
79
    }
91
    }
80
 
92
 
81
    public void addControler(final LightControler controler) {
93
    public void addControler(final LightController controler) {
82
        this.controlers.add(controler);
94
        this.controlers.add(controler);
83
    }
95
    }
84
 
96
 
85
    public List<LightControler> getControlers() {
97
    public List<LightController> getControlers() {
86
        return this.controlers;
98
        return this.controlers;
87
    }
99
    }
88
 
100
 
89
    public void dumpControllers(final PrintStream out) {
101
    public void dumpControllers(final PrintStream out) {
90
        dumpControllers(out, 0);
102
        dumpControllers(out, 0);
91
    }
103
    }
92
 
104
 
93
    public void dumpControllers(final PrintStream out, final int depth) {
105
    public void dumpControllers(final PrintStream out, final int depth) {
94
        addSpacer(out, depth);
106
        addSpacer(out, depth);
95
        out.println("Contollers for id:" + this.getId() + " title: " + this.title);
107
        out.println("Contollers for id:" + this.getId() + " title: " + this.title);
96
        for (LightControler controler : this.controlers) {
108
        for (LightController controler : this.controlers) {
97
            addSpacer(out, depth);
109
            addSpacer(out, depth);
98
            out.println(controler);
110
            out.println(controler);
99
        }
111
        }
100
 
112
 
101
        final int lineCount = this.getChildrenCount();
113
        final int lineCount = this.getChildrenCount();
Line 165... Line 177...
165
    public String getClassName() {
177
    public String getClassName() {
166
        return this.getClass().getName();
178
        return this.getClass().getName();
167
    }
179
    }
168
 
180
 
169
    @Override
181
    @Override
170
    public JSONToLightUIConvertor getConvertor() {
-
 
171
        return new JSONToLightUIConvertor() {
-
 
172
            @Override
-
 
173
            public LightUIElement convert(final JSONObject json) {
-
 
174
                return new LightUIPanel(json);
-
 
175
            }
-
 
176
        };
-
 
177
    }
-
 
178
 
-
 
179
    @Override
-
 
180
    public void dump(final PrintStream out, final int depth) {
182
    public void dump(final PrintStream out, final int depth) {
181
        this.addSpacer(out, depth);
183
        this.addSpacer(out, depth);
182
        out.println("------LightUIPanel-----");
184
        out.println("------LightUIPanel-----");
183
        this.addSpacer(out, depth);
185
        this.addSpacer(out, depth);
184
        out.println("Title : " + this.title);
186
        out.println("Title : " + this.title);
Line 252... Line 254...
252
        final JSONArray jsonControlers = JSONConverter.getParameterFromJSON(json, "controlers", JSONArray.class);
254
        final JSONArray jsonControlers = JSONConverter.getParameterFromJSON(json, "controlers", JSONArray.class);
253
        if (jsonControlers != null) {
255
        if (jsonControlers != null) {
254
            final int controlersSize = jsonControlers.size();
256
            final int controlersSize = jsonControlers.size();
255
            for (int i = 0; i < controlersSize; i++) {
257
            for (int i = 0; i < controlersSize; i++) {
256
                final JSONObject jsonControler = JSONConverter.getObjectFromJSON(jsonControlers.get(i), JSONObject.class);
258
                final JSONObject jsonControler = JSONConverter.getObjectFromJSON(jsonControlers.get(i), JSONObject.class);
257
                this.controlers.add(new LightControler((JSONObject) jsonControler));
259
                this.controlers.add(new LightController((JSONObject) jsonControler));
-
 
260
            }
258
            }
261
        }
259
        }
262
    }
-
 
263
 
-
 
264
    @Override
-
 
265
    public void writeExternal(ObjectOutput out) throws IOException {
-
 
266
        super.writeExternal(out);
-
 
267
        writeIfNotNull(out, this.title);
-
 
268
        writeIfNotNull(out, this.titleColor);
-
 
269
        writeIfNotNull(out, this.titleBackgroundColor);
-
 
270
        out.writeByte(this.controlers.size());
-
 
271
        for (LightController lightControler : controlers) {
-
 
272
            lightControler.writeExternal(out);
-
 
273
        }
-
 
274
    }
-
 
275
 
-
 
276
    @Override
-
 
277
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-
 
278
        super.readExternal(in);
-
 
279
        if (in.readBoolean()) {
-
 
280
            this.title = in.readUTF();
-
 
281
        }
-
 
282
        if (in.readBoolean()) {
-
 
283
            this.titleColor = new Color(in.readInt());
-
 
284
        }
-
 
285
        if (in.readBoolean()) {
-
 
286
            this.titleBackgroundColor = new Color(in.readInt());
-
 
287
        }
-
 
288
        this.controlers.clear();
-
 
289
        final int size = in.readByte();
-
 
290
        for (int i = 0; i < size; i++) {
-
 
291
            final LightController lightControler = new LightController();
-
 
292
            lightControler.readExternal(in);
-
 
293
            this.controlers.add(lightControler);
-
 
294
        }
260
    }
295
    }
261
 
296
 
262
    @Override
297
    @Override
263
    public void setFoldable(boolean foldable) {
298
    public void setFoldable(boolean foldable) {
264
        super.setFoldable(foldable);
299
        super.setFoldable(foldable);