Browse Source

Lambda-ise some things.

pull/105/head
Chris Smith 9 years ago
parent
commit
ab4ac8af48

+ 2
- 6
ui_swing/src/com/dmdirc/addons/ui_swing/EdtHandlerInvocation.java View File

@@ -50,11 +50,7 @@ public class EdtHandlerInvocation extends ReflectiveHandlerInvocation {
50 50
     @Override
51 51
     protected void invokeHandler(final Object message, final Object listener,
52 52
             final Method handler) {
53
-        UIUtilities.invokeAndWait(new Runnable() {
54
-            @Override
55
-            public void run() {
56
-                EdtHandlerInvocation.super.invokeHandler(message, listener, handler);
57
-            }
58
-        });
53
+        UIUtilities.invokeAndWait(
54
+                () -> EdtHandlerInvocation.super.invokeHandler(message, listener, handler));
59 55
     }
60 56
 }

+ 1
- 7
ui_swing/src/com/dmdirc/addons/ui_swing/SwingController.java View File

@@ -88,13 +88,7 @@ public class SwingController extends BaseCommandPlugin implements UIController {
88 88
 
89 89
         swingManager.load();
90 90
 
91
-        UIUtilities.invokeAndWait(new Runnable() {
92
-
93
-            @Override
94
-            public void run() {
95
-                getMainFrame().setVisible(true);
96
-            }
97
-        });
91
+        UIUtilities.invokeAndWait(() -> getMainFrame().setVisible(true));
98 92
 
99 93
         super.onLoad();
100 94
     }

+ 38
- 53
ui_swing/src/com/dmdirc/addons/ui_swing/SwingUIInitialiser.java View File

@@ -95,44 +95,40 @@ public class SwingUIInitialiser {
95 95
      * Initialises the global UI settings for the Swing UI.
96 96
      */
97 97
     private void initUISettings() {
98
-        UIUtilities.invokeAndWait(new Runnable() {
99
-
100
-            @Override
101
-            public void run() {
102
-                // This will do nothing on non OS X Systems
103
-                if (Apple.isApple()) {
104
-                    apple.setUISettings();
105
-                    apple.setListener();
106
-                }
107
-
108
-                final Font defaultFont = new Font(Font.DIALOG, Font.TRUETYPE_FONT, 12);
109
-                if (UIManager.getFont("TextField.font") == null) {
110
-                    UIManager.put("TextField.font", defaultFont);
111
-                }
112
-                if (UIManager.getFont("TextPane.font") == null) {
113
-                    UIManager.put("TextPane.font", defaultFont);
114
-                }
115
-                addonConfig.setOption("ui", "textPaneFontName",
116
-                        UIManager.getFont("TextPane.font").getFamily());
117
-                addonConfig.setOption("ui", "textPaneFontSize",
118
-                        UIManager.getFont("TextPane.font").getSize());
119
-
120
-                try {
121
-                    UIUtilities.initUISettings();
122
-                    UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(
123
-                            globalConfig.getOption("ui", "lookandfeel")));
124
-                    UIUtilities.setUIFont(new Font(globalConfig.getOption("ui", "textPaneFontName"),
125
-                            Font.PLAIN, 12));
126
-                } catch (UnsupportedOperationException | UnsupportedLookAndFeelException |
127
-                        IllegalAccessException | InstantiationException | ClassNotFoundException ex) {
128
-                    eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ex,
129
-                            "Unable to set UI Settings", ""));
130
-                }
131
-
132
-                if ("Metal".equals(UIManager.getLookAndFeel().getName())
133
-                        || Apple.isAppleUI()) {
134
-                    PlatformDefaults.setPlatform(PlatformDefaults.WINDOWS_XP);
135
-                }
98
+        UIUtilities.invokeAndWait(() -> {
99
+            // This will do nothing on non OS X Systems
100
+            if (Apple.isApple()) {
101
+                apple.setUISettings();
102
+                apple.setListener();
103
+            }
104
+
105
+            final Font defaultFont = new Font(Font.DIALOG, Font.TRUETYPE_FONT, 12);
106
+            if (UIManager.getFont("TextField.font") == null) {
107
+                UIManager.put("TextField.font", defaultFont);
108
+            }
109
+            if (UIManager.getFont("TextPane.font") == null) {
110
+                UIManager.put("TextPane.font", defaultFont);
111
+            }
112
+            addonConfig.setOption("ui", "textPaneFontName",
113
+                    UIManager.getFont("TextPane.font").getFamily());
114
+            addonConfig.setOption("ui", "textPaneFontSize",
115
+                    UIManager.getFont("TextPane.font").getSize());
116
+
117
+            try {
118
+                UIUtilities.initUISettings();
119
+                UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(
120
+                        globalConfig.getOption("ui", "lookandfeel")));
121
+                UIUtilities.setUIFont(new Font(globalConfig.getOption("ui", "textPaneFontName"),
122
+                        Font.PLAIN, 12));
123
+            } catch (UnsupportedOperationException | UnsupportedLookAndFeelException |
124
+                    IllegalAccessException | InstantiationException | ClassNotFoundException ex) {
125
+                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ex,
126
+                        "Unable to set UI Settings", ""));
127
+            }
128
+
129
+            if ("Metal".equals(UIManager.getLookAndFeel().getName())
130
+                    || Apple.isAppleUI()) {
131
+                PlatformDefaults.setPlatform(PlatformDefaults.WINDOWS_XP);
136 132
             }
137 133
         });
138 134
     }
@@ -141,14 +137,8 @@ public class SwingUIInitialiser {
141 137
      * Installs the dialog key listener.
142 138
      */
143 139
     private void installKeyListener() {
144
-        UIUtilities.invokeAndWait(new Runnable() {
145
-
146
-            @Override
147
-            public void run() {
148
-                KeyboardFocusManager.getCurrentKeyboardFocusManager()
149
-                        .addKeyEventDispatcher(dialogKeyListener);
150
-            }
151
-        });
140
+        UIUtilities.invokeAndWait(() -> KeyboardFocusManager.getCurrentKeyboardFocusManager()
141
+                .addKeyEventDispatcher(dialogKeyListener));
152 142
     }
153 143
 
154 144
     /**
@@ -163,13 +153,8 @@ public class SwingUIInitialiser {
163 153
      * Installs the DMDirc event queue.
164 154
      */
165 155
     private void installEventQueue() {
166
-        UIUtilities.invokeAndWait(new Runnable() {
167
-
168
-            @Override
169
-            public void run() {
170
-                Toolkit.getDefaultToolkit().getSystemEventQueue().push(eventQueue);
171
-            }
172
-        });
156
+        UIUtilities.invokeAndWait(
157
+                () -> Toolkit.getDefaultToolkit().getSystemEventQueue().push(eventQueue));
173 158
     }
174 159
 
175 160
     /**

+ 4
- 8
ui_swing/src/com/dmdirc/addons/ui_swing/components/frames/ChannelFrame.java View File

@@ -199,14 +199,10 @@ public final class ChannelFrame extends InputTextFrame implements ActionListener
199 199
     }
200 200
 
201 201
     private void saveSplitPanePosition() {
202
-        UIUtilities.invokeAndWait(new Runnable() {
203
-
204
-            @Override
205
-            public void run() {
206
-                if (getContainer().getConfigManager().getOptionInt("ui",
207
-                        "channelSplitPanePosition") != nicklist.getWidth()) {
208
-                    identity.setOption("ui", "channelSplitPanePosition", nicklist.getWidth());
209
-                }
202
+        UIUtilities.invokeAndWait(() -> {
203
+            if (getContainer().getConfigManager().getOptionInt("ui",
204
+                    "channelSplitPanePosition") != nicklist.getWidth()) {
205
+                identity.setOption("ui", "channelSplitPanePosition", nicklist.getWidth());
210 206
             }
211 207
         });
212 208
     }

+ 5
- 16
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/about/LicenceLoader.java View File

@@ -118,27 +118,16 @@ public class LicenceLoader extends LoggingSwingWorker<Void, Void> {
118 118
 
119 119
     private void addLicensesToNode(final Map<String, InputStream> licences,
120 120
             final DefaultMutableTreeNode root) {
121
-        UIUtilities.invokeAndWait(new Runnable() {
122
-
123
-            @Override
124
-            public void run() {
125
-                model.insertNodeInto(root, (MutableTreeNode) model.
126
-                        getRoot(), model.getChildCount(model.getRoot()));
127
-            }
128
-        });
121
+        UIUtilities.invokeAndWait(() -> model.insertNodeInto(root,
122
+                (MutableTreeNode) model.getRoot(), model.getChildCount(model.getRoot())));
129 123
         for (Entry<String, InputStream> entry : licences.entrySet()) {
130 124
             final Licence licence = createLicence(entry);
131 125
             if (licence == null) {
132 126
                 continue;
133 127
             }
134
-            UIUtilities.invokeAndWait(new Runnable() {
135
-
136
-                @Override
137
-                public void run() {
138
-                    model.insertNodeInto(new DefaultMutableTreeNode(licence), root,
139
-                            model.getChildCount(root));
140
-                }
141
-            });
128
+            UIUtilities.invokeAndWait(
129
+                    () -> model.insertNodeInto(new DefaultMutableTreeNode(licence), root,
130
+                            model.getChildCount(root)));
142 131
         }
143 132
     }
144 133
 

+ 28
- 43
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/prefs/CategoryPanel.java View File

@@ -160,40 +160,36 @@ public class CategoryPanel extends JPanel {
160 160
 
161 161
     private void categoryLoaded(final PreferencesCategory category) {
162 162
         if (this.category == category) {
163
-            UIUtilities.invokeAndWait(new Runnable() {
164
-
165
-                @Override
166
-                public void run() {
167
-                    final JPanel panel = panels.get(category);
168
-                    scrollPane.setViewportView(panel);
169
-                    //Hack around mig bug
170
-                    panel.invalidate();
171
-                    panel.validate();
172
-                    for (final Component component : panel.getComponents()) {
173
-                        if (component instanceof JPanel) {
174
-                            component.invalidate();
175
-                            component.validate();
176
-                        }
163
+            UIUtilities.invokeAndWait(() -> {
164
+                final JPanel panel = panels.get(category);
165
+                scrollPane.setViewportView(panel);
166
+                //Hack around mig bug
167
+                panel.invalidate();
168
+                panel.validate();
169
+                for (final Component component : panel.getComponents()) {
170
+                    if (component instanceof JPanel) {
171
+                        component.invalidate();
172
+                        component.validate();
177 173
                     }
178
-                    //And for good measure, hack the crap out of it some more :(
179
-                    SwingUtilities.invokeLater(new Runnable() {
180
-                        @Override
181
-                        public void run() {
182
-                            panel.invalidate();
183
-                            panel.validate();
184
-                            for (final Component component : panel.getComponents()) {
185
-                                if (component instanceof JPanel) {
186
-                                    component.invalidate();
187
-                                    component.validate();
188
-                                }
174
+                }
175
+                //And for good measure, hack the crap out of it some more :(
176
+                SwingUtilities.invokeLater(new Runnable() {
177
+                    @Override
178
+                    public void run() {
179
+                        panel.invalidate();
180
+                        panel.validate();
181
+                        for (final Component component : panel.getComponents()) {
182
+                            if (component instanceof JPanel) {
183
+                                component.invalidate();
184
+                                component.validate();
189 185
                             }
190 186
                         }
191
-                    });
192
-                    if (category == null) {
193
-                        title.setText("Preferences");
194
-                    } else {
195
-                        title.setText(category.getPath());
196 187
                     }
188
+                });
189
+                if (category == null) {
190
+                    title.setText("Preferences");
191
+                } else {
192
+                    title.setText(category.getPath());
197 193
                 }
198 194
             });
199 195
         }
@@ -216,12 +212,7 @@ public class CategoryPanel extends JPanel {
216 212
         if (panels.containsKey(category)) {
217 213
             categoryLoaded(category);
218 214
         } else {
219
-            UIUtilities.invokeAndWait(new Runnable() {
220
-                @Override
221
-                public void run() {
222
-                    scrollPane.setViewportView(loading);
223
-                }
224
-            });
215
+            UIUtilities.invokeAndWait(() -> scrollPane.setViewportView(loading));
225 216
 
226 217
             worker = new PrefsCategoryLoader(factory, eventBus, this, category);
227 218
             worker.execute();
@@ -234,13 +225,7 @@ public class CategoryPanel extends JPanel {
234 225
      * @param b Loading state
235 226
      */
236 227
     public void setWaiting(final boolean b) {
237
-        UIUtilities.invokeLater(new Runnable() {
238
-
239
-            @Override
240
-            public void run() {
241
-                scrollPane.setViewportView(waitingCategory);
242
-            }
243
-        });
228
+        UIUtilities.invokeLater(() -> scrollPane.setViewportView(waitingCategory));
244 229
     }
245 230
 
246 231
     /**

+ 30
- 53
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/prefs/PrefsCategoryLoader.java View File

@@ -34,7 +34,6 @@ import com.dmdirc.config.prefs.PreferencesType;
34 34
 import com.dmdirc.events.UserErrorEvent;
35 35
 import com.dmdirc.logger.ErrorLevel;
36 36
 
37
-import java.util.concurrent.Callable;
38 37
 import java.util.concurrent.ExecutionException;
39 38
 
40 39
 import javax.swing.BorderFactory;
@@ -89,13 +88,10 @@ public class PrefsCategoryLoader extends LoggingSwingWorker<JPanel, Object> {
89 88
         this.categoryPanel = categoryPanel;
90 89
         this.category = category;
91 90
 
92
-        UIUtilities.invokeAndWait(new Runnable() {
93
-            @Override
94
-            public void run() {
95
-                errorCategory = new JPanel(new MigLayout("fillx"));
96
-                errorCategory.add(new TextLabel(
97
-                        "There was an error loading this category."));
98
-            }
91
+        UIUtilities.invokeAndWait(() -> {
92
+            errorCategory = new JPanel(new MigLayout("fillx"));
93
+            errorCategory.add(new TextLabel(
94
+                    "There was an error loading this category."));
99 95
         });
100 96
     }
101 97
 
@@ -139,14 +135,8 @@ public class PrefsCategoryLoader extends LoggingSwingWorker<JPanel, Object> {
139 135
             final JPanel panel) {
140 136
 
141 137
         if (!category.getDescription().isEmpty()) {
142
-            UIUtilities.invokeAndWait(new Runnable() {
143
-
144
-                @Override
145
-                public void run() {
146
-                    panel.add(new TextLabel(category.getDescription()), "span, "
147
-                            + "growx, pushx, wrap 2*unrel");
148
-                }
149
-            });
138
+            UIUtilities.invokeAndWait(() -> panel.add(new TextLabel(category.getDescription()),
139
+                    "span, growx, pushx, wrap 2*unrel"));
150 140
         }
151 141
 
152 142
         for (PreferencesCategory child : category.getSubcats()) {
@@ -192,16 +182,11 @@ public class PrefsCategoryLoader extends LoggingSwingWorker<JPanel, Object> {
192 182
 
193 183
         final TextLabel label = new TextLabel(setting.getTitle() + ": ", false);
194 184
 
195
-        final JComponent option = UIUtilities.invokeAndWait(
196
-                new Callable<JComponent>() {
197
-
198
-                    @Override
199
-                    public JComponent call() {
200
-                        final JComponent option = factory.getComponent(setting);
201
-                        option.setToolTipText(null);
202
-                        return option;
203
-                    }
204
-                });
185
+        final JComponent option = UIUtilities.invokeAndWait(() -> {
186
+            final JComponent option1 = factory.getComponent(setting);
187
+            option1.setToolTipText(null);
188
+            return option1;
189
+        });
205 190
 
206 191
         categoryPanel.getToolTipPanel().registerTooltipHandler(label,
207 192
                 getTooltipText(setting, categoryPanel));
@@ -252,21 +237,17 @@ public class PrefsCategoryLoader extends LoggingSwingWorker<JPanel, Object> {
252 237
      */
253 238
     private void addInlineCategory(final PreferencesCategory category,
254 239
             final JPanel parent) {
255
-        final JPanel panel = UIUtilities.invokeAndWait(
256
-                new Callable<JPanel>() {
257
-                    @Override
258
-                    public JPanel call() {
259
-                        final JPanel panel = new NoRemovePanel(new MigLayout(
260
-                                        "fillx, gap unrel, wrap 2, "
261
-                                        + "hidemode 3, pack, wmax 470-" + leftPadding + "-"
262
-                                        + rightPadding + "-2*"
263
-                                        + padding));
264
-                        panel.setName(category.getPath());
265
-                        panel.setBorder(BorderFactory.createTitledBorder(UIManager.
266
-                                        getBorder("TitledBorder.border"), category.getTitle()));
267
-                        return panel;
268
-                    }
269
-                });
240
+        final JPanel panel = UIUtilities.invokeAndWait(() -> {
241
+            final JPanel panel1 = new NoRemovePanel(new MigLayout(
242
+                            "fillx, gap unrel, wrap 2, "
243
+                            + "hidemode 3, pack, wmax 470-" + leftPadding + '-'
244
+                            + rightPadding + "-2*"
245
+                            + padding));
246
+            panel1.setName(category.getPath());
247
+            panel1.setBorder(BorderFactory.createTitledBorder(UIManager.
248
+                    getBorder("TitledBorder.border"), category.getTitle()));
249
+            return panel1;
250
+        });
270 251
 
271 252
         parent.add(panel, "span, growx, pushx, wrap");
272 253
 
@@ -280,18 +261,14 @@ public class PrefsCategoryLoader extends LoggingSwingWorker<JPanel, Object> {
280 261
      * @param category   The category to be added
281 262
      */
282 263
     private JPanel addCategory(final PreferencesCategory category) {
283
-        final JPanel panel = UIUtilities.invokeAndWait(
284
-                new Callable<JPanel>() {
285
-                    @Override
286
-                    public JPanel call() {
287
-                        final JPanel panel = new NoRemovePanel(
288
-                                new MigLayout("fillx, gap unrel, wrap 2, pack, "
289
-                                        + "hidemode 3, wmax 470-"
290
-                                        + leftPadding + "-" + rightPadding + "-2*" + padding));
291
-                        panel.setName(category.getPath());
292
-                        return panel;
293
-                    }
294
-                });
264
+        final JPanel panel = UIUtilities.invokeAndWait(() -> {
265
+            final JPanel panel1 = new NoRemovePanel(
266
+                    new MigLayout("fillx, gap unrel, wrap 2, pack, "
267
+                            + "hidemode 3, wmax 470-"
268
+                            + leftPadding + "-" + rightPadding + "-2*" + padding));
269
+            panel1.setName(category.getPath());
270
+            return panel1;
271
+        });
295 272
 
296 273
         initCategory(category, panel);
297 274
 

+ 39
- 47
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/tree/TreeFrameManager.java View File

@@ -199,25 +199,21 @@ public class TreeFrameManager implements FrameManager, Serializable, ConfigChang
199 199
     @Handler
200 200
     public void doDeleteWindow(final SwingWindowDeletedEvent event) {
201 201
         final TextFrame window = event.getChildWindow();
202
-        UIUtilities.invokeAndWait(new Runnable() {
203
-
204
-            @Override
205
-            public void run() {
206
-                if (nodes.get(window) == null) {
207
-                    return;
208
-                }
209
-                final DefaultMutableTreeNode node = nodes.get(window);
210
-                if (node.getLevel() == 0) {
211
-                    eventBus.publishAsync(
212
-                            new UserErrorEvent(ErrorLevel.MEDIUM, new IllegalArgumentException(),
213
-                                    "delServer triggered for root node" + node, ""));
214
-                } else {
215
-                    model.removeNodeFromParent(nodes.get(window));
216
-                }
217
-                synchronized (nodes) {
218
-                    eventBus.unsubscribe(nodes.get(window).getLabel());
219
-                    nodes.remove(window);
220
-                }
202
+        UIUtilities.invokeAndWait(() -> {
203
+            if (nodes.get(window) == null) {
204
+                return;
205
+            }
206
+            final DefaultMutableTreeNode node = nodes.get(window);
207
+            if (node.getLevel() == 0) {
208
+                eventBus.publishAsync(
209
+                        new UserErrorEvent(ErrorLevel.MEDIUM, new IllegalArgumentException(),
210
+                                "delServer triggered for root node" + node, ""));
211
+            } else {
212
+                model.removeNodeFromParent(nodes.get(window));
213
+            }
214
+            synchronized (nodes) {
215
+                eventBus.unsubscribe(nodes.get(window).getLabel());
216
+                nodes.remove(window);
221 217
             }
222 218
         });
223 219
     }
@@ -229,35 +225,31 @@ public class TreeFrameManager implements FrameManager, Serializable, ConfigChang
229 225
      * @param window Window to add
230 226
      */
231 227
     public void addWindow(final MutableTreeNode parent, final TextFrame window) {
232
-        UIUtilities.invokeAndWait(new Runnable() {
233
-
234
-            @Override
235
-            public void run() {
236
-                final NodeLabel label = new NodeLabel(window, iconManager);
237
-                eventBus.subscribe(label);
238
-                swingEventBus.subscribe(label);
239
-                final TreeViewNode node = new TreeViewNode(label, window);
240
-                synchronized (nodes) {
241
-                    nodes.put(window, node);
242
-                }
243
-                if (parent == null) {
244
-                    model.insertNodeInto(node, model.getRootNode());
245
-                } else {
246
-                    model.insertNodeInto(node, parent);
247
-                }
248
-                tree.expandPath(new TreePath(node.getPath()).getParentPath());
249
-                final Rectangle view = tree.getRowBounds(tree.getRowForPath(new TreePath(node.
250
-                        getPath())));
251
-                if (view != null) {
252
-                    tree.scrollRectToVisible(new Rectangle(0, (int) view.getY(), 0, 0));
253
-                }
254
-
255
-                // TODO: Should this colour be configurable?
256
-                node.getLabel().notificationSet(new NotificationSetEvent(window.getContainer(),
257
-                        window.getContainer().getNotification().orElse(Colour.BLACK)));
258
-                node.getLabel().iconChanged(new FrameIconChangedEvent(window.getContainer(),
259
-                        window.getContainer().getIcon()));
228
+        UIUtilities.invokeAndWait(() -> {
229
+            final NodeLabel label = new NodeLabel(window, iconManager);
230
+            eventBus.subscribe(label);
231
+            swingEventBus.subscribe(label);
232
+            final TreeViewNode node = new TreeViewNode(label, window);
233
+            synchronized (nodes) {
234
+                nodes.put(window, node);
235
+            }
236
+            if (parent == null) {
237
+                model.insertNodeInto(node, model.getRootNode());
238
+            } else {
239
+                model.insertNodeInto(node, parent);
260 240
             }
241
+            tree.expandPath(new TreePath(node.getPath()).getParentPath());
242
+            final Rectangle view = tree.getRowBounds(tree.getRowForPath(new TreePath(node.
243
+                    getPath())));
244
+            if (view != null) {
245
+                tree.scrollRectToVisible(new Rectangle(0, (int) view.getY(), 0, 0));
246
+            }
247
+
248
+            // TODO: Should this colour be configurable?
249
+            node.getLabel().notificationSet(new NotificationSetEvent(window.getContainer(),
250
+                    window.getContainer().getNotification().orElse(Colour.BLACK)));
251
+            node.getLabel().iconChanged(new FrameIconChangedEvent(window.getContainer(),
252
+                    window.getContainer().getIcon()));
261 253
         });
262 254
     }
263 255
 

Loading…
Cancel
Save