Author:赵志乾
Date:2024-06-27
Declaration:All Right Reserved!!!
1. 应用场景
view area又叫视图区域,其作用是在presentation中标记一块区域,便于动画演示过程中快速切换可视区域;
anylogic为每个agent生成默认的view area,title为[Origin],左上角坐标为(0,0),x轴方向长1000像素,y轴方向长600像素。在图形编辑窗口点击默认view area的边框,属性窗口中显示的frame即为默认的view area。
示例代码:
// step1: 定义视图区域
ViewArea customViewArea = new ViewArea(this, "custom", 0.0, 0.0, 1000.0, 600.0);// step2: 将视图设为当前可视区
customViewArea.navigateTo();
2. 代码解析
//**********************核心字段*****************************
// view area的owner
Presentable owner;
// view area的标题,实际可设置一个便于理解其用途的字符串;
String title;
// 对view area所定义的矩形描述,分别为左上角坐标、宽、高,单位都是像素;
double x;
double y;
double width;
double height;//***********************构造函数****************************
public ViewArea(Presentable owner, String title, double x, double y, double width, double height) {this.owner = owner;this.title = title;this.x = x;this.y = y;this.width = width;this.height = height;
}//***********************getter、setter*********************
public String getTitle() {return this.title;
}
public void setTitle(String title) {this.title = title;
}
public double getX() {return this.x;
}
public void setX(double x) {this.x = x;
}
public double getY() {return this.y;
}
public void setY(double y) {this.y = y;
}
public double getWidth() {return this.width;
}
public void setWidth(double width) {if (width <= 0.0) {error("view area的宽必须大于0!");} this.width = width;
}
public double getHeight() {return this.height;
}
public void setHeight(double height) {if (height <= 0.0) {error("view area的高必须大于0!");} this.height = height;
}
public Presentable getOwner() {return this.owner;
}//*************************导航*************************
// view area设置为当前视图
public void navigateTo() {if (this.owner.getExperimentHost() != null) {this.owner.getExperimentHost().navigateTo(this);}
}