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);}
}