Browse Source

Add Global Auto Commands UI.

pull/394/head
Greg Holmes 9 years ago
parent
commit
67543223b2

+ 76
- 0
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/globalautocommand/GlobalAutoCommandController.java View File

@@ -0,0 +1,76 @@
1
+/*
2
+ * Copyright (c) 2006-2015 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.globalautocommand;
24
+
25
+import com.dmdirc.addons.ui_swing.components.ConsumerDocumentListener;
26
+import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
27
+import com.dmdirc.interfaces.ui.GlobalAutoCommandsDialogModel;
28
+
29
+import javax.swing.JButton;
30
+import javax.swing.JTextArea;
31
+
32
+/**
33
+ * Controls a {@link GlobalAutoCommandDialog}.
34
+ */
35
+public class GlobalAutoCommandController {
36
+
37
+    private StandardDialog dialog;
38
+    private GlobalAutoCommandsDialogModel model;
39
+    private JTextArea response;
40
+    private JButton okButton;
41
+    private JButton cancelButton;
42
+
43
+    public void init(final StandardDialog dialog, final GlobalAutoCommandsDialogModel model,
44
+            final JTextArea response,final JButton okButton, final JButton cancelButton) {
45
+        this.dialog = dialog;
46
+        this.model = model;
47
+        this.response = response;
48
+        this.okButton = okButton;
49
+        this.cancelButton = cancelButton;
50
+
51
+        model.load();
52
+
53
+        initResponse();
54
+        initOK();
55
+        initCancel();
56
+    }
57
+
58
+    private void initResponse() {
59
+        response.setText(model.getResponse());
60
+        response.getDocument().addDocumentListener(new ConsumerDocumentListener(text -> {
61
+            model.setResponse(text);
62
+            okButton.setEnabled(model.isSaveAllowed());
63
+        } ));
64
+    }
65
+
66
+    private void initOK() {
67
+        okButton.addActionListener(l -> {
68
+            model.save();
69
+            dialog.dispose();
70
+        });
71
+    }
72
+
73
+    private void initCancel() {
74
+        cancelButton.addActionListener(l -> dialog.dispose());
75
+    }
76
+}

+ 92
- 0
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/globalautocommand/GlobalAutoCommandDialog.java View File

@@ -0,0 +1,92 @@
1
+/*
2
+ * Copyright (c) 2006-2015 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.globalautocommand;
24
+
25
+import com.dmdirc.addons.ui_swing.components.IconManager;
26
+import com.dmdirc.addons.ui_swing.components.text.TextLabel;
27
+import com.dmdirc.addons.ui_swing.components.validating.ValidationFactory;
28
+import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
29
+import com.dmdirc.addons.ui_swing.injection.MainWindow;
30
+import com.dmdirc.commandparser.auto.AutoCommand;
31
+import com.dmdirc.interfaces.ui.GlobalAutoCommandsDialogModel;
32
+
33
+import java.awt.Dimension;
34
+import java.awt.Window;
35
+
36
+import javax.inject.Inject;
37
+import javax.swing.JScrollPane;
38
+import javax.swing.JTextArea;
39
+
40
+import net.miginfocom.swing.MigLayout;
41
+
42
+/**
43
+ * Command to edit the global {@link AutoCommand} for the client.
44
+ */
45
+public class GlobalAutoCommandDialog extends StandardDialog {
46
+
47
+    private final GlobalAutoCommandsDialogModel model;
48
+    private final IconManager iconManager;
49
+    private JScrollPane scrollPane;
50
+    private JTextArea response;
51
+
52
+    /**
53
+     * Creates a new instance of StandardDialog.
54
+     *
55
+     * @param owner The frame that owns this dialog
56
+     */
57
+    @Inject
58
+    public GlobalAutoCommandDialog(@MainWindow final Window owner,
59
+            final GlobalAutoCommandsDialogModel model,
60
+            final IconManager iconManager) {
61
+        super(owner, ModalityType.MODELESS);
62
+        this.model = model;
63
+        this.iconManager = iconManager;
64
+
65
+        initComponents();
66
+        layoutComponents();
67
+    }
68
+
69
+    private void initComponents() {
70
+        scrollPane = new JScrollPane();
71
+        response = new JTextArea();
72
+        scrollPane.setViewportView(response);
73
+    }
74
+
75
+    private void layoutComponents() {
76
+        setLayout(new MigLayout("fill"));
77
+        add(new TextLabel("These commands will be executed when the client stars."), "wrap, span 2");
78
+        add(ValidationFactory
79
+                .getValidatorPanel(scrollPane, response, model.getResponseValidator(), iconManager),
80
+                "span 2, grow, push, wrap");
81
+        add(getLeftButton(), " right");
82
+        add(getRightButton(), "");
83
+        setMinimumSize(new Dimension(500, 550));
84
+    }
85
+
86
+    @Override
87
+    public void display() {
88
+        new GlobalAutoCommandController()
89
+                .init(this, model, response, getOkButton(), getCancelButton());
90
+        super.display();
91
+    }
92
+}

+ 18
- 1
ui_swing/src/com/dmdirc/addons/ui_swing/injection/DialogModule.java View File

@@ -27,12 +27,14 @@ import com.dmdirc.DMDircMBassador;
27 27
 import com.dmdirc.addons.ui_swing.MainFrame;
28 28
 import com.dmdirc.addons.ui_swing.PrefsComponentFactory;
29 29
 import com.dmdirc.addons.ui_swing.SwingWindowFactory;
30
+import com.dmdirc.addons.ui_swing.components.IconManager;
30 31
 import com.dmdirc.addons.ui_swing.dialogs.about.AboutDialog;
31 32
 import com.dmdirc.addons.ui_swing.dialogs.aliases.AliasManagerDialog;
32 33
 import com.dmdirc.addons.ui_swing.dialogs.channellist.ChannelListDialog;
33 34
 import com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog;
34 35
 import com.dmdirc.addons.ui_swing.dialogs.errors.ErrorsDialog;
35 36
 import com.dmdirc.addons.ui_swing.dialogs.feedback.FeedbackDialog;
37
+import com.dmdirc.addons.ui_swing.dialogs.globalautocommand.GlobalAutoCommandDialog;
36 38
 import com.dmdirc.addons.ui_swing.dialogs.newserver.NewServerDialog;
37 39
 import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
38 40
 import com.dmdirc.addons.ui_swing.dialogs.profile.ProfileManagerDialog;
@@ -51,12 +53,13 @@ import com.dmdirc.interfaces.ui.AboutDialogModel;
51 53
 import com.dmdirc.interfaces.ui.AliasDialogModel;
52 54
 import com.dmdirc.interfaces.ui.ErrorsDialogModel;
53 55
 import com.dmdirc.interfaces.ui.FeedbackDialogModel;
56
+import com.dmdirc.interfaces.ui.GlobalAutoCommandsDialogModel;
54 57
 import com.dmdirc.interfaces.ui.NewServerDialogModel;
55 58
 import com.dmdirc.interfaces.ui.ProfilesDialogModel;
56 59
 import com.dmdirc.plugins.ServiceManager;
57
-import com.dmdirc.addons.ui_swing.components.IconManager;
58 60
 import com.dmdirc.ui.core.about.CoreAboutDialogModel;
59 61
 import com.dmdirc.ui.core.aliases.CoreAliasDialogModel;
62
+import com.dmdirc.ui.core.autocommands.CoreGlobalAutoCommandsDialogModel;
60 63
 import com.dmdirc.ui.core.errors.CoreErrorsDialogModel;
61 64
 import com.dmdirc.ui.core.feedback.CoreFeedbackDialogModel;
62 65
 import com.dmdirc.ui.core.newserver.CoreNewServerDialogModel;
@@ -78,6 +81,7 @@ import dagger.Provides;
78 81
  * Facilitates injection of dialogs.
79 82
  */
80 83
 @Module(library = true, complete = false)
84
+@SuppressWarnings("TypeMayBeWeakened")
81 85
 public class DialogModule {
82 86
 
83 87
     /**
@@ -124,6 +128,12 @@ public class DialogModule {
124 128
         return model;
125 129
     }
126 130
 
131
+    @Provides
132
+    public GlobalAutoCommandsDialogModel getGlobalAutoCommandsdialogModel(
133
+            final CoreGlobalAutoCommandsDialogModel model) {
134
+        return model;
135
+    }
136
+
127 137
     @Provides
128 138
     @Singleton
129 139
     public DialogProvider<NewServerDialog> getNewServerDialogProvider(
@@ -166,6 +176,13 @@ public class DialogModule {
166 176
         return new DialogProvider<>(provider);
167 177
     }
168 178
 
179
+    @Provides
180
+    @Singleton
181
+    public DialogProvider<GlobalAutoCommandDialog> getGlocalAutoCommandDialogModel(
182
+            final Provider<GlobalAutoCommandDialog> provider) {
183
+        return new DialogProvider<>(provider);
184
+    }
185
+
169 186
     @Provides
170 187
     @Singleton
171 188
     public KeyedDialogProvider<Connection, ServerSettingsDialog> getServerSettingsDialogProvider(

Loading…
Cancel
Save