Explorar el Código

Merge pull request #230 from csmith/master

Kill the actions UI. With fire.
pull/231/head
Greg Holmes hace 9 años
padre
commit
4937f76c35
Se han modificado 29 ficheros con 0 adiciones y 4632 borrados
  1. 0
    11
      ui_swing/src/com/dmdirc/addons/ui_swing/components/menubar/SettingsMenu.java
  2. 0
    134
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionAdvancedPanel.java
  3. 0
    290
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionConditionDisplayPanel.java
  4. 0
    315
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionConditionEditorPanel.java
  5. 0
    37
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionConditionRemovalListener.java
  6. 0
    275
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionConditionsListPanel.java
  7. 0
    217
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionConditionsPanel.java
  8. 0
    269
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionConditionsTreePanel.java
  9. 0
    315
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialog.java
  10. 0
    81
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialogFactory.java
  11. 0
    173
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionNamePanel.java
  12. 0
    179
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionResponsePanel.java
  13. 0
    95
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionSubstitutionsPanel.java
  14. 0
    39
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionTriggerRemovalListener.java
  15. 0
    239
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionTriggersListPanel.java
  16. 0
    305
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionTriggersPanel.java
  17. 0
    116
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionTypeModel.java
  18. 0
    136
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionGroupInformationPanel.java
  19. 0
    39
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionGroupNameComparator.java
  20. 0
    77
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionGroupNoDuplicatesInListValidator.java
  21. 0
    177
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionGroupSettingsPanel.java
  22. 0
    220
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionTableModel.java
  23. 0
    55
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionTypeTableCellRenderer.java
  24. 0
    256
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsGroupPanel.java
  25. 0
    49
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsGroupPanelFactory.java
  26. 0
    424
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsManagerDialog.java
  27. 0
    43
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ArrayCellRenderer.java
  28. 0
    58
      ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/SettingsRevertButton.java
  29. 0
    8
      ui_swing/src/com/dmdirc/addons/ui_swing/injection/DialogModule.java

+ 0
- 11
ui_swing/src/com/dmdirc/addons/ui_swing/components/menubar/SettingsMenu.java Ver fichero

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.addons.ui_swing.components.menubar;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.Apple;
26
-import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog;
27 26
 import com.dmdirc.addons.ui_swing.dialogs.aliases.AliasManagerDialog;
28 27
 import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
29 28
 import com.dmdirc.addons.ui_swing.dialogs.profile.ProfileManagerDialog;
@@ -44,8 +43,6 @@ public class SettingsMenu extends JMenu {
44 43
     private static final long serialVersionUID = 1;
45 44
     /** Provider of profile manager dialogs. */
46 45
     private final DialogProvider<ProfileManagerDialog> profileDialogProvider;
47
-    /** Provider of action manager dialogs. */
48
-    private final DialogProvider<ActionsManagerDialog> actionsDialogProvider;
49 46
     /** Provider of preferences dialogs. */
50 47
     private final DialogProvider<SwingPreferencesDialog> prefsDialogProvider;
51 48
     /** Provider of alias manager dialogs. */
@@ -54,12 +51,10 @@ public class SettingsMenu extends JMenu {
54 51
     @Inject
55 52
     public SettingsMenu(
56 53
             final DialogProvider<ProfileManagerDialog> profileDialogProvider,
57
-            final DialogProvider<ActionsManagerDialog> actionsDialogProvider,
58 54
             final DialogProvider<SwingPreferencesDialog> prefsDialogProvider,
59 55
             final DialogProvider<AliasManagerDialog> aliasDialogProvider) {
60 56
         super("Settings");
61 57
         this.profileDialogProvider = profileDialogProvider;
62
-        this.actionsDialogProvider = actionsDialogProvider;
63 58
         this.prefsDialogProvider = prefsDialogProvider;
64 59
         this.aliasDialogProvider = aliasDialogProvider;
65 60
 
@@ -89,12 +84,6 @@ public class SettingsMenu extends JMenu {
89 84
 
90 85
         menuItem = new JMenuItem();
91 86
         menuItem.setMnemonic('a');
92
-        menuItem.setText("Actions Manager");
93
-        menuItem.addActionListener(e -> actionsDialogProvider.displayOrRequestFocus());
94
-        add(menuItem);
95
-
96
-        menuItem = new JMenuItem();
97
-        menuItem.setMnemonic('l');
98 87
         menuItem.setText("Alias Manager");
99 88
         menuItem.addActionListener(e -> aliasDialogProvider.displayOrRequestFocus());
100 89
         add(menuItem);

+ 0
- 134
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionAdvancedPanel.java Ver fichero

@@ -1,134 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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
-    /** A version number for this class. */
40
-    private static final long serialVersionUID = 1;
41
-    private JLabel enabledLabel;
42
-    private JCheckBox enabled;
43
-    private JLabel groupLabel;
44
-    private JTextField group;
45
-    private JLabel stopLabel;
46
-    private JCheckBox stop;
47
-
48
-    /**
49
-     * Creates a new panel to configure advanced options for actions.
50
-     */
51
-    public ActionAdvancedPanel() {
52
-        initComponents();
53
-        layoutComponents();
54
-    }
55
-
56
-    /** Initialises the components. */
57
-    private void initComponents() {
58
-        setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
59
-                "TitledBorder.border"), "Advanced"));
60
-        enabled = new JCheckBox("", true);
61
-        enabled.setName("enabled");
62
-        group = new JTextField();
63
-        stop = new JCheckBox("", false);
64
-        stop.setName("stop");
65
-        enabledLabel = new JLabel("Enabled: ");
66
-        groupLabel = new JLabel("Concurrency group: ");
67
-        stopLabel = new JLabel("Stop default behaviour: ");
68
-    }
69
-
70
-    private void layoutComponents() {
71
-        setLayout(new MigLayout("fillx, pack"));
72
-        add(enabledLabel, "");
73
-        add(enabled, "growx");
74
-        add(stopLabel, "");
75
-        add(stop, "growx, pushx, wrap");
76
-        add(groupLabel, "");
77
-        add(group, "growx, pushx, spanx");
78
-    }
79
-
80
-    /**
81
-     * Gets the concurrency group for this action.
82
-     *
83
-     * @return Current concurrency group
84
-     */
85
-    public String getConcurrencyGroup() {
86
-        return group.getText();
87
-    }
88
-
89
-    /**
90
-     * Is the action currently enabled?
91
-     *
92
-     * @return true iif enabled
93
-     */
94
-    public boolean isActionEnabled() {
95
-        return enabled.isSelected();
96
-    }
97
-
98
-    /**
99
-     * Sets whether this action should be enabled.
100
-     *
101
-     * @param actionEnabled true to enable, false to disable
102
-     */
103
-    public void setActionEnabled(final boolean actionEnabled) {
104
-        enabled.setSelected(actionEnabled);
105
-    }
106
-
107
-    /**
108
-     * Sets this actions concurrency group.
109
-     *
110
-     * @param actionGroup New concurrency group
111
-     */
112
-    public void setConcurrencyGroup(final String actionGroup) {
113
-        group.setText(actionGroup);
114
-    }
115
-
116
-    /**
117
-     * Does the action currently stop the default behaviour?
118
-     *
119
-     * @return true iif stopped
120
-     */
121
-    public boolean isActionStopped() {
122
-        return stop.isSelected();
123
-    }
124
-
125
-    /**
126
-     * Sets whether this action should be enabled.
127
-     *
128
-     * @param actionStopped true to enable, false to disable
129
-     */
130
-    public void setActionStopped(final boolean actionStopped) {
131
-        stop.setSelected(actionStopped);
132
-    }
133
-
134
-}

+ 0
- 290
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionConditionDisplayPanel.java Ver fichero

@@ -1,290 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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 com.dmdirc.actions.ActionCondition;
26
-import com.dmdirc.actions.ActionManager;
27
-import com.dmdirc.addons.ui_swing.components.ImageButton;
28
-import com.dmdirc.addons.ui_swing.components.ImageToggleButton;
29
-import com.dmdirc.addons.ui_swing.components.text.TextLabel;
30
-import com.dmdirc.interfaces.actions.ActionType;
31
-import com.dmdirc.ui.IconManager;
32
-import com.dmdirc.util.collections.ListenerList;
33
-
34
-import java.awt.event.ActionEvent;
35
-import java.awt.event.ActionListener;
36
-import java.beans.PropertyChangeEvent;
37
-import java.beans.PropertyChangeListener;
38
-
39
-import javax.swing.JPanel;
40
-import javax.swing.JToggleButton;
41
-
42
-import net.miginfocom.swing.MigLayout;
43
-
44
-/**
45
- * Action condition display panel.
46
- */
47
-public class ActionConditionDisplayPanel extends JPanel implements
48
-        ActionListener, PropertyChangeListener {
49
-
50
-    /** Serial version UID. */
51
-    private static final long serialVersionUID = 1;
52
-    private final ActionManager actionManager;
53
-    /** Info label. */
54
-    private TextLabel label;
55
-    /** Edit button. */
56
-    private JToggleButton editButton;
57
-    /** Delete button. */
58
-    private ImageButton<Object> deleteButton;
59
-    /** Edit panel. */
60
-    private ActionConditionEditorPanel editPanel;
61
-    /** Listeners. */
62
-    private ListenerList listeners;
63
-    /** Action condition. */
64
-    private ActionCondition condition;
65
-    /** Action trigger. */
66
-    private ActionType trigger;
67
-
68
-    /**
69
-     * Instantiates the panel.
70
-     *
71
-     * @param iconManager Icon Manager
72
-     * @param condition   Action condition
73
-     * @param trigger     Action trigger
74
-     */
75
-    public ActionConditionDisplayPanel(final ActionManager actionManager,
76
-            final IconManager  iconManager,final ActionCondition condition,
77
-            final ActionType trigger) {
78
-
79
-        this.actionManager = actionManager;
80
-        this.trigger = trigger;
81
-        this.condition = new ActionCondition(condition.getArg(),
82
-                condition.getComponent(), condition.getComparison(),
83
-                condition.getTarget());
84
-
85
-        initComponents(iconManager);
86
-        addListeners();
87
-        layoutComponents();
88
-        setTrigger(trigger);
89
-        validate();
90
-        layoutComponents();
91
-
92
-        if (condition.getArg() == -1 && condition.getComponent() == null && condition.
93
-                getComparison() == null
94
-                && condition.getTarget().isEmpty()) {
95
-            editPanel.setVisible(true);
96
-            editButton.setSelected(true);
97
-        }
98
-    }
99
-
100
-    /**
101
-     * Sets the action trigger.
102
-     *
103
-     * @param trigger new trigger
104
-     */
105
-    void setTrigger(final ActionType trigger) {
106
-        this.trigger = trigger;
107
-        editPanel.setTrigger(trigger);
108
-
109
-        editPanel.setVisible(trigger == null);
110
-        editButton.setSelected(trigger == null);
111
-
112
-        label.setText(updateSentence());
113
-    }
114
-
115
-    /**
116
-     * Sets the action condition.
117
-     *
118
-     * @param condition new condition
119
-     */
120
-    protected void setCondition(final ActionCondition condition) {
121
-        this.condition = condition;
122
-
123
-        label.setText(updateSentence());
124
-    }
125
-
126
-    /**
127
-     * Initialises the components.
128
-     *
129
-     * @param iconManager Icon Manager
130
-     */
131
-    private void initComponents(final IconManager iconManager) {
132
-        label = new TextLabel("", false);
133
-        editButton = new ImageToggleButton("edit", iconManager.
134
-                getIcon("edit-inactive"), iconManager.getIcon("edit"));
135
-        deleteButton = new ImageButton<>("delete", iconManager.
136
-                getIcon("close-inactive"), iconManager.
137
-                getIcon("close-inactive"), iconManager.getIcon("close-active"));
138
-
139
-        editPanel = new ActionConditionEditorPanel(actionManager, condition, trigger);
140
-        listeners = new ListenerList();
141
-
142
-        editPanel.setVisible(trigger == null);
143
-        editButton.setSelected(trigger == null);
144
-    }
145
-
146
-    /** Adds the listeners. */
147
-    private void addListeners() {
148
-        editButton.addActionListener(this);
149
-        deleteButton.addActionListener(this);
150
-        editPanel.addPropertyChangeListener("edit", this);
151
-        editPanel.addPropertyChangeListener("validationResult", this);
152
-    }
153
-
154
-    /** Lays out the components. */
155
-    private void layoutComponents() {
156
-        setLayout(new MigLayout("ins 0, fillx, hidemode 3, pack, wmax 90%"));
157
-        add(label, "grow, push, wmax 85%");
158
-        add(editButton, "right");
159
-        add(deleteButton, "right, wrap");
160
-        add(editPanel, "alignx right");
161
-    }
162
-
163
-    @Override
164
-    public void actionPerformed(final ActionEvent e) {
165
-        if (e.getSource().equals(deleteButton)) {
166
-            fireConditionRemoved(this);
167
-        } else if (e.getSource().equals(editButton)) {
168
-            editPanel.setVisible(editButton.getModel().isSelected());
169
-        }
170
-    }
171
-
172
-    /**
173
-     * Adds an ActionConditionRemovalListener to the listener list.
174
-     *
175
-     * @param listener Listener to add
176
-     */
177
-    public void addConditionListener(
178
-            final ActionConditionRemovalListener listener) {
179
-        if (listener == null) {
180
-            return;
181
-        }
182
-
183
-        listeners.add(ActionConditionRemovalListener.class, listener);
184
-    }
185
-
186
-    /**
187
-     * Removes an ActionConditionRemovalListener from the listener list.
188
-     *
189
-     * @param listener Listener to remove
190
-     */
191
-    public void removeConditionListener(
192
-            final ActionConditionRemovalListener listener) {
193
-        listeners.remove(ActionConditionRemovalListener.class, listener);
194
-    }
195
-
196
-    /**
197
-     * Fired when the an action condition is removed.
198
-     *
199
-     * @param condition Removed condition
200
-     */
201
-    protected void fireConditionRemoved(
202
-            final ActionConditionDisplayPanel condition) {
203
-        for (final ActionConditionRemovalListener listener : listeners
204
-                .get(ActionConditionRemovalListener.class)) {
205
-            listener.conditionRemoved(condition);
206
-        }
207
-    }
208
-
209
-    @Override
210
-    public void setEnabled(final boolean enabled) {
211
-        editPanel.setEnabled(enabled);
212
-        editButton.setEnabled(enabled);
213
-        deleteButton.setEnabled(enabled);
214
-    }
215
-
216
-    /**
217
-     * Updates the condition sentence.
218
-     *
219
-     * @return Updated sentence
220
-     */
221
-    private String updateSentence() {
222
-        if (trigger == null) {
223
-            return "...";
224
-        } else {
225
-            final StringBuilder sb = new StringBuilder("The ");
226
-
227
-            if (condition.getArg() == -1) {
228
-                sb.append(" ...");
229
-                return sb.toString();
230
-            }
231
-
232
-            sb.append(trigger.getType().getArgNames()[condition.getArg()]);
233
-            sb.append("'s ");
234
-
235
-            if (condition.getComponent() == null) {
236
-                sb.append(" ...");
237
-                return sb.toString();
238
-            }
239
-
240
-            sb.append(condition.getComponent().getName());
241
-            sb.append(' ');
242
-
243
-            if (condition.getComparison() == null) {
244
-                sb.append(" ...");
245
-                return sb.toString();
246
-            }
247
-
248
-            sb.append(condition.getComparison().getName());
249
-            sb.append(" '");
250
-
251
-            if (condition.getTarget() == null) {
252
-                sb.append(" ...");
253
-                return sb.toString();
254
-            }
255
-
256
-            sb.append(condition.getTarget().replace("<", "&lt;"));
257
-            sb.append('\'');
258
-            return sb.toString();
259
-        }
260
-    }
261
-
262
-    /**
263
-     * Returns the action condition represented by this panel.
264
-     *
265
-     * @return Action condition
266
-     */
267
-    public ActionCondition getCondition() {
268
-        return condition;
269
-    }
270
-
271
-    @Override
272
-    public void propertyChange(final PropertyChangeEvent evt) {
273
-        if ("edit".equals(evt.getPropertyName())) {
274
-            label.setText(updateSentence());
275
-        } else {
276
-            firePropertyChange("validationResult", evt.getOldValue(),
277
-                    evt.getNewValue());
278
-        }
279
-    }
280
-
281
-    /**
282
-     * Checks if this editor panel has errored.
283
-     *
284
-     * @return true iif the content it valid
285
-     */
286
-    public boolean checkError() {
287
-        return editPanel.checkError();
288
-    }
289
-
290
-}

+ 0
- 315
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionConditionEditorPanel.java Ver fichero

@@ -1,315 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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 com.dmdirc.actions.ActionCondition;
26
-import com.dmdirc.addons.ui_swing.UIUtilities;
27
-import com.dmdirc.addons.ui_swing.components.renderers.PropertyListCellRenderer;
28
-import com.dmdirc.addons.ui_swing.components.renderers.ToStringListCellRenderer;
29
-import com.dmdirc.interfaces.ActionController;
30
-import com.dmdirc.interfaces.actions.ActionComparison;
31
-import com.dmdirc.interfaces.actions.ActionComponent;
32
-import com.dmdirc.interfaces.actions.ActionType;
33
-
34
-import java.awt.event.ActionEvent;
35
-import java.awt.event.ActionListener;
36
-import java.beans.PropertyChangeEvent;
37
-import java.beans.PropertyChangeListener;
38
-
39
-import javax.swing.DefaultComboBoxModel;
40
-import javax.swing.JComboBox;
41
-import javax.swing.JLabel;
42
-import javax.swing.JPanel;
43
-import javax.swing.JTextField;
44
-import javax.swing.MutableComboBoxModel;
45
-import javax.swing.event.DocumentEvent;
46
-import javax.swing.event.DocumentListener;
47
-
48
-import net.miginfocom.swing.MigLayout;
49
-
50
-/**
51
- * Action condition editor panel.
52
- */
53
-public class ActionConditionEditorPanel extends JPanel implements
54
-        ActionListener, DocumentListener, PropertyChangeListener {
55
-
56
-    /** A version number for this class. */
57
-    private static final long serialVersionUID = 1;
58
-    /** Condition. */
59
-    private final ActionCondition condition;
60
-    /** Action manager to manage actions. */
61
-    private final ActionController actionManager;
62
-    /** Trigger. */
63
-    private ActionType trigger;
64
-    /** Argument. */
65
-    private JComboBox<String> arguments;
66
-    /** Component. */
67
-    private JComboBox<ActionComponent> components;
68
-    /** Comparison. */
69
-    private JComboBox<ActionComparison> comparisons;
70
-    /** Target. */
71
-    private JTextField target;
72
-
73
-    /**
74
-     * Instantiates the panel.
75
-     *
76
-     * @param condition Action condition
77
-     * @param trigger   Action trigger
78
-     */
79
-    public ActionConditionEditorPanel(final ActionController actionManager,
80
-            final ActionCondition condition, final ActionType trigger) {
81
-
82
-        this.actionManager = actionManager;
83
-        this.condition = condition;
84
-        this.trigger = trigger;
85
-
86
-        initComponents();
87
-
88
-        if (trigger == null) {
89
-            setEnabled(false);
90
-        } else {
91
-            populateArguments();
92
-            populateComponents();
93
-            populateComparisons();
94
-            populateTarget();
95
-        }
96
-
97
-        firePropertyChange("edit", null, null);
98
-
99
-        addListeners();
100
-        layoutComponents();
101
-        setEnabled(trigger != null);
102
-    }
103
-
104
-    /** Initialises the components. */
105
-    private void initComponents() {
106
-        arguments = new JComboBox<>(new DefaultComboBoxModel<>());
107
-        arguments.putClientProperty("JComboBox.isTableCellEditor",
108
-                Boolean.TRUE);
109
-        arguments.setName("argument");
110
-        UIUtilities.addComboBoxWidthModifier(arguments);
111
-        components = new JComboBox<>(new DefaultComboBoxModel<>());
112
-        components.putClientProperty("JComboBox.isTableCellEditor",
113
-                Boolean.TRUE);
114
-        components.setName("component");
115
-        UIUtilities.addComboBoxWidthModifier(components);
116
-        comparisons = new JComboBox<>(new DefaultComboBoxModel<>());
117
-        comparisons.putClientProperty("JComboBox.isTableCellEditor",
118
-                Boolean.TRUE);
119
-        comparisons.setName("comparison");
120
-        UIUtilities.addComboBoxWidthModifier(comparisons);
121
-
122
-        target = new JTextField() {
123
-            /** Serial version UID. */
124
-            private static final long serialVersionUID = 1;
125
-
126
-            @Override
127
-            public void setEnabled(final boolean enabled) {
128
-                firePropertyChange("validationResult", target.isEnabled(),
129
-                        enabled);
130
-                super.setEnabled(enabled);
131
-            }
132
-        };
133
-
134
-        arguments.setRenderer(new ToStringListCellRenderer<>(arguments.getRenderer(), String.class));
135
-        components.setRenderer(new PropertyListCellRenderer<>(components.getRenderer(),
136
-                ActionComponent.class, "name"));
137
-        comparisons.setRenderer(new PropertyListCellRenderer<>(comparisons.getRenderer(),
138
-                ActionComparison.class, "name"));
139
-
140
-        components.setEnabled(false);
141
-        comparisons.setEnabled(false);
142
-        target.setEnabled(false);
143
-    }
144
-
145
-    /** Populates the arguments combo box. */
146
-    private void populateArguments() {
147
-        ((DefaultComboBoxModel<String>) arguments.getModel()).removeAllElements();
148
-
149
-        for (String arg : trigger.getType().getArgNames()) {
150
-            ((MutableComboBoxModel<String>) arguments.getModel()).addElement(arg);
151
-        }
152
-        arguments.setSelectedIndex(condition.getArg());
153
-    }
154
-
155
-    /** Populates the components combo box. */
156
-    private void populateComponents() {
157
-        ((DefaultComboBoxModel<ActionComponent>) components.getModel()).removeAllElements();
158
-
159
-        if (condition.getArg() != -1) {
160
-            actionManager.findCompatibleComponents(trigger.getType()
161
-                    .getArgTypes()[condition.getArg()])
162
-                    .forEach(((MutableComboBoxModel<ActionComponent>) components.getModel())
163
-                            ::addElement);
164
-        }
165
-        components.setSelectedItem(condition.getComponent());
166
-    }
167
-
168
-    /** Populates the comparisons combo box. */
169
-    private void populateComparisons() {
170
-        ((DefaultComboBoxModel<ActionComparison>) comparisons.getModel()).removeAllElements();
171
-
172
-        if (condition.getComponent() != null) {
173
-            actionManager.findCompatibleComparisons(condition.getComponent().getType())
174
-                    .forEach(((MutableComboBoxModel<ActionComparison>) comparisons.getModel())
175
-                            ::addElement);
176
-        }
177
-        comparisons.setSelectedItem(condition.getComparison());
178
-    }
179
-
180
-    /** Populates the target textfield. */
181
-    private void populateTarget() {
182
-        target.setText(condition.getTarget());
183
-    }
184
-
185
-    /** Handles the argument changing. */
186
-    private void handleArgumentChange() {
187
-        condition.setArg(arguments.getSelectedIndex());
188
-        populateComponents();
189
-        components.setEnabled(true);
190
-        components.setSelectedItem(null);
191
-        comparisons.setSelectedItem(null);
192
-        comparisons.setEnabled(false);
193
-        target.setText(null);
194
-        target.setEnabled(false);
195
-    }
196
-
197
-    /** Handles the component changing. */
198
-    private void handleComponentChange() {
199
-        condition.setComponent((ActionComponent) components.getSelectedItem());
200
-        populateComparisons();
201
-        comparisons.setEnabled(true);
202
-        comparisons.setSelectedItem(null);
203
-        target.setText(null);
204
-        target.setEnabled(false);
205
-    }
206
-
207
-    /** Handles the comparison changing. */
208
-    private void handleComparisonChange() {
209
-        condition.setComparison((ActionComparison) comparisons
210
-                .getSelectedItem());
211
-        populateTarget();
212
-        target.setEnabled(true);
213
-    }
214
-
215
-    /** Adds the listeners. */
216
-    private void addListeners() {
217
-        arguments.addActionListener(this);
218
-        components.addActionListener(this);
219
-        comparisons.addActionListener(this);
220
-        target.getDocument().addDocumentListener(this);
221
-        target.addPropertyChangeListener("validationResult", this);
222
-    }
223
-
224
-    /** Lays out the components. */
225
-    private void layoutComponents() {
226
-        setLayout(new MigLayout("wrap 2, pack"));
227
-
228
-        add(new JLabel("Argument:"), "align right");
229
-        add(arguments, "growx, wmax 200");
230
-        add(new JLabel("Component:"), "align right");
231
-        add(components, "growx, wmax 200");
232
-        add(new JLabel("Comparison:"), "align right");
233
-        add(comparisons, "growx, wmax 200");
234
-        add(new JLabel("Target:"), "align right");
235
-        add(target, "growx");
236
-    }
237
-
238
-    @Override
239
-    public void actionPerformed(final ActionEvent e) {
240
-        if (e.getSource() == arguments) {
241
-            handleArgumentChange();
242
-        } else if (e.getSource() == components) {
243
-            handleComponentChange();
244
-        } else if (e.getSource() == comparisons) {
245
-            handleComparisonChange();
246
-        }
247
-        firePropertyChange("edit", null, null);
248
-    }
249
-
250
-    @Override
251
-    public void insertUpdate(final DocumentEvent e) {
252
-        synchronized (condition) {
253
-            condition.setTarget(target.getText());
254
-        }
255
-        firePropertyChange("edit", null, null);
256
-    }
257
-
258
-    @Override
259
-    public void removeUpdate(final DocumentEvent e) {
260
-        synchronized (condition) {
261
-            condition.setTarget(target.getText());
262
-        }
263
-        firePropertyChange("edit", null, null);
264
-    }
265
-
266
-    @Override
267
-    public void changedUpdate(final DocumentEvent e) {
268
-        //Ignore
269
-    }
270
-
271
-    @Override
272
-    public void setEnabled(final boolean enabled) {
273
-        super.setEnabled(enabled);
274
-        arguments.setEnabled(enabled);
275
-        if (enabled) {
276
-            components.setEnabled(arguments.getSelectedIndex() != -1);
277
-            comparisons.setEnabled(components.getSelectedIndex() != -1);
278
-            target.setEnabled(comparisons.getSelectedIndex() != -1);
279
-        } else {
280
-            components.setEnabled(false);
281
-            comparisons.setEnabled(false);
282
-            target.setEnabled(false);
283
-        }
284
-    }
285
-
286
-    /**
287
-     * Sets the action trigger.
288
-     *
289
-     * @param trigger new trigger
290
-     */
291
-    public void setTrigger(final ActionType trigger) {
292
-        this.trigger = trigger;
293
-
294
-        setEnabled(trigger != null);
295
-        if (trigger != null && !trigger.equals(this.trigger)) {
296
-            populateArguments();
297
-        }
298
-    }
299
-
300
-    @Override
301
-    public void propertyChange(final PropertyChangeEvent evt) {
302
-        firePropertyChange("validationResult", evt.getOldValue(),
303
-                evt.getNewValue());
304
-    }
305
-
306
-    /**
307
-     * Checks if this editor panel has errored.
308
-     *
309
-     * @return true iif the content it valid
310
-     */
311
-    public boolean checkError() {
312
-        return target.isEnabled();
313
-    }
314
-
315
-}

+ 0
- 37
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionConditionRemovalListener.java Ver fichero

@@ -1,37 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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
-/**
26
- * Action condition removal listener.
27
- */
28
-public interface ActionConditionRemovalListener {
29
-
30
-    /**
31
-     * A condition was removed from the list.
32
-     *
33
-     * @param condition Condition to be removed
34
-     */
35
-    void conditionRemoved(ActionConditionDisplayPanel condition);
36
-
37
-}

+ 0
- 275
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionConditionsListPanel.java Ver fichero

@@ -1,275 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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 com.dmdirc.actions.ActionCondition;
26
-import com.dmdirc.actions.ActionManager;
27
-import com.dmdirc.addons.ui_swing.components.text.TextLabel;
28
-import com.dmdirc.interfaces.actions.ActionType;
29
-import com.dmdirc.ui.IconManager;
30
-
31
-import java.beans.PropertyChangeEvent;
32
-import java.beans.PropertyChangeListener;
33
-import java.util.ArrayList;
34
-import java.util.HashMap;
35
-import java.util.List;
36
-import java.util.Map;
37
-import java.util.stream.Collectors;
38
-
39
-import javax.swing.JLabel;
40
-import javax.swing.JPanel;
41
-
42
-import net.miginfocom.swing.MigLayout;
43
-
44
-/**
45
- * Action conditions list panel.
46
- */
47
-public class ActionConditionsListPanel extends JPanel implements
48
-        ActionConditionRemovalListener,
49
-        PropertyChangeListener {
50
-
51
-    /** Serial version UID. */
52
-    private static final long serialVersionUID = 1;
53
-    /** Conditions list. */
54
-    private final List<ActionConditionDisplayPanel> conditions;
55
-    /** Condition tree panel. */
56
-    private final ActionConditionsTreePanel treePanel;
57
-    /** Condition validation results. */
58
-    private final Map<ActionConditionDisplayPanel, Boolean> validations;
59
-    /** Icon manager. */
60
-    private final IconManager iconManager;
61
-    private final ActionManager actionManager;
62
-    /** Action trigger. */
63
-    private ActionType trigger;
64
-    /** validates. */
65
-    private boolean validates = true;
66
-
67
-    /**
68
-     * Instantiates the panel.
69
-     *
70
-     * @param iconManager Icon manager
71
-     * @param treePanel   Condition tree panel.
72
-     */
73
-    public ActionConditionsListPanel(final ActionManager actionManager,
74
-            final IconManager iconManager,
75
-            final ActionConditionsTreePanel treePanel) {
76
-        this(actionManager, iconManager, null, new ArrayList<>(),
77
-                treePanel);
78
-    }
79
-
80
-    /**
81
-     * Instantiates the panel.
82
-     *
83
-     * @param iconManager Icon manager to retrieve icons
84
-     * @param trigger     Action trigger
85
-     * @param conditions  List of existing conditions;
86
-     * @param treePanel   Condition tree panel.
87
-     */
88
-    public ActionConditionsListPanel(final ActionManager actionManager,
89
-            final IconManager iconManager,
90
-            final ActionType trigger,
91
-            final List<ActionConditionDisplayPanel> conditions,
92
-            final ActionConditionsTreePanel treePanel) {
93
-
94
-        validations = new HashMap<>();
95
-
96
-        this.actionManager = actionManager;
97
-        this.iconManager = iconManager;
98
-        this.trigger = trigger;
99
-        this.conditions = new ArrayList<>(conditions);
100
-        this.treePanel = treePanel;
101
-
102
-        initComponents();
103
-        addListeners();
104
-        layoutComponents();
105
-    }
106
-
107
-    /** Initialises the components. */
108
-    private void initComponents() {
109
-        setLayout(new MigLayout("fillx, wrap 2, pack"));
110
-
111
-        if (trigger == null) {
112
-            setEnabled(false);
113
-        }
114
-    }
115
-
116
-    /** Adds the listeners. */
117
-    private void addListeners() {
118
-        for (final ActionConditionDisplayPanel condition : conditions) {
119
-            condition.addConditionListener(this);
120
-        }
121
-    }
122
-
123
-    /** Lays out the components. */
124
-    private void layoutComponents() {
125
-        setVisible(false);
126
-        removeAll();
127
-        if (trigger == null) {
128
-            add(new TextLabel(
129
-                    "You must add at least one trigger before you can add conditions."),
130
-                    "alignx center, aligny top, grow, push, w 90%!");
131
-        } else if (trigger.getType().getArgNames().length == 0) {
132
-            add(new TextLabel("Trigger does not have any arguments."),
133
-                    "alignx center, aligny top, grow, push, w 90%!");
134
-        } else {
135
-            int index = 0;
136
-            synchronized (conditions) {
137
-                for (final ActionConditionDisplayPanel condition : conditions) {
138
-                    add(new JLabel(index + "."), "aligny top");
139
-                    add(condition, "growx, pushx, aligny top");
140
-                    index++;
141
-                }
142
-            }
143
-            if (index == 0) {
144
-                add(new JLabel("No conditions."),
145
-                        "alignx center, aligny top, growx, pushx");
146
-            }
147
-        }
148
-        setVisible(true);
149
-
150
-    }
151
-
152
-    /**
153
-     * Adds an action condition to the list.
154
-     *
155
-     * @param condition Action condition
156
-     */
157
-    public void addCondition(final ActionCondition condition) {
158
-        final ActionConditionDisplayPanel panel = new ActionConditionDisplayPanel(actionManager,
159
-                iconManager, condition, trigger);
160
-        panel.addConditionListener(this);
161
-        panel.addPropertyChangeListener("validationResult", this);
162
-        validations.put(panel, panel.checkError());
163
-        propertyChange(null);
164
-        synchronized (conditions) {
165
-            conditions.add(panel);
166
-        }
167
-        treePanel.setConditionCount(conditions.size());
168
-        layoutComponents();
169
-    }
170
-
171
-    /**
172
-     * Deletes an action condition from the list.
173
-     *
174
-     * @param condition Action condition
175
-     */
176
-    public void delCondition(final ActionCondition condition) {
177
-        ActionConditionDisplayPanel removeCondition = null;
178
-
179
-        synchronized (conditions) {
180
-            for (final ActionConditionDisplayPanel localCondition : conditions) {
181
-                if (localCondition.getCondition().equals(condition)) {
182
-                    removeCondition = localCondition;
183
-                    break;
184
-                }
185
-            }
186
-        }
187
-
188
-        treePanel.setConditionCount(conditions.size());
189
-
190
-        if (removeCondition != null) {
191
-            conditionRemoved(removeCondition);
192
-        }
193
-    }
194
-
195
-    /**
196
-     * Clear conditions.
197
-     */
198
-    public void clearConditions() {
199
-        for (final ActionConditionDisplayPanel condition : conditions) {
200
-            delCondition(condition.getCondition());
201
-        }
202
-    }
203
-
204
-    /**
205
-     * Returns the condition list.
206
-     *
207
-     * @return condition list
208
-     */
209
-    public List<ActionCondition> getConditions() {
210
-        final List<ActionCondition> conditionList = new ArrayList<>();
211
-
212
-        synchronized (conditions) {
213
-            conditionList.addAll(conditions.stream()
214
-                    .map(ActionConditionDisplayPanel::getCondition)
215
-                    .collect(Collectors.toList()));
216
-        }
217
-
218
-        return conditionList;
219
-    }
220
-
221
-    /**
222
-     * Sets the action trigger for the panel.
223
-     *
224
-     * @param trigger Action trigger
225
-     */
226
-    public void setTrigger(final ActionType trigger) {
227
-        if (this.trigger == null) {
228
-            conditions.clear();
229
-        }
230
-
231
-        for (final ActionConditionDisplayPanel panel : conditions) {
232
-            panel.setTrigger(trigger);
233
-        }
234
-        this.trigger = trigger;
235
-        setEnabled(trigger != null);
236
-        layoutComponents();
237
-    }
238
-
239
-    @Override
240
-    public void conditionRemoved(final ActionConditionDisplayPanel condition) {
241
-        synchronized (conditions) {
242
-            conditions.remove(condition);
243
-            validations.remove(condition);
244
-        }
245
-        propertyChange(null);
246
-        layoutComponents();
247
-    }
248
-
249
-    @Override
250
-    public void setEnabled(final boolean enabled) {
251
-        for (final ActionConditionDisplayPanel condition : conditions) {
252
-            condition.setEnabled(enabled);
253
-        }
254
-    }
255
-
256
-    @Override
257
-    public void propertyChange(final PropertyChangeEvent evt) {
258
-        if (evt != null) {
259
-            validations.put((ActionConditionDisplayPanel) evt.getSource(),
260
-                    (Boolean) evt.getNewValue());
261
-        }
262
-
263
-        boolean pass = true;
264
-        for (final boolean validation : validations.values()) {
265
-            if (!validation) {
266
-                pass = false;
267
-                break;
268
-            }
269
-        }
270
-
271
-        firePropertyChange("validationResult", validates, pass);
272
-        validates = pass;
273
-    }
274
-
275
-}

+ 0
- 217
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionConditionsPanel.java Ver fichero

@@ -1,217 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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 com.dmdirc.actions.ActionCondition;
26
-import com.dmdirc.actions.ActionManager;
27
-import com.dmdirc.actions.ConditionTree;
28
-import com.dmdirc.actions.ConditionTreeFactory.ConditionTreeFactoryType;
29
-import com.dmdirc.interfaces.actions.ActionType;
30
-import com.dmdirc.ui.IconManager;
31
-
32
-import java.awt.event.ActionEvent;
33
-import java.awt.event.ActionListener;
34
-import java.beans.PropertyChangeEvent;
35
-import java.beans.PropertyChangeListener;
36
-import java.util.List;
37
-
38
-import javax.swing.BorderFactory;
39
-import javax.swing.JButton;
40
-import javax.swing.JPanel;
41
-import javax.swing.JScrollPane;
42
-import javax.swing.JSeparator;
43
-import javax.swing.UIManager;
44
-
45
-import net.miginfocom.swing.MigLayout;
46
-
47
-/**
48
- * Action conditions panel.
49
- */
50
-public class ActionConditionsPanel extends JPanel implements ActionListener,
51
-        PropertyChangeListener {
52
-
53
-    /** Serial version UID. */
54
-    private static final long serialVersionUID = 1;
55
-    private final ActionManager actionManager;
56
-    /** Tree panel. */
57
-    private ActionConditionsTreePanel tree;
58
-    /** List Panel. */
59
-    private ActionConditionsListPanel list;
60
-    /** Add button. */
61
-    private JButton add;
62
-    /** tree validates? */
63
-    private boolean treeValidates = true;
64
-    /** list validates? */
65
-    private boolean listValidates = true;
66
-    /** Icon manager. */
67
-    private final IconManager iconManager;
68
-
69
-    /**
70
-     * Instantiates the panel.
71
-     *
72
-     * @param iconManager Icon manager
73
-     */
74
-    public ActionConditionsPanel(final ActionManager actionManager, final IconManager iconManager) {
75
-        this(actionManager, iconManager, null);
76
-    }
77
-
78
-    /**
79
-     * Instantiates the panel.
80
-     *
81
-     * @param iconManager Icon manager
82
-     * @param trigger     Action trigger
83
-     */
84
-    public ActionConditionsPanel(final ActionManager actionManager, final IconManager iconManager,
85
-            final ActionType trigger) {
86
-
87
-        this.actionManager = actionManager;
88
-        this.iconManager = iconManager;
89
-        initComponents();
90
-        addListeners();
91
-        layoutComponents();
92
-
93
-        if (trigger == null) {
94
-            setEnabled(false);
95
-            add.setEnabled(false);
96
-        }
97
-    }
98
-
99
-    /** Validates the conditions. */
100
-    public void validateConditions() {
101
-        tree.validateConditions();
102
-    }
103
-
104
-    /** Initialises the components. */
105
-    private void initComponents() {
106
-        tree = new ActionConditionsTreePanel(iconManager);
107
-        list = new ActionConditionsListPanel(actionManager, iconManager, tree);
108
-        add = new JButton("Add");
109
-    }
110
-
111
-    /** Adds the listeners. */
112
-    private void addListeners() {
113
-        add.addActionListener(this);
114
-        tree.addPropertyChangeListener("validationResult", this);
115
-        list.addPropertyChangeListener("validationResult", this);
116
-    }
117
-
118
-    /** Lays out the components. */
119
-    private void layoutComponents() {
120
-        setLayout(new MigLayout("fill, wrap 1, pack"));
121
-
122
-        setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
123
-                "TitledBorder.border"), "Conditions"));
124
-
125
-        final JScrollPane sp = new JScrollPane(list);
126
-        sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
127
-        sp.getVerticalScrollBar().setUnitIncrement(10);
128
-
129
-        add(tree, "growx, pushx");
130
-        add(new JSeparator(JSeparator.HORIZONTAL), "growx, pushx");
131
-        add(sp, "grow, push");
132
-        add(add, "right, gaptop push");
133
-    }
134
-
135
-    /**
136
-     * Sets the trigger for this conditions panel.
137
-     *
138
-     * @param trigger Action trigger.
139
-     */
140
-    public void setActionTrigger(final ActionType trigger) {
141
-        list.setTrigger(trigger);
142
-        add.setEnabled(trigger != null);
143
-        add.setEnabled(trigger != null && trigger.getType().getArgNames().length != 0);
144
-    }
145
-
146
-    @Override
147
-    public void setEnabled(final boolean enabled) {
148
-        tree.setEnabled(enabled);
149
-        list.setEnabled(enabled);
150
-    }
151
-
152
-    @Override
153
-    public void actionPerformed(final ActionEvent e) {
154
-        list.addCondition(new ActionCondition(-1, null, null, ""));
155
-    }
156
-
157
-    /**
158
-     * Sets the conditions.
159
-     *
160
-     * @param conditions conditions list
161
-     */
162
-    public void setConditions(final List<ActionCondition> conditions) {
163
-        list.clearConditions();
164
-
165
-        conditions.forEach(list::addCondition);
166
-    }
167
-
168
-    /**
169
-     * Sets the condition tree.
170
-     *
171
-     * @param conditionTree new condition tree
172
-     */
173
-    public void setConditionTree(final ConditionTree conditionTree) {
174
-        tree.setRule(list.getConditions().size(), conditionTree);
175
-    }
176
-
177
-    /**
178
-     * Gets the condition type.
179
-     *
180
-     * @return condition type
181
-     */
182
-    public ConditionTreeFactoryType getConditionTreeType() {
183
-        return tree.getRuleType(list.getConditions().size());
184
-    }
185
-
186
-    /**
187
-     * Gets the condition tree.
188
-     *
189
-     * @return condition tree
190
-     */
191
-    public ConditionTree getConditionTree() {
192
-        return tree.getRule(list.getConditions().size());
193
-    }
194
-
195
-    /**
196
-     * Returns the condition list.
197
-     *
198
-     * @return condition list
199
-     */
200
-    public List<ActionCondition> getConditions() {
201
-        return list.getConditions();
202
-    }
203
-
204
-    @Override
205
-    public void propertyChange(final PropertyChangeEvent evt) {
206
-        final boolean currentlyValidates = listValidates && treeValidates;
207
-        if (evt.getSource() == list) {
208
-            listValidates = (Boolean) evt.getNewValue();
209
-        } else {
210
-            treeValidates = (Boolean) evt.getNewValue();
211
-        }
212
-
213
-        firePropertyChange("validationResult", currentlyValidates,
214
-                listValidates && treeValidates);
215
-    }
216
-
217
-}

+ 0
- 269
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionConditionsTreePanel.java Ver fichero

@@ -1,269 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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 com.dmdirc.actions.ConditionTree;
26
-import com.dmdirc.actions.ConditionTreeFactory;
27
-import com.dmdirc.actions.ConditionTreeFactory.ConditionTreeFactoryType;
28
-import com.dmdirc.actions.validators.ConditionRuleValidator;
29
-import com.dmdirc.addons.ui_swing.components.text.TextLabel;
30
-import com.dmdirc.addons.ui_swing.components.validating.ValidatingJTextField;
31
-import com.dmdirc.ui.IconManager;
32
-
33
-import java.awt.event.ActionEvent;
34
-import java.awt.event.ActionListener;
35
-import java.beans.PropertyChangeEvent;
36
-import java.beans.PropertyChangeListener;
37
-
38
-import javax.swing.ButtonGroup;
39
-import javax.swing.JPanel;
40
-import javax.swing.JRadioButton;
41
-import javax.swing.event.DocumentEvent;
42
-import javax.swing.event.DocumentListener;
43
-
44
-import net.miginfocom.swing.MigLayout;
45
-
46
-/**
47
- * Action conditions tree panel.
48
- */
49
-public class ActionConditionsTreePanel extends JPanel implements ActionListener,
50
-        PropertyChangeListener, DocumentListener {
51
-
52
-    /** A version number for this class. */
53
-    private static final long serialVersionUID = 1;
54
-    /** Icon manager. */
55
-    private final IconManager iconManager;
56
-    /** Button group. */
57
-    private ButtonGroup group;
58
-    /** All triggers button. */
59
-    private JRadioButton allButton;
60
-    /** One trigger button. */
61
-    private JRadioButton oneButton;
62
-    /** Custom rule button. */
63
-    private JRadioButton customButton;
64
-    /** Custom rule field. */
65
-    private ValidatingJTextField rule;
66
-    /** Condition tree factory. */
67
-    private ConditionTreeFactory treeFactory;
68
-    /** Condition count. */
69
-    private int conditionCount = 0;
70
-    /** Condition rule validator. */
71
-    private ConditionRuleValidator treeValidator;
72
-    /** validates. */
73
-    private boolean validates = true;
74
-
75
-    /**
76
-     * Instantiates the panel.
77
-     *
78
-     * @param iconManager Icon manager
79
-     */
80
-    public ActionConditionsTreePanel(final IconManager iconManager) {
81
-
82
-        this.iconManager = iconManager;
83
-        initComponents();
84
-        addListeners();
85
-        layoutComponents();
86
-
87
-        selectTreeButton();
88
-    }
89
-
90
-    /** Initialises the components. */
91
-    private void initComponents() {
92
-        group = new ButtonGroup();
93
-        allButton = new JRadioButton("All of the conditions are true");
94
-        oneButton = new JRadioButton("At least one of the conditions is true");
95
-        customButton = new JRadioButton("The conditions match a custom rule");
96
-        treeValidator = new ConditionRuleValidator(conditionCount);
97
-
98
-        rule = new ValidatingJTextField(iconManager, treeValidator);
99
-
100
-        group.add(allButton);
101
-        group.add(oneButton);
102
-        group.add(customButton);
103
-    }
104
-
105
-    /** Adds the listeners. */
106
-    private void addListeners() {
107
-        allButton.addActionListener(this);
108
-        oneButton.addActionListener(this);
109
-        customButton.addActionListener(this);
110
-        rule.addPropertyChangeListener("validationResult", this);
111
-        rule.getDocument().addDocumentListener(this);
112
-    }
113
-
114
-    /** Lays out the components. */
115
-    private void layoutComponents() {
116
-        setLayout(new MigLayout("fill, wrap 1, pack, hidemode 3"));
117
-        add(new TextLabel("Only execute this action if..."), "growx, pushx");
118
-        add(allButton, "growx, pushx");
119
-        add(oneButton, "growx, pushx");
120
-        add(customButton, "growx, pushx");
121
-        add(rule, "growx, pushx");
122
-    }
123
-
124
-    /**
125
-     * Selects the appropriate radio button for the tree.
126
-     */
127
-    private void selectTreeButton() {
128
-        group.clearSelection();
129
-        final ConditionTreeFactoryType type;
130
-        if (treeFactory == null) {
131
-            type = ConditionTreeFactoryType.CONJUNCTION;
132
-        } else {
133
-            type = treeFactory.getType();
134
-        }
135
-
136
-        switch (type) {
137
-            case CONJUNCTION:
138
-                allButton.setSelected(true);
139
-                rule.setText("");
140
-                rule.setEnabled(false);
141
-                break;
142
-            case DISJUNCTION:
143
-                oneButton.setSelected(true);
144
-                rule.setText("");
145
-                rule.setEnabled(false);
146
-                break;
147
-            case CUSTOM:
148
-                customButton.setSelected(true);
149
-                rule.setText(treeFactory.getConditionTree(conditionCount).
150
-                        toString());
151
-                rule.setEnabled(true);
152
-                break;
153
-            default:
154
-                allButton.setSelected(true);
155
-                rule.setText("");
156
-                rule.setEnabled(false);
157
-                break;
158
-        }
159
-
160
-        sortTreeFactory();
161
-    }
162
-
163
-    /** Sorts the tree factory out. */
164
-    private void sortTreeFactory() {
165
-        if (group.getSelection().equals(allButton.getModel())) {
166
-            treeFactory = new ConditionTreeFactory.ConjunctionFactory();
167
-            firePropertyChange("validationResult", validates, true);
168
-        } else if (group.getSelection().equals(oneButton.getModel())) {
169
-            treeFactory = new ConditionTreeFactory.DisjunctionFactory();
170
-            firePropertyChange("validationResult", validates, true);
171
-            validates = true;
172
-        } else {
173
-            treeFactory = new ConditionTreeFactory.CustomFactory(ConditionTree.parseString(rule.
174
-                    getText()));
175
-            rule.checkError();
176
-        }
177
-
178
-    }
179
-
180
-    @Override
181
-    public void actionPerformed(final ActionEvent e) {
182
-        rule.setEnabled(e.getSource().equals(customButton));
183
-        sortTreeFactory();
184
-    }
185
-
186
-    @Override
187
-    public void setEnabled(final boolean enabled) {
188
-        allButton.setEnabled(enabled);
189
-        oneButton.setEnabled(enabled);
190
-        customButton.setEnabled(enabled);
191
-    }
192
-
193
-    /**
194
-     * Returns the selected rule type.
195
-     *
196
-     * @param conditionCount Condition count
197
-     *
198
-     * @return Selected rule type
199
-     */
200
-    public ConditionTreeFactoryType getRuleType(final int conditionCount) {
201
-        return treeFactory.getType();
202
-    }
203
-
204
-    /**
205
-     * Returns the current custom rule.
206
-     *
207
-     * @param conditionCount number of conditions
208
-     *
209
-     * @return Custom rule
210
-     */
211
-    public ConditionTree getRule(final int conditionCount) {
212
-        treeFactory.getConditionTree(conditionCount);
213
-        return treeFactory.getConditionTree(conditionCount);
214
-    }
215
-
216
-    /**
217
-     * Sets the tree rule.
218
-     *
219
-     * @param conditionCount condition count
220
-     * @param tree           new condition tree
221
-     */
222
-    public void setRule(final int conditionCount, final ConditionTree tree) {
223
-        if (tree != null) {
224
-            this.conditionCount = conditionCount;
225
-            treeFactory = ConditionTreeFactory.getFactory(tree, conditionCount);
226
-            selectTreeButton();
227
-        }
228
-    }
229
-
230
-    /**
231
-     * Sets the new condition count.
232
-     *
233
-     * @param conditionCount new condition count.
234
-     */
235
-    public void setConditionCount(final int conditionCount) {
236
-        this.conditionCount = conditionCount;
237
-        treeValidator.setArgs(conditionCount);
238
-        rule.checkError();
239
-    }
240
-
241
-    @Override
242
-    public void propertyChange(final PropertyChangeEvent evt) {
243
-        firePropertyChange("validationResult", validates, evt.getNewValue());
244
-        validates = (Boolean) evt.getNewValue();
245
-    }
246
-
247
-    /** Validates the conditions. */
248
-    public void validateConditions() {
249
-        selectTreeButton();
250
-    }
251
-
252
-    @Override
253
-    public void insertUpdate(final DocumentEvent e) {
254
-        treeFactory = new ConditionTreeFactory.CustomFactory(ConditionTree.parseString(rule.
255
-                getText()));
256
-    }
257
-
258
-    @Override
259
-    public void removeUpdate(final DocumentEvent e) {
260
-        treeFactory = new ConditionTreeFactory.CustomFactory(ConditionTree.parseString(rule.
261
-                getText()));
262
-    }
263
-
264
-    @Override
265
-    public void changedUpdate(final DocumentEvent e) {
266
-        //Ignore
267
-    }
268
-
269
-}

+ 0
- 315
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialog.java Ver fichero

@@ -1,315 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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 com.dmdirc.actions.Action;
26
-import com.dmdirc.actions.ActionFactory;
27
-import com.dmdirc.actions.ActionManager;
28
-import com.dmdirc.actions.ActionStatus;
29
-import com.dmdirc.actions.ActionSubstitutorFactory;
30
-import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
31
-import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog;
32
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
33
-import com.dmdirc.ui.IconManager;
34
-import com.dmdirc.ui.messages.ColourManagerFactory;
35
-
36
-import java.awt.Dimension;
37
-import java.awt.event.ActionEvent;
38
-import java.awt.event.ActionListener;
39
-import java.beans.PropertyChangeEvent;
40
-import java.beans.PropertyChangeListener;
41
-
42
-import javax.swing.JButton;
43
-import javax.swing.SwingUtilities;
44
-
45
-import net.miginfocom.swing.MigLayout;
46
-
47
-import org.slf4j.Logger;
48
-import org.slf4j.LoggerFactory;
49
-
50
-/**
51
- * Action editor dialog.
52
- */
53
-public class ActionEditorDialog extends StandardDialog implements ActionListener,
54
-        PropertyChangeListener {
55
-
56
-    private static final Logger LOG = LoggerFactory.getLogger(ActionEditorDialog.class);
57
-    /** Serial version UID. */
58
-    private static final long serialVersionUID = 1;
59
-    private final ActionManager actionManager;
60
-    /** Name panel. */
61
-    private ActionNamePanel name;
62
-    /** Triggers panel. */
63
-    private ActionTriggersPanel triggers;
64
-    /** Response panel. */
65
-    private ActionResponsePanel response;
66
-    /** Conditions panel. */
67
-    private ActionConditionsPanel conditions;
68
-    /** Substitutions panel. */
69
-    private ActionSubstitutionsPanel substitutions;
70
-    /** Advanced panel. */
71
-    private ActionAdvancedPanel advanced;
72
-    /** Show substitutions button. */
73
-    private JButton showSubstitutions;
74
-    /** Show advanced button. */
75
-    private JButton showAdvanced;
76
-    /** Is the name valid? */
77
-    private boolean nameValid = false;
78
-    /** Are the triggers valid? */
79
-    private boolean triggersValid = false;
80
-    /** Are the conditions valid? */
81
-    private boolean conditionsValid = false;
82
-    /** Action to be edited. */
83
-    private final Action action;
84
-    /** Action group. */
85
-    private final String group;
86
-    /** Factory to use to create new actions. */
87
-    private final ActionFactory actionFactory;
88
-
89
-    /**
90
-     * Instantiates the panel.
91
-     *
92
-     * @param iconManager   Icon manager
93
-     * @param config        Config
94
-     * @param subsFactory   Actions substitution factory
95
-     * @param actionFactory Actions factory
96
-     * @param parentWindow  Parent window
97
-     * @param group         Action's group
98
-     */
99
-    public ActionEditorDialog(
100
-            final ActionManager actionManager,
101
-            final IconManager iconManager,
102
-            final ColourManagerFactory colourManagerFactory,
103
-            final AggregateConfigProvider config,
104
-            final ActionSubstitutorFactory subsFactory,
105
-            final ActionFactory actionFactory,
106
-            final ActionsManagerDialog parentWindow,
107
-            final String group) {
108
-        super(parentWindow, ModalityType.DOCUMENT_MODAL);
109
-        LOG.debug("loading with group: " + group);
110
-        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
111
-        setTitle("Action Editor");
112
-
113
-        this.actionManager = actionManager;
114
-        this.group = group;
115
-        this.action = null;
116
-        this.actionFactory = actionFactory;
117
-
118
-        initComponents(iconManager, config, subsFactory, colourManagerFactory);
119
-        addListeners();
120
-        doComponents();
121
-        layoutComponents();
122
-
123
-        setResizable(false);
124
-    }
125
-
126
-    /**
127
-     * Instantiates the panel.
128
-     *
129
-     * @param iconManager   Icon manager
130
-     * @param config        Config
131
-     * @param subsFactory   Actions substitution factory
132
-     * @param actionFactory Actions factory
133
-     * @param parentWindow  Parent window
134
-     * @param action        Action to be edited
135
-     */
136
-    public ActionEditorDialog(
137
-            final ActionManager actionManager,
138
-            final IconManager iconManager,
139
-            final ColourManagerFactory colourManagerFactory,
140
-            final AggregateConfigProvider config,
141
-            final ActionSubstitutorFactory subsFactory,
142
-            final ActionFactory actionFactory,
143
-            final ActionsManagerDialog parentWindow,
144
-            final Action action) {
145
-        super(parentWindow, ModalityType.DOCUMENT_MODAL);
146
-        LOG.debug("loading with action: " + action);
147
-        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
148
-        setTitle("Action Editor");
149
-
150
-        this.actionManager = actionManager;
151
-        this.group = action.getGroup();
152
-        this.action = action;
153
-        this.actionFactory = actionFactory;
154
-
155
-        initComponents(iconManager, config, subsFactory, colourManagerFactory);
156
-        addListeners();
157
-        doComponents();
158
-        layoutComponents();
159
-
160
-        setResizable(false);
161
-    }
162
-
163
-    /** Sets components initial states and stuff. */
164
-    private void doComponents() {
165
-        triggers.setEnabled(action != null);
166
-        response.setEnabled(action != null);
167
-        conditions.setEnabled(action != null);
168
-        substitutions.setVisible(false);
169
-        advanced.setVisible(false);
170
-
171
-        triggersValid = action != null;
172
-        conditionsValid = true;
173
-        nameValid = action != null;
174
-        getOkButton().setEnabled(action != null);
175
-
176
-        if (action != null) {
177
-            name.setActionName(action.getName());
178
-            triggers.setTriggers(action.getTriggers());
179
-            response.setResponse(action.getResponse());
180
-            response.setFormatter(action.getNewFormat());
181
-            conditions.setActionTrigger(action.getTriggers()[0]);
182
-            conditions.setConditions(action.getConditions());
183
-            conditions.setConditionTree(action.getRealConditionTree());
184
-            advanced.setActionEnabled(action.getStatus() != ActionStatus.DISABLED);
185
-            advanced.setConcurrencyGroup(action.getConcurrencyGroup());
186
-            advanced.setActionStopped(action.isStopping());
187
-        }
188
-    }
189
-
190
-    /** Initialises the components. */
191
-    private void initComponents(final IconManager iconManager,
192
-            final AggregateConfigProvider config, final ActionSubstitutorFactory subsFactory,
193
-            final ColourManagerFactory colourManagerFactory) {
194
-        orderButtons(new JButton(), new JButton());
195
-        name = new ActionNamePanel(actionManager, iconManager, "", group);
196
-        triggers = new ActionTriggersPanel(actionManager, iconManager);
197
-        response = new ActionResponsePanel(iconManager, colourManagerFactory, config);
198
-        conditions = new ActionConditionsPanel(actionManager, iconManager);
199
-        substitutions = new ActionSubstitutionsPanel(subsFactory);
200
-        advanced = new ActionAdvancedPanel();
201
-        showSubstitutions = new JButton("Show Substitutions");
202
-        showAdvanced = new JButton("Show Advanced Options");
203
-    }
204
-
205
-    /** Adds the listeners. */
206
-    private void addListeners() {
207
-        showSubstitutions.addActionListener(this);
208
-        showAdvanced.addActionListener(this);
209
-        getOkButton().addActionListener(this);
210
-        getCancelButton().addActionListener(this);
211
-
212
-        name.addPropertyChangeListener("validationResult", this);
213
-        triggers.addPropertyChangeListener("validationResult", this);
214
-        conditions.addPropertyChangeListener("validationResult", this);
215
-    }
216
-
217
-    /** Lays out the components. */
218
-    private void layoutComponents() {
219
-        setMinimumSize(new Dimension(800, 600));
220
-        setLayout(new MigLayout("fill, hidemode 3, wrap 2, pack, hmax 80sp," + "wmin 800, wmax 800"));
221
-
222
-        add(name, "grow, w 50%");
223
-        add(conditions, "spany 3, grow, pushx, w 50%");
224
-        add(triggers, "grow, w 50%");
225
-        add(response, "grow, pushy, w 50%");
226
-        add(substitutions, "spanx, grow, push");
227
-        add(advanced, "spanx, grow, push");
228
-        add(showSubstitutions, "left, sgx button, split 2");
229
-        add(showAdvanced, "left, sgx button");
230
-        add(getLeftButton(), "right, sgx button, gapleft push, split");
231
-        add(getRightButton(), "right, sgx button");
232
-    }
233
-
234
-    @Override
235
-    public void actionPerformed(final ActionEvent e) {
236
-        if (e.getSource().equals(showSubstitutions)) {
237
-            substitutions.setVisible(!substitutions.isVisible());
238
-            showSubstitutions
239
-                    .setText(substitutions.isVisible() ? "Hide Substitutions"
240
-                            : "Show Substitutions");
241
-            pack();
242
-        } else if (e.getSource().equals(showAdvanced)) {
243
-            advanced.setVisible(!advanced.isVisible());
244
-            showAdvanced.setText(advanced.isVisible() ? "Hide Advanced Options"
245
-                    : "Show Advanced Options");
246
-        } else if (e.getSource().equals(getOkButton())) {
247
-            save();
248
-            dispose();
249
-        } else if (e.getSource().equals(getCancelButton())) {
250
-            dispose();
251
-        }
252
-    }
253
-
254
-    @Override
255
-    public void validate() {
256
-        super.validate();
257
-
258
-        SwingUtilities.invokeLater(this::centreOnOwner);
259
-    }
260
-
261
-    /** Saves the action being edited. */
262
-    private void save() {
263
-        name.getActionName();
264
-        triggers.getTriggers();
265
-        response.getResponse();
266
-        response.getFormatter();
267
-        conditions.getConditions();
268
-        conditions.getConditionTree();
269
-        if (action == null) {
270
-            final Action newAction = actionFactory.getAction(group, name.getActionName(),
271
-                    triggers.getTriggers(), response.getResponse(),
272
-                    conditions.getConditions(), conditions.getConditionTree(),
273
-                    response.getFormatter());
274
-            newAction.setConcurrencyGroup(advanced.getConcurrencyGroup());
275
-            newAction.setEnabled(advanced.isActionEnabled());
276
-            newAction.setStopping(advanced.isActionStopped());
277
-        } else {
278
-            action.setName(name.getActionName());
279
-            action.setConditionTree(conditions.getConditionTree());
280
-            action.setConditions(conditions.getConditions());
281
-            action.setNewFormat(response.getFormatter());
282
-            action.setResponse(response.getResponse());
283
-            action.setTriggers(triggers.getTriggers());
284
-            action.setConcurrencyGroup(advanced.getConcurrencyGroup());
285
-            action.setEnabled(advanced.isActionEnabled());
286
-            action.setStopping(advanced.isActionStopped());
287
-            action.save();
288
-        }
289
-    }
290
-
291
-    @Override
292
-    public void propertyChange(final PropertyChangeEvent evt) {
293
-        if (evt.getSource().equals(name)) {
294
-            nameValid = (Boolean) evt.getNewValue();
295
-            triggers.setEnabled((Boolean) evt.getNewValue());
296
-            conditions.setEnabled((Boolean) evt.getNewValue());
297
-            response.setEnabled((Boolean) evt.getNewValue());
298
-        } else if (evt.getSource().equals(triggers)) {
299
-            triggersValid = (Boolean) evt.getNewValue();
300
-
301
-            response.setEnabled((Boolean) evt.getNewValue());
302
-            conditions.setEnabled((Boolean) evt.getNewValue());
303
-            substitutions.setEnabled((Boolean) evt.getNewValue());
304
-            advanced.setEnabled((Boolean) evt.getNewValue());
305
-
306
-            substitutions.setType(triggers.getPrimaryTrigger());
307
-            conditions.setActionTrigger(triggers.getPrimaryTrigger());
308
-        } else if (evt.getSource().equals(conditions)) {
309
-            conditionsValid = (Boolean) evt.getNewValue();
310
-        }
311
-
312
-        getOkButton().setEnabled(triggersValid && conditionsValid && nameValid);
313
-    }
314
-
315
-}

+ 0
- 81
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionEditorDialogFactory.java Ver fichero

@@ -1,81 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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 com.dmdirc.ClientModule;
26
-import com.dmdirc.actions.Action;
27
-import com.dmdirc.actions.ActionFactory;
28
-import com.dmdirc.actions.ActionManager;
29
-import com.dmdirc.actions.ActionSubstitutorFactory;
30
-import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog;
31
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
32
-import com.dmdirc.ui.IconManager;
33
-import com.dmdirc.ui.messages.ColourManagerFactory;
34
-
35
-import javax.inject.Inject;
36
-import javax.inject.Singleton;
37
-
38
-/**
39
- * Factory for {@link ActionEditorDialog}s.
40
- */
41
-@Singleton
42
-public class ActionEditorDialogFactory {
43
-
44
-    private final IconManager iconManager;
45
-    private final AggregateConfigProvider config;
46
-    private final ActionSubstitutorFactory subsFactory;
47
-    private final ActionFactory actionFactory;
48
-    private final ColourManagerFactory colourManagerFactory;
49
-    private final ActionManager actionManager;
50
-
51
-    @Inject
52
-    public ActionEditorDialogFactory(
53
-            final ActionManager actionManager,
54
-            @ClientModule.GlobalConfig final IconManager iconManager,
55
-            @ClientModule.GlobalConfig final AggregateConfigProvider config,
56
-            final ActionSubstitutorFactory subsFactory,
57
-            final ActionFactory actionFactory,
58
-            final ColourManagerFactory colourManagerFactory) {
59
-        this.actionManager = actionManager;
60
-        this.iconManager = iconManager;
61
-        this.config = config;
62
-        this.subsFactory = subsFactory;
63
-        this.actionFactory = actionFactory;
64
-        this.colourManagerFactory = colourManagerFactory;
65
-    }
66
-
67
-    public ActionEditorDialog getActionEditorDialog(
68
-            final ActionsManagerDialog parentWindow,
69
-            final String group) {
70
-        return new ActionEditorDialog(actionManager, iconManager, colourManagerFactory, config,
71
-                subsFactory, actionFactory, parentWindow, group);
72
-    }
73
-
74
-    public ActionEditorDialog getActionEditorDialog(
75
-            final ActionsManagerDialog parentWindow,
76
-            final Action action) {
77
-        return new ActionEditorDialog(actionManager, iconManager, colourManagerFactory, config,
78
-                subsFactory, actionFactory, parentWindow, action);
79
-    }
80
-
81
-}

+ 0
- 173
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionNamePanel.java Ver fichero

@@ -1,173 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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 com.dmdirc.actions.ActionGroup;
26
-import com.dmdirc.actions.validators.ActionNameValidator;
27
-import com.dmdirc.addons.ui_swing.components.validating.ValidatingJTextField;
28
-import com.dmdirc.interfaces.ActionController;
29
-import com.dmdirc.ui.IconManager;
30
-import com.dmdirc.util.validators.FileNameValidator;
31
-import com.dmdirc.util.validators.ValidatorChain;
32
-
33
-import java.beans.PropertyChangeEvent;
34
-import java.beans.PropertyChangeListener;
35
-
36
-import javax.swing.BorderFactory;
37
-import javax.swing.JLabel;
38
-import javax.swing.JPanel;
39
-import javax.swing.UIManager;
40
-
41
-import net.miginfocom.swing.MigLayout;
42
-
43
-/**
44
- * Action name panel.
45
- */
46
-public class ActionNamePanel extends JPanel implements PropertyChangeListener {
47
-
48
-    /** A version number for this class. */
49
-    private static final long serialVersionUID = 1;
50
-    /** Original name. */
51
-    private String existingName;
52
-    /** Action name field. */
53
-    private ValidatingJTextField name;
54
-    /** Action group. */
55
-    private final ActionGroup group;
56
-    /** Icon manager. */
57
-    private final IconManager iconManager;
58
-
59
-    /**
60
-     * Instantiates the panel.
61
-     *
62
-     * @param iconManager Icon manager
63
-     * @param group       Associated group for this action
64
-     */
65
-    public ActionNamePanel(final ActionController actionManager, final IconManager iconManager,
66
-            final String group) {
67
-        this(actionManager, iconManager, "", group);
68
-    }
69
-
70
-    /**
71
-     * Instantiates the panel.
72
-     *
73
-     * @param iconManager Icon manager
74
-     * @param name        Initial name of the action
75
-     * @param group       Associated group for this action
76
-     */
77
-    public ActionNamePanel(final ActionController actionManager, final IconManager iconManager,
78
-            final String name, final String group) {
79
-
80
-        if (name == null) {
81
-            this.existingName = "";
82
-        } else {
83
-            this.existingName = name;
84
-        }
85
-        this.iconManager = iconManager;
86
-        this.group = actionManager.getOrCreateGroup(group);
87
-
88
-        initComponents();
89
-        addListeners();
90
-        layoutComponents();
91
-        this.name.checkError();
92
-    }
93
-
94
-    /**
95
-     * Sets the action name.
96
-     *
97
-     * @param newName new name
98
-     */
99
-    void setActionName(final String newName) {
100
-        if (newName == null) {
101
-            this.existingName = "";
102
-        } else {
103
-            this.existingName = newName;
104
-        }
105
-        name.setValidator(ValidatorChain.<String>builder()
106
-                .addValidator(new FileNameValidator())
107
-                .addValidator(new ActionNameValidator(group, existingName))
108
-                .build());
109
-        this.name.setText(newName);
110
-    }
111
-
112
-    /** Validates the name. */
113
-    public void validateName() {
114
-        name.checkError();
115
-    }
116
-
117
-    /** Initialises the components. */
118
-    private void initComponents() {
119
-        name = new ValidatingJTextField(iconManager,
120
-                existingName,
121
-                ValidatorChain.<String>builder()
122
-                .addValidator(new FileNameValidator())
123
-                .addValidator(new ActionNameValidator(group, existingName))
124
-                .build());
125
-    }
126
-
127
-    /** Adds the listeners. */
128
-    private void addListeners() {
129
-        name.addPropertyChangeListener("validationResult", this);
130
-    }
131
-
132
-    /** Lays out the components. */
133
-    private void layoutComponents() {
134
-        setLayout(new MigLayout("wrap 1"));
135
-
136
-        setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
137
-                "TitledBorder.border"), "Name"));
138
-
139
-        add(new JLabel("This action's name:"));
140
-        add(name, "growx, pushx");
141
-    }
142
-
143
-    /**
144
-     * Has the action's name changed.
145
-     *
146
-     * @return true if the action name has changed.
147
-     *
148
-     */
149
-    public boolean hasNameChanged() {
150
-        return getActionName().equals(existingName);
151
-    }
152
-
153
-    /**
154
-     * Returns the name represented by this component.
155
-     *
156
-     * @return Current name of this action
157
-     */
158
-    public String getActionName() {
159
-        return name.getText();
160
-    }
161
-
162
-    @Override
163
-    public void setEnabled(final boolean enabled) {
164
-        name.setEnabled(enabled);
165
-    }
166
-
167
-    @Override
168
-    public void propertyChange(final PropertyChangeEvent evt) {
169
-        firePropertyChange("validationResult", evt.getOldValue(), evt.
170
-                getNewValue());
171
-    }
172
-
173
-}

+ 0
- 179
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionResponsePanel.java Ver fichero

@@ -1,179 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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 com.dmdirc.addons.ui_swing.UIUtilities;
26
-import com.dmdirc.addons.ui_swing.components.inputfields.TextAreaInputField;
27
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
28
-import com.dmdirc.ui.IconManager;
29
-import com.dmdirc.ui.messages.ColourManagerFactory;
30
-
31
-import java.util.Collection;
32
-import java.util.TreeSet;
33
-
34
-import javax.swing.BorderFactory;
35
-import javax.swing.DefaultComboBoxModel;
36
-import javax.swing.JComboBox;
37
-import javax.swing.JLabel;
38
-import javax.swing.JPanel;
39
-import javax.swing.JScrollPane;
40
-import javax.swing.JTextArea;
41
-import javax.swing.MutableComboBoxModel;
42
-import javax.swing.UIManager;
43
-
44
-import net.miginfocom.swing.MigLayout;
45
-
46
-/**
47
- * Action response panel.
48
- */
49
-public class ActionResponsePanel extends JPanel {
50
-
51
-    /** Serial version UID. */
52
-    private static final long serialVersionUID = 1;
53
-    /** Response text area. */
54
-    private JTextArea response;
55
-    /** Formatter combo box. */
56
-    private JComboBox<String> formatter;
57
-    /** Response scrollpane. */
58
-    private JScrollPane scrollPane;
59
-
60
-    /**
61
-     * Instantiates the panel.
62
-     *
63
-     * @param iconManager Icon manager
64
-     * @param config      Config
65
-     */
66
-    public ActionResponsePanel(final IconManager iconManager,
67
-            final ColourManagerFactory colourManagerFactory, final AggregateConfigProvider config) {
68
-        initComponents(iconManager, colourManagerFactory, config);
69
-        addListeners();
70
-        layoutComponents();
71
-    }
72
-
73
-    private void initComponents(final IconManager iconManager,
74
-            final ColourManagerFactory colourManagerFactory, final AggregateConfigProvider config) {
75
-        response = new TextAreaInputField(iconManager, colourManagerFactory, config, "");
76
-        scrollPane = new JScrollPane(response);
77
-        response.setRows(4);
78
-        formatter = new JComboBox<>(new DefaultComboBoxModel<>());
79
-
80
-        final MutableComboBoxModel<String> model =
81
-                (MutableComboBoxModel<String>) formatter.getModel();
82
-        model.addElement("No change");
83
-        model.addElement("No response");
84
-
85
-        final Collection<String> formatters = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
86
-        formatters.addAll(config.getOptions("formatter").keySet());
87
-
88
-        formatters.forEach(model::addElement);
89
-    }
90
-
91
-    /** Adds the listeners. */
92
-    private void addListeners() {
93
-    }
94
-
95
-    /** Lays out the components. */
96
-    private void layoutComponents() {
97
-        setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
98
-                "TitledBorder.border"), "Response"));
99
-        setLayout(new MigLayout("fill, wrap 1"));
100
-
101
-        add(new JLabel("Execute these commands: "));
102
-        add(scrollPane, "grow, push");
103
-        add(new JLabel("Alter the event's formatter"));
104
-        add(formatter, "growx, pushx");
105
-    }
106
-
107
-    /**
108
-     * Sets the response.
109
-     *
110
-     * @param response new response
111
-     */
112
-    public void setResponse(final String... response) {
113
-        if (response == null) {
114
-            this.response.setText("");
115
-        } else {
116
-            final StringBuilder sb = new StringBuilder();
117
-            for (String responseLine : response) {
118
-                responseLine = responseLine.replace("\n", "\\n");
119
-                sb.append(responseLine).append('\n');
120
-            }
121
-            if (sb.length() > 0) {
122
-                this.response.setText(sb.substring(0, sb.length() - 1));
123
-            }
124
-        }
125
-        UIUtilities.resetScrollPane(scrollPane);
126
-    }
127
-
128
-    /**
129
-     * Sets the new formatter for the response panel.
130
-     *
131
-     * @param newFormat new formatter.
132
-     */
133
-    public void setFormatter(final String newFormat) {
134
-        if (newFormat == null) {
135
-            formatter.setSelectedIndex(0);
136
-        } else if (newFormat.isEmpty()) {
137
-            formatter.setSelectedIndex(1);
138
-        } else {
139
-            formatter.setSelectedItem(newFormat);
140
-        }
141
-    }
142
-
143
-    /**
144
-     * Returns the current response.
145
-     *
146
-     * @return Response text
147
-     */
148
-    public String[] getResponse() {
149
-        final String[] text = response.getText().split("\n");
150
-        for (int i = 0; i < text.length; i++) {
151
-            text[i] = text[i].replace("\\n", "\n");
152
-        }
153
-        return text;
154
-    }
155
-
156
-    /**
157
-     * Returns the current formatter.
158
-     *
159
-     * @return Formatter text
160
-     */
161
-    public String getFormatter() {
162
-        final String newFormat = (String) formatter.getSelectedItem();
163
-        switch (newFormat) {
164
-            case "No change":
165
-                return null;
166
-            case "No response":
167
-                return "";
168
-            default:
169
-                return newFormat;
170
-        }
171
-    }
172
-
173
-    @Override
174
-    public void setEnabled(final boolean enabled) {
175
-        response.setEnabled(enabled);
176
-        formatter.setEnabled(enabled);
177
-    }
178
-
179
-}

+ 0
- 95
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionSubstitutionsPanel.java Ver fichero

@@ -1,95 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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 com.dmdirc.actions.ActionSubstitutor;
26
-import com.dmdirc.actions.ActionSubstitutorFactory;
27
-import com.dmdirc.addons.ui_swing.components.substitutions.Substitution;
28
-import com.dmdirc.addons.ui_swing.components.substitutions.SubstitutionLabel;
29
-import com.dmdirc.addons.ui_swing.components.substitutions.SubstitutionsPanel;
30
-import com.dmdirc.interfaces.actions.ActionType;
31
-
32
-import java.util.ArrayList;
33
-import java.util.stream.Collectors;
34
-
35
-import javax.swing.SwingUtilities;
36
-
37
-/**
38
- * Action substitutions panel
39
- */
40
-public class ActionSubstitutionsPanel extends SubstitutionsPanel<ActionType> {
41
-
42
-    /** A version number for this class. */
43
-    private static final long serialVersionUID = 1;
44
-    /** Factory to use to create {@link ActionSubstitutor}s. */
45
-    private final ActionSubstitutorFactory substitutorFactory;
46
-
47
-    /**
48
-     * Instantiates the panel.
49
-     *
50
-     * @param substitutorFactory Factory to use to create {@link ActionSubstitutor}s.
51
-     */
52
-    public ActionSubstitutionsPanel(final ActionSubstitutorFactory substitutorFactory) {
53
-        super("Substitutions may be used in the response and target fields",
54
-                SubstitutionsPanel.Alignment.VERTICAL,
55
-                null);
56
-
57
-        this.substitutorFactory = substitutorFactory;
58
-    }
59
-
60
-    /**
61
-     * Sets the action type for this substitution panel.
62
-     *
63
-     * @param type New action type
64
-     */
65
-    @Override
66
-    public void setType(final ActionType type) {
67
-        SwingUtilities.invokeLater(() -> {
68
-            substitutions = new ArrayList<>();
69
-
70
-            if (type != null) {
71
-                final ActionSubstitutor sub = substitutorFactory.getActionSubstitutor(type);
72
-
73
-                substitutions.addAll(sub.getComponentSubstitutions().
74
-                        entrySet().stream()
75
-                        .map(entry -> new SubstitutionLabel(
76
-                                new Substitution(entry.getValue(), entry.getKey())))
77
-                        .collect(Collectors.toList()));
78
-
79
-                substitutions.addAll(sub.getConfigSubstitutions().stream()
80
-                        .map(entry -> new SubstitutionLabel(new Substitution(entry, entry)))
81
-                        .collect(Collectors.toList()));
82
-
83
-                substitutions.addAll(sub.getServerSubstitutions().entrySet().stream()
84
-                        .map(entry -> new SubstitutionLabel(
85
-                                new Substitution(entry.getValue(), entry.getKey())))
86
-                        .collect(Collectors.toList()));
87
-            }
88
-
89
-            layoutComponents();
90
-            validate();
91
-            layoutComponents();
92
-        });
93
-    }
94
-
95
-}

+ 0
- 39
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionTriggerRemovalListener.java Ver fichero

@@ -1,39 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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 com.dmdirc.interfaces.actions.ActionType;
26
-
27
-/**
28
- * Action trigger removal listener.
29
- */
30
-public interface ActionTriggerRemovalListener {
31
-
32
-    /**
33
-     * A trigger was removed from the list.
34
-     *
35
-     * @param trigger Removed trigger
36
-     */
37
-    void triggerRemoved(ActionType trigger);
38
-
39
-}

+ 0
- 239
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionTriggersListPanel.java Ver fichero

@@ -1,239 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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 com.dmdirc.addons.ui_swing.components.ImageButton;
26
-import com.dmdirc.addons.ui_swing.components.text.TextLabel;
27
-import com.dmdirc.interfaces.actions.ActionType;
28
-import com.dmdirc.ui.IconManager;
29
-import com.dmdirc.util.collections.ListenerList;
30
-
31
-import java.util.ArrayList;
32
-import java.util.List;
33
-
34
-import javax.swing.JLabel;
35
-import javax.swing.JPanel;
36
-import javax.swing.SwingUtilities;
37
-
38
-import net.miginfocom.swing.MigLayout;
39
-
40
-/**
41
- * Action triggers list panel.
42
- */
43
-public class ActionTriggersListPanel extends JPanel {
44
-
45
-    /** A version number for this class. */
46
-    private static final long serialVersionUID = 1;
47
-    /** Trigger list. */
48
-    private final List<ActionType> triggers;
49
-    /** Listeners. */
50
-    private final ListenerList listeners = new ListenerList();
51
-    /** Icon manager. */
52
-    private final IconManager iconManager;
53
-
54
-    /**
55
-     * Instantiates the panel.
56
-     *
57
-     * @param iconManager Icon Manager
58
-     */
59
-    public ActionTriggersListPanel(final IconManager iconManager) {
60
-        this(iconManager, new ArrayList<>());
61
-    }
62
-
63
-    /**
64
-     * Instantiates the panel.
65
-     *
66
-     * @param iconManager Icon Manager
67
-     * @param triggers    Trigger list
68
-     */
69
-    public ActionTriggersListPanel(final IconManager iconManager,
70
-            final List<ActionType> triggers) {
71
-
72
-        this.iconManager = iconManager;
73
-        this.triggers = new ArrayList<>(triggers);
74
-
75
-        initComponents();
76
-        layoutComponents();
77
-    }
78
-
79
-    /**
80
-     * Initialises the components.
81
-     */
82
-    private void initComponents() {
83
-        setOpaque(false);
84
-        setLayout(new MigLayout("fillx, wrap 2"));
85
-    }
86
-
87
-    /** Lays out the components. */
88
-    private void layoutComponents() {
89
-        synchronized (triggers) {
90
-            setVisible(false);
91
-
92
-            removeAll();
93
-
94
-            for (final ActionType trigger : triggers) {
95
-                final ImageButton<?> button = new ImageButton<>(
96
-                        "delete", iconManager.getIcon("close-inactive"),
97
-                        iconManager.getIcon("close-active"));
98
-                button.addActionListener(e -> delTrigger(trigger));
99
-
100
-                button.setEnabled(isEnabled());
101
-
102
-                add(new JLabel(trigger.getName()), "growx, pushx");
103
-                add(button, "right");
104
-            }
105
-
106
-            if (triggers.isEmpty()) {
107
-                if (isEnabled()) {
108
-                    add(new TextLabel("<b>Select a trigger and click Add.</b>"));
109
-                } else {
110
-                    add(new TextLabel("No Triggers."));
111
-                }
112
-            }
113
-            setVisible(true);
114
-        }
115
-    }
116
-
117
-    /**
118
-     * Adds a trigger to the list.
119
-     *
120
-     * @param trigger Trigger to add
121
-     */
122
-    public void addTrigger(final ActionType trigger) {
123
-        SwingUtilities.invokeLater(() -> {
124
-            synchronized (triggers) {
125
-                triggers.add(trigger);
126
-                firePropertyChange("triggerCount", triggers.size() - 1,
127
-                        triggers.size());
128
-
129
-                layoutComponents();
130
-            }
131
-        });
132
-    }
133
-
134
-    /**
135
-     * Deletes a trigger from the list.
136
-     *
137
-     * @param trigger Trigger to delete
138
-     */
139
-    public void delTrigger(final ActionType trigger) {
140
-        SwingUtilities.invokeLater(() -> {
141
-            synchronized (triggers) {
142
-                triggers.remove(trigger);
143
-                fireTriggerRemoved(trigger);
144
-                firePropertyChange("triggerCount", triggers.size() + 1,
145
-                        triggers.size());
146
-
147
-                layoutComponents();
148
-            }
149
-        });
150
-    }
151
-
152
-    /**
153
-     * Clears the trigger list.
154
-     */
155
-    public void clearTriggers() {
156
-        triggers.forEach(this::delTrigger);
157
-    }
158
-
159
-    /**
160
-     * Returns the current list of triggers.
161
-     *
162
-     * @return Trigger list
163
-     */
164
-    public List<ActionType> getTriggers() {
165
-        synchronized (triggers) {
166
-            return triggers;
167
-        }
168
-    }
169
-
170
-    /**
171
-     * Gets the trigger at the specified index.
172
-     *
173
-     * @param index Index to retrieve
174
-     *
175
-     * @return Requested action trigger
176
-     */
177
-    public ActionType getTrigger(final int index) {
178
-        return triggers.get(index);
179
-    }
180
-
181
-    /**
182
-     * Returns the number of triggers.
183
-     *
184
-     * @return Trigger count
185
-     */
186
-    public int getTriggerCount() {
187
-        synchronized (triggers) {
188
-            return triggers.size();
189
-        }
190
-    }
191
-
192
-    /**
193
-     * Adds an ActionTriggerRemovalListener to the listener list.
194
-     *
195
-     * @param listener Listener to add
196
-     */
197
-    public void addTriggerListener(
198
-            final ActionTriggerRemovalListener listener) {
199
-        if (listener == null) {
200
-            return;
201
-        }
202
-
203
-        listeners.add(ActionTriggerRemovalListener.class, listener);
204
-    }
205
-
206
-    /**
207
-     * Removes an ActionTriggerRemovalListener from the listener list.
208
-     *
209
-     * @param listener Listener to remove
210
-     */
211
-    public void removeTriggerListener(
212
-            final ActionTriggerRemovalListener listener) {
213
-        listeners.remove(ActionTriggerRemovalListener.class, listener);
214
-    }
215
-
216
-    /**
217
-     * Fired when the an action trigger is removed.
218
-     *
219
-     * @param type Removed trigger
220
-     */
221
-    protected void fireTriggerRemoved(final ActionType type) {
222
-        for (final ActionTriggerRemovalListener listener : listeners.get(
223
-                ActionTriggerRemovalListener.class)) {
224
-            listener.triggerRemoved(type);
225
-        }
226
-    }
227
-
228
-    @Override
229
-    public void setEnabled(final boolean enabled) {
230
-        super.setEnabled(enabled);
231
-        SwingUtilities.invokeLater(this::layoutComponents);
232
-    }
233
-
234
-    /** Validates the triggers. */
235
-    public void validateTriggers() {
236
-        firePropertyChange("triggerCount", triggers.size(), triggers.size());
237
-    }
238
-
239
-}

+ 0
- 305
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionTriggersPanel.java Ver fichero

@@ -1,305 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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 com.dmdirc.actions.ActionTypeComparator;
26
-import com.dmdirc.addons.ui_swing.ComboBoxWidthModifier;
27
-import com.dmdirc.addons.ui_swing.components.renderers.ActionTypeRenderer;
28
-import com.dmdirc.addons.ui_swing.components.text.TextLabel;
29
-import com.dmdirc.interfaces.ActionController;
30
-import com.dmdirc.interfaces.actions.ActionType;
31
-import com.dmdirc.ui.IconManager;
32
-import com.dmdirc.util.collections.MapList;
33
-
34
-import java.awt.event.ActionEvent;
35
-import java.awt.event.ActionListener;
36
-import java.beans.PropertyChangeEvent;
37
-import java.beans.PropertyChangeListener;
38
-import java.util.ArrayList;
39
-import java.util.Collections;
40
-import java.util.List;
41
-import java.util.Map;
42
-
43
-import javax.swing.BorderFactory;
44
-import javax.swing.DefaultComboBoxModel;
45
-import javax.swing.JComboBox;
46
-import javax.swing.JPanel;
47
-import javax.swing.MutableComboBoxModel;
48
-import javax.swing.UIManager;
49
-
50
-import net.miginfocom.swing.MigLayout;
51
-
52
-/**
53
- * Action triggers panel.
54
- */
55
-public class ActionTriggersPanel extends JPanel implements ActionListener,
56
-        ActionTriggerRemovalListener, PropertyChangeListener {
57
-
58
-    /** A version number for this class. */
59
-    private static final long serialVersionUID = 1;
60
-    /** Action controller. */
61
-    private final ActionController actionController;
62
-    /** Trigger combo box. */
63
-    private JComboBox<Object> triggerGroup;
64
-    /** Trigger combo box. */
65
-    private JComboBox<Object> triggerItem;
66
-    /** Triggers list. */
67
-    private ActionTriggersListPanel triggerList;
68
-    /** Are we internally changing the combo boxes? */
69
-    private boolean comboChange;
70
-    /** Triggers compatible with the currently added triggers. */
71
-    private final List<ActionType> compatibleTriggers;
72
-
73
-    /**
74
-     * Instantiates the panel.
75
-     */
76
-    public ActionTriggersPanel(final ActionController actionController,
77
-            final IconManager iconManager) {
78
-
79
-        this.actionController = actionController;
80
-        compatibleTriggers = new ArrayList<>();
81
-
82
-        initComponents(iconManager);
83
-        addListeners();
84
-        layoutComponents();
85
-    }
86
-
87
-    /**
88
-     * Initialises the components.
89
-     *
90
-     * @param iconManager Icon manager
91
-     * */
92
-    private void initComponents(final IconManager iconManager) {
93
-        setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
94
-                "TitledBorder.border"), "Triggers"));
95
-
96
-        triggerGroup = new JComboBox<>(new DefaultComboBoxModel<>());
97
-        // Only fire events on selection not on highlight
98
-        triggerGroup.putClientProperty("JComboBox.isTableCellEditor",
99
-                Boolean.TRUE);
100
-        triggerGroup.setRenderer(new ActionTypeRenderer(triggerGroup.getRenderer()));
101
-        triggerGroup.addPopupMenuListener(new ComboBoxWidthModifier());
102
-
103
-        triggerItem = new JComboBox<>(new DefaultComboBoxModel<>());
104
-        // Only fire events on selection not on highlight
105
-        triggerItem.putClientProperty("JComboBox.isTableCellEditor",
106
-                Boolean.TRUE);
107
-        triggerItem.setRenderer(new ActionTypeRenderer(triggerItem.getRenderer()));
108
-        triggerItem.addPopupMenuListener(new ComboBoxWidthModifier());
109
-
110
-        triggerList = new ActionTriggersListPanel(iconManager);
111
-        addAll(actionController.getGroupedTypes());
112
-    }
113
-
114
-    /** Adds the listeners. */
115
-    private void addListeners() {
116
-        triggerGroup.addActionListener(this);
117
-        triggerItem.addActionListener(this);
118
-        triggerList.addTriggerListener(this);
119
-
120
-        triggerList.addPropertyChangeListener("triggerCount", this);
121
-    }
122
-
123
-    /** Lays out the components. */
124
-    private void layoutComponents() {
125
-        setLayout(new MigLayout("fill, pack, wmax 50%"));
126
-
127
-        add(new TextLabel("This action will be triggered when any of these "
128
-                + "events occurs: "), "growx, pushx, wrap, spanx");
129
-        add(triggerList, "grow, push, wrap, spanx");
130
-        add(triggerGroup, "growx, wmax 50%-(4*rel), wmin 50%-(4*rel)");
131
-        add(triggerItem, "growx, wmax 50%-(4*rel), wmin 50%-(4*rel)");
132
-    }
133
-
134
-    /**
135
-     * Returns the primary trigger for this panel.
136
-     *
137
-     * @return Primary trigger or null
138
-     */
139
-    public ActionType getPrimaryTrigger() {
140
-        if (triggerList.getTriggerCount() == 0) {
141
-            return null;
142
-        }
143
-        return triggerList.getTrigger(0);
144
-    }
145
-
146
-    /**
147
-     * Returns the list of triggers.
148
-     *
149
-     * @return Trigger list
150
-     */
151
-    public ActionType[] getTriggers() {
152
-        final List<ActionType> triggers = triggerList.getTriggers();
153
-        return triggers.toArray(new ActionType[triggers.size()]);
154
-    }
155
-
156
-    /**
157
-     * Sets the triggers.
158
-     *
159
-     * @param triggers Sets the triggers.
160
-     */
161
-    public void setTriggers(final ActionType... triggers) {
162
-        triggerList.clearTriggers();
163
-
164
-        for (final ActionType localTrigger : triggers) {
165
-            triggerList.addTrigger(localTrigger);
166
-        }
167
-
168
-        if (triggers.length > 0) {
169
-            addCompatible(triggers[0]);
170
-            setEnabled(true);
171
-        }
172
-    }
173
-
174
-    @Override
175
-    public void actionPerformed(final ActionEvent e) {
176
-        if (comboChange) {
177
-            return;
178
-        }
179
-        if (e.getSource() == triggerGroup) {
180
-            if (triggerList.getTriggerCount() == 0) {
181
-                addList(actionController.getGroupedTypes()
182
-                        .get((String) triggerGroup.getSelectedItem()));
183
-            } else {
184
-                addList(compatibleTriggers);
185
-            }
186
-        } else {
187
-            triggerList.addTrigger((ActionType) triggerItem.getSelectedItem());
188
-            addCompatible((ActionType) triggerItem.getSelectedItem());
189
-        }
190
-    }
191
-
192
-    @Override
193
-    public void triggerRemoved(final ActionType trigger) {
194
-        if (triggerList.getTriggerCount() == 0) {
195
-            addAll(actionController.getGroupedTypes());
196
-        } else {
197
-            addCompatible(triggerList.getTrigger(0));
198
-        }
199
-    }
200
-
201
-    private void addAll(final MapList<String, ActionType> mapList) {
202
-        comboChange = true;
203
-        compatibleTriggers.clear();
204
-        final DefaultComboBoxModel<Object> triggerModel
205
-                = (DefaultComboBoxModel<Object>) triggerGroup.getModel();
206
-        triggerModel.removeAllElements();
207
-        ((DefaultComboBoxModel<Object>) triggerItem.getModel()).removeAllElements();
208
-        for (final Map.Entry<String, List<ActionType>> entry : mapList
209
-                .entrySet()) {
210
-            triggerModel.addElement(entry.getKey());
211
-        }
212
-        triggerGroup.setSelectedIndex(-1);
213
-        triggerGroup.setEnabled(triggerGroup.getModel().getSize() > 0);
214
-        triggerItem.setEnabled(triggerItem.getModel().getSize() > 0);
215
-        comboChange = false;
216
-    }
217
-
218
-    /**
219
-     * Populates the combo boxes with triggers compatible with the specified type.
220
-     *
221
-     * @param primaryType Primary type
222
-     */
223
-    private void addCompatible(final ActionType primaryType) {
224
-        final DefaultComboBoxModel<Object> groupModel = (DefaultComboBoxModel<Object>) triggerGroup.
225
-                getModel();
226
-        final DefaultComboBoxModel<Object> itemModel = (DefaultComboBoxModel<Object>) triggerItem.
227
-                getModel();
228
-
229
-        comboChange = true;
230
-        compatibleTriggers.clear();
231
-        groupModel.removeAllElements();
232
-        itemModel.removeAllElements();
233
-        final List<ActionType> types = triggerList.getTriggers();
234
-
235
-        actionController.findCompatibleTypes(primaryType).stream()
236
-                .filter(thisType -> !types.contains(thisType))
237
-                .forEach(thisType -> {
238
-                    compatibleTriggers.add(thisType);
239
-                    itemModel.addElement(thisType);
240
-                    if (groupModel.getIndexOf(thisType.getType().getGroup()) == -1) {
241
-                        groupModel.addElement(thisType.getType().getGroup());
242
-                    }
243
-                });
244
-        triggerGroup.setSelectedIndex(-1);
245
-        triggerItem.setSelectedIndex(-1);
246
-        if (itemModel.getSize() == 0) {
247
-            groupModel.removeAllElements();
248
-        }
249
-        triggerGroup.setEnabled(groupModel.getSize() > 0);
250
-        if (groupModel.getSize() == 1) {
251
-            triggerGroup.setSelectedIndex(0);
252
-        }
253
-
254
-        triggerItem.setEnabled(itemModel.getSize() > 0);
255
-        triggerItem.setEnabled(triggerGroup.getSelectedIndex() != -1);
256
-
257
-        comboChange = false;
258
-    }
259
-
260
-    /**
261
-     * Adds the specified list of triggers to the items list.
262
-     *
263
-     * @param list List of triggers to add
264
-     */
265
-    private void addList(final List<ActionType> list) {
266
-        comboChange = true;
267
-        ((DefaultComboBoxModel<Object>) triggerItem.getModel()).removeAllElements();
268
-        Collections.sort(list, new ActionTypeComparator());
269
-        list.stream()
270
-                .filter(entry -> compatibleTriggers.isEmpty() || compatibleTriggers.contains(entry))
271
-                .forEach(((MutableComboBoxModel<Object>) triggerItem.getModel())::addElement);
272
-        triggerItem.setSelectedIndex(-1);
273
-        triggerGroup.setEnabled(triggerGroup.getModel().getSize() > 0);
274
-        triggerItem.setEnabled(triggerItem.getModel().getSize() > 0);
275
-        comboChange = false;
276
-    }
277
-
278
-    @Override
279
-    public void setEnabled(final boolean enabled) {
280
-        triggerList.setEnabled(enabled);
281
-        if (enabled) {
282
-            if (triggerGroup.getModel().getSize() > 0) {
283
-                triggerGroup.setEnabled(true);
284
-            }
285
-            if (triggerItem.getModel().getSize() > 0) {
286
-                triggerItem.setEnabled(true);
287
-            }
288
-        } else {
289
-            triggerGroup.setEnabled(false);
290
-            triggerItem.setEnabled(false);
291
-        }
292
-    }
293
-
294
-    @Override
295
-    public void propertyChange(final PropertyChangeEvent evt) {
296
-        firePropertyChange("validationResult", (Integer) evt.getOldValue() > 0,
297
-                (Integer) evt.getNewValue() > 0);
298
-    }
299
-
300
-    /** Validates the triggers. */
301
-    public void validateTriggers() {
302
-        triggerList.validateTriggers();
303
-    }
304
-
305
-}

+ 0
- 116
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionTypeModel.java Ver fichero

@@ -1,116 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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 com.dmdirc.actions.ActionTypeComparator;
26
-import com.dmdirc.interfaces.actions.ActionType;
27
-import com.dmdirc.util.collections.MapList;
28
-
29
-import java.awt.FontMetrics;
30
-import java.util.Collections;
31
-import java.util.List;
32
-import java.util.Map;
33
-
34
-import javax.swing.DefaultComboBoxModel;
35
-import javax.swing.SwingUtilities;
36
-
37
-/**
38
- * Model for the "trigger" list of the actions editor. Adds type group headers, and ensures they
39
- * can't be selected.
40
- */
41
-public final class ActionTypeModel extends DefaultComboBoxModel<Object> {
42
-
43
-    /** A version number for this class. */
44
-    private static final long serialVersionUID = 1;
45
-    /** Font metrics. */
46
-    private final FontMetrics fm;
47
-    /** Max Width. */
48
-    private int maxWidth = -1;
49
-
50
-    /**
51
-     * Creates a new instance of ActionTypeModel.
52
-     *
53
-     * @param fm         Font metrics
54
-     * @param typeGroups The action type groups to use
55
-     */
56
-    public ActionTypeModel(final FontMetrics fm, final MapList<String, ActionType> typeGroups) {
57
-
58
-        this.fm = fm;
59
-
60
-        for (Map.Entry<String, List<ActionType>> entry : typeGroups.entrySet()) {
61
-            addElement(entry.getKey());
62
-
63
-            final List<ActionType> types = entry.getValue();
64
-            Collections.sort(types, new ActionTypeComparator());
65
-
66
-            types.forEach(this::addElement);
67
-        }
68
-    }
69
-
70
-    @Override
71
-    public void addElement(final Object anObject) {
72
-        super.addElement(anObject);
73
-        int width = maxWidth;
74
-        if (anObject instanceof String) {
75
-            width = SwingUtilities.computeStringWidth(fm, (String) anObject);
76
-        } else if (anObject instanceof ActionType) {
77
-            width = SwingUtilities.computeStringWidth(fm, ((ActionType) anObject).getName());
78
-        }
79
-        maxWidth = Math.max(width, maxWidth);
80
-    }
81
-
82
-    @Override
83
-    public void setSelectedItem(final Object anObject) {
84
-        if (!(anObject instanceof String)) {
85
-            super.setSelectedItem(anObject);
86
-        }
87
-    }
88
-
89
-    /**
90
-     * Sets the type group for this model.
91
-     *
92
-     * @param typeGroup New type group
93
-     */
94
-    public void setTypeGroup(final MapList<String, ActionType> typeGroup) {
95
-        removeAllElements();
96
-
97
-        for (Map.Entry<String, List<ActionType>> entry : typeGroup.entrySet()) {
98
-            addElement(entry.getKey());
99
-
100
-            final List<ActionType> types = entry.getValue();
101
-            Collections.sort(types, new ActionTypeComparator());
102
-
103
-            types.forEach(this::addElement);
104
-        }
105
-    }
106
-
107
-    /**
108
-     * Returns the maximum width of a string in this model.
109
-     *
110
-     * @return String max width
111
-     */
112
-    public int getMaxWidth() {
113
-        return maxWidth;
114
-    }
115
-
116
-}

+ 0
- 136
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionGroupInformationPanel.java Ver fichero

@@ -1,136 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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.actionsmanager;
24
-
25
-import com.dmdirc.actions.ActionGroup;
26
-import com.dmdirc.addons.ui_swing.components.text.TextLabel;
27
-
28
-import javax.swing.JLabel;
29
-import javax.swing.JPanel;
30
-
31
-import net.miginfocom.swing.MigLayout;
32
-
33
-/**
34
- * Action group information panel.
35
- */
36
-public final class ActionGroupInformationPanel extends JPanel {
37
-
38
-    /** A version number for this class. */
39
-    private static final long serialVersionUID = 1;
40
-    /** Action group. */
41
-    private ActionGroup group;
42
-    /** Description field. */
43
-    private TextLabel infoLabel;
44
-    /** Version label label. */
45
-    private JLabel versionLabel;
46
-    /** Version label. */
47
-    private JLabel version;
48
-    /** Author label label. */
49
-    private JLabel authorLabel;
50
-    /** Author label. */
51
-    private JLabel author;
52
-
53
-    /**
54
-     * Initialises a new action group information panel.
55
-     *
56
-     * @param group Action group
57
-     */
58
-    public ActionGroupInformationPanel(final ActionGroup group) {
59
-
60
-        this.group = group;
61
-
62
-        initComponents();
63
-        addListeners();
64
-        layoutComponents();
65
-    }
66
-
67
-    /**
68
-     * Initialises the components.
69
-     */
70
-    private void initComponents() {
71
-        infoLabel = new TextLabel("");
72
-        versionLabel = new JLabel("Version: ");
73
-        version = new JLabel();
74
-        authorLabel = new JLabel("Author: ");
75
-        author = new JLabel();
76
-
77
-        setActionGroup(group);
78
-    }
79
-
80
-    /**
81
-     * Adds listeners.
82
-     */
83
-    private void addListeners() {
84
-        //Empty
85
-    }
86
-
87
-    /**
88
-     * Lays out the components.
89
-     */
90
-    private void layoutComponents() {
91
-        setLayout(new MigLayout("fill, wrap 2, hidemode 2"));
92
-
93
-        add(infoLabel, "spanx 2, grow, push");
94
-        add(authorLabel, "");
95
-        add(author, "growx, pushx");
96
-        add(versionLabel, "");
97
-        add(version, "growx, pushx");
98
-    }
99
-
100
-    /**
101
-     * Sets the action group for the panel.
102
-     *
103
-     * @param group New action group
104
-     */
105
-    public void setActionGroup(final ActionGroup group) {
106
-        this.group = group;
107
-
108
-        if (shouldDisplay()) {
109
-            //Prevent HTML text displaying, replace newlines with <br>
110
-            infoLabel.setText(group.getDescription().replace("<", "&lt;")
111
-                    .replace("\n", "<br>"));
112
-            author.setText(group.getAuthor());
113
-            version.setText(group.getVersion() == null ? "" : group.getVersion().toString());
114
-
115
-            author.setVisible(group.getAuthor() != null);
116
-            version.setVisible(group.getVersion() != null);
117
-            authorLabel.setVisible(group.getAuthor() != null);
118
-            versionLabel.setVisible(group.getVersion() != null);
119
-        } else {
120
-            //Value require for mig/swing layouting bug
121
-            infoLabel.setText("Non empty string");
122
-            author.setText("");
123
-            version.setText("");
124
-        }
125
-    }
126
-
127
-    /**
128
-     * Should the info panel be shown?
129
-     *
130
-     * @return true iif the panel should be shown
131
-     */
132
-    public boolean shouldDisplay() {
133
-        return group != null && group.getDescription() != null;
134
-    }
135
-
136
-}

+ 0
- 39
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionGroupNameComparator.java Ver fichero

@@ -1,39 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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.actionsmanager;
24
-
25
-import com.dmdirc.actions.ActionGroup;
26
-
27
-import java.util.Comparator;
28
-
29
-/**
30
- * Action group name comparator.
31
- */
32
-public class ActionGroupNameComparator implements Comparator<ActionGroup> {
33
-
34
-    @Override
35
-    public int compare(final ActionGroup o1, final ActionGroup o2) {
36
-        return o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase());
37
-    }
38
-
39
-}

+ 0
- 77
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionGroupNoDuplicatesInListValidator.java Ver fichero

@@ -1,77 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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.actionsmanager;
24
-
25
-import com.dmdirc.actions.ActionGroup;
26
-import com.dmdirc.addons.ui_swing.components.validating.NoDuplicatesInListValidator;
27
-
28
-import javax.swing.DefaultListModel;
29
-import javax.swing.JList;
30
-
31
-/**
32
- * No duplicates list validator, overridden to work with action groups.
33
- */
34
-class ActionGroupNoDuplicatesInListValidator extends NoDuplicatesInListValidator<ActionGroup> {
35
-
36
-    /**
37
-     * Creates a new validator.
38
-     *
39
-     * @param list  List
40
-     * @param model Model to validate
41
-     */
42
-    public ActionGroupNoDuplicatesInListValidator(final JList<ActionGroup> list,
43
-            final DefaultListModel<ActionGroup> model) {
44
-        super(true, list, model);
45
-    }
46
-
47
-    /**
48
-     * Creates a new validator.
49
-     *
50
-     * @param list          List
51
-     * @param caseSensitive Case sensitive check?
52
-     * @param model         Model to validate
53
-     */
54
-    public ActionGroupNoDuplicatesInListValidator(final boolean caseSensitive,
55
-            final JList<ActionGroup> list, final DefaultListModel<ActionGroup> model) {
56
-        super(caseSensitive, list, model);
57
-    }
58
-
59
-    @Override
60
-    public String listValueToString(final Object object) {
61
-        return ((ActionGroup) object).getName();
62
-    }
63
-
64
-    @Override
65
-    public int indexOfString(final String string) {
66
-        final String value = caseSensitive ? string : string.toLowerCase();
67
-        int index = -1;
68
-        for (int i = 0; i < model.getSize(); i++) {
69
-            if (((ActionGroup) model.get(i)).getName().equals(value)) {
70
-                index = i;
71
-                break;
72
-            }
73
-        }
74
-        return index;
75
-    }
76
-
77
-}

+ 0
- 177
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionGroupSettingsPanel.java Ver fichero

@@ -1,177 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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.actionsmanager;
24
-
25
-import com.dmdirc.actions.ActionGroup;
26
-import com.dmdirc.addons.ui_swing.PrefsComponentFactory;
27
-import com.dmdirc.addons.ui_swing.components.colours.ColourChooser;
28
-import com.dmdirc.addons.ui_swing.components.colours.OptionalColourChooser;
29
-import com.dmdirc.addons.ui_swing.components.durationeditor.DurationDisplay;
30
-import com.dmdirc.config.prefs.PreferencesSetting;
31
-
32
-import java.awt.Window;
33
-import java.awt.event.ActionEvent;
34
-import java.awt.event.ActionListener;
35
-import java.util.ArrayList;
36
-import java.util.Collection;
37
-import java.util.HashMap;
38
-import java.util.Map;
39
-
40
-import javax.swing.JButton;
41
-import javax.swing.JComponent;
42
-import javax.swing.JLabel;
43
-import javax.swing.JPanel;
44
-
45
-import net.miginfocom.swing.MigLayout;
46
-
47
-/**
48
- * Action group settings panel.
49
- */
50
-public final class ActionGroupSettingsPanel extends JPanel implements ActionListener {
51
-
52
-    /** A version number for this class. */
53
-    private static final long serialVersionUID = 1;
54
-    /** Settings list. */
55
-    private Collection<PreferencesSetting> settings;
56
-    /** Button to Component map. */
57
-    private Map<JButton, PreferencesSetting> settingMap;
58
-    /** Parent dialog. */
59
-    private final Window window;
60
-    /** Prefs component factory. */
61
-    private final PrefsComponentFactory factory;
62
-
63
-    /**
64
-     * Initialises a new action group information panel.
65
-     *
66
-     * @param factory Prefs component factory
67
-     * @param group   Action group
68
-     */
69
-    public ActionGroupSettingsPanel(final PrefsComponentFactory factory,
70
-            final ActionGroup group) {
71
-        this(factory, group, null);
72
-    }
73
-
74
-    /**
75
-     * Initialises a new action group information panel.
76
-     *
77
-     * @param factory Prefs component factory
78
-     * @param group   Action group
79
-     * @param window  Parent window
80
-     *
81
-     * @since 0.6
82
-     */
83
-    public ActionGroupSettingsPanel(final PrefsComponentFactory factory,
84
-            final ActionGroup group, final Window window) {
85
-
86
-        this.factory = factory;
87
-        this.window = window;
88
-
89
-        initComponents();
90
-        addListeners();
91
-
92
-        setActionGroup(group);
93
-    }
94
-
95
-    /**
96
-     * Initialises the components.
97
-     */
98
-    private void initComponents() {
99
-        settingMap = new HashMap<>();
100
-    }
101
-
102
-    /**
103
-     * Adds listeners.
104
-     */
105
-    private void addListeners() {
106
-        //Empty
107
-    }
108
-
109
-    /**
110
-     * Lays out the components.
111
-     */
112
-    private void layoutComponents() {
113
-        removeAll();
114
-        setLayout(new MigLayout("fill, hidemode 3"));
115
-
116
-        for (PreferencesSetting setting : settings) {
117
-            final JLabel label = new JLabel(setting.getTitle());
118
-            label.setToolTipText(setting.getTitle());
119
-            final JComponent component = factory.getComponent(setting);
120
-
121
-            if (component instanceof DurationDisplay) {
122
-                ((DurationDisplay) component).setWindow(window);
123
-            } else if (component instanceof ColourChooser) {
124
-                ((ColourChooser) component).setWindow(window);
125
-            } else if (component instanceof OptionalColourChooser) {
126
-                ((OptionalColourChooser) component).setWindow(window);
127
-            }
128
-
129
-            final JButton button = new SettingsRevertButton(setting);
130
-            settingMap.put(button, setting);
131
-            button.addActionListener(this);
132
-            add(label, "newline");
133
-            add(component, "growx, pushx");
134
-            add(button, "");
135
-        }
136
-    }
137
-
138
-    /**
139
-     * Sets the action group for the panel.
140
-     *
141
-     * @param group New action group
142
-     */
143
-    public void setActionGroup(final ActionGroup group) {
144
-        if (group == null || group.getSettings().isEmpty()) {
145
-            this.settings = new ArrayList<>();
146
-        } else {
147
-            this.settings = group.getSettings().values();
148
-        }
149
-
150
-        layoutComponents();
151
-    }
152
-
153
-    /**
154
-     * Should the settings panel be shown?
155
-     *
156
-     * @return true iif the panel should be shown
157
-     */
158
-    public boolean shouldDisplay() {
159
-        return !settings.isEmpty();
160
-    }
161
-
162
-    /**
163
-     * Saves the changes to the settings.
164
-     */
165
-    public void save() {
166
-        settings.forEach(PreferencesSetting::save);
167
-    }
168
-
169
-    @Override
170
-    public void actionPerformed(final ActionEvent e) {
171
-        setVisible(false);
172
-        settingMap.get(e.getSource()).dismiss();
173
-        layoutComponents();
174
-        setVisible(true);
175
-    }
176
-
177
-}

+ 0
- 220
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionTableModel.java Ver fichero

@@ -1,220 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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.actionsmanager;
24
-
25
-import com.dmdirc.actions.Action;
26
-import com.dmdirc.actions.ActionGroup;
27
-import com.dmdirc.interfaces.actions.ActionType;
28
-
29
-import com.google.common.base.Preconditions;
30
-
31
-import java.util.ArrayList;
32
-import java.util.Collection;
33
-import java.util.List;
34
-
35
-import javax.swing.table.AbstractTableModel;
36
-
37
-/**
38
- * Action table model.
39
- */
40
-public class ActionTableModel extends AbstractTableModel {
41
-
42
-    /** A version number for this class. */
43
-    private static final long serialVersionUID = 1;
44
-    /** Action list. */
45
-    private final List<Action> actions;
46
-
47
-    /**
48
-     * Instantiates a new table model.
49
-     *
50
-     * @param actions Actions to show
51
-     */
52
-    public ActionTableModel(final Collection<Action> actions) {
53
-        Preconditions.checkNotNull(actions);
54
-        this.actions = new ArrayList<>(actions);
55
-    }
56
-
57
-    @Override
58
-    public int getRowCount() {
59
-        synchronized (actions) {
60
-            return actions.size();
61
-        }
62
-    }
63
-
64
-    @Override
65
-    public int getColumnCount() {
66
-        return 3;
67
-    }
68
-
69
-    @Override
70
-    public String getColumnName(final int columnIndex) {
71
-        switch (columnIndex) {
72
-            case 0:
73
-                return "Name";
74
-            case 1:
75
-                return "Trigger";
76
-            case 2:
77
-                return "Response";
78
-            default:
79
-                throw new IllegalArgumentException("Unknown column: " + columnIndex);
80
-        }
81
-    }
82
-
83
-    @Override
84
-    public Class<?> getColumnClass(final int columnIndex) {
85
-        switch (columnIndex) {
86
-            case 0:
87
-                return String.class;
88
-            case 1:
89
-                return ActionType.class;
90
-            case 2:
91
-                return String[].class;
92
-            default:
93
-                throw new IllegalArgumentException("Unknown column: " + columnIndex);
94
-        }
95
-    }
96
-
97
-    @Override
98
-    public Object getValueAt(final int rowIndex, final int columnIndex) {
99
-        synchronized (actions) {
100
-            switch (columnIndex) {
101
-                case 0:
102
-                    return actions.get(rowIndex).getName();
103
-                case 1:
104
-                    return actions.get(rowIndex).getTriggers()[0];
105
-                case 2:
106
-                    return actions.get(rowIndex).getResponse();
107
-                default:
108
-                    throw new IllegalArgumentException("Unknown column: " + columnIndex);
109
-            }
110
-        }
111
-    }
112
-
113
-    /**
114
-     * Returns the action at the specified row.
115
-     *
116
-     * @param rowIndex Row index
117
-     *
118
-     * @return Action
119
-     */
120
-    public Action getAction(final int rowIndex) {
121
-        synchronized (actions) {
122
-            return actions.get(rowIndex);
123
-        }
124
-    }
125
-
126
-    /**
127
-     * Returns the row index of the specified index.
128
-     *
129
-     * @param action Action to get
130
-     *
131
-     * @return Action row index or -1 if not found.
132
-     */
133
-    public int getAction(final Action action) {
134
-        synchronized (actions) {
135
-            return actions.indexOf(action);
136
-        }
137
-    }
138
-
139
-    /**
140
-     * Replaces the model data with the specified action group.
141
-     *
142
-     * @param group New Action group
143
-     */
144
-    public void setActionGroup(final ActionGroup group) {
145
-        synchronized (actions) {
146
-            actions.clear();
147
-            if (group != null) {
148
-                actions.addAll(group.getActions());
149
-            }
150
-            fireTableDataChanged();
151
-        }
152
-    }
153
-
154
-    /**
155
-     * Adds an action to the model.
156
-     *
157
-     * @param action Action to add
158
-     */
159
-    public void add(final Action action) {
160
-        synchronized (actions) {
161
-            if (action == null) {
162
-                return;
163
-            }
164
-            actions.add(action);
165
-            fireTableRowsInserted(actions.size() - 1, actions.size() - 1);
166
-        }
167
-    }
168
-
169
-    /**
170
-     * Removes an action from the model.
171
-     *
172
-     * @param action Action to remove
173
-     */
174
-    public void remove(final Action action) {
175
-        if (action == null) {
176
-            return;
177
-        }
178
-        remove(actions.indexOf(action));
179
-    }
180
-
181
-    /**
182
-     * Removes an action from the model.
183
-     *
184
-     * @param index Index of the action to remove
185
-     */
186
-    public void remove(final int index) {
187
-        synchronized (actions) {
188
-            if (index != -1) {
189
-                actions.remove(index);
190
-                fireTableRowsDeleted(index, index);
191
-            }
192
-        }
193
-    }
194
-
195
-    /**
196
-     * Checks if this model contains the specified action.
197
-     *
198
-     * @param action Action to check for
199
-     *
200
-     * @return true if the action exists
201
-     */
202
-    public boolean contains(final Action action) {
203
-        synchronized (actions) {
204
-            return actions.contains(action);
205
-        }
206
-    }
207
-
208
-    public int findAction(final String name) {
209
-        int location = -1;
210
-        synchronized (actions) {
211
-            for (Action action : actions) {
212
-                if (action.getName().equals(name)) {
213
-                    location = actions.indexOf(action);
214
-                }
215
-            }
216
-        }
217
-        return location;
218
-    }
219
-
220
-}

+ 0
- 55
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionTypeTableCellRenderer.java Ver fichero

@@ -1,55 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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.actionsmanager;
24
-
25
-import com.dmdirc.interfaces.actions.ActionType;
26
-
27
-import java.awt.Color;
28
-import java.awt.Font;
29
-
30
-import javax.swing.table.DefaultTableCellRenderer;
31
-
32
-/**
33
- * Displays actions types and headers in a pretty fashion.
34
- */
35
-public final class ActionTypeTableCellRenderer extends DefaultTableCellRenderer {
36
-
37
-    /** A version number for this class. */
38
-    private static final long serialVersionUID = 1;
39
-
40
-    @Override
41
-    public void setValue(final Object value) {
42
-        if (value == null) {
43
-            setText("");
44
-        } else if (value instanceof String && !((String) value).isEmpty()) {
45
-            setBackground(Color.GRAY);
46
-            setFont(getFont().deriveFont(Font.BOLD));
47
-            setText(value.toString());
48
-        } else if (value instanceof ActionType) {
49
-            setText(((ActionType) value).getName());
50
-        } else {
51
-            setText(value.toString());
52
-        }
53
-    }
54
-
55
-}

+ 0
- 256
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsGroupPanel.java Ver fichero

@@ -1,256 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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.actionsmanager;
24
-
25
-import com.dmdirc.actions.Action;
26
-import com.dmdirc.actions.ActionGroup;
27
-import com.dmdirc.actions.ActionTypeComparator;
28
-import com.dmdirc.addons.ui_swing.components.PackingTable;
29
-import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
30
-import com.dmdirc.addons.ui_swing.dialogs.StringArrayComparator;
31
-import com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionEditorDialogFactory;
32
-
33
-import java.awt.Dialog.ModalityType;
34
-import java.awt.event.ActionEvent;
35
-import java.awt.event.ActionListener;
36
-import java.awt.event.MouseAdapter;
37
-import java.awt.event.MouseEvent;
38
-import java.util.ArrayList;
39
-
40
-import javax.swing.JButton;
41
-import javax.swing.JPanel;
42
-import javax.swing.JScrollPane;
43
-import javax.swing.ListSelectionModel;
44
-import javax.swing.event.ListSelectionEvent;
45
-import javax.swing.event.ListSelectionListener;
46
-import javax.swing.table.TableCellRenderer;
47
-import javax.swing.table.TableRowSorter;
48
-
49
-import net.miginfocom.swing.MigLayout;
50
-
51
-/**
52
- * The actions group panel is the control displayed within the tabbed control of the actions manager
53
- * dialog. It shows the user all actions belonging to a particular group.
54
- */
55
-public class ActionsGroupPanel extends JPanel implements ActionListener,
56
-        ListSelectionListener {
57
-
58
-    /** A version number for this class. */
59
-    private static final long serialVersionUID = 1;
60
-    /** Factory to use to create editor dialogs. */
61
-    private final ActionEditorDialogFactory editorDialogFactory;
62
-    /** Parent dialog. */
63
-    private final ActionsManagerDialog parent;
64
-    /** Table scrollpane. */
65
-    private JScrollPane scrollPane;
66
-    /** Actions table. */
67
-    private PackingTable table;
68
-    /** Table mode. */
69
-    private ActionTableModel model;
70
-    /** Add button. */
71
-    private JButton add;
72
-    /** Edit button. */
73
-    private JButton edit;
74
-    /** Delete button. */
75
-    private JButton delete;
76
-    /** Action group. */
77
-    private ActionGroup group;
78
-
79
-    /**
80
-     * Creates a new instance of ActionsManagerDialog.
81
-     *
82
-     * @param editorDialogFactory Factory to use to create editor dialogs.
83
-     * @param parent              Parent window
84
-     * @param group               Action group to display
85
-     */
86
-    public ActionsGroupPanel(
87
-            final ActionEditorDialogFactory editorDialogFactory,
88
-            final ActionsManagerDialog parent,
89
-            final ActionGroup group) {
90
-
91
-        this.editorDialogFactory = editorDialogFactory;
92
-        this.parent = parent;
93
-        this.group = group;
94
-
95
-        initComponents();
96
-        addListeners();
97
-        layoutComponents();
98
-    }
99
-
100
-    /**
101
-     * Updates or creates the new action.
102
-     *
103
-     * @param action Action changed or created
104
-     */
105
-    public void actionChanged(final Action action) {
106
-        if (model.contains(action)) {
107
-            final int row = model.getAction(action);
108
-            model.fireTableCellUpdated(row, 0);
109
-            model.fireTableCellUpdated(row, 1);
110
-            model.fireTableCellUpdated(row, 2);
111
-        } else {
112
-            model.add(action);
113
-        }
114
-    }
115
-
116
-    /**
117
-     * Deletes an action from the group.
118
-     *
119
-     * @param name Name of the action
120
-     */
121
-    public void actionDeleted(final String name) {
122
-        final int location = model.findAction(name);
123
-        if (location != -1) {
124
-            model.remove(location);
125
-        }
126
-    }
127
-
128
-    /**
129
-     * Initialises the components.
130
-     */
131
-    private void initComponents() {
132
-        scrollPane = new JScrollPane();
133
-        model = new ActionTableModel(group == null ? new ArrayList<>() : group.getActions());
134
-        table = new PackingTable(model, scrollPane, false) {
135
-            /** A version number for this class. */
136
-            private static final long serialVersionUID = 1;
137
-            /** Action type renderer. */
138
-            private final TableCellRenderer typeRenderer = new ActionTypeTableCellRenderer();
139
-            /** Action response renderer. */
140
-            private final TableCellRenderer arrayRenderer = new ArrayCellRenderer();
141
-
142
-            @Override
143
-            public TableCellRenderer getCellRenderer(final int row, final int column) {
144
-                switch (column) {
145
-                    case 1:
146
-                        return typeRenderer;
147
-                    case 2:
148
-                        return arrayRenderer;
149
-                    default:
150
-                        return super.getCellRenderer(row, column);
151
-                }
152
-            }
153
-        };
154
-
155
-        final TableRowSorter<ActionTableModel> sorter = new TableRowSorter<>(model);
156
-        sorter.setComparator(1, new ActionTypeComparator());
157
-        sorter.setComparator(2, new StringArrayComparator());
158
-
159
-        table.setRowSorter(sorter);
160
-        table.addMouseListener(new MouseAdapter() {
161
-
162
-            @Override
163
-            public void mouseClicked(final MouseEvent e) {
164
-                if (e.getClickCount() == 2) {
165
-                    edit.doClick();
166
-                }
167
-            }
168
-        });
169
-        add = new JButton("Add");
170
-        edit = new JButton("Edit");
171
-        delete = new JButton("Delete");
172
-
173
-        scrollPane.setViewportView(table);
174
-
175
-        table.setAutoCreateColumnsFromModel(true);
176
-        table.setColumnSelectionAllowed(false);
177
-        table.setCellSelectionEnabled(false);
178
-        table.setFillsViewportHeight(false);
179
-        table.setRowSelectionAllowed(true);
180
-        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
181
-        table.getRowSorter().toggleSortOrder(0);
182
-
183
-        edit.setEnabled(false);
184
-        delete.setEnabled(false);
185
-        add.setEnabled(group != null);
186
-    }
187
-
188
-    /**
189
-     * Adds listeners.
190
-     */
191
-    private void addListeners() {
192
-        add.addActionListener(this);
193
-        edit.addActionListener(this);
194
-        delete.addActionListener(this);
195
-        table.getSelectionModel().addListSelectionListener(this);
196
-    }
197
-
198
-    /**
199
-     * Lays out the components.
200
-     */
201
-    private void layoutComponents() {
202
-        setLayout(new MigLayout("fill"));
203
-
204
-        add(scrollPane, "grow, push, span 3, wrap");
205
-        add(add, "right, sgx button");
206
-        add(edit, "right, sgx button");
207
-        add(delete, "right, sgx button");
208
-    }
209
-
210
-    /**
211
-     * Sets the action group for the panel.
212
-     *
213
-     * @param group New action group
214
-     */
215
-    public void setActionGroup(final ActionGroup group) {
216
-        this.group = group;
217
-
218
-        model.setActionGroup(group);
219
-        add.setEnabled(group != null);
220
-    }
221
-
222
-    @Override
223
-    public void actionPerformed(final ActionEvent e) {
224
-        if (e.getSource() == add) {
225
-            editorDialogFactory.getActionEditorDialog(parent, group.getName()).display();
226
-        } else if (e.getSource() == edit) {
227
-            editorDialogFactory.getActionEditorDialog(parent,
228
-                    model.getAction(table.getRowSorter().convertRowIndexToModel(
229
-                                    table.getSelectedRow()))).display();
230
-        } else if (e.getSource() == delete) {
231
-            final Action action = model.getAction(
232
-                    table.getRowSorter().convertRowIndexToModel(table.
233
-                            getSelectedRow()));
234
-            new StandardQuestionDialog(parent,
235
-                    ModalityType.APPLICATION_MODAL, "Confirm deletion",
236
-                    "Are you sure you wish to delete the action '" + action.
237
-                    getName() + "'?", () -> group.deleteAction(action)).display();
238
-        }
239
-    }
240
-
241
-    @Override
242
-    public void valueChanged(final ListSelectionEvent e) {
243
-        if (e.getValueIsAdjusting()) {
244
-            return;
245
-        }
246
-
247
-        if (table.getSelectedRow() == -1) {
248
-            edit.setEnabled(false);
249
-            delete.setEnabled(false);
250
-        } else {
251
-            edit.setEnabled(true);
252
-            delete.setEnabled(true);
253
-        }
254
-    }
255
-
256
-}

+ 0
- 49
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsGroupPanelFactory.java Ver fichero

@@ -1,49 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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.actionsmanager;
24
-
25
-import com.dmdirc.actions.ActionGroup;
26
-import com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionEditorDialogFactory;
27
-
28
-import javax.inject.Inject;
29
-import javax.inject.Singleton;
30
-
31
-/**
32
- * Factory for {@link ActionsGroupPanel}s.
33
- */
34
-@Singleton
35
-public class ActionsGroupPanelFactory {
36
-
37
-    private final ActionEditorDialogFactory editorDialogFactory;
38
-
39
-    @Inject
40
-    public ActionsGroupPanelFactory(final ActionEditorDialogFactory editorDialogFactory) {
41
-        this.editorDialogFactory = editorDialogFactory;
42
-    }
43
-
44
-    public ActionsGroupPanel getActionsGroupPanel(
45
-            final ActionsManagerDialog parent,
46
-            final ActionGroup group) {
47
-        return new ActionsGroupPanel(editorDialogFactory, parent, group);
48
-    }
49
-}

+ 0
- 424
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsManagerDialog.java Ver fichero

@@ -1,424 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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.actionsmanager;
24
-
25
-import com.dmdirc.ClientModule.GlobalConfig;
26
-import com.dmdirc.ClientModule.UserConfig;
27
-import com.dmdirc.DMDircMBassador;
28
-import com.dmdirc.actions.Action;
29
-import com.dmdirc.actions.ActionGroup;
30
-import com.dmdirc.addons.ui_swing.Apple;
31
-import com.dmdirc.addons.ui_swing.MainFrame;
32
-import com.dmdirc.addons.ui_swing.PrefsComponentFactory;
33
-import com.dmdirc.addons.ui_swing.components.ListScroller;
34
-import com.dmdirc.addons.ui_swing.components.SortedListModel;
35
-import com.dmdirc.addons.ui_swing.components.frames.AppleJFrame;
36
-import com.dmdirc.addons.ui_swing.components.renderers.PropertyListCellRenderer;
37
-import com.dmdirc.addons.ui_swing.components.text.TextLabel;
38
-import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
39
-import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
40
-import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
41
-import com.dmdirc.events.ActionCreatedEvent;
42
-import com.dmdirc.events.ActionDeletedEvent;
43
-import com.dmdirc.events.ActionUpdatedEvent;
44
-import com.dmdirc.interfaces.ActionController;
45
-import com.dmdirc.interfaces.config.ConfigProvider;
46
-import com.dmdirc.ui.IconManager;
47
-import com.dmdirc.util.validators.FileNameValidator;
48
-import com.dmdirc.util.validators.ValidatorChain;
49
-
50
-import java.awt.event.ActionEvent;
51
-import java.awt.event.ActionListener;
52
-import java.util.HashMap;
53
-import java.util.Map;
54
-import java.util.concurrent.atomic.AtomicBoolean;
55
-
56
-import javax.inject.Inject;
57
-import javax.swing.BorderFactory;
58
-import javax.swing.DefaultListModel;
59
-import javax.swing.JButton;
60
-import javax.swing.JList;
61
-import javax.swing.JPanel;
62
-import javax.swing.JScrollPane;
63
-import javax.swing.ListSelectionModel;
64
-import javax.swing.UIManager;
65
-import javax.swing.event.ListSelectionEvent;
66
-import javax.swing.event.ListSelectionListener;
67
-
68
-import net.miginfocom.swing.MigLayout;
69
-
70
-import net.engio.mbassy.listener.Handler;
71
-
72
-/**
73
- * Allows the user to manage actions.
74
- */
75
-public class ActionsManagerDialog extends StandardDialog implements
76
-        ActionListener, ListSelectionListener {
77
-
78
-    /** A version number for this class. */
79
-    private static final long serialVersionUID = 1;
80
-    /** Config instance. */
81
-    private final ConfigProvider config;
82
-    /** Preferences setting component factory. */
83
-    private final PrefsComponentFactory compFactory;
84
-    /** Are we saving? */
85
-    private final AtomicBoolean saving = new AtomicBoolean(false);
86
-    /** Duplicate action group validator. */
87
-    private final ValidatorChain<String> validator;
88
-    /** Event bus to post events to and subscribe to events on. */
89
-    private final DMDircMBassador eventbus;
90
-    /** Action manager to manage actions with. */
91
-    private final ActionController actionManager;
92
-    /** Info label. */
93
-    private TextLabel infoLabel;
94
-    /** Group list. */
95
-    private JList<ActionGroup> groups;
96
-    /** Add button. */
97
-    private JButton add;
98
-    /** Edit button. */
99
-    private JButton edit;
100
-    /** Delete button. */
101
-    private JButton delete;
102
-    /** Info panel. */
103
-    private ActionGroupInformationPanel info;
104
-    /** Actions panel. */
105
-    private ActionsGroupPanel actions;
106
-    /** Settings panels. */
107
-    private Map<ActionGroup, ActionGroupSettingsPanel> settings;
108
-    /** Active s panel. */
109
-    private ActionGroupSettingsPanel activeSettings;
110
-    /** Group panel. */
111
-    private JPanel groupPanel;
112
-    /** The icon manager to use for validating text fields. */
113
-    private final IconManager iconManager;
114
-    /** Factory to use to create group panels. */
115
-    private final ActionsGroupPanelFactory groupPanelFactory;
116
-
117
-    /**
118
-     * Creates a new instance of ActionsManagerDialog.
119
-     */
120
-    @Inject
121
-    public ActionsManagerDialog(
122
-            final ActionController actionManager,
123
-            final DMDircMBassador eventBus,
124
-            final Apple apple,
125
-            final MainFrame parentWindow,
126
-            @UserConfig final ConfigProvider config,
127
-            final PrefsComponentFactory compFactory,
128
-            @GlobalConfig final IconManager iconManager,
129
-            final ActionsGroupPanelFactory groupPanelFactory) {
130
-        super(Apple.isAppleUI() ? new AppleJFrame(apple, parentWindow)
131
-                : parentWindow, ModalityType.MODELESS);
132
-        this.actionManager = actionManager;
133
-        this.eventbus = eventBus;
134
-        this.config = config;
135
-        this.compFactory = compFactory;
136
-        this.iconManager = iconManager;
137
-        this.groupPanelFactory = groupPanelFactory;
138
-
139
-        initComponents();
140
-        validator = ValidatorChain.<String>builder().addValidator(
141
-                new ActionGroupNoDuplicatesInListValidator(
142
-                        groups, (DefaultListModel<ActionGroup>) groups.getModel()))
143
-                .addValidator(new FileNameValidator()).build();
144
-        addListeners();
145
-        layoutGroupPanel();
146
-        layoutComponents();
147
-
148
-        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
149
-        setTitle("Actions Manager");
150
-        setResizable(false);
151
-    }
152
-
153
-    /**
154
-     * Initialises the components.
155
-     */
156
-    private void initComponents() {
157
-        orderButtons(new JButton(), new JButton());
158
-        infoLabel = new TextLabel("Actions allow you to make DMDirc"
159
-                + " intelligently respond to various events.  Action groups are"
160
-                + " there for you to organise groups, add or remove them"
161
-                + " to suit your needs.");
162
-        groups = new JList<>(new SortedListModel<>(new ActionGroupNameComparator()));
163
-        actions = groupPanelFactory.getActionsGroupPanel(this, null);
164
-        info = new ActionGroupInformationPanel(null);
165
-        settings = new HashMap<>();
166
-        activeSettings = new ActionGroupSettingsPanel(compFactory, null, this);
167
-        settings.put(null, activeSettings);
168
-        add = new JButton("Add");
169
-        edit = new JButton("Edit");
170
-        delete = new JButton("Delete");
171
-        groupPanel = new JPanel();
172
-        groupPanel.setName("Groups");
173
-
174
-        groupPanel.setBorder(BorderFactory.createTitledBorder(UIManager.
175
-                getBorder("TitledBorder.border"), "Groups"));
176
-        info.setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
177
-                "TitledBorder.border"), "Information"));
178
-        actions.setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
179
-                "TitledBorder.border"), "Actions"));
180
-
181
-        groups.setCellRenderer(new PropertyListCellRenderer<>(groups.getCellRenderer(),
182
-                ActionGroup.class, "name"));
183
-        groups.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
184
-        edit.setEnabled(false);
185
-        delete.setEnabled(false);
186
-
187
-        info.setVisible(false);
188
-        activeSettings.setVisible(false);
189
-
190
-        ListScroller.register(groups);
191
-
192
-        reloadGroups();
193
-    }
194
-
195
-    /**
196
-     * Adds listeners.
197
-     */
198
-    private void addListeners() {
199
-        getOkButton().addActionListener(this);
200
-        getCancelButton().addActionListener(this);
201
-        add.addActionListener(this);
202
-        edit.addActionListener(this);
203
-        delete.addActionListener(this);
204
-        groups.getSelectionModel().addListSelectionListener(this);
205
-        eventbus.subscribe(this);
206
-    }
207
-
208
-    /**
209
-     * Lays out the group panel.
210
-     */
211
-    private void layoutGroupPanel() {
212
-        groupPanel.setLayout(new MigLayout("fill, wrap 1"));
213
-
214
-        groupPanel.add(new JScrollPane(groups), "growy, pushy, w 150!");
215
-        groupPanel.add(add, "sgx button, w 150!");
216
-        groupPanel.add(edit, "sgx button, w 150!");
217
-        groupPanel.add(delete, "sgx button, w 150!");
218
-    }
219
-
220
-    /**
221
-     * Lays out the components.
222
-     */
223
-    private void layoutComponents() {
224
-
225
-        getContentPane().setLayout(new MigLayout(
226
-                "fill, wrap 2, hidemode 3, wmax 800"));
227
-
228
-        getContentPane().add(infoLabel, "spanx 2, growx");
229
-        if (info.isVisible() && activeSettings.isVisible()) {
230
-            getContentPane().add(groupPanel, "growy, pushy, spany 3");
231
-        } else if (info.isVisible() || activeSettings.isVisible()) {
232
-            getContentPane().add(groupPanel, "growy, pushy, spany 2");
233
-        } else {
234
-            getContentPane().add(groupPanel, "growy, pushy");
235
-        }
236
-        getContentPane().add(info, "growx, pushx");
237
-        getContentPane().add(actions, "grow, push");
238
-        getContentPane().add(activeSettings, "growx, pushx");
239
-        getContentPane().add(getOkButton(), "skip, right, sgx button");
240
-    }
241
-
242
-    /**
243
-     * Reloads the action groups.
244
-     */
245
-    private void reloadGroups() {
246
-        reloadGroups(null);
247
-    }
248
-
249
-    /**
250
-     * Reloads the action groups.
251
-     *
252
-     * @param selectedGroup Newly selected group
253
-     */
254
-    private void reloadGroups(final ActionGroup selectedGroup) {
255
-        ((DefaultListModel<ActionGroup>) groups.getModel()).clear();
256
-        actionManager.getGroupsMap().values()
257
-                .forEach(((DefaultListModel<ActionGroup>) groups.getModel())::addElement);
258
-        groups.setSelectedValue(selectedGroup, true);
259
-    }
260
-
261
-    /**
262
-     * Changes the active group.
263
-     *
264
-     * @param group New group
265
-     */
266
-    private void changeActiveGroup(final ActionGroup group) {
267
-        info.setActionGroup(group);
268
-        actions.setActionGroup(group);
269
-        if (!settings.containsKey(group)) {
270
-            final ActionGroupSettingsPanel currentSettings = new ActionGroupSettingsPanel(
271
-                    compFactory, group, this);
272
-            settings.put(group, currentSettings);
273
-            currentSettings.setBorder(BorderFactory.createTitledBorder(
274
-                    UIManager.getBorder("TitledBorder.border"), "Settings"));
275
-        }
276
-        activeSettings = settings.get(group);
277
-
278
-        info.setVisible(info.shouldDisplay());
279
-        activeSettings.setVisible(activeSettings.shouldDisplay());
280
-
281
-        getContentPane().setVisible(false);
282
-        getContentPane().removeAll();
283
-        layoutComponents();
284
-        validate();
285
-        layoutComponents();
286
-        getContentPane().setVisible(true);
287
-    }
288
-
289
-    @Override
290
-    public void actionPerformed(final ActionEvent e) {
291
-        if (e.getSource() == add) {
292
-            addGroup();
293
-        } else if (e.getSource() == edit) {
294
-            editGroup();
295
-        } else if (e.getSource() == delete) {
296
-            delGroup();
297
-        } else if ((e.getSource() == getOkButton() || e.getSource()
298
-                == getCancelButton()) && !saving.getAndSet(true)) {
299
-            settings.values().forEach(ActionGroupSettingsPanel::save);
300
-            config.setOption("dialogstate", "actionsmanagerdialog", groups.getSelectedIndex());
301
-            dispose();
302
-        }
303
-    }
304
-
305
-    /**
306
-     * Prompts then adds an action group.
307
-     */
308
-    private void addGroup() {
309
-        final int index = groups.getSelectedIndex();
310
-        groups.getSelectionModel().clearSelection();
311
-        new StandardInputDialog(this, ModalityType.DOCUMENT_MODAL, iconManager, "New action group",
312
-                "Please enter the name of the new action group", validator,
313
-                (String s) -> doSaveAddGroup(s, index), () -> doCancelledAddGroup(index))
314
-                .display(this);
315
-    }
316
-
317
-    private boolean doSaveAddGroup(final String text, final int index) {
318
-        if (!saving.getAndSet(true)) {
319
-            groups.setSelectedIndex(index);
320
-            if (text == null || text.isEmpty()
321
-                    && !actionManager.getGroupsMap().containsKey(text)) {
322
-                return false;
323
-            } else {
324
-                final ActionGroup group = actionManager.createGroup(text);
325
-                reloadGroups(group);
326
-                return true;
327
-            }
328
-        }
329
-        return false;
330
-    }
331
-
332
-    private void doCancelledAddGroup(final int index) {
333
-        groups.setSelectedIndex(index);
334
-    }
335
-
336
-    /**
337
-     * Prompts then edits an action group.
338
-     */
339
-    private void editGroup() {
340
-        final String oldName = groups.getSelectedValue().getName();
341
-        final StandardInputDialog inputDialog = new StandardInputDialog(
342
-                this, ModalityType.DOCUMENT_MODAL, iconManager, "Edit action group",
343
-                "Please enter the new name of the action group", validator,
344
-                (String s) -> doSaveEditGroup(oldName, s), () -> {});
345
-        inputDialog.setText(oldName);
346
-        inputDialog.display(this);
347
-    }
348
-
349
-    private boolean doSaveEditGroup(final String oldText, final String text) {
350
-        if (!saving.getAndSet(true)) {
351
-            if (text == null || text.isEmpty()) {
352
-                return false;
353
-            } else {
354
-                actionManager.changeGroupName(oldText, text);
355
-                reloadGroups();
356
-                return true;
357
-            }
358
-        }
359
-        return false;
360
-    }
361
-
362
-    /**
363
-     * Prompts then deletes an action group.
364
-     */
365
-    private void delGroup() {
366
-        final String group = groups.getSelectedValue().getName();
367
-        new StandardQuestionDialog(this, ModalityType.APPLICATION_MODAL, "Confirm deletion",
368
-                "Are you sure you wish to delete the '" + group +
369
-                        "' group and all actions within it?", () -> {
370
-            int location = ((DefaultListModel<ActionGroup>) groups.getModel())
371
-                    .indexOf(actionManager.getOrCreateGroup(group));
372
-            actionManager.deleteGroup(group);
373
-            reloadGroups();
374
-            if (groups.getModel().getSize() == 0) {
375
-                location = -1;
376
-            } else if (location >= groups.getModel().getSize()) {
377
-                location = groups.getModel().getSize();
378
-            } else if (location <= 0) {
379
-                location = 0;
380
-            }
381
-            groups.setSelectedIndex(location);
382
-        }).display();
383
-    }
384
-
385
-    @Override
386
-    public void valueChanged(final ListSelectionEvent e) {
387
-        if (e.getValueIsAdjusting()) {
388
-            return;
389
-        }
390
-
391
-        changeActiveGroup(groups.getSelectedValue());
392
-        if (groups.getSelectedIndex() == -1 || !groups.getSelectedValue().isDelible()) {
393
-            edit.setEnabled(false);
394
-            delete.setEnabled(false);
395
-        } else {
396
-            edit.setEnabled(true);
397
-            delete.setEnabled(true);
398
-        }
399
-    }
400
-
401
-    @Handler
402
-    public void handleActionCreated(final ActionCreatedEvent event) {
403
-        handleActionCreatedOrUpdated(event.getAction());
404
-    }
405
-
406
-    @Handler
407
-    public void handleActionUpdated(final ActionUpdatedEvent event) {
408
-        handleActionCreatedOrUpdated(event.getAction());
409
-    }
410
-
411
-    private void handleActionCreatedOrUpdated(final Action action) {
412
-        if (action.getGroup().equals(groups.getSelectedValue().getName())) {
413
-            actions.actionChanged(action);
414
-        }
415
-    }
416
-
417
-    @Handler
418
-    public void handleActionDeleted(final ActionDeletedEvent event) {
419
-        if (event.getGroup().getName().equals(groups.getSelectedValue().getName())) {
420
-            actions.actionDeleted(event.getName());
421
-        }
422
-    }
423
-
424
-}

+ 0
- 43
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ArrayCellRenderer.java Ver fichero

@@ -1,43 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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.actionsmanager;
24
-
25
-import java.util.Arrays;
26
-
27
-import javax.swing.table.DefaultTableCellRenderer;
28
-
29
-/**
30
- * Renders an array as an inline string.
31
- */
32
-public final class ArrayCellRenderer extends DefaultTableCellRenderer {
33
-
34
-    /** A version number for this class. */
35
-    private static final long serialVersionUID = 1;
36
-
37
-    @Override
38
-    public void setValue(final Object value) {
39
-        final String response = Arrays.toString((String[]) value);
40
-        setText(response.substring(1, response.length() - 1));
41
-    }
42
-
43
-}

+ 0
- 58
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/SettingsRevertButton.java Ver fichero

@@ -1,58 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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.actionsmanager;
24
-
25
-import com.dmdirc.config.prefs.PreferencesSetting;
26
-import com.dmdirc.config.prefs.SettingChangeListener;
27
-
28
-import java.awt.Insets;
29
-
30
-import javax.swing.JButton;
31
-
32
-/**
33
- * Settings revert button.
34
- */
35
-public class SettingsRevertButton extends JButton implements SettingChangeListener {
36
-
37
-    /** A version number for this class. */
38
-    private static final long serialVersionUID = 1;
39
-
40
-    /**
41
-     * Instantiates a new settings revert button.
42
-     *
43
-     * @param setting Setting to revert
44
-     */
45
-    public SettingsRevertButton(final PreferencesSetting setting) {
46
-        super("Revert");
47
-
48
-        setting.registerChangeListener(this);
49
-        setMargin(new Insets(0, 2, 0, 2));
50
-        setVisible(false);
51
-    }
52
-
53
-    @Override
54
-    public void settingChanged(final PreferencesSetting setting) {
55
-        setVisible(setting.needsSaving());
56
-    }
57
-
58
-}

+ 0
- 8
ui_swing/src/com/dmdirc/addons/ui_swing/injection/DialogModule.java Ver fichero

@@ -30,7 +30,6 @@ import com.dmdirc.addons.ui_swing.MainFrame;
30 30
 import com.dmdirc.addons.ui_swing.PrefsComponentFactory;
31 31
 import com.dmdirc.addons.ui_swing.SwingWindowFactory;
32 32
 import com.dmdirc.addons.ui_swing.dialogs.about.AboutDialog;
33
-import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog;
34 33
 import com.dmdirc.addons.ui_swing.dialogs.aliases.AliasManagerDialog;
35 34
 import com.dmdirc.addons.ui_swing.dialogs.channellist.ChannelListDialog;
36 35
 import com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog;
@@ -131,13 +130,6 @@ public class DialogModule {
131 130
         return new DialogProvider<>(provider);
132 131
     }
133 132
 
134
-    @Provides
135
-    @Singleton
136
-    public DialogProvider<ActionsManagerDialog> getActionsManagerDialogProvider(
137
-            final Provider<ActionsManagerDialog> provider) {
138
-        return new DialogProvider<>(provider);
139
-    }
140
-
141 133
     @Provides
142 134
     @Singleton
143 135
     public DialogProvider<AliasManagerDialog> getAliasManagerDialogProvider(

Loading…
Cancelar
Guardar