diff --git a/src/com/sheepit/client/Client.java b/src/com/sheepit/client/Client.java index f78982b..0294ff7 100644 --- a/src/com/sheepit/client/Client.java +++ b/src/com/sheepit/client/Client.java @@ -306,6 +306,7 @@ public class Client { return -99; // the this.stop will be done after the return of this.run() } + this.gui.stop(); return 0; } @@ -342,7 +343,6 @@ public class Client { this.server = null; - this.gui.stop(); return 0; } @@ -363,6 +363,15 @@ public class Client { System.out.println("Client::askForStop"); this.running = false; } + + public void cancelStop() { + System.out.println("Client::cancelStop"); + this.running = true; + } + + public boolean isRunning() { + return this.running; + } public int senderLoop() { int step = log.newCheckPoint(); diff --git a/src/com/sheepit/client/standalone/GuiSwing.java b/src/com/sheepit/client/standalone/GuiSwing.java index 22437f3..8bddb8e 100644 --- a/src/com/sheepit/client/standalone/GuiSwing.java +++ b/src/com/sheepit/client/standalone/GuiSwing.java @@ -117,6 +117,7 @@ public class GuiSwing extends JFrame implements Gui { @Override public void stop() { System.out.println("GuiSwing::stop()"); + System.exit(0); } @Override diff --git a/src/com/sheepit/client/standalone/swing/activity/Working.java b/src/com/sheepit/client/standalone/swing/activity/Working.java index ee9bd6b..4446712 100644 --- a/src/com/sheepit/client/standalone/swing/activity/Working.java +++ b/src/com/sheepit/client/standalone/swing/activity/Working.java @@ -28,6 +28,7 @@ public class Working implements Activity { JLabel lastRender; JLabel creditEarned; JButton pauseButton; + JButton exitAfterFrame; public Working(GuiSwing parent_) { parent = parent_; @@ -129,16 +130,25 @@ public class Working implements Activity { pauseButton = new JButton("Pause"); pauseButton.addActionListener(new PauseAction()); constraints.gridx = 2; + constraints.gridy = currentRow; parent.getContentPane().add(pauseButton, constraints); + ++currentRow; //Add hide button if os supports it if (SystemTray.isSupported()) { JButton hideButton = new JButton("Hide window"); hideButton.addActionListener(new HideAction()); - constraints.gridx = 3; + constraints.gridx = 1; + constraints.gridy = currentRow; parent.getContentPane().add(hideButton, constraints); } + exitAfterFrame = new JButton("Exit after this frame"); + constraints.gridx = 2; + constraints.gridy = currentRow; + exitAfterFrame.addActionListener(new ExitAfterAction()); + parent.getContentPane().add(exitAfterFrame, constraints); + parent.addPadding(1, ++currentRow, 2, 1); parent.addPadding(0, 0, 1, currentRow + 1); parent.addPadding(3, 0, 1, currentRow + 1); @@ -228,5 +238,22 @@ public class Working implements Activity { } } } + + class ExitAfterAction implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + Client client = parent.getClient(); + if (client != null) { + if (client.isRunning()) { + exitAfterFrame.setText("Cancel exit"); + client.askForStop(); + } + else { + exitAfterFrame.setText("Exit after this frame"); + client.cancelStop(); + } + } + } + } }