minor bugfix: not all mote type identifiers were reserved when reloading simulation. this caused loading some simulations with several mote types to fail

+ added key accelerator for reloading a simulation (ctrl+r or ctrl+shift+r). thanks to David Gustafsson for patching :)

+ added yet another key accelerator for starting/stopping simulation (ctrl+s)
This commit is contained in:
fros4943 2009-02-25 16:11:59 +00:00
parent 6f8ec800c5
commit 5b258ce104

View file

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: GUI.java,v 1.107 2009/02/23 08:33:23 joxe Exp $ * $Id: GUI.java,v 1.108 2009/02/25 16:11:59 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -596,6 +596,9 @@ public class GUI extends Observable {
menu.add(menuItem); menu.add(menuItem);
JMenuItem menuItem2 = new JMenuItem("same random seed"); JMenuItem menuItem2 = new JMenuItem("same random seed");
menuItem2.setMnemonic(KeyEvent.VK_R);
menuItem2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,
ActionEvent.CTRL_MASK));
menuItem2.addActionListener(new ActionListener() { menuItem2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
reloadCurrentSimulation(false, getSimulation().getRandomSeed()); reloadCurrentSimulation(false, getSimulation().getRandomSeed());
@ -604,6 +607,9 @@ public class GUI extends Observable {
menuItem.add(menuItem2); menuItem.add(menuItem2);
menuItem2 = new JMenuItem("new random seed"); menuItem2 = new JMenuItem("new random seed");
menuItem2.setMnemonic(KeyEvent.VK_R);
menuItem2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,
ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
menuItem2.addActionListener(new ActionListener() { menuItem2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
reloadCurrentSimulation(false, getSimulation().getRandomSeed()+1); reloadCurrentSimulation(false, getSimulation().getRandomSeed()+1);
@ -650,6 +656,25 @@ public class GUI extends Observable {
menuItem.addActionListener(guiEventHandler); menuItem.addActionListener(guiEventHandler);
menu.add(menuItem); menu.add(menuItem);
menuItem = new JMenuItem("Start/Stop simulation");
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
ActionEvent.CTRL_MASK));
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
/* Start/Stop current simulation */
Simulation sim = getSimulation();
if (sim == null) {
return;
}
if (sim.isRunning()) {
sim.stopSimulation();
} else {
sim.startSimulation();
}
}
});
menu.add(menuItem);
menu.addSeparator(); menu.addSeparator();
menuItem = new JMenuItem("Exit"); menuItem = new JMenuItem("Exit");
@ -3474,7 +3499,10 @@ public class GUI extends Observable {
if (mySimulation != null) { if (mySimulation != null) {
existingMoteTypes = mySimulation.getMoteTypes(); existingMoteTypes = mySimulation.getMoteTypes();
} }
String newID = ContikiMoteType.generateUniqueMoteTypeID(existingMoteTypes, moteTypeIDMappings.values()); ArrayList<Object> reserved = new ArrayList<Object>();
reserved.addAll(moteTypeIDMappings.keySet());
reserved.addAll(moteTypeIDMappings.values());
String newID = ContikiMoteType.generateUniqueMoteTypeID(existingMoteTypes, reserved);
moteTypeIDMappings.setProperty(existingIdentifier, newID); moteTypeIDMappings.setProperty(existingIdentifier, newID);
} }
@ -4010,7 +4038,7 @@ public class GUI extends Observable {
* Runs work method in event dispatcher thread. * Runs work method in event dispatcher thread.
* Worker method returns a value. * Worker method returns a value.
* *
* @author Fredrik Österlind * @author Fredrik Osterlind
*/ */
public static abstract class RunnableInEDT<T> { public static abstract class RunnableInEDT<T> {
private T val; private T val;