ui包中的类及代码分析

ui包(user interface)
Contains superclass for all user interfaces and a simple user interface(s). 
包含所有用户接口的父类和一个简单用户接口



ui.DTNSimUI
功能:所有用户接口的抽象父类,也包含一些仿真设置(Abstract superclass for user interfaces; contains also some simulation settings.)

public abstract class DTNSimUI

outline:

意义
属性
public static final String NROF_REPORT_S = "Report.nrofReports"; //Number of reports(报告数量)
public static final String REPORT_S = "Report.report"; //Report class name(报告类名称)(注)Must be suffixed with numbers starting from one.
public static final String MM_WARMUP_S = movement.MovementModel.MOVEMENT_MODEL_NS + ".warmup" //Movement model warmup time(移动模型准备时间)Defines how many seconds of movement simulation is run without connectivity etc
private static final String REPORT_PAC = "report."; //report class' package name(报告类的包的名字)

protected World world; //The World where all actors of the simulator are(所模拟的世界)
protected Vector<Report> reports; //Reports that are loaded for this simulation(从模拟中获取的报告)
protected boolean simDone; //has simulation terminated normally(仿真是否正常结束)
protected boolean simCancelled; //is simulation termination requested(仿真是否求终止)
protected SimScenario scen; //Scenario of the current simulation(正在模拟的场景)
protected double lastUpdate; //simtime of last UI update(上次更新的仿真时间)

方法
public DTNSimUI() //Constructor
public void start() //Starts the simulation(调用initModel() runSim(), 仿真开始  )
protected abstract void runSim(); //Runs simulation after the model has been initialized.
private void initModel() //Initializes the simulator model.(初始化移动模型)
             从core.SimScenario 获得运行模拟的实例,添加多个报告(调用addReport() ),并设置模拟世界的warmupTime 。设置报错机制。
for (int i=1, n = settings.getInt(NROF_REPORT_S); i<=n; i++){
String reportClass = settings.getSetting(REPORT_S + i);
addReport((Report)settings.createObject(REPORT_PAC + 
reportClass));    即所需报告的报的名字+报告类的名称class
               }

   
public void done() //Runs maintenance jobs that are needed before exiting运行结束前所需的维护工作
public void done() {
for (Report r : this.reports) {
r.done(); //Called when the simulation is done, user requested premature termination or intervalled report generating decided that it's time for the next report.
}
}
protected void addReport(Report r) //Adds a new report for simulator(为仿真增加报告)先判断所需报告类是哪种实例,相应为所有节点增加 listener
          this.reports.add(r)
类型:MessageListener,ConnectionListener, MovementListener,UpdateListener, ApplicationListener





ui.DTNSimTextUI
功能:简单的基于text的用户接口(Simple text-based user interface),是DTNSimUI 的子类

public class DTNSimTextUI extends DTNSimUI    


outline:

意义
属性
private  ---           lastUpdateRt:上一次ui更新的时间(real time of last ui update)
                              startTime:模拟开始时间(simulation start time)
public static ---   UI_UP_INTERVAL:ui多长时间更新一次(How often the UI view is updated (milliseconds))

方法:
protected void runSim()   //覆写
print("Running simulation '" + scen.getName()+"'");
在仿真时间内,更新世界内所有节点。
double duration = (System.currentTimeMillis() - startTime)/1000.0 //持续时间
this.update(true); //调用update()强制更新
print("Simulation done in " + String.format("%.2f", duration) + "s");

private void update(boolean forced) //Updates user interface if the long enough (real)time (update interval) has passed from the previous update(更新用户接口)
ssps = ((SimClock.getTime() - lastUpdate)*1000) / diff; //simulated seconds/second calc
print(String.format("%.1f %d: %.2f 1/s", dur, 
SimClock.getIntTime(),ssps));

private void print(String txt) // 打印txt














  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值