OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
142 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
142 ilm 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
 
16
import org.openconcerto.utils.io.JSONConverter;
17
 
18
import net.minidev.json.JSONObject;
19
 
20
public class LightUIHourEditor extends LightUserControl {
21
 
22
    private int hour;
23
    private int minute;
24
 
25
    public LightUIHourEditor(final JSONObject json) {
26
        super(json);
27
    }
28
 
144 ilm 29
    @Override
30
    public void fromJSON(JSONObject json) {
31
        super.fromJSON(json);
32
        this.hour = ((Number) json.get("hour")).intValue();
33
        this.minute = ((Number) json.get("minute")).intValue();
34
    }
35
 
36
    @Override
37
    public JSONObject toJSON() {
38
        JSONObject o = super.toJSON();
39
        o.put("hour", hour);
40
        o.put("minute", minute);
41
        return o;
42
    }
43
 
142 ilm 44
    public LightUIHourEditor(final String id, int hour, int minute) {
45
        super(id);
46
        this.hour = hour;
47
        this.minute = minute;
48
        this.setType(TYPE_HOUR_EDITOR);
49
        this.setValueType(LightUIElement.VALUE_TYPE_INTEGER);
144 ilm 50
        this.setValue(String.valueOf(getIntVal()));
142 ilm 51
    }
52
 
53
    public LightUIHourEditor(LightUIHourEditor lightUIHourEditor) {
54
        super(lightUIHourEditor);
55
        this.hour = lightUIHourEditor.hour;
56
        this.minute = lightUIHourEditor.minute;
144 ilm 57
        this.setValue(String.valueOf(getIntVal()));
142 ilm 58
    }
59
 
60
    public int getHour() {
61
        return hour;
62
    }
63
 
64
    public void setHour(int hour) {
65
        this.hour = hour;
66
    }
67
 
68
    public int getMinute() {
69
        return minute;
70
    }
71
 
72
    public void setMinute(int minute) {
73
        this.minute = minute;
74
    }
75
 
76
    @Override
77
    public Object getValueForContext() {
144 ilm 78
        return getIntVal();
142 ilm 79
    }
80
 
144 ilm 81
    public int getIntVal() {
82
        return this.hour * 60 + this.minute;
83
    }
84
 
142 ilm 85
    @Override
86
    public void _setValueFromContext(Object value) {
144 ilm 87
        final Integer strValue = JSONConverter.getObjectFromJSON(value, Integer.class);
142 ilm 88
        this.hour = strValue / 60;
89
        this.minute = strValue % 60;
144 ilm 90
        // For JSON
91
        this.setValue(String.valueOf(strValue));
142 ilm 92
    }
93
 
94
}