/*
* 用于绘制项目集簇
*/
import java.awt.* ;
class Picture extends Panel
{
Relation[] relation = new Relation[40] ;//创建关系数组
Table[] table = new Table[40] ;//创建表数组
List[] tablelist ;
int tablelength ;
int relationlength ;
int front = 0 ;
int behind = 1 ;
boolean allowed = false ;
public Picture(Relation[] relation , Table[] table)
{
this.setLayout(null) ;
this.relation = relation ;
this.table = table ;
}
public void paint(Graphics g)
{
if(allowed == true)
{//如果是初始化则不绘制图形
tablelist = new List[tablelength] ; //根据表的个数来建立相应的列表
for(int i=0 ; i<tablelength ; i++)
{//根据table中的内容添加到列表中
int lengthtemp = table[i].tablength ;
tablelist[i] = new List(lengthtemp,false) ;
for(int j=0 ; j<lengthtemp ; j++)
{
String temp0 = table[i].element[j].frontstr ;
String temp1 = table[i].element[j].behindstr ;
String temp2 = table[i].element[j].suifustr ;
if(j == 0)
{
tablelist[i].add("I"+i+" "+temp0+"."+temp1+","+temp2) ;
}
else
{
tablelist[i].add(" "+temp0+"."+temp1+","+temp2) ;
}
}
}
tablelist[0].setBounds(0,0,100,17*tablelist[0].getItemCount()) ;
front = 0 ;
int i ;
for(i=0 ; i<relationlength ; i++)
{
if(relation[i].fathernumber != 0)
{
break ;
}
}
behind = i ;
i = 1 ;//用于记录列表在panel中的行位置
int j = 0 ; //用于记录列表在panel中的列位置
while(front-behind != 0)
{
for(int jj=front ; jj<behind ; jj++)
{//根据第几列来确定其在panel中的位置
int temp = relation[jj].childnumber ;
int ii = 0 ;
for(ii=0 ; ii<jj ; ii++)
{//用于判断该节点是否在之前已经被设定了
if(temp == relation[ii].childnumber)
{
break ;
}
}
if(ii == jj)
{//该节点没有在之前被设定
tablelist[temp].setBounds(i*150,j,100,17*tablelist[temp].getItemCount()) ;
j = j + 17*tablelist[temp].getItemCount() + 50 ;
}
}
int jj ;
for(jj=behind ; jj<relationlength ; jj++)
{//用于确定下一列的列值位置
int k ;
for(k=front ; k<behind ; k++)
{//用于确定下一列的父结点是否是上一列的孩子结点
if(relation[jj].fathernumber == relation[k].childnumber)
{
break ;
}
}
if(k == behind)
{//下一列的父结点不是上一列的孩子结点
break ;
}
}
front = behind ;//确定下一列的第一个元素
behind = jj ;//确定下一列的最后一个元素
j=0 ;//将列值初值置0
i ++ ;//将行增量加1
}
for(int kk=0 ; kk<tablelength ; kk++)
{
this.add(tablelist[kk]) ;
}
//绘制直线
int temp = 0 ;
int samefather = 0 ;
for(int ii=0 ; ii<relationlength ; ii++)
{
Point start = new Point() ;
Point end = new Point() ;
int kk ;
for(kk=0 ; kk<ii ;kk++)
{//判断当前的表是否在之前出现
if(relation[ii].childnumber == relation[kk].childnumber)
{
break ;
}
}
if(kk == ii)
{//没有出现
if(relation[ii].fathernumber == 0)
{
start.x = 0 ;
start.y = 0 ;
}
else
{
tablelist[relation[ii].fathernumber].getLocation(start) ;
}
tablelist[relation[ii].childnumber].getLocation(end) ;
start.x += 100 ;
g.drawLine(start.x,start.y,end.x,end.y) ;
}
else
{//出现
if(samefather != relation[ii].fathernumber)
{
temp = 0 ;
samefather = relation[ii].fathernumber ;
}
tablelist[relation[ii].fathernumber].getLocation(start) ;
start.x = start.x + 100 ;
start.y += tablelist[relation[ii].fathernumber].getItemCount()*17 ;
end.x = start.x + 40 ;
end.y = start.y + 50*temp ;
temp ++ ;
g.drawLine(start.x, start.y, end.x, end.y) ;
g.drawString("I"+relation[ii].childnumber, end.x+4, end.y+5) ;
}
if(start.y < end.y)
{
start.x = (start.x+end.x)/2 ;
start.y = (start.y+end.y)/2 - 8 ;
}
else
{
start.x = (start.x+end.x)/2 -4 ;
start.y = (start.y+end.y)/2 -4 ;
}
g.drawString(""+relation[ii].condition,start.x , start.y) ;
}
}
else
{
allowed = true ;
}
}
}