|
@@ -22,7 +22,21 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.ui.swing.dialogs.actioneditor;
|
24
|
24
|
|
|
25
|
+import com.dmdirc.actions.interfaces.ActionType;
|
|
26
|
+import com.dmdirc.ui.IconManager;
|
|
27
|
+import com.dmdirc.ui.swing.components.ImageButton;
|
|
28
|
+import com.dmdirc.ui.swing.components.TextLabel;
|
|
29
|
+
|
|
30
|
+import java.awt.event.ActionEvent;
|
|
31
|
+import java.awt.event.ActionListener;
|
|
32
|
+import java.util.ArrayList;
|
|
33
|
+import java.util.List;
|
|
34
|
+
|
|
35
|
+import javax.swing.JLabel;
|
25
|
36
|
import javax.swing.JPanel;
|
|
37
|
+import javax.swing.SwingUtilities;
|
|
38
|
+
|
|
39
|
+import net.miginfocom.swing.MigLayout;
|
26
|
40
|
|
27
|
41
|
/**
|
28
|
42
|
* Action triggers list panel.
|
|
@@ -35,11 +49,19 @@ public class ActionTriggersListPanel extends JPanel {
|
35
|
49
|
* objects being unserialized with the new class).
|
36
|
50
|
*/
|
37
|
51
|
private static final long serialVersionUID = 1;
|
|
52
|
+ private List<ActionType> triggers;
|
38
|
53
|
|
39
|
54
|
/** Instantiates the panel. */
|
40
|
55
|
public ActionTriggersListPanel() {
|
|
56
|
+ this(new ArrayList<ActionType>());
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ /** Instantiates the panel. */
|
|
60
|
+ public ActionTriggersListPanel(final List<ActionType> triggers) {
|
41
|
61
|
super();
|
42
|
|
-
|
|
62
|
+
|
|
63
|
+ this.triggers = new ArrayList<ActionType>(triggers);
|
|
64
|
+
|
43
|
65
|
initComponents();
|
44
|
66
|
addListeners();
|
45
|
67
|
layoutComponents();
|
|
@@ -47,6 +69,7 @@ public class ActionTriggersListPanel extends JPanel {
|
47
|
69
|
|
48
|
70
|
/** Initialises the components. */
|
49
|
71
|
private void initComponents() {
|
|
72
|
+ setLayout(new MigLayout("fillx, wrap 2, debug"));
|
50
|
73
|
}
|
51
|
74
|
|
52
|
75
|
/** Adds the listeners. */
|
|
@@ -55,5 +78,69 @@ public class ActionTriggersListPanel extends JPanel {
|
55
|
78
|
|
56
|
79
|
/** Lays out the components. */
|
57
|
80
|
private void layoutComponents() {
|
|
81
|
+ synchronized (triggers) {
|
|
82
|
+ setVisible(false);
|
|
83
|
+
|
|
84
|
+ removeAll();
|
|
85
|
+
|
|
86
|
+ for (final ActionType trigger : triggers) {
|
|
87
|
+ final ImageButton button = new ImageButton("delete",
|
|
88
|
+ IconManager.getIconManager().getIcon("close-inactive"),
|
|
89
|
+ IconManager.getIconManager().getIcon("close-active"));
|
|
90
|
+ button.addActionListener(new ActionListener() {
|
|
91
|
+
|
|
92
|
+ /** {@inheritDoc} */
|
|
93
|
+ @Override
|
|
94
|
+ public void actionPerformed(ActionEvent e) {
|
|
95
|
+ delTrigger(trigger);
|
|
96
|
+ }
|
|
97
|
+ });
|
|
98
|
+
|
|
99
|
+ add(new JLabel(trigger.getName()), "growx");
|
|
100
|
+ add(button, "right");
|
|
101
|
+ }
|
|
102
|
+
|
|
103
|
+ if (getComponentCount() == 0) {
|
|
104
|
+ add(new TextLabel("No triggers."));
|
|
105
|
+ }
|
|
106
|
+ getLayout().layoutContainer(this);
|
|
107
|
+ setVisible(true);
|
|
108
|
+ }
|
|
109
|
+ }
|
|
110
|
+
|
|
111
|
+ public void addTrigger(final ActionType trigger) {
|
|
112
|
+ SwingUtilities.invokeLater(new Runnable() {
|
|
113
|
+
|
|
114
|
+ /** {@inheritDoc} */
|
|
115
|
+ @Override
|
|
116
|
+ public void run() {
|
|
117
|
+ synchronized (triggers) {
|
|
118
|
+ triggers.add(trigger);
|
|
119
|
+
|
|
120
|
+ layoutComponents();
|
|
121
|
+ }
|
|
122
|
+ }
|
|
123
|
+ });
|
|
124
|
+ }
|
|
125
|
+
|
|
126
|
+ public void delTrigger(final ActionType trigger) {
|
|
127
|
+ SwingUtilities.invokeLater(new Runnable() {
|
|
128
|
+
|
|
129
|
+ /** {@inheritDoc} */
|
|
130
|
+ @Override
|
|
131
|
+ public void run() {
|
|
132
|
+ synchronized (triggers) {
|
|
133
|
+ triggers.remove(trigger);
|
|
134
|
+
|
|
135
|
+ layoutComponents();
|
|
136
|
+ }
|
|
137
|
+ }
|
|
138
|
+ });
|
|
139
|
+ }
|
|
140
|
+
|
|
141
|
+ public List<ActionType> getTriggers() {
|
|
142
|
+ synchronized (triggers) {
|
|
143
|
+ return triggers;
|
|
144
|
+ }
|
58
|
145
|
}
|
59
|
146
|
}
|