OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 149 Rev 156
Line 13... Line 13...
13
 
13
 
14
 package org.openconcerto.ui.light;
14
 package org.openconcerto.ui.light;
15
 
15
 
16
import org.openconcerto.utils.io.JSONConverter;
16
import org.openconcerto.utils.io.JSONConverter;
17
 
17
 
-
 
18
import java.io.Externalizable;
-
 
19
import java.io.IOException;
-
 
20
import java.io.ObjectInput;
-
 
21
import java.io.ObjectOutput;
18
import java.util.HashMap;
22
import java.util.HashMap;
19
import java.util.Map;
23
import java.util.Map;
20
 
24
 
21
import net.minidev.json.JSONObject;
25
import net.minidev.json.JSONObject;
22
 
26
 
23
public class LightUISlider extends LightUserControl {
27
public class LightUISlider extends LightUserControl implements Externalizable {
-
 
28
 
24
    private Integer maxValue = 1;
29
    private int minValue = 0;
25
    private Integer minValue = 0;
30
    private int maxValue = 1;
26
    private Integer increment = 1;
31
    private int increment = 1;
27
    private Map<Integer, String> mapLabels = new HashMap<>();
32
    private Map<Integer, String> mapLabels = new HashMap<>();
28
 
33
 
-
 
34
    public LightUISlider() {
-
 
35
        // Serialization
-
 
36
    }
-
 
37
 
29
    public LightUISlider(final String id) {
38
    public LightUISlider(final String id) {
30
        super(id);
39
        super(id);
31
        this.setType(TYPE_SLIDER);
40
        this.setType(TYPE_SLIDER);
32
        this.setValueType(VALUE_TYPE_INTEGER);
41
        this.setValueType(VALUE_TYPE_INTEGER);
33
        this.setValue("0");
42
        this.setValue("0");
Line 147... Line 156...
147
            return Integer.parseInt(this.getValue());
156
            return Integer.parseInt(this.getValue());
148
        }
157
        }
149
    }
158
    }
150
 
159
 
151
    @Override
160
    @Override
152
    public JSONToLightUIConvertor getConvertor() {
161
    public void writeExternal(ObjectOutput out) throws IOException {
-
 
162
        super.writeExternal(out);
-
 
163
        out.writeInt(this.minValue);
-
 
164
        out.writeInt(this.maxValue);
153
        return new JSONToLightUIConvertor() {
165
        out.writeInt(this.increment);
154
            @Override
166
        // map
-
 
167
        out.writeInt(this.mapLabels.size());
-
 
168
        for (Map.Entry<Integer, String> entry : mapLabels.entrySet()) {
155
            public LightUIElement convert(JSONObject json) {
169
            out.writeInt(entry.getKey());
156
                return new LightUISlider(json);
170
            out.writeUTF(entry.getValue());
157
            }
171
        }
-
 
172
    }
-
 
173
 
-
 
174
    @Override
-
 
175
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-
 
176
        super.readExternal(in);
-
 
177
        this.minValue = in.readInt();
-
 
178
        this.maxValue = in.readInt();
-
 
179
        this.increment = in.readInt();
-
 
180
        this.mapLabels.clear();
-
 
181
        int size = in.readInt();
-
 
182
        for (int i = 0; i < size; i++) {
-
 
183
            this.mapLabels.put(in.readInt(), in.readUTF());
158
        };
184
        }
159
    }
185
    }
160
}
186
}