//******************************************************************************
// Copy right : Tips 17/11/1997 //
//******************************************************************************
//******************************************************************************
// CContainerPage.java //
//******************************************************************************
import java.awt.* ;
import java.awt.event.* ;
class CContainerPage extends Panel
{
private int m_nCount ;
CardLayout m_cardLayout;
boolean isShow = true;
int m_iOrientation = 0 ;
int m_iPageClicked = 0 ;
class MyMouseAdapter extends MouseAdapter
{
public void mousePressed(MouseEvent e)
{
int nCount = getComponentCount();
Rectangle rect = getBounds() ;
Color clr = getBackground() ;
Point pt = e.getPoint() ;
System.out.println("ort="+m_iOrientation) ;
switch(m_iOrientation)
{
case 2 :
{
int cellHeight = rect.height/nCount ;
int yOrg = 0 ;
for(int i = 0; i < nCount ; i++)
{
Component c = getComponent(i) ;
Rectangle boundRect = new Rectangle(0, yOrg + i*cellHeight,48,cellHeight-2) ;
if(boundRect.contains(pt))
{
if(i==m_iPageClicked)
return ;
m_iPageClicked = i ;
break ;
}
}
break ;
}
case 3 :
{
int cellWidth = rect.width/nCount ;
int xOrg = 0 ;
for(int i = 0; i < nCount ; i++)
{
Component c = getComponent(i) ;
Rectangle boundRect = new Rectangle(xOrg + i*cellWidth,rect.height-48,cellWidth-2,48) ;
if(boundRect.contains(pt))
{
if(i==m_iPageClicked) return ;
m_iPageClicked = i ; break ;
}
} break ;
}
case 0 :
{
int cellWidth = rect.width/nCount ;
int xOrg = 0 ;
for(int i = 0; i < nCount ; i++)
{
Component c = getComponent(i) ;
Rectangle boundRect = new Rectangle(xOrg + i*cellWidth, 0,cellWidth-2,48) ;
if(boundRect.contains(pt))
{
if(i==m_iPageClicked)
return ;
m_iPageClicked = i ;
break ;
}
}
break ;
}
case 1 :
{
int cellHeight = rect.height/nCount ;
int yOrg = 0 ;
for(int i = 0; i < nCount ; i++)
{
Component c = getComponent(i) ;
Rectangle boundRect = new Rectangle(rect.width-50, yOrg + i*cellHeight,48,cellHeight-2) ;
if(boundRect.contains(pt))
{
if(i==m_iPageClicked) return ;
m_iPageClicked = i ;
break ;
}
}
break ;
}
}
System.out.println("Activating the page") ;
Component comp = getComponent(m_iPageClicked);
vActivatePage((CPropPage)comp) ;
}
}
public CContainerPage()
{
super() ;
setLayout(m_cardLayout = new CardLayout());
addMouseListener(new MyMouseAdapter()) ;
}
public void vSetPage(CPropPage page)
{
Rectangle rect = getBounds();
switch(m_iOrientation)
{
case 0 : page.fixSize(3,50,rect.width-5,rect.height-50) ;
page.setBounds(3,50,rect.width-5,rect.height-50); break ;
case 1 :
page.fixSize(3,3,rect.width - 50,rect.height-5) ;
page.setBounds(3,3,rect.width - 50,rect.height-5);
break ;
case 2 :
page.fixSize(50,3,rect.width-50,rect.height-6) ;
page.setBounds(50,3,rect.width-50,rect.height-6);
break ;
case 3 :
page.fixSize(3,3,rect.width-3,rect.height-50) ;
page.setBounds(3,3,rect.width-3,rect.height-50);
break ;
}
String str = page.GetTitle() ;
System.out.println(str) ;
add(page,str) ;
m_cardLayout.addLayoutComponent(page,str);
}
public void vSetOrientation(int iOrient)
{
m_iOrientation = iOrient ;
}
public void vDeletePage(CPropPage page)
{ }
public void vDrawPage(Graphics g)
{
int nCount = getComponentCount();
Rectangle rect = getBounds() ;
Color clr = getBackground() ;
String pageTitle ;
switch(m_iOrientation)
{
case 2 :
{
int cellHeight = rect.height/nCount ;
int yOrg = 0 ;
for(int i = 0; i < nCount ; i++)
{
Component c = getComponent(i) ;
pageTitle = ((CPropPage)c).GetTitle() ;
g.setColor(c.getBackground()) ;
if(i==m_iPageClicked)
{
g.fillRect(3, yOrg + i*cellHeight+3,48,cellHeight-4) ;
}
else
{
g.fillRect(3, yOrg + i*cellHeight+3,48,cellHeight-3) ;
g.setColor(Color.black) ;
g.drawRect(3, yOrg + i*cellHeight+3,46,cellHeight-4) ;
}
g.setColor(Color.black) ;
g.drawString(pageTitle,5,yOrg + i*cellHeight + cellHeight/2) ;
}
break ;
}
case 3 :
{
int cellWidth = rect.width/nCount ;
int xOrg = 0 ;
for(int i = 0; i < nCount ; i++)
{
Component c = getComponent(i) ;
pageTitle = ((CPropPage)c).GetTitle() ;
g.setColor(c.getBackground()) ;
if(i==m_iPageClicked)
{
g.fillRect(xOrg + i*cellWidth+2,rect.height-48,cellWidth-2,46) ;
}
else
{
g.fillRect(xOrg + i*cellWidth+2,rect.height-48,cellWidth-2,46) ;
g.setColor(Color.black) ;
g.drawRect(xOrg + i*cellWidth+2,rect.height-47,cellWidth-3,45) ;
}
g.setColor(Color.black) ;
g.drawString(pageTitle,xOrg + i*cellWidth+4,rect.height-25) ;
}
break ;
}
case 0 :
{
int cellWidth = rect.width/nCount ;
int xOrg = 0 ;
for(int i = 0; i < nCount ; i++)
{
Component c = getComponent(i) ;
pageTitle = ((CPropPage)c).GetTitle() ;
g.setColor(c.getBackground()) ;
if(i==m_iPageClicked)
{
g.fillRect(xOrg + i*cellWidth+2, 3,cellWidth-4,50) ;
}
else
{
g.fillRect(xOrg + i*cellWidth, 0,cellWidth-2,48) ;
g.setColor(Color.black) ;
g.drawRect(xOrg + i*cellWidth+1, 3,cellWidth-3,47) ;
}
g.setColor(Color.black) ;
g.drawString(pageTitle,xOrg + i*cellWidth+3,25) ;
}
break ;
}
case 1 :
{
int cellHeight = rect.height/nCount ;
int yOrg = 0 ;
for(int i = 0; i < nCount ; i++)
{
Component c = getComponent(i) ;
pageTitle = ((CPropPage)c).GetTitle() ;
g.setColor(c.getBackground()) ;
if(i==m_iPageClicked)
{
g.fillRect(rect.width-50, yOrg + i*cellHeight+4,48,cellHeight-4) ;
}
else
{
g.fillRect(rect.width-48, yOrg + i*cellHeight+4,48,cellHeight-4) ;
g.setColor(Color.black) ;
g.drawRect(rect.width-47, yOrg + i*cellHeight+5,48,cellHeight-5) ;
}
g.setColor(Color.black) ;
g.drawString(pageTitle,rect.width-46,yOrg + i*cellHeight+cellHeight/2) ;
}
break ;
}
}
setBackground(Color.white);
}
public void paint(Graphics g)
{
Color clr = g.getColor() ;
Rectangle rect = getBounds() ;
g.setColor(Color.black) ;
g.drawRect(1,1,rect.width-3,rect.height-3) ;
// g.setColor(Color.darkGray) ;
// g.drawRect(2,2,rect.width-2,rect.height-3) ;
// g.setColor(Color.white) ;
// g.drawRect(3,3,rect.width-3,rect.height-4) ;
g.setColor(Color.black) ;
vDrawPage(g) ; }
public void vActivatePage(CPropPage page)
{
m_cardLayout.show(this,page.GetTitle()) ; repaint() ;
}
}