OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 182
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
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 net.minidev.json.JSONObject;
18
import net.minidev.json.JSONObject;
19
 
19
 
20
public class LightUIHourEditor extends LightUserControl {
20
public class LightUIHourEditor extends LightUserControl {
21
 
21
 
22
    private int hour;
22
    private int hour;
23
    private int minute;
23
    private int minute;
24
 
24
 
25
    public LightUIHourEditor(final JSONObject json) {
25
    public LightUIHourEditor(final JSONObject json) {
26
        super(json);
26
        super(json);
27
    }
27
    }
28
 
28
 
29
    @Override
29
    @Override
30
    public void fromJSON(JSONObject json) {
30
    public void fromJSON(JSONObject json) {
31
        super.fromJSON(json);
31
        super.fromJSON(json);
32
        this.hour = ((Number) json.get("hour")).intValue();
32
        this.hour = ((Number) json.get("hour")).intValue();
33
        this.minute = ((Number) json.get("minute")).intValue();
33
        this.minute = ((Number) json.get("minute")).intValue();
34
    }
34
    }
35
 
35
 
36
    @Override
36
    @Override
37
    public JSONObject toJSON() {
37
    public JSONObject toJSON() {
38
        JSONObject o = super.toJSON();
38
        JSONObject o = super.toJSON();
39
        o.put("hour", hour);
39
        o.put("hour", hour);
40
        o.put("minute", minute);
40
        o.put("minute", minute);
41
        return o;
41
        return o;
42
    }
42
    }
43
 
43
 
44
    public LightUIHourEditor(final String id, int hour, int minute) {
44
    public LightUIHourEditor(final String id, int hour, int minute) {
45
        super(id);
45
        super(id);
46
        this.hour = hour;
46
        this.hour = hour;
47
        this.minute = minute;
47
        this.minute = minute;
48
        this.setType(TYPE_HOUR_EDITOR);
48
        this.setType(TYPE_HOUR_EDITOR);
49
        this.setValueType(LightUIElement.VALUE_TYPE_INTEGER);
49
        this.setValueType(LightUIElement.VALUE_TYPE_INTEGER);
50
        this.setValue(String.valueOf(getIntVal()));
50
        this.setValue(String.valueOf(getIntVal()));
51
    }
51
    }
52
 
52
 
53
    public LightUIHourEditor(LightUIHourEditor lightUIHourEditor) {
53
    public LightUIHourEditor(LightUIHourEditor lightUIHourEditor) {
54
        super(lightUIHourEditor);
54
        super(lightUIHourEditor);
55
        this.hour = lightUIHourEditor.hour;
55
        this.hour = lightUIHourEditor.hour;
56
        this.minute = lightUIHourEditor.minute;
56
        this.minute = lightUIHourEditor.minute;
57
        this.setValue(String.valueOf(getIntVal()));
57
        this.setValue(String.valueOf(getIntVal()));
58
    }
58
    }
59
 
59
 
60
    public int getHour() {
60
    public int getHour() {
61
        return hour;
61
        return hour;
62
    }
62
    }
63
 
63
 
64
    public void setHour(int hour) {
64
    public void setHour(int hour) {
65
        this.hour = hour;
65
        this.hour = hour;
66
    }
66
    }
67
 
67
 
68
    public int getMinute() {
68
    public int getMinute() {
69
        return minute;
69
        return minute;
70
    }
70
    }
71
 
71
 
72
    public void setMinute(int minute) {
72
    public void setMinute(int minute) {
73
        this.minute = minute;
73
        this.minute = minute;
74
    }
74
    }
75
 
75
 
76
    @Override
76
    @Override
77
    public Object getValueForContext() {
77
    public Object getValueForContext() {
78
        return getIntVal();
78
        return getIntVal();
79
    }
79
    }
80
 
80
 
81
    public int getIntVal() {
81
    public int getIntVal() {
82
        return this.hour * 60 + this.minute;
82
        return this.hour * 60 + this.minute;
83
    }
83
    }
84
 
84
 
85
    @Override
85
    @Override
86
    public void _setValueFromContext(Object value) {
86
    public void _setValueFromContext(Object value) {
87
        final Integer strValue = JSONConverter.getObjectFromJSON(value, Integer.class);
87
        final Integer strValue = JSONConverter.getObjectFromJSON(value, Integer.class);
88
        this.hour = strValue / 60;
88
        this.hour = strValue / 60;
89
        this.minute = strValue % 60;
89
        this.minute = strValue % 60;
90
        // For JSON
90
        // For JSON
91
        this.setValue(String.valueOf(strValue));
91
        this.setValue(String.valueOf(strValue));
92
    }
92
    }
93
 
93
 
94
}
94
}