Made exit configurable

This commit is contained in:
nifi 2010-10-28 21:49:01 +00:00
parent 9a1f902881
commit f0417d8be3

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: CollectServer.java,v 1.32 2010/10/28 14:17:10 nifi Exp $ * $Id: CollectServer.java,v 1.33 2010/10/28 21:49:01 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,14 +34,15 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 3 jul 2008 * Created : 3 jul 2008
* Updated : $Date: 2010/10/28 14:17:10 $ * Updated : $Date: 2010/10/28 21:49:01 $
* $Revision: 1.32 $ * $Revision: 1.33 $
*/ */
package se.sics.contiki.collect; package se.sics.contiki.collect;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
@ -63,7 +64,6 @@ import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
@ -147,6 +147,10 @@ public class CollectServer implements SerialConnectionListener {
private boolean doSendInitAtStartup = false; private boolean doSendInitAtStartup = false;
private String initScript; private String initScript;
private boolean hasStarted = false;
private boolean doExitOnRequest = true;
private JMenuItem exitItem;
private int defaultMaxItemCount = 250; private int defaultMaxItemCount = 250;
private long nodeTimeDelta; private long nodeTimeDelta;
@ -660,15 +664,15 @@ public class CollectServer implements SerialConnectionListener {
fileMenu.add(item); fileMenu.add(item);
fileMenu.addSeparator(); fileMenu.addSeparator();
item = new JMenuItem("Exit", KeyEvent.VK_X); exitItem = new JMenuItem("Exit", KeyEvent.VK_X);
item.addActionListener(new ActionListener() { exitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
exit(); exit();
} }
}); });
fileMenu.add(item); fileMenu.add(exitItem);
JMenu toolsMenu = new JMenu("Tools"); JMenu toolsMenu = new JMenu("Tools");
toolsMenu.setMnemonic(KeyEvent.VK_T); toolsMenu.setMnemonic(KeyEvent.VK_T);
@ -765,10 +769,11 @@ public class CollectServer implements SerialConnectionListener {
return -1; return -1;
} }
void start(SerialConnection connection) { public void start(SerialConnection connection) {
if (this.serialConnection != null) { if (hasStarted) {
throw new IllegalStateException("already started"); throw new IllegalStateException("already started");
} }
hasStarted = true;
this.serialConnection = connection; this.serialConnection = connection;
if (isSensorLogUsed) { if (isSensorLogUsed) {
initSensorData(); initSensorData();
@ -793,7 +798,7 @@ public class CollectServer implements SerialConnectionListener {
} }
} }
private void exit() { public void stop() {
save(); save();
if (serialConnection != null) { if (serialConnection != null) {
serialConnection.close(); serialConnection.close();
@ -802,7 +807,27 @@ public class CollectServer implements SerialConnectionListener {
if (output != null) { if (output != null) {
output.close(); output.close();
} }
System.exit(0); window.setVisible(false);
}
public void setExitOnRequest(boolean doExit) {
this.doExitOnRequest = doExit;
if (exitItem != null) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
exitItem.setEnabled(doExitOnRequest);
}
});
}
}
private void exit() {
if (doExitOnRequest) {
stop();
System.exit(0);
} else {
Toolkit.getDefaultToolkit().beep();
}
} }
private void sleep(long delay) { private void sleep(long delay) {