OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Rev 174 | Go to most recent revision | 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(
38
                "#unlock"), DOWNLOAD("#download"), UPLOAD("#upload");
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;
203
    private static Integer counterLock = new Integer(123456);
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) {
73 ilm 539
        this.id = id;
540
    }
541
 
132 ilm 542
    public String getUUID() {
543
        return this.UUID;
544
    }
545
 
73 ilm 546
    public String getLabel() {
93 ilm 547
        return this.label;
73 ilm 548
    }
549
 
550
    public void setLabel(String label) {
551
        this.label = label;
552
    }
553
 
554
    public String getValue() {
93 ilm 555
        return this.value;
73 ilm 556
    }
557
 
80 ilm 558
    public String getDisplayPrecision() {
93 ilm 559
        return this.displayPrecision;
80 ilm 560
    }
561
 
562
    public void setDisplayPrecision(String displayPrecision) {
563
        this.displayPrecision = displayPrecision;
564
    }
565
 
566
    public String getValuePrecision() {
93 ilm 567
        return this.valuePrecision;
80 ilm 568
    }
569
 
570
    public void setValuePrecision(String valuePrecision) {
571
        this.valuePrecision = valuePrecision;
572
    }
573
 
574
    public String getValueRange() {
93 ilm 575
        return this.valueRange;
80 ilm 576
    }
577
 
578
    public void setValueRange(String valueRange) {
579
        this.valueRange = valueRange;
580
    }
581
 
73 ilm 582
    public void setValue(String value) {
583
        this.value = value;
584
    }
585
 
586
    public boolean isRequired() {
93 ilm 587
        return this.required;
73 ilm 588
    }
589
 
590
    public void setRequired(boolean required) {
591
        this.required = required;
592
    }
593
 
594
    public String getToolTip() {
93 ilm 595
        return this.toolTip;
73 ilm 596
    }
597
 
598
    public void setToolTip(String toolTip) {
599
        this.toolTip = toolTip;
600
    }
601
 
94 ilm 602
    public final boolean isVerticallyResizable() {
603
        return this.verticallyResizable;
73 ilm 604
    }
605
 
142 ilm 606
    public final void setVerticallyResizable(boolean verticallyResizable) {
94 ilm 607
        this.verticallyResizable = verticallyResizable;
83 ilm 608
    }
609
 
142 ilm 610
    public final boolean isHorizontallyResizable() {
94 ilm 611
        return this.horizontallyResizable;
83 ilm 612
    }
613
 
142 ilm 614
    public final void setHorizontallyResizable(boolean horizontallyResizable) {
94 ilm 615
        this.horizontallyResizable = horizontallyResizable;
83 ilm 616
    }
617
 
142 ilm 618
    public final boolean isHorizontallyScrollable() {
619
        return this.horizontallyScrollable;
620
    }
621
 
622
    public final void setHorizontallyScrollable(boolean horizontallyScrollable) {
623
        this.horizontallyScrollable = horizontallyScrollable;
624
    }
625
 
626
    public final boolean isVerticallyScrollable() {
627
        return this.verticallyScrollable;
628
    }
629
 
630
    public final void setVerticallyScrollable(boolean verticallyScrollable) {
631
        this.verticallyScrollable = verticallyScrollable;
632
    }
633
 
132 ilm 634
    public final LightUIElement getParent() {
635
        return this.parent;
83 ilm 636
    }
637
 
142 ilm 638
    public final <T extends LightUIElement> T getParent(final Class<T> expectedClass) {
132 ilm 639
        LightUIElement parent = this.parent;
142 ilm 640
        while (parent != null && !expectedClass.isAssignableFrom(parent.getClass())) {
132 ilm 641
            parent = parent.getParent();
642
        }
142 ilm 643
        return expectedClass.cast(parent);
94 ilm 644
    }
645
 
132 ilm 646
    public void setParent(LightUIElement parent) {
647
        this.parent = parent;
94 ilm 648
    }
649
 
132 ilm 650
    public void dump(PrintStream out, final int depth) {
144 ilm 651
        final String typeAsString = this.getTypeAsString();
652
        String valueTypeAsString = "?";
132 ilm 653
        if (this.valueType != null) {
654
            if (this.valueType == VALUE_TYPE_STRING) {
144 ilm 655
                valueTypeAsString = "string";
132 ilm 656
            } else if (this.valueType == VALUE_TYPE_INTEGER) {
144 ilm 657
                valueTypeAsString = "int";
132 ilm 658
            } else if (this.valueType == VALUE_TYPE_REF) {
144 ilm 659
                valueTypeAsString = "ref";
132 ilm 660
            } else if (this.valueType == VALUE_TYPE_LIST) {
144 ilm 661
                valueTypeAsString = "list";
132 ilm 662
            } else if (this.valueType == VALUE_TYPE_DECIMAL) {
144 ilm 663
                valueTypeAsString = "decimal";
132 ilm 664
            }
73 ilm 665
        }
666
 
144 ilm 667
        String str = "LightUIElement" + "class:" + this.getClassName() + " type:" + typeAsString + " id:" + this.id + " uuid:" + this.UUID + " w:" + this.gridWidth + " fill:" + this.fillWidth;
668
        str += " value:" + this.value + "(" + valueTypeAsString + ")";
93 ilm 669
        if (this.valueRange != null) {
670
            str += "range: " + this.valueRange;
80 ilm 671
        }
93 ilm 672
        if (this.valuePrecision != null) {
673
            str += "precision: " + this.valuePrecision;
80 ilm 674
        }
93 ilm 675
        if (this.displayPrecision != null) {
676
            str += "display prec.: " + this.displayPrecision;
80 ilm 677
        }
93 ilm 678
        if (this.label != null) {
679
            str += " label:" + this.label;
80 ilm 680
        }
94 ilm 681
        if (this.horizontallyResizable) {
83 ilm 682
            str += "|- H ->";
683
        }
94 ilm 684
        if (this.verticallyResizable) {
83 ilm 685
            str += "|- V ->";
686
        }
94 ilm 687
 
688
        switch (this.fontSize) {
689
        case FONT_XXSMALL:
690
            str += " font: xx-small";
691
            break;
692
        case FONT_XSMALL:
693
            str += " font: x-small";
694
            break;
695
        case FONT_SMALL:
696
            str += " font: small";
697
            break;
698
        case FONT_MEDIUM:
699
            str += " font: medium";
700
            break;
701
        case FONT_LARGE:
702
            str += " font: large";
703
            break;
704
        case FONT_XLARGE:
705
            str += " font: x-large";
706
            break;
707
        case FONT_XXLARGE:
708
            str += " font: xx-large";
709
            break;
710
        }
711
 
132 ilm 712
        switch (this.horizontalAlignment) {
94 ilm 713
        case HALIGN_RIGHT:
714
            str += " horiz-align: right";
715
            break;
716
        case HALIGN_CENTER:
717
            str += " horiz-align: center";
718
            break;
719
        case HALIGN_LEFT:
720
            str += " horiz-align: left";
721
            break;
722
        }
723
 
132 ilm 724
        switch (this.verticalAlignment) {
94 ilm 725
        case HALIGN_RIGHT:
726
            str += " vert-align: top";
727
            break;
728
        case HALIGN_CENTER:
729
            str += " vert-align: center";
730
            break;
731
        case HALIGN_LEFT:
732
            str += " vert-align: bottom";
733
            break;
734
        }
132 ilm 735
        addSpacer(out, depth);
80 ilm 736
        out.println(str);
73 ilm 737
 
738
    }
739
 
142 ilm 740
    protected final void addSpacer(PrintStream out, int depth) {
132 ilm 741
        for (int i = 0; i < depth; i++) {
742
            out.print("  ");
743
        }
744
    }
745
 
142 ilm 746
    public final String getTypeAsString() {
156 ilm 747
        String result = "?";
132 ilm 748
        if (this.type == TYPE_CHECKBOX) {
156 ilm 749
            result = "checkbox";
132 ilm 750
        } else if (this.type == TYPE_COMBOBOX) {
156 ilm 751
            result = "combobox";
132 ilm 752
        } else if (this.type == TYPE_LABEL) {
156 ilm 753
            result = "label";
132 ilm 754
        } else if (this.type == TYPE_TEXT_AREA) {
156 ilm 755
            result = "textarea";
132 ilm 756
        } else if (this.type == TYPE_TEXT_FIELD) {
156 ilm 757
            result = "textfield";
132 ilm 758
        } else if (this.type == TYPE_TABLE) {
156 ilm 759
            result = "table";
132 ilm 760
        } else if (this.type == TYPE_TABBED_UI) {
156 ilm 761
            result = "tabs";
132 ilm 762
        } else if (this.type == TYPE_TREE) {
156 ilm 763
            result = "tree";
132 ilm 764
        } else if (this.type == TYPE_BUTTON) {
156 ilm 765
            result = "button";
132 ilm 766
        } else if (this.type == TYPE_BUTTON_WITH_CONTEXT) {
156 ilm 767
            result = "button with context";
132 ilm 768
        } else if (this.type == TYPE_BUTTON_CANCEL) {
156 ilm 769
            result = "cancel button";
132 ilm 770
        } else if (this.type == TYPE_COMBOBOX_ELEMENT) {
156 ilm 771
            result = "combo element";
132 ilm 772
        } else if (this.type == TYPE_BUTTON_WITH_SELECTION_CONTEXT) {
156 ilm 773
            result = "button with selection context";
142 ilm 774
        } else if (this.type == TYPE_FILE_UPLOAD_WITH_SELECTION) {
156 ilm 775
            result = "file upload with selection";
132 ilm 776
        } else if (this.type == TYPE_FRAME) {
156 ilm 777
            result = "frame";
132 ilm 778
        } else if (this.type == TYPE_DROPDOWN_BUTTON) {
156 ilm 779
            result = "drop down button";
132 ilm 780
        } else if (this.type == TYPE_IMAGE) {
156 ilm 781
            result = "image";
132 ilm 782
        } else if (this.type == TYPE_LIST) {
156 ilm 783
            result = "list";
132 ilm 784
        } else if (this.type == TYPE_RAW_HTML) {
156 ilm 785
            result = "raw html";
142 ilm 786
        } else if (this.type == TYPE_SLIDER) {
156 ilm 787
            result = "slider";
142 ilm 788
        } else if (this.type == TYPE_PICTURE_UPLOAD) {
156 ilm 789
            result = "picture upload";
142 ilm 790
        } else if (this.type == TYPE_FILE_UPLOAD) {
156 ilm 791
            result = "file upload";
132 ilm 792
        }
793
 
156 ilm 794
        return result;
132 ilm 795
    }
796
 
797
    public String getClassName() {
798
        return this.getClass().getName();
799
    }
800
 
149 ilm 801
    /**
802
     * { return new JSONToLightUIConvertor() {
803
     *
804
     * @Override public LightUIElement convert(final JSONObject json) { return new
805
     *           LightUIElement(json); } }; }
806
     */
807
 
132 ilm 808
    protected void copy(final LightUIElement element) {
809
        if (element == null) {
810
            throw new IllegalArgumentException("Try to copy attributes of null element in " + this.getId());
811
        }
812
        this.fontSize = element.fontSize;
813
        this.gridHeight = element.gridHeight;
814
        this.gridWidth = element.gridWidth;
815
        this.horizontalAlignment = element.horizontalAlignment;
816
        this.verticalAlignment = element.verticalAlignment;
817
        this.weightX = element.weightX;
818
 
819
        this.commitMode = element.commitMode;
820
        this.height = element.height;
821
        this.marginBottom = element.marginBottom;
822
        this.marginLeft = element.marginLeft;
823
        this.marginRight = element.marginRight;
824
        this.marginTop = element.marginTop;
825
        this.maxHeight = element.maxHeight;
826
        this.maxWidth = element.maxWidth;
827
        this.minInputSize = element.minInputSize;
828
        this.minHeight = element.minHeight;
829
        this.minWidth = element.minWidth;
830
        this.paddingBottom = element.paddingBottom;
831
        this.paddingLeft = element.paddingLeft;
832
        this.paddingRight = element.paddingRight;
833
        this.paddingTop = element.paddingTop;
834
        this.valueType = element.valueType;
835
        this.width = element.width;
836
 
837
        this.enabled = element.enabled;
838
        this.fillWidth = element.fillWidth;
142 ilm 839
        this.fillHeight = element.fillHeight;
132 ilm 840
        this.foldable = element.foldable;
841
        this.folded = element.folded;
842
        this.fontBold = element.fontBold;
843
        this.fontItalic = element.fontItalic;
844
        this.horizontallyResizable = element.horizontallyResizable;
142 ilm 845
        this.horizontallyScrollable = element.horizontallyScrollable;
132 ilm 846
        this.required = element.required;
847
        this.readOnly = element.readOnly;
848
        this.verticallyResizable = element.verticallyResizable;
142 ilm 849
        this.verticallyScrollable = element.verticallyScrollable;
132 ilm 850
        this.visible = element.visible;
142 ilm 851
        this.notSaved = element.notSaved;
132 ilm 852
 
853
        this.displayPrecision = element.displayPrecision;
854
        this.icon = element.icon;
855
        this.label = element.label;
856
        this.toolTip = element.toolTip;
857
        this.value = element.value;
858
        this.valuePrecision = element.valuePrecision;
859
        this.valueRange = element.valueRange;
860
 
861
        this.backgroundColor = element.backgroundColor;
862
        this.borderColor = element.borderColor;
863
        this.cellBackgroundColor = element.cellBackgroundColor;
864
        this.foreColor = element.foreColor;
865
    }
866
 
73 ilm 867
    @Override
868
    public String toString() {
156 ilm 869
        if (!destroyed) {
870
            return super.toString() + " " + this.id;
871
        } else {
872
            return super.toString() + " " + this.id + " DESTROYED";
873
        }
73 ilm 874
    }
875
 
94 ilm 876
    @Override
877
    public JSONObject toJSON() {
878
        final JSONObject result = new JSONObject();
73 ilm 879
 
132 ilm 880
        result.put("class-name", this.getClassName());
94 ilm 881
 
132 ilm 882
        if (this.fontSize != FONT_SMALL) {
883
            result.put("font-size", this.fontSize);
94 ilm 884
        }
132 ilm 885
        if (this.gridWidth != DEFAULT_GRID_WIDTH) {
886
            result.put("grid-width", this.gridWidth);
887
        }
888
        if (this.gridHeight != DEFAULT_GRID_HEIGHT) {
889
            result.put("grid-height", this.gridHeight);
890
        }
891
        if (this.horizontalAlignment != HALIGN_LEFT) {
892
            result.put("horizontal-alignment", this.horizontalAlignment);
893
        }
894
        if (this.verticalAlignment != VALIGN_TOP) {
895
            result.put("vertical-alignment", this.verticalAlignment);
896
        }
897
        if (this.weightX != DEFAULT_WEIGHT_X) {
898
            result.put("weight-x", this.weightX);
899
        }
156 ilm 900
        if (this.weightY != DEFAULT_WEIGHT_Y) {
901
            result.put("weight-y", this.weightY);
902
        }
94 ilm 903
        if (this.commitMode != null) {
904
            result.put("commit-mode", this.commitMode);
905
        }
156 ilm 906
        if (this.width != null) {
907
            result.put("width", this.width);
908
        }
132 ilm 909
        if (this.height != null) {
910
            result.put("height", this.height);
94 ilm 911
        }
132 ilm 912
        if (this.marginBottom != null) {
913
            result.put("m-bottom", this.marginBottom);
914
        }
915
        if (this.marginLeft != null) {
916
            result.put("m-left", this.marginLeft);
917
        }
918
        if (this.marginRight != null) {
919
            result.put("m-right", this.marginRight);
920
        }
921
        if (this.marginTop != null) {
922
            result.put("m-top", this.marginTop);
923
        }
924
        if (this.maxHeight != null) {
925
            result.put("max-height", this.maxHeight);
926
        }
927
        if (this.maxWidth != null) {
928
            result.put("max-width", this.maxWidth);
929
        }
930
        if (this.minInputSize != null) {
931
            result.put("min-input-size", this.minInputSize);
932
        }
933
        if (this.minHeight != null) {
934
            result.put("min-height", this.minHeight);
935
        }
936
        if (this.minWidth != null) {
937
            result.put("min-width", this.minWidth);
938
        }
939
        if (this.paddingBottom != null) {
940
            result.put("p-bottom", this.paddingBottom);
941
        }
942
        if (this.paddingLeft != null) {
943
            result.put("p-left", this.paddingLeft);
944
        }
945
        if (this.paddingRight != null) {
946
            result.put("p-right", this.paddingRight);
947
        }
948
        if (this.paddingTop != null) {
949
            result.put("p-top", this.paddingTop);
950
        }
951
        result.put("type", this.type);
952
        if (this.valueType != null) {
953
            result.put("value-type", this.valueType);
954
        }
955
 
956
        if (!this.enabled) {
957
            result.put("enabled", false);
958
        }
959
        if (this.fillWidth) {
960
            result.put("fill-width", true);
961
        }
142 ilm 962
        if (this.fillHeight) {
963
            result.put("fill-height", true);
964
        }
94 ilm 965
        if (this.foldable) {
966
            result.put("foldable", true);
967
        }
968
        if (this.folded) {
969
            result.put("folded", true);
970
        }
132 ilm 971
        if (this.fontBold) {
972
            result.put("bold", true);
94 ilm 973
        }
132 ilm 974
        if (this.fontItalic) {
975
            result.put("italic", true);
94 ilm 976
        }
977
        if (this.horizontallyResizable) {
142 ilm 978
            result.put(HORIZONTALLY_RESIZABLE, true);
94 ilm 979
        }
142 ilm 980
        if (this.horizontallyScrollable) {
981
            result.put(HORIZONTALLY_SCROLLABLE, true);
982
        }
132 ilm 983
        if (this.required) {
984
            result.put("required", true);
985
        }
986
        if (this.readOnly) {
987
            result.put("read-only", true);
988
        }
94 ilm 989
        if (this.verticallyResizable) {
142 ilm 990
            result.put(VERTICALLY_RESIZABLE, true);
94 ilm 991
        }
142 ilm 992
        if (this.verticallyScrollable) {
993
            result.put(VERTICALLY_SCROLLABLE, true);
994
        }
132 ilm 995
        if (!this.visible) {
996
            result.put("visible", false);
997
        }
142 ilm 998
        if (this.notSaved) {
999
            result.put("not-saved", true);
1000
        }
132 ilm 1001
 
1002
        if (this.displayPrecision != null) {
1003
            result.put("display-precision", this.displayPrecision);
1004
        }
94 ilm 1005
        if (this.icon != null) {
1006
            result.put("icon", this.icon);
1007
        }
132 ilm 1008
        result.put("id", this.id);
94 ilm 1009
        if (this.label != null) {
1010
            result.put("label", this.label);
1011
        }
1012
        if (this.toolTip != null) {
1013
            result.put("tool-tip", this.toolTip);
1014
        }
132 ilm 1015
        result.put("uuid", this.UUID);
1016
        if (this.value != null) {
1017
            result.put("value", this.value);
1018
        }
94 ilm 1019
        if (this.valuePrecision != null) {
1020
            result.put("value-precision", this.valuePrecision);
1021
        }
1022
        if (this.valueRange != null) {
1023
            result.put("value-range", this.valueRange);
1024
        }
132 ilm 1025
 
1026
        if (this.backgroundColor != null) {
1027
            result.put("background-color", JSONConverter.getJSON(this.backgroundColor));
94 ilm 1028
        }
132 ilm 1029
        if (this.borderColor != null) {
1030
            result.put("border-color", JSONConverter.getJSON(this.borderColor));
94 ilm 1031
        }
132 ilm 1032
        if (this.cellBackgroundColor != null) {
1033
            result.put("cell-background-color", JSONConverter.getJSON(this.cellBackgroundColor));
94 ilm 1034
        }
132 ilm 1035
        if (this.foreColor != null) {
1036
            result.put("fore-color", JSONConverter.getJSON(this.foreColor));
94 ilm 1037
        }
149 ilm 1038
        if (this instanceof HTMLable) {
1039
            result.put("html", ((HTMLable) this).getHTML());
1040
        }
94 ilm 1041
        return result;
73 ilm 1042
    }
1043
 
93 ilm 1044
    @Override
94 ilm 1045
    public void fromJSON(final JSONObject json) {
132 ilm 1046
        this.id = JSONConverter.getParameterFromJSON(json, "id", String.class);
1047
        this.UUID = JSONConverter.getParameterFromJSON(json, "uuid", String.class);
1048
        this.displayPrecision = JSONConverter.getParameterFromJSON(json, "display-precision", String.class);
1049
        this.icon = JSONConverter.getParameterFromJSON(json, "icon", String.class);
1050
        this.label = JSONConverter.getParameterFromJSON(json, "label", String.class);
93 ilm 1051
 
132 ilm 1052
        this.toolTip = JSONConverter.getParameterFromJSON(json, "tool-tip", String.class);
1053
        this.value = JSONConverter.getParameterFromJSON(json, "value", String.class);
1054
        this.valuePrecision = JSONConverter.getParameterFromJSON(json, "value-precision", String.class);
1055
        this.valueRange = JSONConverter.getParameterFromJSON(json, "value-range", String.class);
93 ilm 1056
 
132 ilm 1057
        this.commitMode = JSONConverter.getParameterFromJSON(json, "commit-mode", Integer.class);
1058
        this.fontSize = JSONConverter.getParameterFromJSON(json, "font-size", Integer.class, FONT_SMALL);
1059
        this.gridWidth = JSONConverter.getParameterFromJSON(json, "grid-width", Integer.class, DEFAULT_GRID_WIDTH);
1060
        this.gridHeight = JSONConverter.getParameterFromJSON(json, "grid-height", Integer.class, DEFAULT_GRID_HEIGHT);
1061
        this.horizontalAlignment = JSONConverter.getParameterFromJSON(json, "horizontal-alignment", Integer.class, HALIGN_LEFT);
1062
        this.verticalAlignment = JSONConverter.getParameterFromJSON(json, "vertical-alignment", Integer.class, VALIGN_TOP);
1063
        this.weightX = JSONConverter.getParameterFromJSON(json, "weight-x", Integer.class, DEFAULT_WEIGHT_X);
156 ilm 1064
        this.weightY = JSONConverter.getParameterFromJSON(json, "weight-y", Integer.class, DEFAULT_WEIGHT_Y);
132 ilm 1065
        this.minInputSize = JSONConverter.getParameterFromJSON(json, "min-input-size", Integer.class);
1066
        this.type = JSONConverter.getParameterFromJSON(json, "type", Integer.class);
1067
        this.valueType = JSONConverter.getParameterFromJSON(json, "value-type", Integer.class);
1068
        this.width = JSONConverter.getParameterFromJSON(json, "width", Integer.class);
156 ilm 1069
        this.height = JSONConverter.getParameterFromJSON(json, "height", Integer.class);
132 ilm 1070
        this.marginTop = JSONConverter.getParameterFromJSON(json, "m-top", Integer.class);
1071
        this.marginBottom = JSONConverter.getParameterFromJSON(json, "m-bottom", Integer.class);
1072
        this.marginLeft = JSONConverter.getParameterFromJSON(json, "m-left", Integer.class);
1073
        this.marginRight = JSONConverter.getParameterFromJSON(json, "m-right", Integer.class);
1074
        this.maxWidth = JSONConverter.getParameterFromJSON(json, "max-width", Integer.class);
1075
        this.minWidth = JSONConverter.getParameterFromJSON(json, "min-width", Integer.class);
156 ilm 1076
 
132 ilm 1077
        this.maxHeight = JSONConverter.getParameterFromJSON(json, "max-height", Integer.class);
1078
        this.minHeight = JSONConverter.getParameterFromJSON(json, "min-height", Integer.class);
1079
        this.paddingTop = JSONConverter.getParameterFromJSON(json, "p-top", Integer.class);
1080
        this.paddingBottom = JSONConverter.getParameterFromJSON(json, "p-bottom", Integer.class);
1081
        this.paddingLeft = JSONConverter.getParameterFromJSON(json, "p-left", Integer.class);
1082
        this.paddingRight = JSONConverter.getParameterFromJSON(json, "p-right", Integer.class);
93 ilm 1083
 
132 ilm 1084
        this.enabled = JSONConverter.getParameterFromJSON(json, "enabled", Boolean.class, true);
1085
        this.foldable = JSONConverter.getParameterFromJSON(json, "foldable", Boolean.class, false);
1086
        this.folded = JSONConverter.getParameterFromJSON(json, "folded", Boolean.class, false);
1087
        this.fillWidth = JSONConverter.getParameterFromJSON(json, "fill-width", Boolean.class, false);
1088
        this.fontBold = JSONConverter.getParameterFromJSON(json, "bold", Boolean.class, false);
1089
        this.fontItalic = JSONConverter.getParameterFromJSON(json, "italic", Boolean.class, false);
142 ilm 1090
        this.horizontallyResizable = JSONConverter.getParameterFromJSON(json, HORIZONTALLY_RESIZABLE, Boolean.class, false);
1091
        this.horizontallyScrollable = JSONConverter.getParameterFromJSON(json, HORIZONTALLY_SCROLLABLE, Boolean.class, false);
1092
        this.verticallyResizable = JSONConverter.getParameterFromJSON(json, VERTICALLY_RESIZABLE, Boolean.class, false);
1093
        this.verticallyScrollable = JSONConverter.getParameterFromJSON(json, VERTICALLY_SCROLLABLE, Boolean.class, false);
132 ilm 1094
        this.required = JSONConverter.getParameterFromJSON(json, "required", Boolean.class, false);
1095
        this.readOnly = JSONConverter.getParameterFromJSON(json, "read-only", Boolean.class, false);
1096
        this.visible = JSONConverter.getParameterFromJSON(json, "visible", Boolean.class, true);
142 ilm 1097
        this.notSaved = JSONConverter.getParameterFromJSON(json, "not-saved", Boolean.class, false);
132 ilm 1098
 
1099
        this.backgroundColor = JSONConverter.getParameterFromJSON(json, "background-color", Color.class);
1100
        this.borderColor = JSONConverter.getParameterFromJSON(json, "border-color", Color.class);
1101
        this.cellBackgroundColor = JSONConverter.getParameterFromJSON(json, "cell-background-color", Color.class);
1102
        this.foreColor = JSONConverter.getParameterFromJSON(json, "fore-color", Color.class);
93 ilm 1103
    }
142 ilm 1104
 
1105
    public void destroy() {
1106
        this.setValue(null);
156 ilm 1107
        this.parent = null;
1108
        this.destroyed = true;
142 ilm 1109
    }
156 ilm 1110
 
1111
    public boolean isDestroyed() {
1112
        return destroyed;
1113
    }
1114
 
1115
    @Override
1116
    public void writeExternal(ObjectOutput out) throws IOException {
1117
        out.writeInt(this.type);
1118
        if (this.id == null) {
1119
            throw new IllegalStateException("null id");
1120
        }
1121
        out.writeUTF(this.id);
1122
        if (this.UUID == null) {
1123
            throw new IllegalStateException("UUID");
1124
        }
1125
        out.writeUTF(this.UUID);
1126
 
1127
        writeIfNotNull(out, this.label);
1128
        writeIfNotNull(out, this.value);
1129
 
1130
        out.writeInt(this.fontSize);
1131
        out.writeInt(this.gridWidth);
1132
        out.writeInt(this.gridHeight);
1133
 
1134
        out.writeByte(this.horizontalAlignment);
1135
        out.writeByte(this.verticalAlignment);
1136
        out.writeByte(this.weightX);
1137
        out.writeByte(this.weightY);
1138
 
1139
        writeIfNotNull(out, this.commitMode);
1140
        writeIfNotNull(out, this.width);
1141
        writeIfNotNull(out, this.height);
1142
 
1143
        // Margins
1144
        writeIfNotNull(out, this.marginBottom);
1145
        writeIfNotNull(out, this.marginLeft);
1146
        writeIfNotNull(out, this.marginRight);
1147
        writeIfNotNull(out, this.marginTop);
1148
        //
1149
        writeIfNotNull(out, this.maxHeight);
1150
        writeIfNotNull(out, this.maxWidth);
1151
 
1152
        writeIfNotNull(out, this.minInputSize);
1153
        writeIfNotNull(out, this.minHeight);
1154
        writeIfNotNull(out, this.minWidth);
1155
 
1156
        // Paddings
1157
        writeIfNotNull(out, this.paddingBottom);
1158
        writeIfNotNull(out, this.paddingLeft);
1159
        writeIfNotNull(out, this.paddingRight);
1160
        writeIfNotNull(out, this.paddingTop);
1161
 
1162
        writeIfNotNull(out, this.valueType);
1163
 
1164
        out.writeBoolean(this.enabled);
1165
        out.writeBoolean(this.fillWidth);
1166
        out.writeBoolean(this.fillHeight);
1167
        out.writeBoolean(this.foldable);
1168
        out.writeBoolean(this.folded);
1169
        out.writeBoolean(this.fontBold);
1170
        out.writeBoolean(this.fontItalic);
1171
        out.writeBoolean(this.horizontallyResizable);
1172
        out.writeBoolean(this.horizontallyScrollable);
1173
        out.writeBoolean(this.required);
1174
        out.writeBoolean(this.readOnly);
1175
        out.writeBoolean(this.verticallyResizable);
1176
        out.writeBoolean(this.verticallyScrollable);
1177
 
1178
        out.writeBoolean(this.visible);
1179
        out.writeBoolean(this.notSaved);
1180
 
1181
        writeIfNotNull(out, this.displayPrecision);
1182
        writeIfNotNull(out, this.icon);
1183
        writeIfNotNull(out, this.toolTip);
1184
        writeIfNotNull(out, this.valuePrecision);
1185
        writeIfNotNull(out, this.valueRange);
1186
 
1187
        // Colors
1188
        writeIfNotNull(out, this.backgroundColor);
1189
        writeIfNotNull(out, this.borderColor);
1190
        writeIfNotNull(out, this.cellBackgroundColor);
1191
        writeIfNotNull(out, this.foreColor);
1192
    }
1193
 
1194
    void writeIfNotNull(ObjectOutput out, String s) throws IOException {
1195
        if (s != null) {
1196
            out.writeBoolean(true);
1197
            out.writeUTF(s);
1198
        } else {
1199
            out.writeBoolean(false);
1200
        }
1201
    }
1202
 
1203
    void writeIfNotNull(ObjectOutput out, Integer s) throws IOException {
1204
        if (s != null) {
1205
            out.writeBoolean(true);
1206
            out.writeInt(s);
1207
        } else {
1208
            out.writeBoolean(false);
1209
        }
1210
    }
1211
 
1212
    void writeIfNotNull(ObjectOutput out, Color s) throws IOException {
1213
        if (s != null) {
1214
            out.writeBoolean(true);
1215
            out.writeInt(s.getRGB());
1216
        } else {
1217
            out.writeBoolean(false);
1218
        }
1219
    }
1220
 
1221
    @Override
1222
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
1223
        this.type = in.readInt();
1224
        this.id = in.readUTF();
1225
        this.UUID = in.readUTF();
1226
        if (in.readBoolean()) {
1227
            this.label = in.readUTF();
1228
        }
1229
        if (in.readBoolean()) {
1230
            this.value = in.readUTF();
1231
        }
1232
        this.fontSize = in.readInt();
1233
        this.gridWidth = in.readInt();
1234
        this.gridHeight = in.readInt();
1235
        this.horizontalAlignment = in.readByte();
1236
        this.verticalAlignment = in.readByte();
1237
        this.weightX = in.readByte();
1238
        this.weightY = in.readByte();
1239
 
1240
        if (in.readBoolean()) {
1241
            this.commitMode = in.readInt();
1242
        }
1243
        if (in.readBoolean()) {
1244
            this.width = in.readInt();
1245
        }
1246
        if (in.readBoolean()) {
1247
            this.height = in.readInt();
1248
        }
1249
        // Margins
1250
        if (in.readBoolean()) {
1251
            this.marginBottom = in.readInt();
1252
        }
1253
        if (in.readBoolean()) {
1254
            this.marginLeft = in.readInt();
1255
        }
1256
        if (in.readBoolean()) {
1257
            this.marginRight = in.readInt();
1258
        }
1259
        if (in.readBoolean()) {
1260
            this.marginTop = in.readInt();
1261
        }
1262
 
1263
        //
1264
        if (in.readBoolean()) {
1265
            this.maxHeight = in.readInt();
1266
        }
1267
        if (in.readBoolean()) {
1268
            this.maxWidth = in.readInt();
1269
        }
1270
 
1271
        if (in.readBoolean()) {
1272
            this.minInputSize = in.readInt();
1273
        }
1274
        if (in.readBoolean()) {
1275
            this.minHeight = in.readInt();
1276
        }
1277
        if (in.readBoolean()) {
1278
            this.minWidth = in.readInt();
1279
        }
1280
 
1281
        // Paddings
1282
        if (in.readBoolean()) {
1283
            this.paddingBottom = in.readInt();
1284
        }
1285
        if (in.readBoolean()) {
1286
            this.paddingLeft = in.readInt();
1287
        }
1288
        if (in.readBoolean()) {
1289
            this.paddingRight = in.readInt();
1290
        }
1291
        if (in.readBoolean()) {
1292
            this.paddingTop = in.readInt();
1293
        }
1294
        if (in.readBoolean()) {
1295
            this.valueType = in.readInt();
1296
        }
1297
 
1298
        this.enabled = in.readBoolean();
1299
        this.fillWidth = in.readBoolean();
1300
        this.fillHeight = in.readBoolean();
1301
        this.foldable = in.readBoolean();
1302
        this.folded = in.readBoolean();
1303
        this.fontBold = in.readBoolean();
1304
        this.fontItalic = in.readBoolean();
1305
        this.horizontallyResizable = in.readBoolean();
1306
        this.horizontallyScrollable = in.readBoolean();
1307
        this.required = in.readBoolean();
1308
        this.readOnly = in.readBoolean();
1309
        this.verticallyResizable = in.readBoolean();
1310
        this.verticallyScrollable = in.readBoolean();
1311
 
1312
        //
1313
        this.visible = in.readBoolean();
1314
        this.notSaved = in.readBoolean();
1315
        if (in.readBoolean()) {
1316
            this.displayPrecision = in.readUTF();
1317
        }
1318
        if (in.readBoolean()) {
1319
            this.icon = in.readUTF();
1320
        }
1321
        if (in.readBoolean()) {
1322
            this.toolTip = in.readUTF();
1323
        }
1324
        if (in.readBoolean()) {
1325
            this.valuePrecision = in.readUTF();
1326
        }
1327
        if (in.readBoolean()) {
1328
            this.valueRange = in.readUTF();
1329
        }
1330
        // Colors
1331
        if (in.readBoolean()) {
1332
            this.backgroundColor = new Color(in.readInt());
1333
        }
1334
        if (in.readBoolean()) {
1335
            this.borderColor = new Color(in.readInt());
1336
        }
1337
        if (in.readBoolean()) {
1338
            this.cellBackgroundColor = new Color(in.readInt());
1339
        }
1340
        if (in.readBoolean()) {
1341
            this.foreColor = new Color(in.readInt());
1342
        }
1343
    }
73 ilm 1344
}