OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 156
Line 20... Line 20...
20
import java.util.List;
20
import java.util.List;
21
 
21
 
22
import net.minidev.json.JSONObject;
22
import net.minidev.json.JSONObject;
23
 
23
 
24
public class LightUIButton extends LightUIElement {
24
public class LightUIButton extends LightUIElement {
25
    private transient List<ActionListener> clickListeners = new ArrayList<ActionListener>();
25
    protected transient List<ActionListener> clickListeners = new ArrayList<>();
-
 
26
 
-
 
27
    public LightUIButton() {
-
 
28
        // Serialization
-
 
29
    }
26
 
30
 
27
    public LightUIButton(final JSONObject json) {
31
    public LightUIButton(final JSONObject json) {
28
        super(json);
32
        super(json);
29
    }
33
    }
30
 
34
 
Line 61... Line 65...
61
    public LightUIButton(final LightUIButton button) {
65
    public LightUIButton(final LightUIButton button) {
62
        super(button);
66
        super(button);
63
    }
67
    }
64
 
68
 
65
    public void addClickListener(final ActionListener listener) {
69
    public void addClickListener(final ActionListener listener) {
-
 
70
        if (!clickListeners.contains(listener)) {
66
        this.clickListeners.add(listener);
71
            this.clickListeners.add(listener);
67
    }
72
        }
-
 
73
    }
68
 
74
 
69
    public void removeClickListeners() {
75
    public void removeClickListener(final ActionListener listener) {
70
        this.clickListeners.clear();
76
        this.clickListeners.remove(listener);
71
    }
77
    }
72
 
78
 
73
    public List<ActionListener> getClickListeners() {
79
    public List<ActionListener> getClickListeners() {
74
        return Collections.unmodifiableList(this.clickListeners);
80
        return Collections.unmodifiableList(this.clickListeners);
75
    }
81
    }
76
 
82
 
77
    public void fireClick() {
83
    public void fireClick() {
-
 
84
        final List<ActionListener> listeners = new ArrayList<>(this.clickListeners.size());
-
 
85
        listeners.addAll(this.clickListeners);
-
 
86
        // The list is duplicated to avoid ConcurrentModificationException when a listener destroys
-
 
87
        // this button
78
        for (final ActionListener listener : this.clickListeners) {
88
        for (final ActionListener listener : listeners) {
79
            listener.actionPerformed(new ActionEvent(this, 1, "click"));
89
            listener.actionPerformed(new ActionEvent(this, 1, "click"));
80
        }
90
        }
81
    }
91
    }
82
 
92
 
83
    @Override
93
    @Override
84
    public void destroy() {
94
    public void destroy() {
85
        super.destroy();
95
        super.destroy();
86
        this.clickListeners.clear();
96
        this.clickListeners = null;
87
    }
97
    }
88
 
98
 
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
    }
-
 
98
}
99
}