📄 simstate.java
字号:
// $Id: SimState.java,v 1.3.8.3 2003/08/26 09:08:11 cssharp Exp $/* tab:2 * * * "Copyright (c) 2000 and The Regents of the University * of California. All rights reserved. * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose, without fee, and without written * agreement is hereby granted, provided that the above copyright * notice and the following two paragraphs appear in all copies of * this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, * UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * * Authors: Dennis Chi * Date: October 16 2002 * Desc: * *//** * @author Dennis Chi */package net.tinyos.sim;import java.util.*;import net.tinyos.sim.event.*;public class SimState { private TinyViz tv; private SimEventBus eventBus; private HashSet simObjects = new HashSet(); private HashSet moteObjects = new HashSet(); private Hashtable simObjectGenerators = new Hashtable(); private MoteSimObjectGenerator moteSimObjectGenerator; public SimState(TinyViz tv) { this.tv = tv; this.eventBus = tv.getEventBus(); } synchronized public Set getSimObjects() { return (Set)simObjects.clone(); } synchronized public Set getMoteSimObjects() { return (Set)moteObjects.clone(); } synchronized public Set getSelectedSimObjects() { HashSet selected = new HashSet(); Iterator it = simObjects.iterator(); while (it.hasNext()) { SimObject so = (SimObject)it.next(); if (so.isSelected()) selected.add(so); } return selected; } synchronized public Set getSelectedMoteSimObjects() { HashSet selected = new HashSet(); Iterator it = moteObjects.iterator(); while (it.hasNext()) { MoteSimObject so = (MoteSimObject)it.next(); if (so.isSelected()) selected.add(so); } return selected; } synchronized public void addSOGenerator(SimObjectGenerator s) { String name = s.getClass().getName(); simObjectGenerators.put(name.substring(1+name.lastIndexOf('.')), s); } synchronized public void addSOGenerator(String name, SimObjectGenerator s) { simObjectGenerators.put(name, s); } synchronized public SimObjectGenerator getSOGenerator(String name) { return (SimObjectGenerator)simObjectGenerators.get(name); } synchronized public void removeSOGenerator(String name) { simObjectGenerators.remove(name); } synchronized public void removeSOGenerator(SimObjectGenerator s) { simObjectGenerators.remove(s.getClass().getName()); } synchronized public void addSimObject(SimObject simObject) { simObjects.add(simObject); if (simObject instanceof MoteSimObject) moteObjects.add(simObject); eventBus.addEvent(new SimObjectEvent(SimObjectEvent.OBJECT_ADDED, simObject)); } synchronized public void removeSimObject(SimObject simObject) { simObjects.remove(simObject); if (simObject instanceof MoteSimObject) moteObjects.remove(simObject); eventBus.addEvent(new SimObjectEvent(SimObjectEvent.OBJECT_REMOVED, simObject)); } synchronized public void removeAllObjects() { simObjects = new HashSet(); moteObjects = new HashSet(); simObjectGenerators = new Hashtable(); } synchronized public SimObject getSimObject(int windowX, int windowY, CoordinateTransformer cT) { Iterator it = simObjects.iterator(); while (it.hasNext()) { SimObject s = (SimObject)it.next(); if (s.pointInSimObjectSpace(windowX, windowY, cT)) return s; } return null; } synchronized public MoteSimObject getMoteSimObject (int moteID) { Iterator it = simObjects.iterator(); while (it.hasNext()) { SimObject simObject = (SimObject)it.next(); if (simObject instanceof MoteSimObject) { MoteSimObject mote = (MoteSimObject)simObject; MoteIDAttribute idAttrib = (MoteIDAttribute) (mote.getAttribute("net.tinyos.sim.MoteIDAttribute")); if (idAttrib.getID() == moteID) { return mote; } } } return null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -