📄 table.java~18~
字号:
package App;
/**
* <p>Title: 表</p>
* <p>Description: 为了以后的树的作图,故需要计算各个节点的x和y的坐标值。由此设计了表数组</p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author liuli
* @version 1.1(2005.6.29
*/
class Table {
protected TableNode tables[];
protected int number;
protected int treeCeng;//树的高度
public Table() {
this(1000);
}
public Table(int number){
tables=new TableNode [number];
}
/**查找某个元素,找到,返回数组序号,否则返回-1*/
int search(Object name){
int i;
for(i=0;tables[i].name!=null&&!tables[i].name.equals(name);i++);
if(tables[i].name!=null) return i;
else return -1;
}
/**根据字符串构造表,记录各个节点的信息*/
void creatTable(String s){
String fa,ch;//双亲和孩子所表示的字符串
int i=0;//控制循环语句
//记录节点名字,双亲位置,所在层数
int j;
int n=0;//控制数组
fa=s.substring(i,i+1);ch=s.substring(i+1,i+2);
for(;ch.compareTo("#")!=0;i+=2,fa=s.substring(i,i+1),ch=s.substring(i+1,i+2)){//每两个取为一组
if(fa.compareTo("#")==0){
tables[0]=new TableNode(ch,-1,1);
}
else {
if((j=search(fa))!=-1)//找出f双亲所在的序号
tables[n]=new TableNode(ch,j,tables[j].ceng+1);
}
n++;
}
this.number=n;
this.treeCeng=tables[number-1].ceng;
//记录在兄弟间的排行
i=0;
while(tables[i]!=null){
if(i==0){
tables[i].SiblingNumbers = 1;
tables[i].locate = 1;
}
else if(tables[i].parents!=tables[i-1].parents){
tables[i].locate = 1;
}
else
tables[i].locate=tables[i-1].locate+1;
i++;
}
//记录含有的兄弟个数
tables[number-1].SiblingNumbers=tables[number-1].locate;
for(i=number-2;i>0;i--){
if(tables[i].parents!=tables[i+1].parents)
tables[i].SiblingNumbers=tables[i].locate;
else
tables[i].SiblingNumbers=tables[i+1].SiblingNumbers;
}
}
/**计算各节点的x,y坐标值
* 包括了一个内部类WH,记录宽度和高度*/
class WeightHight{
int w;//宽度
int h;//高度
public WeightHight(){}
public WeightHight(int w,int h){
this.w=w; this.h=h;
}
void setW(int w){
this.w=w;
}
void setH(int h){
this.h =h;
}
}
void xAndy(){
WeightHight wh[]=new WeightHight[treeCeng+1];//宽和高的数组
int r;//节点的半径
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -