Skip to content

Commit

Permalink
Merge pull request #379 from greboid/dev4
Browse files Browse the repository at this point in the history
Quit the client off the EDT.
  • Loading branch information
csmith committed Jan 20, 2015
2 parents e89a027 + 1272351 commit 4643020
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void handlePrefsDialog(final ClientPrefsOpenedEvent event) {
new NumericalValidator(0, Integer.MAX_VALUE), domain, "whointerval",
"Who Interval", "The interval WHO requests will be sent to channels",
event.getModel().getConfigManager(), event.getModel().getIdentity()));
event.getModel().getCategory("Plugins").addSubCategory(category);
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ public void unload() {

@VisibleForTesting
void checkWho() {
connectionManager.getConnections().forEach(connection ->
connection.getGroupChatManager().getChannels().forEach(channel -> {
if (channel.getWindowModel().getConfigManager().getOptionBool(domain, "sendwho")) {
connectionManager.getConnections().forEach(
connection -> connection.getGroupChatManager().getChannels().forEach(channel -> {
if (channel.getWindowModel().getConfigManager()
.getOptionBool(domain, "sendwho")) {
channel.requestUsersInfo();
}}));
}
}));
}

@VisibleForTesting
Expand Down
5 changes: 5 additions & 0 deletions ui_swing/src/com/dmdirc/addons/ui_swing/UIUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.dmdirc.DMDircMBassador;
import com.dmdirc.addons.ui_swing.components.DMDircUndoableEditListener;
import com.dmdirc.addons.ui_swing.components.RunnableSwingWorker;
import com.dmdirc.util.colours.Colour;

import java.awt.Color;
Expand Down Expand Up @@ -245,6 +246,10 @@ public static void invokeLater(final Runnable runnable) {
}
}

public static void invokeOffEDT(final Runnable runnable) {
new RunnableSwingWorker<Void,Void>(runnable).execute();
}

/**
* Check if we are using the GTK look and feel.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2006-2015 DMDirc Developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.dmdirc.addons.ui_swing.components;

import com.dmdirc.DMDircMBassador;

/**
* {@link LoggingSwingWorker} that runs a {@link Runnable}.
*/
public class RunnableLoggingSwingWorker<T, V> extends LoggingSwingWorker<T, V> {

private final Runnable runnable;

/**
* Creates a new logging swing worker.
*
* @param eventBus Event bus to post errors to.
*/
public RunnableLoggingSwingWorker(final DMDircMBassador eventBus, final Runnable runnable) {
super(eventBus);
this.runnable = runnable;
}

@Override
protected T doInBackground() throws Exception {
runnable.run();
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2006-2015 DMDirc Developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.dmdirc.addons.ui_swing.components;

import javax.swing.SwingWorker;

/**
* {@link SwingWorker} that takes a {@link Runnable}.
*/
public class RunnableSwingWorker<T, V> extends SwingWorker<T, V> {

private final Runnable runnable;

public RunnableSwingWorker(final Runnable runnable) {
this.runnable = runnable;
}

@Override
protected T doInBackground() throws Exception {
runnable.run();
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.dmdirc.ServerState;
import com.dmdirc.addons.ui_swing.Apple;
import com.dmdirc.addons.ui_swing.UIUtilities;
import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
import com.dmdirc.addons.ui_swing.dialogs.newserver.NewServerDialog;
import com.dmdirc.addons.ui_swing.dialogs.serversetting.ServerSettingsDialog;
Expand Down Expand Up @@ -120,7 +121,7 @@ private void initServerMenu() {
final JMenuItem exit = new JMenuItem();
exit.setText("Exit");
exit.setMnemonic('x');
exit.addActionListener(e -> lifecycleController.quit());
exit.addActionListener(e -> UIUtilities.invokeOffEDT(lifecycleController::quit));
add(exit);
}
}
Expand Down

0 comments on commit 4643020

Please sign in to comment.