Browse Source

Adds some advanced options to the AED.

Fixes issue 3911

Change-Id: I6c137739de587f77139cc12265bf627c10284af9
Reviewed-on: http://gerrit.dmdirc.com/1248
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.4
Greboid 14 years ago
parent
commit
7f2045cc20

+ 111
- 0
src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionAdvancedPanel.java View File

@@ -0,0 +1,111 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ * 
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ * 
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ * 
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.dialogs.actioneditor;
24
+
25
+import javax.swing.BorderFactory;
26
+import javax.swing.JCheckBox;
27
+import javax.swing.JLabel;
28
+import javax.swing.JPanel;
29
+import javax.swing.JTextField;
30
+import javax.swing.UIManager;
31
+
32
+import net.miginfocom.swing.MigLayout;
33
+
34
+/**
35
+ * Advanced options panel, show concurrency groups and enabled states.
36
+ */
37
+public class ActionAdvancedPanel extends JPanel {
38
+
39
+    /**
40
+     * A version number for this class. It should be changed whenever the class
41
+     * structure is changed (or anything else that would prevent serialized
42
+     * objects being unserialized with the new class).
43
+     */
44
+    private static final long serialVersionUID = 1;
45
+    private JLabel enabledLabel;
46
+    private JCheckBox enabled;
47
+    private JLabel groupLabel;
48
+    private JTextField group;
49
+
50
+    /**
51
+     * Creates a new panel to configure advanced options for actions.
52
+     */
53
+    public ActionAdvancedPanel() {
54
+        initComponents();
55
+        layoutComponents();
56
+    }
57
+
58
+    /** Initialises the components. */
59
+    private void initComponents() {
60
+        setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
61
+                "TitledBorder.border"), "Advanced"));
62
+        enabled = new JCheckBox("", true);
63
+        group = new JTextField();
64
+        enabledLabel = new JLabel("Enabled: ");
65
+        groupLabel = new JLabel("Concurrency group: ");
66
+    }
67
+
68
+    private void layoutComponents() {
69
+        setLayout(new MigLayout("fill, pack"));
70
+        add(enabledLabel, "");
71
+        add(enabled, "growx");
72
+        add(groupLabel, "");
73
+        add(group, "growx, pushx");
74
+    }
75
+
76
+    /**
77
+     * Gets the concurrency group for this action.
78
+     *
79
+     * @return Current concurrency group
80
+     */
81
+    public String getConcurrencyGroup() {
82
+        return group.getText();
83
+    }
84
+
85
+    /**
86
+     * Is the action currently enabled?
87
+     *
88
+     * @return true iif enabled
89
+     */
90
+    public boolean isActionEnabled() {
91
+        return enabled.isSelected();
92
+    }
93
+
94
+    /**
95
+     * Sets whether this action should be enabled.
96
+     *
97
+     * @param actionEnabled true to enable, false to disable
98
+     */
99
+    public void setActionEnabled(final boolean actionEnabled) {
100
+        enabled.setSelected(actionEnabled);
101
+    }
102
+
103
+    /**
104
+     * Sets this actions concurrency group.
105
+     *
106
+     * @param actionGroup New concurrency group
107
+     */
108
+    public void setConcurrencyGroup(final String actionGroup) {
109
+        group.setText(actionGroup);
110
+    }
111
+}

+ 27
- 5
src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialog.java View File

@@ -61,8 +61,12 @@ public class ActionEditorDialog extends StandardDialog implements ActionListener
61 61
     private ActionConditionsPanel conditions;
62 62
     /** Substitutions panel. */
63 63
     private ActionSubstitutionsPanel substitutions;
64
+    /** Advanced panel. */
65
+    private ActionAdvancedPanel advanced;
64 66
     /** Show substitutions button. */
65 67
     private JButton showSubstitutions;
68
+    /** Show advanced button. */
69
+    private JButton showAdvanced;
66 70
     /** Is the name valid? */
67 71
     private boolean nameValid = false;
68 72
     /** Are the triggers valid? */
@@ -183,6 +187,7 @@ public class ActionEditorDialog extends StandardDialog implements ActionListener
183 187
         response.setEnabled(action != null);
184 188
         conditions.setEnabled(action != null);
185 189
         substitutions.setVisible(false);
190
+        advanced.setVisible(false);
186 191
 
187 192
         triggersValid = action != null;
188 193
         conditionsValid = true;
@@ -197,6 +202,8 @@ public class ActionEditorDialog extends StandardDialog implements ActionListener
197 202
             conditions.setActionTrigger(action.getTriggers()[0]);
198 203
             conditions.setConditions(action.getConditions());
199 204
             conditions.setConditionTree(action.getRealConditionTree());
205
+            advanced.setActionEnabled(action.isEnabled());
206
+            advanced.setConcurrencyGroup(action.getConcurrencyGroup());
200 207
         }
201 208
     }
202 209
 
@@ -208,12 +215,15 @@ public class ActionEditorDialog extends StandardDialog implements ActionListener
208 215
         response = new ActionResponsePanel();
209 216
         conditions = new ActionConditionsPanel();
210 217
         substitutions = new ActionSubstitutionsPanel();
218
+        advanced = new ActionAdvancedPanel();
211 219
         showSubstitutions = new JButton("Show Substitutions");
220
+        showAdvanced = new JButton("Show Advanced Options");
212 221
     }
213 222
 
214 223
     /** Adds the listeners. */
215 224
     private void addListeners() {
216 225
         showSubstitutions.addActionListener(this);
226
+        showAdvanced.addActionListener(this);
217 227
         getOkButton().addActionListener(this);
218 228
         getCancelButton().addActionListener(this);
219 229
 
@@ -232,8 +242,10 @@ public class ActionEditorDialog extends StandardDialog implements ActionListener
232 242
         add(triggers, "grow, w 50%");
233 243
         add(response, "grow, pushy, w 50%");
234 244
         add(substitutions, "spanx, grow, push");
235
-        add(showSubstitutions, "left, sgx button, split 3, spanx 2");
236
-        add(getLeftButton(), "right, sgx button, gapleft push");
245
+        add(advanced, "spanx, grow, push");
246
+        add(showSubstitutions, "left, sgx button, split 2");
247
+        add(showAdvanced, "left, sgx button");
248
+        add(getLeftButton(), "right, sgx button, gapleft push, split");
237 249
         add(getRightButton(), "right, sgx button");
238 250
     }
239 251
 
@@ -249,6 +261,10 @@ public class ActionEditorDialog extends StandardDialog implements ActionListener
249 261
             showSubstitutions.setText(substitutions.isVisible() ? "Hide Substitutions"
250 262
                     : "Show Substitutions");
251 263
                     pack();
264
+        } else if (e.getSource().equals(showAdvanced)) {
265
+            advanced.setVisible(!advanced.isVisible());
266
+            showAdvanced.setText(advanced.isVisible() ? "Hide Advanced Options"
267
+                    : "Show Advanced Options");
252 268
         } else if (e.getSource().equals(getOkButton())) {
253 269
             save();
254 270
             dispose();
@@ -281,9 +297,12 @@ public class ActionEditorDialog extends StandardDialog implements ActionListener
281 297
         conditions.getConditions();
282 298
         conditions.getConditionTree();
283 299
         if (action == null) {
284
-            new Action(group, name.getActionName(), triggers.getTriggers(),
285
-                    response.getResponse(), conditions.getConditions(),
286
-                    conditions.getConditionTree(), response.getFormatter());
300
+            final Action newAction = new Action(group, name.getActionName(),
301
+                    triggers.getTriggers(), response.getResponse(),
302
+                    conditions.getConditions(), conditions.getConditionTree(),
303
+                    response.getFormatter());
304
+            newAction.setConcurrencyGroup(advanced.getConcurrencyGroup());
305
+            newAction.setEnabled(advanced.isActionEnabled());
287 306
         } else {
288 307
             action.setName(name.getActionName());
289 308
             action.setConditionTree(conditions.getConditionTree());
@@ -291,6 +310,8 @@ public class ActionEditorDialog extends StandardDialog implements ActionListener
291 310
             action.setNewFormat(response.getFormatter());
292 311
             action.setResponse(response.getResponse());
293 312
             action.setTriggers(triggers.getTriggers());
313
+            action.setConcurrencyGroup(advanced.getConcurrencyGroup());
314
+            action.setEnabled(advanced.isActionEnabled());
294 315
             action.save();
295 316
         }
296 317
     }
@@ -309,6 +330,7 @@ public class ActionEditorDialog extends StandardDialog implements ActionListener
309 330
             response.setEnabled((Boolean) evt.getNewValue());
310 331
             conditions.setEnabled((Boolean) evt.getNewValue());
311 332
             substitutions.setEnabled((Boolean) evt.getNewValue());
333
+            advanced.setEnabled((Boolean) evt.getNewValue());
312 334
 
313 335
             substitutions.setType(triggers.getPrimaryTrigger());
314 336
             conditions.setActionTrigger(triggers.getPrimaryTrigger());

Loading…
Cancel
Save