您的位置:首页 > 产品设计 > UI/UE

ui包中的类及代码分析

2015-11-13 16:11 381 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: