Fix #15: Option to shutdown at the end of frame (standalone client)
This commit is contained in:
committed by
Laurent Clouet
parent
7f475348fc
commit
2560a2d4d2
@@ -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;
|
||||
}
|
||||
|
||||
@@ -364,6 +364,15 @@ public class Client {
|
||||
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();
|
||||
Error.Type ret;
|
||||
|
||||
@@ -117,6 +117,7 @@ public class GuiSwing extends JFrame implements Gui {
|
||||
@Override
|
||||
public void stop() {
|
||||
System.out.println("GuiSwing::stop()");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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);
|
||||
@@ -229,4 +239,21 @@ 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user