Bläddra i källkod

Fix annoying WindowProvider logic in DCCManager.

pull/288/head
Chris Smith 9 år sedan
förälder
incheckning
ee14219e3e
1 ändrade filer med 48 tillägg och 44 borttagningar
  1. 48
    44
      dcc/src/com/dmdirc/addons/dcc/DCCManager.java

+ 48
- 44
dcc/src/com/dmdirc/addons/dcc/DCCManager.java Visa fil

@@ -40,6 +40,7 @@ import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
40 40
 import com.dmdirc.addons.ui_swing.injection.MainWindow;
41 41
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
42 42
 import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
43
+import com.dmdirc.commandparser.parsers.CommandParser;
43 44
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
44 45
 import com.dmdirc.config.prefs.PluginPreferencesCategory;
45 46
 import com.dmdirc.config.prefs.PreferencesCategory;
@@ -63,7 +64,7 @@ import com.dmdirc.ui.input.TabCompleterFactory;
63 64
 import com.dmdirc.ui.messages.BackBufferFactory;
64 65
 import com.dmdirc.ui.messages.sink.MessageSinkManager;
65 66
 
66
-import com.google.common.collect.Lists;
67
+import com.google.common.collect.Sets;
67 68
 
68 69
 import java.awt.Dialog;
69 70
 import java.awt.Window;
@@ -72,7 +73,6 @@ import java.io.IOException;
72 73
 import java.net.InetAddress;
73 74
 import java.net.UnknownHostException;
74 75
 import java.util.Collections;
75
-import java.util.HashSet;
76 76
 import java.util.Set;
77 77
 import java.util.function.Supplier;
78 78
 
@@ -142,36 +142,12 @@ public class DCCManager {
142 142
         this.eventBus = eventBus;
143 143
         this.backBufferFactory = backBufferFactory;
144 144
 
145
-        windowFactory.registerImplementation(
146
-                new SwingWindowFactory.WindowProvider() {
147
-                    @Override
148
-                    public TextFrame getWindow(final FrameContainer container) {
149
-                        return componentFrameFactory.getComponentFrame(container, commandParser,
150
-                                Lists.<Supplier<? extends JComponent>>newArrayList(
151
-                                        PlaceholderPanel::new));
152
-                    }
153
-
154
-                    @Override
155
-                    public Set<String> getComponents() {
156
-                        return new HashSet<>(Collections.singletonList(
157
-                                "com.dmdirc.addons.dcc.ui.PlaceholderPanel"));
158
-                    }
159
-                });
160
-        windowFactory.registerImplementation(
161
-                new SwingWindowFactory.WindowProvider() {
162
-                    @Override
163
-                    public TextFrame getWindow(final FrameContainer container) {
164
-                        return componentFrameFactory.getComponentFrame(container, commandParser,
165
-                                Lists.<Supplier<? extends JComponent>>newArrayList(
166
-                                        () -> new TransferPanel(container, eventBus)));
167
-                    }
168
-
169
-                    @Override
170
-                    public Set<String> getComponents() {
171
-                        return new HashSet<>(Collections.singletonList(
172
-                                "com.dmdirc.addons.dcc.ui.TransferPanel"));
173
-                    }
174
-                });
145
+        windowFactory.registerImplementation(new ComponentFrameWindowProvider(
146
+                "com.dmdirc.addons.dcc.ui.PlaceholderPanel", componentFrameFactory,
147
+                commandParser, PlaceholderPanel::new));
148
+        windowFactory.registerImplementation(new ComponentFrameWindowProvider(
149
+                "com.dmdirc.addons.dcc.ui.TransferPanel", componentFrameFactory,
150
+                commandParser, () -> new TransferPanel(container, eventBus)));
175 151
 
176 152
         final ConfigProvider defaults = identityController.getAddonSettings();
177 153
         defaults.setOption(domain, "receive.savelocation",
@@ -195,14 +171,14 @@ public class DCCManager {
195 171
         general.addSubCategory(sending.setInline());
196 172
         general.addSubCategory(receiving.setInline());
197 173
 
198
-        firewall.addSetting(new PreferencesSetting(PreferencesType.TEXT,
199
-                pluginInfo.getDomain(), "firewall.ip", "Forced IP",
200
-                "What IP should be sent as our IP (Blank = work it out)",
174
+        firewall.addSetting(
175
+                new PreferencesSetting(PreferencesType.TEXT, pluginInfo.getDomain(), "firewall.ip",
176
+                        "Forced IP", "What IP should be sent as our IP (Blank = work it out)",
177
+                        manager.getConfigManager(), manager.getIdentity()));
178
+        firewall.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, pluginInfo.getDomain(),
179
+                "firewall.ports.usePortRange", "Use Port Range",
180
+                "Useful if you have a firewall that only forwards specific " + "ports",
201 181
                 manager.getConfigManager(), manager.getIdentity()));
202
-        firewall.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
203
-                pluginInfo.getDomain(), "firewall.ports.usePortRange", "Use Port Range",
204
-                "Useful if you have a firewall that only forwards specific "
205
-                        + "ports", manager.getConfigManager(), manager.getIdentity()));
206 182
         firewall.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
207 183
                 pluginInfo.getDomain(), "firewall.ports.startPort", "Start Port",
208 184
                 "Port to try to listen on first", manager.getConfigManager(),
@@ -236,11 +212,10 @@ public class DCCManager {
236 212
                 "Change the block size for send/receive, this can "
237 213
                         + "sometimes speed up transfers.", manager.getConfigManager(),
238 214
                 manager.getIdentity()));
239
-        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
240
-                pluginInfo.getDomain(), "general.percentageInTitle",
241
-                "Show percentage of transfers in the window title",
242
-                "Show the current percentage of transfers in the DCC window "
243
-                        + "title", manager.getConfigManager(), manager.getIdentity()));
215
+        general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, pluginInfo.getDomain(),
216
+                "general.percentageInTitle", "Show percentage of transfers in the window title",
217
+                "Show the current percentage of transfers in the DCC window " + "title",
218
+                manager.getConfigManager(), manager.getIdentity()));
244 219
     }
245 220
 
246 221
     public String getDomain() {
@@ -795,4 +770,33 @@ public class DCCManager {
795 770
         }
796 771
     }
797 772
 
773
+    private static class ComponentFrameWindowProvider implements SwingWindowFactory.WindowProvider {
774
+
775
+        private final String component;
776
+        private final ComponentFrameFactory componentFrameFactory;
777
+        private final CommandParser commandParser;
778
+        private final Supplier<? extends JComponent> componentSupplier;
779
+
780
+        ComponentFrameWindowProvider(final String component,
781
+                final ComponentFrameFactory componentFrameFactory,
782
+                final CommandParser commandParser,
783
+                final Supplier<? extends JComponent> componentSupplier) {
784
+            this.component = component;
785
+            this.componentFrameFactory = componentFrameFactory;
786
+            this.commandParser = commandParser;
787
+            this.componentSupplier = componentSupplier;
788
+        }
789
+
790
+        @Override
791
+        public TextFrame getWindow(final FrameContainer container) {
792
+            return componentFrameFactory.getComponentFrame(container, commandParser,
793
+                    Collections.singletonList(componentSupplier));
794
+        }
795
+
796
+        @Override
797
+        public Set<String> getComponents() {
798
+            return Sets.newHashSet(component);
799
+        }
800
+    }
801
+
798 802
 }

Laddar…
Avbryt
Spara