OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
73 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.ui.light;
15
 
149 ilm 16
import org.openconcerto.utils.io.HTMLable;
132 ilm 17
import org.openconcerto.utils.io.JSONConverter;
18
import org.openconcerto.utils.io.Transferable;
19
 
73 ilm 20
import java.awt.Color;
156 ilm 21
import java.io.Externalizable;
22
import java.io.IOException;
23
import java.io.ObjectInput;
24
import java.io.ObjectOutput;
73 ilm 25
import java.io.PrintStream;
26
 
94 ilm 27
import net.minidev.json.JSONObject;
93 ilm 28
 
156 ilm 29
public abstract class LightUIElement implements Transferable, Externalizable {
132 ilm 30
 
142 ilm 31
    private static final String HORIZONTALLY_RESIZABLE = "horizontally-resizable";
32
    private static final String VERTICALLY_SCROLLABLE = "vertically-scrollable";
33
    private static final String VERTICALLY_RESIZABLE = "vertically-resizable";
34
    private static final String HORIZONTALLY_SCROLLABLE = "horizontally-scrollable";
35
 
132 ilm 36
    public enum GlyphIcon {
37
        WARNING("#warning"), PLUS("#plus"), PENCIL("#pencil"), SEARCH("#search"), REMOVE("#remove"), STAR("#star"), STAR_EMPTY("#star-empty"), USER("#user"), LOCK("#lock"), UNLOCK(
177 ilm 38
                "#unlock"), DOWNLOAD("#download"), UPLOAD("#upload"), ARROW_LEFT("#arrow-left"), ARROW_RIGHT("#arrow-right");
132 ilm 39
 
40
        private final String id;
41
 
42
        GlyphIcon(String id) {
43
            this.id = id;
44
        }
45
 
46
        public String getId() {
47
            return this.id;
48
        }
49
    };
50
 
73 ilm 51
    /**
52
     *
53
     */
54
    private static final long serialVersionUID = 3272357171610073289L;
80 ilm 55
    // type
73 ilm 56
    public static final int TYPE_LABEL = 0;
57
    public static final int TYPE_TEXT_FIELD = 1;
58
    public static final int TYPE_DATE = 2;
59
    public static final int TYPE_COMBOBOX = 3;
94 ilm 60
    public static final int TYPE_TABLE = 4;
73 ilm 61
    public static final int TYPE_CHECKBOX = 5;
62
    public static final int TYPE_TABBED_UI = 6;
63
    public static final int TYPE_COMBOBOX_ELEMENT = 7;
94 ilm 64
    public static final int TYPE_PANEL = 8;
83 ilm 65
    public static final int TYPE_TREE = 9;
93 ilm 66
    public static final int TYPE_TEXT = 10;
132 ilm 67
    public static final int TYPE_LIST = 11;
68
    public static final int TYPE_DROPDOWN_BUTTON = 12;
69
    public static final int TYPE_FRAME = 13;
70
    public static final int TYPE_IMAGE = 14;
142 ilm 71
    public static final int TYPE_FILE_UPLOAD_WITH_SELECTION = 15;
132 ilm 72
    public static final int TYPE_PANEL_LINE = 16;
73
    public static final int TYPE_TAB_ELEMENT = 17;
142 ilm 74
    public static final int TYPE_SLIDER = 18;
75
    public static final int TYPE_PICTURE_UPLOAD = 19;
73 ilm 76
    public static final int TYPE_BUTTON = 20;
77
    public static final int TYPE_BUTTON_WITH_CONTEXT = 21;
78
    public static final int TYPE_BUTTON_CANCEL = 22;
79
    public static final int TYPE_BUTTON_UNMANAGED = 23;
80 ilm 80
    public static final int TYPE_BUTTON_WITH_SELECTION_CONTEXT = 24;
94 ilm 81
    public static final int TYPE_BUTTON_LINK = 25;
132 ilm 82
    public static final int TYPE_RAW_HTML = 26;
83
    public static final int TYPE_TEXT_AREA = 27;
142 ilm 84
    public static final int TYPE_FILE_UPLOAD = 28;
85
    public static final int TYPE_LIST_ROW = 29;
86
    public static final int TYPE_BADGE = 30;
87
    public static final int TYPE_AUTOCOMPLETE_COMBOBOX = 31;
88
    public static final int TYPE_COLOR_PICKER = 32;
89
    public static final int TYPE_HOUR_EDITOR = 33;
149 ilm 90
    public static final int TYPE_RADIO_BUTTONS = 34;
156 ilm 91
    public static final int TYPE_PASSWORD_FIELD = 35;
92
 
80 ilm 93
    // valueType
73 ilm 94
    public static final int VALUE_TYPE_STRING = 0;
95
    public static final int VALUE_TYPE_INTEGER = 1;
96
    public static final int VALUE_TYPE_DATE = 2;
97
    public static final int VALUE_TYPE_REF = 3;
98
    public static final int VALUE_TYPE_LIST = 4;
80 ilm 99
    public static final int VALUE_TYPE_DECIMAL = 5;
94 ilm 100
    public static final int VALUE_TYPE_BOOLEAN = 6;
101
    // actionType
102
    public static final int ACTION_TYPE_SELECTION = 0;
103
    public static final int ACTION_TYPE_REMOVE = 1;
104
    public static final int ACTION_TYPE_REFRESH = 2;
105
 
80 ilm 106
    // commitMode
107
    public static final int COMMIT_ONCE = 0;
108
    public static final int COMMIT_INTERACTIVE = 1;
94 ilm 109
    // horizontalAlignement
110
    public static final int HALIGN_RIGHT = 0;
111
    public static final int HALIGN_CENTER = 1;
112
    public static final int HALIGN_LEFT = 2; // Default
113
    // verticalAlignement
114
    public static final int VALIGN_TOP = 0; // Default
115
    public static final int VALIGN_CENTER = 1;
116
    public static final int VALIGN_BOTTOM = 2;
117
    // font size
118
    public static final int FONT_XXSMALL = 0;
119
    public static final int FONT_XSMALL = 1;
120
    public static final int FONT_SMALL = 2; // Default
121
    public static final int FONT_MEDIUM = 3;
122
    public static final int FONT_LARGE = 4;
123
    public static final int FONT_XLARGE = 5;
124
    public static final int FONT_XXLARGE = 6;
73 ilm 125
 
132 ilm 126
    public static final int DEFAULT_GRID_HEIGHT = 1;
127
    public static final int DEFAULT_GRID_WIDTH = 1;
128
    public static final int DEFAULT_WEIGHT_X = 0;
129
    public static final int DEFAULT_WEIGHT_Y = 0;
130
 
131
    private int fontSize = FONT_SMALL;
132
    private int gridHeight = DEFAULT_GRID_HEIGHT;
133
    private int gridWidth = DEFAULT_GRID_WIDTH;
134
    private int horizontalAlignment = HALIGN_LEFT;
135
    private int verticalAlignment = VALIGN_TOP;
136
    private int weightX = DEFAULT_WEIGHT_X;
137
    private int weightY = DEFAULT_WEIGHT_Y;
138
 
94 ilm 139
    private Integer commitMode;
132 ilm 140
    private Integer height;
141
    private Integer marginBottom;
142
    private Integer marginLeft;
143
    private Integer marginRight;
144
    private Integer marginTop;
145
    private Integer maxHeight;
146
    private Integer maxWidth;
94 ilm 147
    private Integer minInputSize;
132 ilm 148
    private Integer minHeight;
149
    private Integer minWidth;
150
    private Integer paddingBottom;
151
    private Integer paddingLeft;
152
    private Integer paddingRight;
153
    private Integer paddingTop;
94 ilm 154
    private Integer type;
155
    private Integer valueType;
132 ilm 156
    private Integer width;
94 ilm 157
 
132 ilm 158
    private boolean enabled = true;
159
    private boolean fillHeight = false;
160
    private boolean fillWidth = false;
94 ilm 161
    private boolean foldable = false;
162
    private boolean folded = false;
132 ilm 163
    private boolean fontBold = false;
164
    private boolean fontItalic = false;
165
    private boolean horizontallyResizable = false;
166
    private boolean readOnly = false;
167
    private boolean required = false;
168
    private boolean verticallyResizable = false;
169
    private boolean visible = true;
142 ilm 170
    private boolean notSaved = false;
171
    private boolean verticallyScrollable = false;
172
    private boolean horizontallyScrollable = false;
94 ilm 173
 
174
    private String displayPrecision;// "(1,2)" means that 0.159 is shown as 0.16
175
    private String icon;
73 ilm 176
    private String id;
177
    private String label;
94 ilm 178
    private String toolTip;
132 ilm 179
    private String UUID;
94 ilm 180
    // Values
73 ilm 181
    private String value;
80 ilm 182
    private String valuePrecision;// "(6,2)" 999999.99 is the max
183
    private String valueRange; // [-3.14,3.14]
184
 
94 ilm 185
    private Color backgroundColor;
132 ilm 186
    private Color borderColor;
187
    private Color cellBackgroundColor;
94 ilm 188
    private Color foreColor;
73 ilm 189
 
132 ilm 190
    private LightUIElement parent;
156 ilm 191
    private boolean destroyed;
132 ilm 192
 
156 ilm 193
    public LightUIElement() {
194
        // Serialization
195
    }
196
 
132 ilm 197
    public LightUIElement(final String id) {
198
        this.id = id;
156 ilm 199
        this.UUID = getNextUUID();// java.util.UUID.randomUUID().toString();
200
    }
132 ilm 201
 
156 ilm 202
    private static long count = 0;
174 ilm 203
    private static Object counterLock = new Object();
156 ilm 204
 
205
    private String getNextUUID() {
206
        String result;
207
        synchronized (counterLock) {
208
            count++;
209
            result = "UUID" + count;
210
        }
211
        return result;
94 ilm 212
    }
213
 
214
    // Init from json constructor
215
    public LightUIElement(final JSONObject json) {
216
        this.fromJSON(json);
217
    }
218
 
219
    // Clone constructor
220
    public LightUIElement(final LightUIElement element) {
149 ilm 221
        throw new IllegalAccessError("??");
222
        // this.id = element.id;
223
        // this.parent = element.parent;
224
        // this.UUID = element.UUID;
225
        // this.type = element.type;
226
        //
227
        // this.copy(element);
94 ilm 228
    }
229
 
132 ilm 230
    public int getFontSize() {
231
        return this.fontSize;
73 ilm 232
    }
233
 
132 ilm 234
    public void setFontSize(final int fontSize) {
235
        this.fontSize = fontSize;
73 ilm 236
    }
237
 
238
    public int getGridWidth() {
93 ilm 239
        return this.gridWidth;
73 ilm 240
    }
241
 
242
    public void setGridWidth(int gridWidth) {
243
        this.gridWidth = gridWidth;
244
    }
245
 
132 ilm 246
    public Integer getHeight() {
247
        return this.height;
248
    }
249
 
250
    public void setHeight(Integer height) {
251
        this.height = height;
252
    }
253
 
254
    public final int getHorizontalAlignment() {
255
        return this.horizontalAlignment;
256
    }
257
 
258
    public final void setHorizontalAlignement(int horizontalAlignement) {
259
        this.horizontalAlignment = horizontalAlignement;
260
    }
261
 
262
    public int getValueType() {
263
        return this.valueType;
264
    }
265
 
266
    public void setValueType(int valueType) {
267
        this.valueType = valueType;
268
    }
269
 
270
    public final int getVerticalAlignment() {
271
        return this.verticalAlignment;
272
    }
273
 
274
    public void setVerticalAlignement(int verticalAlignement) {
275
        this.verticalAlignment = verticalAlignement;
276
    }
277
 
278
    public int getWeightX() {
279
        return this.weightX;
280
    }
281
 
282
    public void setWeightX(final int weightX) {
283
        this.weightX = weightX;
284
    }
285
 
286
    public int getWeightY() {
287
        return this.weightY;
288
    }
289
 
290
    public void setWeightY(final int weightY) {
291
        this.weightY = weightY;
292
    }
293
 
294
    public Integer getCommitMode() {
295
        return this.commitMode;
296
    }
297
 
298
    public void setCommitMode(int commitMode) {
299
        this.commitMode = commitMode;
300
    }
301
 
302
    public Integer getMarginTop() {
303
        return this.marginTop;
304
    }
305
 
306
    public void setMarginTop(Integer marginTop) {
307
        this.marginTop = marginTop;
308
    }
309
 
310
    public Integer getMarginBottom() {
311
        return this.marginBottom;
312
    }
313
 
314
    public void setMarginBottom(Integer marginBottom) {
315
        this.marginBottom = marginBottom;
316
    }
317
 
318
    public Integer getMarginLeft() {
319
        return this.marginLeft;
320
    }
321
 
322
    public void setMarginLeft(final Integer marginLeft) {
323
        this.marginLeft = marginLeft;
324
    }
325
 
326
    public Integer getMarginRight() {
327
        return this.marginRight;
328
    }
329
 
330
    public void setMarginRight(final Integer marginRight) {
331
        this.marginRight = marginRight;
332
    }
333
 
334
    public Integer getMinInputSize() {
335
        return this.minInputSize;
336
    }
337
 
338
    public Integer getMaxHeight() {
339
        return this.maxHeight;
340
    }
341
 
342
    public void setMaxHeight(Integer maxHeight) {
343
        this.maxHeight = maxHeight;
344
    }
345
 
346
    public Integer getMinHeight() {
347
        return this.minHeight;
348
    }
349
 
350
    public void setMinHeight(Integer minHeight) {
351
        this.minHeight = minHeight;
352
    }
353
 
354
    public Integer getMaxWidth() {
355
        return this.maxWidth;
356
    }
357
 
358
    public void setMaxWidth(Integer maxWidth) {
359
        this.maxWidth = maxWidth;
360
    }
361
 
362
    public Integer getMinWidth() {
363
        return this.minWidth;
364
    }
365
 
366
    public void setMinWidth(Integer minWidth) {
367
        this.minWidth = minWidth;
368
    }
369
 
370
    public void setMinInputSize(Integer minInputSize) {
371
        this.minInputSize = minInputSize;
372
    }
373
 
374
    public Integer getPaddingTop() {
375
        return this.paddingTop;
376
    }
377
 
378
    public void setPaddingTop(Integer paddingTop) {
379
        this.paddingTop = paddingTop;
380
    }
381
 
382
    public Integer getPaddingBottom() {
383
        return this.paddingBottom;
384
    }
385
 
386
    public void setPaddingBottom(Integer paddingBottom) {
387
        this.paddingBottom = paddingBottom;
388
    }
389
 
390
    public Integer getPaddingLeft() {
391
        return this.paddingLeft;
392
    }
393
 
394
    public void setPaddingLeft(Integer paddingLeft) {
395
        this.paddingLeft = paddingLeft;
396
    }
397
 
398
    public Integer getPaddingRight() {
399
        return this.paddingRight;
400
    }
401
 
402
    public void setPaddingRight(Integer paddingRight) {
403
        this.paddingRight = paddingRight;
404
    }
405
 
406
    public Integer getType() {
407
        return this.type;
408
    }
409
 
410
    public void setType(int type) {
411
        this.type = type;
412
    }
413
 
414
    public Integer getWidth() {
415
        return this.width;
416
    }
417
 
418
    public void setWidth(Integer width) {
419
        this.width = width;
420
    }
421
 
422
    public boolean isEnabled() {
423
        return this.enabled;
424
    }
425
 
426
    public void setEnabled(boolean enabled) {
427
        this.enabled = enabled;
428
    }
429
 
94 ilm 430
    public boolean isFoldable() {
431
        return this.foldable;
432
    }
433
 
434
    public void setFoldable(boolean foldable) {
435
        this.foldable = foldable;
436
    }
132 ilm 437
 
94 ilm 438
    public boolean isFolded() {
439
        return this.folded;
440
    }
441
 
442
    public void setFolded(boolean folded) {
443
        this.folded = folded;
444
    }
132 ilm 445
 
446
    public boolean isFillHeight() {
447
        return this.fillHeight;
448
    }
449
 
450
    public void setFillHeight(boolean fillHeight) {
451
        this.fillHeight = fillHeight;
452
    }
453
 
73 ilm 454
    public boolean isFillWidth() {
93 ilm 455
        return this.fillWidth;
73 ilm 456
    }
457
 
458
    public void setFillWidth(boolean fillWidth) {
459
        this.fillWidth = fillWidth;
460
    }
461
 
132 ilm 462
    public boolean isReadOnly() {
463
        return this.readOnly;
464
    }
465
 
466
    public void setReadOnly(boolean readOnly) {
467
        this.readOnly = readOnly;
468
    }
469
 
142 ilm 470
    public boolean isNotSaved() {
471
        return this.notSaved;
472
    }
473
 
474
    public void setNotSaved(boolean notSaved) {
475
        this.notSaved = notSaved;
476
    }
477
 
94 ilm 478
    public Color getBackgroundColor() {
479
        return this.backgroundColor;
73 ilm 480
    }
481
 
94 ilm 482
    public void setBackgroundColor(Color backgroundColor) {
483
        this.backgroundColor = backgroundColor;
73 ilm 484
    }
485
 
132 ilm 486
    public Color getBorderColor() {
487
        return this.borderColor;
94 ilm 488
    }
489
 
132 ilm 490
    public void setBorderColor(Color borderColor) {
491
        this.borderColor = borderColor;
94 ilm 492
    }
493
 
132 ilm 494
    public Color getCellBackgroundColor() {
495
        return this.cellBackgroundColor;
94 ilm 496
    }
497
 
132 ilm 498
    public void setCellBackgroundColor(Color cellBackgroundColor) {
499
        this.cellBackgroundColor = cellBackgroundColor;
500
    }
501
 
502
    public Color getForeColor() {
503
        return this.foreColor;
504
    }
505
 
94 ilm 506
    public void setForeColor(Color foreColor) {
507
        this.foreColor = foreColor;
508
    }
509
 
132 ilm 510
    public boolean isFontItalic() {
511
        return this.fontItalic;
512
    }
513
 
514
    public void setFontBold(boolean fontBold) {
515
        this.fontBold = fontBold;
516
    }
517
 
518
    public boolean isFontBold() {
519
        return this.fontBold;
520
    }
521
 
522
    public void setFontItalic(boolean fontItalic) {
523
        this.fontItalic = fontItalic;
524
    }
525
 
73 ilm 526
    public String getIcon() {
93 ilm 527
        return this.icon;
73 ilm 528
    }
529
 
530
    public void setIcon(String icon) {
531
        this.icon = icon;
532
    }
533
 
534
    public String getId() {
93 ilm 535
        return this.id;
73 ilm 536
    }
537
 
132 ilm 538
    public void setId(final String id) {
174 ilm 539
        if (id == null) {
540
            throw new IllegalArgumentException("id cannot be null");
541
        }
73 ilm 542
        this.id = id;
174 ilm 543
 
73 ilm 544
    }
545
 
132 ilm 546
    public String getUUID() {
547
        return this.UUID;
548
    }
549
 
73 ilm 550
    public String getLabel() {
93 ilm 551
        return this.label;
73 ilm 552
    }
553
 
554
    public void setLabel(String label) {
555
        this.label = label;
556
    }
557
 
558
    public String getValue() {
93 ilm 559
        return this.value;
73 ilm 560
    }
561
 
80 ilm 562
    public String getDisplayPrecision() {
93 ilm 563
        return this.displayPrecision;
80 ilm 564
    }
565
 
566
    public void setDisplayPrecision(String displayPrecision) {
567
        this.displayPrecision = displayPrecision;
568
    }
569
 
570
    public String getValuePrecision() {
93 ilm 571
        return this.valuePrecision;
80 ilm 572
    }
573
 
574
    public void setValuePrecision(String valuePrecision) {
575
        this.valuePrecision = valuePrecision;
576
    }
577
 
578
    public String getValueRange() {
93 ilm 579
        return this.valueRange;
80 ilm 580
    }
581
 
582
    public void setValueRange(String valueRange) {
583
        this.valueRange = valueRange;
584
    }
585
 
73 ilm 586
    public void setValue(String value) {
587
        this.value = value;
588
    }
589
 
590
    public boolean isRequired() {
93 ilm 591
        return this.required;
73 ilm 592
    }
593
 
594
    public void setRequired(boolean required) {
595
        this.required = required;
596
    }
597
 
598
    public String getToolTip() {
93 ilm 599
        return this.toolTip;
73 ilm 600
    }
601
 
602
    public void setToolTip(String toolTip) {
603
        this.toolTip = toolTip;
604
    }
605
 
94 ilm 606
    public final boolean isVerticallyResizable() {
607
        return this.verticallyResizable;
73 ilm 608
    }
609
 
142 ilm 610
    public final void setVerticallyResizable(boolean verticallyResizable) {
94 ilm 611
        this.verticallyResizable = verticallyResizable;
83 ilm 612
    }
613
 
142 ilm 614
    public final boolean isHorizontallyResizable() {
94 ilm 615
        return this.horizontallyResizable;
83 ilm 616
    }
617
 
142 ilm 618
    public final void setHorizontallyResizable(boolean horizontallyResizable) {
94 ilm 619
        this.horizontallyResizable = horizontallyResizable;
83 ilm 620
    }
621
 
142 ilm 622
    public final boolean isHorizontallyScrollable() {
623
        return this.horizontallyScrollable;
624
    }
625
 
626
    public final void setHorizontallyScrollable(boolean horizontallyScrollable) {
627
        this.horizontallyScrollable = horizontallyScrollable;
628
    }
629
 
630
    public final boolean isVerticallyScrollable() {
631
        return this.verticallyScrollable;
632
    }
633
 
634
    public final void setVerticallyScrollable(boolean verticallyScrollable) {
635
        this.verticallyScrollable = verticallyScrollable;
636
    }
637
 
132 ilm 638
    public final LightUIElement getParent() {
639
        return this.parent;
83 ilm 640
    }
641
 
142 ilm 642
    public final <T extends LightUIElement> T getParent(final Class<T> expectedClass) {
132 ilm 643
        LightUIElement parent = this.parent;
142 ilm 644
        while (parent != null && !expectedClass.isAssignableFrom(parent.getClass())) {
132 ilm 645
            parent = parent.getParent();
646
        }
142 ilm 647
        return expectedClass.cast(parent);
94 ilm 648
    }
649
 
132 ilm 650
    public void setParent(LightUIElement parent) {
651
        this.parent = parent;
94 ilm 652
    }
653
 
132 ilm 654
    public void dump(PrintStream out, final int depth) {
144 ilm 655
        final String typeAsString = this.getTypeAsString();
656
        String valueTypeAsString = "?";
132 ilm 657
        if (this.valueType != null) {
658
            if (this.valueType == VALUE_TYPE_STRING) {
144 ilm 659
                valueTypeAsString = "string";
132 ilm 660
            } else if (this.valueType == VALUE_TYPE_INTEGER) {
144 ilm 661
                valueTypeAsString = "int";
132 ilm 662
            } else if (this.valueType == VALUE_TYPE_REF) {
144 ilm 663
                valueTypeAsString = "ref";
132 ilm 664
            } else if (this.valueType == VALUE_TYPE_LIST) {
144 ilm 665
                valueTypeAsString = "list";
132 ilm 666
            } else if (this.valueType == VALUE_TYPE_DECIMAL) {
144 ilm 667
                valueTypeAsString = "decimal";
132 ilm 668
            }
73 ilm 669
        }
670
 
144 ilm 671
        String str = "LightUIElement" + "class:" + this.getClassName() + " type:" + typeAsString + " id:" + this.id + " uuid:" + this.UUID + " w:" + this.gridWidth + " fill:" + this.fillWidth;
672
        str += " value:" + this.value + "(" + valueTypeAsString + ")";
93 ilm 673
        if (this.valueRange != null) {
674
            str += "range: " + this.valueRange;
80 ilm 675
        }
93 ilm 676
        if (this.valuePrecision != null) {
677
            str += "precision: " + this.valuePrecision;
80 ilm 678
        }
93 ilm 679
        if (this.displayPrecision != null) {
680
            str += "display prec.: " + this.displayPrecision;
80 ilm 681
        }
93 ilm 682
        if (this.label != null) {
683
            str += " label:" + this.label;
80 ilm 684
        }
94 ilm 685
        if (this.horizontallyResizable) {
83 ilm 686
            str += "|- H ->";
687
        }
94 ilm 688
        if (this.verticallyResizable) {
83 ilm 689
            str += "|- V ->";
690
        }
94 ilm 691
 
692
        switch (this.fontSize) {
693
        case FONT_XXSMALL:
694
            str += " font: xx-small";
695
            break;
696
        case FONT_XSMALL:
697
            str += " font: x-small";
698
            break;
699
        case FONT_SMALL:
700
            str += " font: small";
701
            break;
702
        case FONT_MEDIUM:
703
            str += " font: medium";
704
            break;
705
        case FONT_LARGE:
706
            str += " font: large";
707
            break;
708
        case FONT_XLARGE:
709
            str += " font: x-large";
710
            break;
711
        case FONT_XXLARGE:
712
            str += " font: xx-large";
713
            break;
714
        }
715
 
132 ilm 716
        switch (this.horizontalAlignment) {
94 ilm 717
        case HALIGN_RIGHT:
718
            str += " horiz-align: right";
719
            break;
720
        case HALIGN_CENTER:
721
            str += " horiz-align: center";
722
            break;
723
        case HALIGN_LEFT:
724
            str += " horiz-align: left";
725
            break;
726
        }
727
 
132 ilm 728
        switch (this.verticalAlignment) {
94 ilm 729
        case HALIGN_RIGHT:
730
            str += " vert-align: top";
731
            break;
732
        case HALIGN_CENTER:
733
            str += " vert-align: center";
734
            break;
735
        case HALIGN_LEFT:
736
            str += " vert-align: bottom";
737
            break;
738
        }
132 ilm 739
        addSpacer(out, depth);
80 ilm 740
        out.println(str);
73 ilm 741
 
742
    }
743
 
142 ilm 744
    protected final void addSpacer(PrintStream out, int depth) {
132 ilm 745
        for (int i = 0; i < depth; i++) {
746
            out.print("  ");
747
        }
748
    }
749
 
142 ilm 750
    public final String getTypeAsString() {
156 ilm 751
        String result = "?";
132 ilm 752
        if (this.type == TYPE_CHECKBOX) {
156 ilm 753
            result = "checkbox";
132 ilm 754
        } else if (this.type == TYPE_COMBOBOX) {
156 ilm 755
            result = "combobox";
132 ilm 756
        } else if (this.type == TYPE_LABEL) {
156 ilm 757
            result = "label";
132 ilm 758
        } else if (this.type == TYPE_TEXT_AREA) {
156 ilm 759
            result = "textarea";
132 ilm 760
        } else if (this.type == TYPE_TEXT_FIELD) {
156 ilm 761
            result = "textfield";
132 ilm 762
        } else if (this.type == TYPE_TABLE) {
156 ilm 763
            result = "table";
132 ilm 764
        } else if (this.type == TYPE_TABBED_UI) {
156 ilm 765
            result = "tabs";
132 ilm 766
        } else if (this.type == TYPE_TREE) {
156 ilm 767
            result = "tree";
132 ilm 768
        } else if (this.type == TYPE_BUTTON) {
156 ilm 769
            result = "button";
132 ilm 770
        } else if (this.type == TYPE_BUTTON_WITH_CONTEXT) {
156 ilm 771
            result = "button with context";
132 ilm 772
        } else if (this.type == TYPE_BUTTON_CANCEL) {
156 ilm 773
            result = "cancel button";
132 ilm 774
        } else if (this.type == TYPE_COMBOBOX_ELEMENT) {
156 ilm 775
            result = "combo element";
132 ilm 776
        } else if (this.type == TYPE_BUTTON_WITH_SELECTION_CONTEXT) {
156 ilm 777
            result = "button with selection context";
142 ilm 778
        } else if (this.type == TYPE_FILE_UPLOAD_WITH_SELECTION) {
156 ilm 779
            result = "file upload with selection";
132 ilm 780
        } else if (this.type == TYPE_FRAME) {
156 ilm 781
            result = "frame";
132 ilm 782
        } else if (this.type == TYPE_DROPDOWN_BUTTON) {
156 ilm 783
            result = "drop down button";
132 ilm 784
        } else if (this.type == TYPE_IMAGE) {
156 ilm 785
            result = "image";
132 ilm 786
        } else if (this.type == TYPE_LIST) {
156 ilm 787
            result = "list";
132 ilm 788
        } else if (this.type == TYPE_RAW_HTML) {
156 ilm 789
            result = "raw html";
142 ilm 790
        } else if (this.type == TYPE_SLIDER) {
156 ilm 791
            result = "slider";
142 ilm 792
        } else if (this.type == TYPE_PICTURE_UPLOAD) {
156 ilm 793
            result = "picture upload";
142 ilm 794
        } else if (this.type == TYPE_FILE_UPLOAD) {
156 ilm 795
            result = "file upload";
132 ilm 796
        }
797
 
156 ilm 798
        return result;
132 ilm 799
    }
800
 
801
    public String getClassName() {
802
        return this.getClass().getName();
803
    }
804
 
149 ilm 805
    /**
806
     * { return new JSONToLightUIConvertor() {
807
     *
808
     * @Override public LightUIElement convert(final JSONObject json) { return new
809
     *           LightUIElement(json); } }; }
810
     */
811
 
132 ilm 812
    protected void copy(final LightUIElement element) {
813
        if (element == null) {
814
            throw new IllegalArgumentException("Try to copy attributes of null element in " + this.getId());
815
        }
174 ilm 816
        System.err.println("LightUIElement.copy() " + element);
817
        this.UUID = getNextUUID();
818
        this.id = element.getId();
132 ilm 819
        this.fontSize = element.fontSize;
820
        this.gridHeight = element.gridHeight;
821
        this.gridWidth = element.gridWidth;
822
        this.horizontalAlignment = element.horizontalAlignment;
823
        this.verticalAlignment = element.verticalAlignment;
824
        this.weightX = element.weightX;
825
 
826
        this.commitMode = element.commitMode;
827
        this.height = element.height;
828
        this.marginBottom = element.marginBottom;
829
        this.marginLeft = element.marginLeft;
830
        this.marginRight = element.marginRight;
831
        this.marginTop = element.marginTop;
832
        this.maxHeight = element.maxHeight;
833
        this.maxWidth = element.maxWidth;
834
        this.minInputSize = element.minInputSize;
835
        this.minHeight = element.minHeight;
836
        this.minWidth = element.minWidth;
837
        this.paddingBottom = element.paddingBottom;
838
        this.paddingLeft = element.paddingLeft;
839
        this.paddingRight = element.paddingRight;
840
        this.paddingTop = element.paddingTop;
841
        this.valueType = element.valueType;
842
        this.width = element.width;
843
 
844
        this.enabled = element.enabled;
845
        this.fillWidth = element.fillWidth;
142 ilm 846
        this.fillHeight = element.fillHeight;
132 ilm 847
        this.foldable = element.foldable;
848
        this.folded = element.folded;
849
        this.fontBold = element.fontBold;
850
        this.fontItalic = element.fontItalic;
851
        this.horizontallyResizable = element.horizontallyResizable;
142 ilm 852
        this.horizontallyScrollable = element.horizontallyScrollable;
132 ilm 853
        this.required = element.required;
854
        this.readOnly = element.readOnly;
855
        this.verticallyResizable = element.verticallyResizable;
142 ilm 856
        this.verticallyScrollable = element.verticallyScrollable;
132 ilm 857
        this.visible = element.visible;
142 ilm 858
        this.notSaved = element.notSaved;
132 ilm 859
 
860
        this.displayPrecision = element.displayPrecision;
861
        this.icon = element.icon;
862
        this.label = element.label;
863
        this.toolTip = element.toolTip;
864
        this.value = element.value;
865
        this.valuePrecision = element.valuePrecision;
866
        this.valueRange = element.valueRange;
867
 
868
        this.backgroundColor = element.backgroundColor;
869
        this.borderColor = element.borderColor;
870
        this.cellBackgroundColor = element.cellBackgroundColor;
871
        this.foreColor = element.foreColor;
872
    }
873
 
73 ilm 874
    @Override
875
    public String toString() {
174 ilm 876
        if (!this.destroyed) {
156 ilm 877
            return super.toString() + " " + this.id;
878
        } else {
879
            return super.toString() + " " + this.id + " DESTROYED";
880
        }
73 ilm 881
    }
882
 
94 ilm 883
    @Override
884
    public JSONObject toJSON() {
885
        final JSONObject result = new JSONObject();
73 ilm 886
 
132 ilm 887
        result.put("class-name", this.getClassName());
94 ilm 888
 
132 ilm 889
        if (this.fontSize != FONT_SMALL) {
890
            result.put("font-size", this.fontSize);
94 ilm 891
        }
132 ilm 892
        if (this.gridWidth != DEFAULT_GRID_WIDTH) {
893
            result.put("grid-width", this.gridWidth);
894
        }
895
        if (this.gridHeight != DEFAULT_GRID_HEIGHT) {
896
            result.put("grid-height", this.gridHeight);
897
        }
898
        if (this.horizontalAlignment != HALIGN_LEFT) {
899
            result.put("horizontal-alignment", this.horizontalAlignment);
900
        }
901
        if (this.verticalAlignment != VALIGN_TOP) {
902
            result.put("vertical-alignment", this.verticalAlignment);
903
        }
904
        if (this.weightX != DEFAULT_WEIGHT_X) {
905
            result.put("weight-x", this.weightX);
906
        }
156 ilm 907
        if (this.weightY != DEFAULT_WEIGHT_Y) {
908
            result.put("weight-y", this.weightY);
909
        }
94 ilm 910
        if (this.commitMode != null) {
911
            result.put("commit-mode", this.commitMode);
912
        }
156 ilm 913
        if (this.width != null) {
914
            result.put("width", this.width);
915
        }
132 ilm 916
        if (this.height != null) {
917
            result.put("height", this.height);
94 ilm 918
        }
132 ilm 919
        if (this.marginBottom != null) {
920
            result.put("m-bottom", this.marginBottom);
921
        }
922
        if (this.marginLeft != null) {
923
            result.put("m-left", this.marginLeft);
924
        }
925
        if (this.marginRight != null) {
926
            result.put("m-right", this.marginRight);
927
        }
928
        if (this.marginTop != null) {
929
            result.put("m-top", this.marginTop);
930
        }
931
        if (this.maxHeight != null) {
932
            result.put("max-height", this.maxHeight);
933
        }
934
        if (this.maxWidth != null) {
935
            result.put("max-width", this.maxWidth);
936
        }
937
        if (this.minInputSize != null) {
938
            result.put("min-input-size", this.minInputSize);
939
        }
940
        if (this.minHeight != null) {
941
            result.put("min-height", this.minHeight);
942
        }
943
        if (this.minWidth != null) {
944
            result.put("min-width", this.minWidth);
945
        }
946
        if (this.paddingBottom != null) {
947
            result.put("p-bottom", this.paddingBottom);
948
        }
949
        if (this.paddingLeft != null) {
950
            result.put("p-left", this.paddingLeft);
951
        }
952
        if (this.paddingRight != null) {
953
            result.put("p-right", this.paddingRight);
954
        }
955
        if (this.paddingTop != null) {
956
            result.put("p-top", this.paddingTop);
957
        }
958
        result.put("type", this.type);
959
        if (this.valueType != null) {
960
            result.put("value-type", this.valueType);
961
        }
962
 
963
        if (!this.enabled) {
964
            result.put("enabled", false);
965
        }
966
        if (this.fillWidth) {
967
            result.put("fill-width", true);
968
        }
142 ilm 969
        if (this.fillHeight) {
970
            result.put("fill-height", true);
971
        }
94 ilm 972
        if (this.foldable) {
973
            result.put("foldable", true);
974
        }
975
        if (this.folded) {
976
            result.put("folded", true);
977
        }
132 ilm 978
        if (this.fontBold) {
979
            result.put("bold", true);
94 ilm 980
        }
132 ilm 981
        if (this.fontItalic) {
982
            result.put("italic", true);
94 ilm 983
        }
984
        if (this.horizontallyResizable) {
142 ilm 985
            result.put(HORIZONTALLY_RESIZABLE, true);
94 ilm 986
        }
142 ilm 987
        if (this.horizontallyScrollable) {
988
            result.put(HORIZONTALLY_SCROLLABLE, true);
989
        }
132 ilm 990
        if (this.required) {
991
            result.put("required", true);
992
        }
993
        if (this.readOnly) {
994
            result.put("read-only", true);
995
        }
94 ilm 996
        if (this.verticallyResizable) {
142 ilm 997
            result.put(VERTICALLY_RESIZABLE, true);
94 ilm 998
        }
142 ilm 999
        if (this.verticallyScrollable) {
1000
            result.put(VERTICALLY_SCROLLABLE, true);
1001
        }
132 ilm 1002
        if (!this.visible) {
1003
            result.put("visible", false);
1004
        }
142 ilm 1005
        if (this.notSaved) {
1006
            result.put("not-saved", true);
1007
        }
132 ilm 1008
 
1009
        if (this.displayPrecision != null) {
1010
            result.put("display-precision", this.displayPrecision);
1011
        }
94 ilm 1012
        if (this.icon != null) {
1013
            result.put("icon", this.icon);
1014
        }
132 ilm 1015
        result.put("id", this.id);
94 ilm 1016
        if (this.label != null) {
1017
            result.put("label", this.label);
1018
        }
1019
        if (this.toolTip != null) {
1020
            result.put("tool-tip", this.toolTip);
1021
        }
174 ilm 1022
        if (this.UUID == null) {
1023
            throw new IllegalStateException("null UUID, id: " + this.id);
1024
        }
132 ilm 1025
        result.put("uuid", this.UUID);
1026
        if (this.value != null) {
1027
            result.put("value", this.value);
1028
        }
94 ilm 1029
        if (this.valuePrecision != null) {
1030
            result.put("value-precision", this.valuePrecision);
1031
        }
1032
        if (this.valueRange != null) {
1033
            result.put("value-range", this.valueRange);
1034
        }
132 ilm 1035
 
1036
        if (this.backgroundColor != null) {
1037
            result.put("background-color", JSONConverter.getJSON(this.backgroundColor));
94 ilm 1038
        }
132 ilm 1039
        if (this.borderColor != null) {
1040
            result.put("border-color", JSONConverter.getJSON(this.borderColor));
94 ilm 1041
        }
132 ilm 1042
        if (this.cellBackgroundColor != null) {
1043
            result.put("cell-background-color", JSONConverter.getJSON(this.cellBackgroundColor));
94 ilm 1044
        }
132 ilm 1045
        if (this.foreColor != null) {
1046
            result.put("fore-color", JSONConverter.getJSON(this.foreColor));
94 ilm 1047
        }
149 ilm 1048
        if (this instanceof HTMLable) {
1049
            result.put("html", ((HTMLable) this).getHTML());
1050
        }
94 ilm 1051
        return result;
73 ilm 1052
    }
1053
 
93 ilm 1054
    @Override
94 ilm 1055
    public void fromJSON(final JSONObject json) {
132 ilm 1056
        this.id = JSONConverter.getParameterFromJSON(json, "id", String.class);
1057
        this.UUID = JSONConverter.getParameterFromJSON(json, "uuid", String.class);
174 ilm 1058
        if (this.UUID == null) {
1059
            throw new IllegalArgumentException("null UUID, id : " + this.id);
1060
        }
132 ilm 1061
        this.displayPrecision = JSONConverter.getParameterFromJSON(json, "display-precision", String.class);
1062
        this.icon = JSONConverter.getParameterFromJSON(json, "icon", String.class);
1063
        this.label = JSONConverter.getParameterFromJSON(json, "label", String.class);
93 ilm 1064
 
132 ilm 1065
        this.toolTip = JSONConverter.getParameterFromJSON(json, "tool-tip", String.class);
1066
        this.value = JSONConverter.getParameterFromJSON(json, "value", String.class);
1067
        this.valuePrecision = JSONConverter.getParameterFromJSON(json, "value-precision", String.class);
1068
        this.valueRange = JSONConverter.getParameterFromJSON(json, "value-range", String.class);
93 ilm 1069
 
132 ilm 1070
        this.commitMode = JSONConverter.getParameterFromJSON(json, "commit-mode", Integer.class);
1071
        this.fontSize = JSONConverter.getParameterFromJSON(json, "font-size", Integer.class, FONT_SMALL);
1072
        this.gridWidth = JSONConverter.getParameterFromJSON(json, "grid-width", Integer.class, DEFAULT_GRID_WIDTH);
1073
        this.gridHeight = JSONConverter.getParameterFromJSON(json, "grid-height", Integer.class, DEFAULT_GRID_HEIGHT);
1074
        this.horizontalAlignment = JSONConverter.getParameterFromJSON(json, "horizontal-alignment", Integer.class, HALIGN_LEFT);
1075
        this.verticalAlignment = JSONConverter.getParameterFromJSON(json, "vertical-alignment", Integer.class, VALIGN_TOP);
1076
        this.weightX = JSONConverter.getParameterFromJSON(json, "weight-x", Integer.class, DEFAULT_WEIGHT_X);
156 ilm 1077
        this.weightY = JSONConverter.getParameterFromJSON(json, "weight-y", Integer.class, DEFAULT_WEIGHT_Y);
132 ilm 1078
        this.minInputSize = JSONConverter.getParameterFromJSON(json, "min-input-size", Integer.class);
1079
        this.type = JSONConverter.getParameterFromJSON(json, "type", Integer.class);
1080
        this.valueType = JSONConverter.getParameterFromJSON(json, "value-type", Integer.class);
1081
        this.width = JSONConverter.getParameterFromJSON(json, "width", Integer.class);
156 ilm 1082
        this.height = JSONConverter.getParameterFromJSON(json, "height", Integer.class);
132 ilm 1083
        this.marginTop = JSONConverter.getParameterFromJSON(json, "m-top", Integer.class);
1084
        this.marginBottom = JSONConverter.getParameterFromJSON(json, "m-bottom", Integer.class);
1085
        this.marginLeft = JSONConverter.getParameterFromJSON(json, "m-left", Integer.class);
1086
        this.marginRight = JSONConverter.getParameterFromJSON(json, "m-right", Integer.class);
1087
        this.maxWidth = JSONConverter.getParameterFromJSON(json, "max-width", Integer.class);
1088
        this.minWidth = JSONConverter.getParameterFromJSON(json, "min-width", Integer.class);
156 ilm 1089
 
132 ilm 1090
        this.maxHeight = JSONConverter.getParameterFromJSON(json, "max-height", Integer.class);
1091
        this.minHeight = JSONConverter.getParameterFromJSON(json, "min-height", Integer.class);
1092
        this.paddingTop = JSONConverter.getParameterFromJSON(json, "p-top", Integer.class);
1093
        this.paddingBottom = JSONConverter.getParameterFromJSON(json, "p-bottom", Integer.class);
1094
        this.paddingLeft = JSONConverter.getParameterFromJSON(json, "p-left", Integer.class);
1095
        this.paddingRight = JSONConverter.getParameterFromJSON(json, "p-right", Integer.class);
93 ilm 1096
 
132 ilm 1097
        this.enabled = JSONConverter.getParameterFromJSON(json, "enabled", Boolean.class, true);
1098
        this.foldable = JSONConverter.getParameterFromJSON(json, "foldable", Boolean.class, false);
1099
        this.folded = JSONConverter.getParameterFromJSON(json, "folded", Boolean.class, false);
1100
        this.fillWidth = JSONConverter.getParameterFromJSON(json, "fill-width", Boolean.class, false);
1101
        this.fontBold = JSONConverter.getParameterFromJSON(json, "bold", Boolean.class, false);
1102
        this.fontItalic = JSONConverter.getParameterFromJSON(json, "italic", Boolean.class, false);
142 ilm 1103
        this.horizontallyResizable = JSONConverter.getParameterFromJSON(json, HORIZONTALLY_RESIZABLE, Boolean.class, false);
1104
        this.horizontallyScrollable = JSONConverter.getParameterFromJSON(json, HORIZONTALLY_SCROLLABLE, Boolean.class, false);
1105
        this.verticallyResizable = JSONConverter.getParameterFromJSON(json, VERTICALLY_RESIZABLE, Boolean.class, false);
1106
        this.verticallyScrollable = JSONConverter.getParameterFromJSON(json, VERTICALLY_SCROLLABLE, Boolean.class, false);
132 ilm 1107
        this.required = JSONConverter.getParameterFromJSON(json, "required", Boolean.class, false);
1108
        this.readOnly = JSONConverter.getParameterFromJSON(json, "read-only", Boolean.class, false);
1109
        this.visible = JSONConverter.getParameterFromJSON(json, "visible", Boolean.class, true);
142 ilm 1110
        this.notSaved = JSONConverter.getParameterFromJSON(json, "not-saved", Boolean.class, false);
132 ilm 1111
 
1112
        this.backgroundColor = JSONConverter.getParameterFromJSON(json, "background-color", Color.class);
1113
        this.borderColor = JSONConverter.getParameterFromJSON(json, "border-color", Color.class);
1114
        this.cellBackgroundColor = JSONConverter.getParameterFromJSON(json, "cell-background-color", Color.class);
1115
        this.foreColor = JSONConverter.getParameterFromJSON(json, "fore-color", Color.class);
93 ilm 1116
    }
142 ilm 1117
 
1118
    public void destroy() {
1119
        this.setValue(null);
156 ilm 1120
        this.parent = null;
1121
        this.destroyed = true;
142 ilm 1122
    }
156 ilm 1123
 
1124
    public boolean isDestroyed() {
174 ilm 1125
        return this.destroyed;
156 ilm 1126
    }
1127
 
1128
    @Override
1129
    public void writeExternal(ObjectOutput out) throws IOException {
1130
        out.writeInt(this.type);
1131
        if (this.id == null) {
1132
            throw new IllegalStateException("null id");
1133
        }
1134
        out.writeUTF(this.id);
1135
        if (this.UUID == null) {
174 ilm 1136
            throw new IllegalStateException("null UUID, id : " + this.id);
156 ilm 1137
        }
1138
        out.writeUTF(this.UUID);
1139
 
1140
        writeIfNotNull(out, this.label);
1141
        writeIfNotNull(out, this.value);
1142
 
1143
        out.writeInt(this.fontSize);
1144
        out.writeInt(this.gridWidth);
1145
        out.writeInt(this.gridHeight);
1146
 
1147
        out.writeByte(this.horizontalAlignment);
1148
        out.writeByte(this.verticalAlignment);
1149
        out.writeByte(this.weightX);
1150
        out.writeByte(this.weightY);
1151
 
1152
        writeIfNotNull(out, this.commitMode);
1153
        writeIfNotNull(out, this.width);
1154
        writeIfNotNull(out, this.height);
1155
 
1156
        // Margins
1157
        writeIfNotNull(out, this.marginBottom);
1158
        writeIfNotNull(out, this.marginLeft);
1159
        writeIfNotNull(out, this.marginRight);
1160
        writeIfNotNull(out, this.marginTop);
1161
        //
1162
        writeIfNotNull(out, this.maxHeight);
1163
        writeIfNotNull(out, this.maxWidth);
1164
 
1165
        writeIfNotNull(out, this.minInputSize);
1166
        writeIfNotNull(out, this.minHeight);
1167
        writeIfNotNull(out, this.minWidth);
1168
 
1169
        // Paddings
1170
        writeIfNotNull(out, this.paddingBottom);
1171
        writeIfNotNull(out, this.paddingLeft);
1172
        writeIfNotNull(out, this.paddingRight);
1173
        writeIfNotNull(out, this.paddingTop);
1174
 
1175
        writeIfNotNull(out, this.valueType);
1176
 
1177
        out.writeBoolean(this.enabled);
1178
        out.writeBoolean(this.fillWidth);
1179
        out.writeBoolean(this.fillHeight);
1180
        out.writeBoolean(this.foldable);
1181
        out.writeBoolean(this.folded);
1182
        out.writeBoolean(this.fontBold);
1183
        out.writeBoolean(this.fontItalic);
1184
        out.writeBoolean(this.horizontallyResizable);
1185
        out.writeBoolean(this.horizontallyScrollable);
1186
        out.writeBoolean(this.required);
1187
        out.writeBoolean(this.readOnly);
1188
        out.writeBoolean(this.verticallyResizable);
1189
        out.writeBoolean(this.verticallyScrollable);
1190
 
1191
        out.writeBoolean(this.visible);
1192
        out.writeBoolean(this.notSaved);
1193
 
1194
        writeIfNotNull(out, this.displayPrecision);
1195
        writeIfNotNull(out, this.icon);
1196
        writeIfNotNull(out, this.toolTip);
1197
        writeIfNotNull(out, this.valuePrecision);
1198
        writeIfNotNull(out, this.valueRange);
1199
 
1200
        // Colors
1201
        writeIfNotNull(out, this.backgroundColor);
1202
        writeIfNotNull(out, this.borderColor);
1203
        writeIfNotNull(out, this.cellBackgroundColor);
1204
        writeIfNotNull(out, this.foreColor);
1205
    }
1206
 
1207
    void writeIfNotNull(ObjectOutput out, String s) throws IOException {
1208
        if (s != null) {
1209
            out.writeBoolean(true);
1210
            out.writeUTF(s);
1211
        } else {
1212
            out.writeBoolean(false);
1213
        }
1214
    }
1215
 
1216
    void writeIfNotNull(ObjectOutput out, Integer s) throws IOException {
1217
        if (s != null) {
1218
            out.writeBoolean(true);
1219
            out.writeInt(s);
1220
        } else {
1221
            out.writeBoolean(false);
1222
        }
1223
    }
1224
 
1225
    void writeIfNotNull(ObjectOutput out, Color s) throws IOException {
1226
        if (s != null) {
1227
            out.writeBoolean(true);
1228
            out.writeInt(s.getRGB());
1229
        } else {
1230
            out.writeBoolean(false);
1231
        }
1232
    }
1233
 
1234
    @Override
1235
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
1236
        this.type = in.readInt();
1237
        this.id = in.readUTF();
1238
        this.UUID = in.readUTF();
174 ilm 1239
        if (this.UUID == null) {
1240
            throw new IllegalStateException("null UUID, id : " + this.id);
1241
        }
156 ilm 1242
        if (in.readBoolean()) {
1243
            this.label = in.readUTF();
1244
        }
1245
        if (in.readBoolean()) {
1246
            this.value = in.readUTF();
1247
        }
1248
        this.fontSize = in.readInt();
1249
        this.gridWidth = in.readInt();
1250
        this.gridHeight = in.readInt();
1251
        this.horizontalAlignment = in.readByte();
1252
        this.verticalAlignment = in.readByte();
1253
        this.weightX = in.readByte();
1254
        this.weightY = in.readByte();
1255
 
1256
        if (in.readBoolean()) {
1257
            this.commitMode = in.readInt();
1258
        }
1259
        if (in.readBoolean()) {
1260
            this.width = in.readInt();
1261
        }
1262
        if (in.readBoolean()) {
1263
            this.height = in.readInt();
1264
        }
1265
        // Margins
1266
        if (in.readBoolean()) {
1267
            this.marginBottom = in.readInt();
1268
        }
1269
        if (in.readBoolean()) {
1270
            this.marginLeft = in.readInt();
1271
        }
1272
        if (in.readBoolean()) {
1273
            this.marginRight = in.readInt();
1274
        }
1275
        if (in.readBoolean()) {
1276
            this.marginTop = in.readInt();
1277
        }
1278
 
1279
        //
1280
        if (in.readBoolean()) {
1281
            this.maxHeight = in.readInt();
1282
        }
1283
        if (in.readBoolean()) {
1284
            this.maxWidth = in.readInt();
1285
        }
1286
 
1287
        if (in.readBoolean()) {
1288
            this.minInputSize = in.readInt();
1289
        }
1290
        if (in.readBoolean()) {
1291
            this.minHeight = in.readInt();
1292
        }
1293
        if (in.readBoolean()) {
1294
            this.minWidth = in.readInt();
1295
        }
1296
 
1297
        // Paddings
1298
        if (in.readBoolean()) {
1299
            this.paddingBottom = in.readInt();
1300
        }
1301
        if (in.readBoolean()) {
1302
            this.paddingLeft = in.readInt();
1303
        }
1304
        if (in.readBoolean()) {
1305
            this.paddingRight = in.readInt();
1306
        }
1307
        if (in.readBoolean()) {
1308
            this.paddingTop = in.readInt();
1309
        }
1310
        if (in.readBoolean()) {
1311
            this.valueType = in.readInt();
1312
        }
1313
 
1314
        this.enabled = in.readBoolean();
1315
        this.fillWidth = in.readBoolean();
1316
        this.fillHeight = in.readBoolean();
1317
        this.foldable = in.readBoolean();
1318
        this.folded = in.readBoolean();
1319
        this.fontBold = in.readBoolean();
1320
        this.fontItalic = in.readBoolean();
1321
        this.horizontallyResizable = in.readBoolean();
1322
        this.horizontallyScrollable = in.readBoolean();
1323
        this.required = in.readBoolean();
1324
        this.readOnly = in.readBoolean();
1325
        this.verticallyResizable = in.readBoolean();
1326
        this.verticallyScrollable = in.readBoolean();
1327
 
1328
        //
1329
        this.visible = in.readBoolean();
1330
        this.notSaved = in.readBoolean();
1331
        if (in.readBoolean()) {
1332
            this.displayPrecision = in.readUTF();
1333
        }
1334
        if (in.readBoolean()) {
1335
            this.icon = in.readUTF();
1336
        }
1337
        if (in.readBoolean()) {
1338
            this.toolTip = in.readUTF();
1339
        }
1340
        if (in.readBoolean()) {
1341
            this.valuePrecision = in.readUTF();
1342
        }
1343
        if (in.readBoolean()) {
1344
            this.valueRange = in.readUTF();
1345
        }
1346
        // Colors
1347
        if (in.readBoolean()) {
1348
            this.backgroundColor = new Color(in.readInt());
1349
        }
1350
        if (in.readBoolean()) {
1351
            this.borderColor = new Color(in.readInt());
1352
        }
1353
        if (in.readBoolean()) {
1354
            this.cellBackgroundColor = new Color(in.readInt());
1355
        }
1356
        if (in.readBoolean()) {
1357
            this.foreColor = new Color(in.readInt());
1358
        }
1359
    }
73 ilm 1360
}