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()
|
return -99; // the this.stop will be done after the return of this.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.gui.stop();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,7 +343,6 @@ public class Client {
|
|||||||
|
|
||||||
this.server = null;
|
this.server = null;
|
||||||
|
|
||||||
this.gui.stop();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,6 +364,15 @@ public class Client {
|
|||||||
this.running = false;
|
this.running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cancelStop() {
|
||||||
|
System.out.println("Client::cancelStop");
|
||||||
|
this.running = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRunning() {
|
||||||
|
return this.running;
|
||||||
|
}
|
||||||
|
|
||||||
public int senderLoop() {
|
public int senderLoop() {
|
||||||
int step = log.newCheckPoint();
|
int step = log.newCheckPoint();
|
||||||
Error.Type ret;
|
Error.Type ret;
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ public class GuiSwing extends JFrame implements Gui {
|
|||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
System.out.println("GuiSwing::stop()");
|
System.out.println("GuiSwing::stop()");
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public class Working implements Activity {
|
|||||||
JLabel lastRender;
|
JLabel lastRender;
|
||||||
JLabel creditEarned;
|
JLabel creditEarned;
|
||||||
JButton pauseButton;
|
JButton pauseButton;
|
||||||
|
JButton exitAfterFrame;
|
||||||
|
|
||||||
public Working(GuiSwing parent_) {
|
public Working(GuiSwing parent_) {
|
||||||
parent = parent_;
|
parent = parent_;
|
||||||
@@ -129,16 +130,25 @@ public class Working implements Activity {
|
|||||||
pauseButton = new JButton("Pause");
|
pauseButton = new JButton("Pause");
|
||||||
pauseButton.addActionListener(new PauseAction());
|
pauseButton.addActionListener(new PauseAction());
|
||||||
constraints.gridx = 2;
|
constraints.gridx = 2;
|
||||||
|
constraints.gridy = currentRow;
|
||||||
parent.getContentPane().add(pauseButton, constraints);
|
parent.getContentPane().add(pauseButton, constraints);
|
||||||
|
|
||||||
|
++currentRow;
|
||||||
//Add hide button if os supports it
|
//Add hide button if os supports it
|
||||||
if (SystemTray.isSupported()) {
|
if (SystemTray.isSupported()) {
|
||||||
JButton hideButton = new JButton("Hide window");
|
JButton hideButton = new JButton("Hide window");
|
||||||
hideButton.addActionListener(new HideAction());
|
hideButton.addActionListener(new HideAction());
|
||||||
constraints.gridx = 3;
|
constraints.gridx = 1;
|
||||||
|
constraints.gridy = currentRow;
|
||||||
parent.getContentPane().add(hideButton, constraints);
|
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(1, ++currentRow, 2, 1);
|
||||||
parent.addPadding(0, 0, 1, currentRow + 1);
|
parent.addPadding(0, 0, 1, currentRow + 1);
|
||||||
parent.addPadding(3, 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