Fix stopping threads again

This commit is contained in:
zzz
2022-01-12 09:06:59 -05:00
parent cdcc40e871
commit d7865d233b
3 changed files with 34 additions and 6 deletions

View File

@ -34,8 +34,9 @@ import java.awt.FlowLayout;
public class Main { public class Main {
private JFrame frame; private RegisteredFrame frame;
private JTabbedPane tabbedPane; private JTabbedPane tabbedPane;
private OverviewTab overviewTab;
private final WindowHandler windowHandler; private final WindowHandler windowHandler;
private final ConfigurationManager _conf; private final ConfigurationManager _conf;
public final static int FRAME_WIDTH = 550; public final static int FRAME_WIDTH = 550;
@ -70,6 +71,24 @@ public class Main {
initialize(); initialize();
} }
/**
* Stop all the threads in overview tab
* on plugin stop, but not on frame x-out
* @since 0.0.4
*/
private class KillableFrame extends RegisteredFrame {
public KillableFrame(String s, WindowHandler wh) {
super(s, wh);
}
@Override
public void kill() {
if (overviewTab != null)
overviewTab.destroy();
super.kill();
}
}
/** /**
* Initialize the contents of the frame. * Initialize the contents of the frame.
*/ */
@ -77,7 +96,7 @@ public class Main {
GUIHelper.setDefaultStyle(); GUIHelper.setDefaultStyle();
//GUIHelper.setTabLooks(); //GUIHelper.setTabLooks();
frame = new RegisteredFrame("itoopie", windowHandler); frame = new KillableFrame("itoopie", windowHandler);
frame.setBounds(0, 0, FRAME_WIDTH, FRAME_HEIGHT); frame.setBounds(0, 0, FRAME_WIDTH, FRAME_HEIGHT);
frame.setResizable(false); frame.setResizable(false);
frame.setBackground(GUIHelper.VERY_LIGHT); frame.setBackground(GUIHelper.VERY_LIGHT);
@ -91,7 +110,7 @@ public class Main {
root.add(tabbedPane); root.add(tabbedPane);
tabbedPane.setBounds(0, 0, FRAME_WIDTH-9, TABBED_PANE_HEIGHT); tabbedPane.setBounds(0, 0, FRAME_WIDTH-9, TABBED_PANE_HEIGHT);
OverviewTab overviewTab = new OverviewTab("itoopie-opaque12", _conf); overviewTab = new OverviewTab("itoopie-opaque12", _conf);
tabbedPane.addTab(' ' + Transl._t("Overview") + ' ', null, overviewTab, null); tabbedPane.addTab(' ' + Transl._t("Overview") + ' ', null, overviewTab, null);
tabbedPane.addChangeListener(new TabChangeListener(overviewTab)); tabbedPane.addChangeListener(new TabChangeListener(overviewTab));

View File

@ -6,10 +6,11 @@ import java.util.HashSet;
import javax.swing.JFrame; import javax.swing.JFrame;
import net.i2p.itoopie.configuration.ConfigurationManager; import net.i2p.itoopie.configuration.ConfigurationManager;
import net.i2p.itoopie.gui.component.RegisteredFrame;
public class WindowHandler { public class WindowHandler {
private final HashSet<JFrame> _frames = new HashSet<JFrame>(); private final HashSet<JFrame> _frames = new HashSet<JFrame>();
private JFrame mainFrame; private RegisteredFrame mainFrame;
private boolean areFramesShown; private boolean areFramesShown;
private final ConfigurationManager _conf; private final ConfigurationManager _conf;
@ -21,13 +22,13 @@ public class WindowHandler {
_frames.add(frame); _frames.add(frame);
} }
public void registerMain(JFrame frame){ public void registerMain(RegisteredFrame frame){
mainFrame = frame; mainFrame = frame;
} }
public void destroyMain() { public void destroyMain() {
if (mainFrame != null) { if (mainFrame != null) {
mainFrame.dispose(); mainFrame.kill();
_frames.remove(mainFrame); _frames.remove(mainFrame);
mainFrame = null; mainFrame = null;
} }

View File

@ -61,4 +61,12 @@ public class RegisteredFrame extends JFrame implements WindowListener{
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
/**
* @since 0.0.4
*/
public void kill() {
dispose();
}
} }