|
@@ -22,12 +22,27 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.ui.swing.dialogs.actioneditor;
|
24
|
24
|
|
|
25
|
+import com.dmdirc.actions.ActionManager;
|
|
26
|
+import com.dmdirc.actions.interfaces.ActionType;
|
|
27
|
+import com.dmdirc.ui.swing.components.TextLabel;
|
|
28
|
+import com.dmdirc.ui.swing.components.renderers.ActionTypeRenderer;
|
|
29
|
+
|
|
30
|
+import java.awt.event.ActionEvent;
|
|
31
|
+import java.awt.event.ActionListener;
|
|
32
|
+
|
|
33
|
+import javax.swing.BorderFactory;
|
|
34
|
+import javax.swing.JButton;
|
|
35
|
+import javax.swing.JComboBox;
|
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 panel.
|
29
|
43
|
*/
|
30
|
|
-public class ActionTriggersPanel extends JPanel {
|
|
44
|
+public class ActionTriggersPanel extends JPanel implements ActionListener,
|
|
45
|
+ ActionTriggerRemovalListener {
|
31
|
46
|
|
32
|
47
|
/**
|
33
|
48
|
* A version number for this class. It should be changed whenever the class
|
|
@@ -35,11 +50,14 @@ public class ActionTriggersPanel extends JPanel {
|
35
|
50
|
* objects being unserialized with the new class).
|
36
|
51
|
*/
|
37
|
52
|
private static final long serialVersionUID = 1;
|
|
53
|
+ private JComboBox trigger;
|
|
54
|
+ private JButton add;
|
|
55
|
+ private ActionTriggersListPanel triggerList;
|
38
|
56
|
|
39
|
57
|
/** Instantiates the panel. */
|
40
|
58
|
public ActionTriggersPanel() {
|
41
|
59
|
super();
|
42
|
|
-
|
|
60
|
+
|
43
|
61
|
initComponents();
|
44
|
62
|
addListeners();
|
45
|
63
|
layoutComponents();
|
|
@@ -47,13 +65,73 @@ public class ActionTriggersPanel extends JPanel {
|
47
|
65
|
|
48
|
66
|
/** Initialises the components. */
|
49
|
67
|
private void initComponents() {
|
|
68
|
+ setBorder(BorderFactory.createTitledBorder(getBorder(), "Triggers"));
|
|
69
|
+
|
|
70
|
+ trigger =
|
|
71
|
+ new JComboBox(new ActionTypeModel(ActionManager.getTypeGroups()));
|
|
72
|
+ //Only fire events on selection not on highlight
|
|
73
|
+ trigger.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
|
|
74
|
+ trigger.setRenderer(new ActionTypeRenderer());
|
|
75
|
+
|
|
76
|
+ add = new JButton("Add");
|
|
77
|
+ add.setEnabled(trigger.getSelectedIndex() != -1);
|
|
78
|
+
|
|
79
|
+ triggerList = new ActionTriggersListPanel();
|
50
|
80
|
}
|
51
|
81
|
|
52
|
82
|
/** Adds the listeners. */
|
53
|
83
|
private void addListeners() {
|
|
84
|
+ add.addActionListener(this);
|
|
85
|
+ trigger.addActionListener(this);
|
54
|
86
|
}
|
55
|
87
|
|
56
|
88
|
/** Lays out the components. */
|
57
|
89
|
private void layoutComponents() {
|
|
90
|
+ setLayout(new MigLayout("fill, pack"));
|
|
91
|
+
|
|
92
|
+ add(new TextLabel("This action will be triggered when any of these events occurs: "),
|
|
93
|
+ "growx, wrap, spanx");
|
|
94
|
+ add(triggerList, "grow, wrap, spanx");
|
|
95
|
+ add(trigger, "growx");
|
|
96
|
+ add(add, "right");
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+ /** {@inheritDoc} */
|
|
100
|
+ @Override
|
|
101
|
+ public void actionPerformed(final ActionEvent e) {
|
|
102
|
+ if (e.getSource() == trigger) {
|
|
103
|
+ add.setEnabled(trigger.getSelectedIndex() != -1);
|
|
104
|
+ } else {
|
|
105
|
+ triggerList.addTrigger((ActionType) trigger.getSelectedItem());
|
|
106
|
+ repopulateTriggers();
|
|
107
|
+ }
|
|
108
|
+ }
|
|
109
|
+
|
|
110
|
+ /** {@inheritDoc} */
|
|
111
|
+ @Override
|
|
112
|
+ public void triggerRemoved(final ActionType trigger) {
|
|
113
|
+ repopulateTriggers();
|
|
114
|
+ }
|
|
115
|
+
|
|
116
|
+ private void repopulateTriggers() {
|
|
117
|
+ SwingUtilities.invokeLater(new Runnable() {
|
|
118
|
+
|
|
119
|
+ /** {@inheritDoc} */
|
|
120
|
+ @Override
|
|
121
|
+ public void run() {
|
|
122
|
+ ((ActionTypeModel) trigger.getModel()).removeAllElements();
|
|
123
|
+
|
|
124
|
+ if (triggerList.getTriggerCount() == 0) {
|
|
125
|
+ System.out.println("all");
|
|
126
|
+ ((ActionTypeModel) trigger.getModel()).setTypeGroup(ActionManager.getTypeGroups());
|
|
127
|
+ return;
|
|
128
|
+ }
|
|
129
|
+
|
|
130
|
+ System.out.println("typed");
|
|
131
|
+ for (ActionType thisType : ActionManager.getCompatibleTypes(triggerList.getTrigger(0))) {
|
|
132
|
+ ((ActionTypeModel) trigger.getModel()).addElement(thisType);
|
|
133
|
+ }
|
|
134
|
+ }
|
|
135
|
+ });
|
58
|
136
|
}
|
59
|
137
|
}
|