Browse Source

Use some more dialog providers, and a factory.

Change-Id: Ic7daa40a269ec2593dd56cc0a3a38dc5dbce1466
Reviewed-on: http://gerrit.dmdirc.com/3247
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
changes/47/3247/2
Greg Holmes 10 years ago
parent
commit
f4a1b9386f

+ 20
- 18
src/com/dmdirc/addons/ui_swing/components/menubar/ChannelMenu.java View File

@@ -28,10 +28,11 @@ import com.dmdirc.ServerState;
28 28
 import com.dmdirc.addons.ui_swing.MainFrame;
29 29
 import com.dmdirc.addons.ui_swing.SwingController;
30 30
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
31
-import com.dmdirc.addons.ui_swing.dialogs.ChannelJoinDialog;
31
+import com.dmdirc.addons.ui_swing.dialogs.ChannelJoinDialogFactory;
32 32
 import com.dmdirc.addons.ui_swing.dialogs.channellist.ChannelListDialog;
33
+import com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog;
34
+import com.dmdirc.addons.ui_swing.injection.KeyedDialogProvider;
33 35
 
34
-import java.awt.Dialog.ModalityType;
35 36
 import java.awt.event.ActionEvent;
36 37
 import java.awt.event.ActionListener;
37 38
 
@@ -49,12 +50,12 @@ import javax.swing.event.MenuListener;
49 50
 public class ChannelMenu extends JMenu implements ActionListener,
50 51
         MenuListener {
51 52
 
52
-    /**
53
-     * A version number for this class. It should be changed whenever the class structure is changed
54
-     * (or anything else that would prevent serialized objects being unserialized with the new
55
-     * class).
56
-     */
53
+    /** A version number for this class. */
57 54
     private static final long serialVersionUID = 1;
55
+    /** Dialog provider. */
56
+    private final KeyedDialogProvider<Channel, ChannelSettingsDialog> dialogProvider;
57
+    /** Channel join dialog factory. */
58
+    private final ChannelJoinDialogFactory channelJoinDialogFactory;
58 59
     /** Swing controller. */
59 60
     private final SwingController controller;
60 61
     /** Main frame. */
@@ -67,16 +68,22 @@ public class ChannelMenu extends JMenu implements ActionListener,
67 68
     /**
68 69
      * Creates a new channel menu.
69 70
      *
70
-     * @param controller Parent swing controller.
71
-     * @param mainFrame  Parent mainframe
71
+     * @param controller               Parent swing controller.
72
+     * @param mainFrame                Parent mainframe
73
+     * @param dialogProvider           Channel settings dialog provider
74
+     * @param channelJoinDialogFactory Channel join dialog factory
72 75
      */
73 76
     @Inject
74 77
     public ChannelMenu(
75 78
             final SwingController controller,
76
-            final MainFrame mainFrame) {
79
+            final MainFrame mainFrame,
80
+            final KeyedDialogProvider<Channel, ChannelSettingsDialog> dialogProvider,
81
+            final ChannelJoinDialogFactory channelJoinDialogFactory) {
77 82
         super("Channel");
78 83
         this.controller = controller;
79 84
         this.mainFrame = mainFrame;
85
+        this.dialogProvider = dialogProvider;
86
+        this.channelJoinDialogFactory = channelJoinDialogFactory;
80 87
         setMnemonic('c');
81 88
         addMenuListener(this);
82 89
         initChannelMenu();
@@ -109,19 +116,17 @@ public class ChannelMenu extends JMenu implements ActionListener,
109 116
         add(list);
110 117
     }
111 118
 
112
-    /** {@inheritDoc} */
113 119
     @Override
114 120
     public void actionPerformed(final ActionEvent e) {
115 121
         switch (e.getActionCommand()) {
116 122
             case "JoinChannel":
117
-                new ChannelJoinDialog(controller.getMainFrame(),
118
-                        ModalityType.MODELESS, controller.getIconManager(), "Join channel",
119
-                        "Enter the name of the channel to join.").display();
123
+                channelJoinDialogFactory.getChannelJoinDialog("Join channel",
124
+                        "Enter the name of the channel to join.").displayOrRequestFocus();
120 125
                 break;
121 126
             case "ChannelSettings":
122 127
                 final FrameContainer activeWindow = mainFrame.getActiveFrame().getContainer();
123 128
                 if (activeWindow instanceof Channel) {
124
-                    controller.showChannelSettingsDialog(((Channel) activeWindow));
129
+                    dialogProvider.displayOrRequestFocus(((Channel) activeWindow));
125 130
                 }
126 131
                 break;
127 132
             case "ListChannels":
@@ -130,7 +135,6 @@ public class ChannelMenu extends JMenu implements ActionListener,
130 135
         }
131 136
     }
132 137
 
133
-    /** {@inheritDoc} */
134 138
     @Override
135 139
     public final void menuSelected(final MenuEvent e) {
136 140
         final TextFrame activeFrame = mainFrame.getActiveFrame();
@@ -146,13 +150,11 @@ public class ChannelMenu extends JMenu implements ActionListener,
146 150
         list.setEnabled(connected);
147 151
     }
148 152
 
149
-    /** {@inheritDoc} */
150 153
     @Override
151 154
     public final void menuDeselected(final MenuEvent e) {
152 155
         //Ignore
153 156
     }
154 157
 
155
-    /** {@inheritDoc} */
156 158
     @Override
157 159
     public final void menuCanceled(final MenuEvent e) {
158 160
         //Ignore

+ 9
- 8
src/com/dmdirc/addons/ui_swing/dialogs/ChannelJoinDialog.java View File

@@ -22,13 +22,18 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.dialogs;
24 24
 
25
+import com.dmdirc.ClientModule.GlobalConfig;
25 26
 import com.dmdirc.addons.ui_swing.MainFrame;
26 27
 import com.dmdirc.parser.common.ChannelJoinRequest;
27 28
 import com.dmdirc.ui.IconManager;
29
+import com.dmdirc.util.annotations.factory.Factory;
30
+import com.dmdirc.util.annotations.factory.Unbound;
31
+
28 32
 
29 33
 /**
30 34
  * A dialog to prompt the user for a channel and then join that channel.
31 35
  */
36
+@Factory(inject = true)
32 37
 public class ChannelJoinDialog extends StandardInputDialog {
33 38
 
34 39
     /** Serial version UID. */
@@ -40,23 +45,20 @@ public class ChannelJoinDialog extends StandardInputDialog {
40 45
      * Creates a new dialog which prompts a user and then joins the channel they specify.
41 46
      *
42 47
      * @param mainFrame   Main frame
43
-     * @param modality    Window modality
44 48
      * @param iconManager The icon manager to use for validating text fields.
45 49
      * @param title       Window title
46 50
      * @param message     Window message
47 51
      */
48 52
     public ChannelJoinDialog(
49 53
             final MainFrame mainFrame,
50
-            final ModalityType modality,
51
-            final IconManager iconManager,
52
-            final String title,
53
-            final String message) {
54
-        super(mainFrame, modality, iconManager, title, message);
54
+            @SuppressWarnings("qualifiers") @GlobalConfig final IconManager iconManager,
55
+            @Unbound final String title,
56
+            @Unbound final String message) {
57
+        super(mainFrame, ModalityType.APPLICATION_MODAL, iconManager, title, message);
55 58
 
56 59
         this.mainFrame = mainFrame;
57 60
     }
58 61
 
59
-    /** {@inheritDoc} */
60 62
     @Override
61 63
     public boolean save() {
62 64
         mainFrame.getActiveFrame().getContainer().getConnection()
@@ -64,7 +66,6 @@ public class ChannelJoinDialog extends StandardInputDialog {
64 66
         return true;
65 67
     }
66 68
 
67
-    /** {@inheritDoc} */
68 69
     @Override
69 70
     public void cancelled() {
70 71
         //Ignore

Loading…
Cancel
Save