OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
80 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
 
132 ilm 16
import java.awt.event.ActionEvent;
17
import java.awt.event.ActionListener;
18
import java.util.ArrayList;
144 ilm 19
import java.util.Collections;
132 ilm 20
import java.util.List;
21
 
22
import net.minidev.json.JSONObject;
23
 
80 ilm 24
public class LightUIButton extends LightUIElement {
144 ilm 25
    private transient List<ActionListener> clickListeners = new ArrayList<ActionListener>();
132 ilm 26
 
27
    public LightUIButton(final JSONObject json) {
28
        super(json);
80 ilm 29
    }
132 ilm 30
 
31
    public LightUIButton(final String id) {
32
        super(id);
33
        this.init(TYPE_BUTTON);
34
    }
35
 
144 ilm 36
    public LightUIButton(final String id, String text) {
37
        super(id);
38
        this.init(TYPE_BUTTON);
39
        this.setLabel(text);
40
    }
41
 
132 ilm 42
    protected LightUIButton(final String id, final int buttonType) {
43
        super(id);
44
        this.init(buttonType);
45
    }
46
 
144 ilm 47
    protected LightUIButton(final String id, final int buttonType, String text) {
48
        super(id);
49
        this.init(buttonType);
50
        this.setLabel(text);
51
    }
52
 
53
    public void setText(String text) {
54
        this.setLabel(text);
55
    }
56
 
132 ilm 57
    private void init(final int buttonType) {
58
        this.setType(buttonType);
59
    }
60
 
61
    public LightUIButton(final LightUIButton button) {
62
        super(button);
63
    }
64
 
65
    public void addClickListener(final ActionListener listener) {
66
        this.clickListeners.add(listener);
67
    }
68
 
69
    public void removeClickListeners() {
70
        this.clickListeners.clear();
71
    }
72
 
144 ilm 73
    public List<ActionListener> getClickListeners() {
74
        return Collections.unmodifiableList(this.clickListeners);
75
    }
76
 
132 ilm 77
    public void fireClick() {
78
        for (final ActionListener listener : this.clickListeners) {
79
            listener.actionPerformed(new ActionEvent(this, 1, "click"));
80
        }
81
    }
142 ilm 82
 
83
    @Override
84
    public void destroy() {
85
        super.destroy();
86
        this.clickListeners.clear();
87
    }
149 ilm 88
 
89
    @Override
90
    public JSONToLightUIConvertor getConvertor() {
91
        return new JSONToLightUIConvertor() {
92
            @Override
93
            public LightUIElement convert(JSONObject json) {
94
                return new LightUIButton(json);
95
            }
96
        };
97
    }
80 ilm 98
}