import java.awt.Color;
import javax.swing.JFrame;
public class UKPedestrainLightOrig extends StandardTrafficLightOrig{
protected SuspendableThread newflashingGreenThread=null;
private boolean modiFlag=false;
public UKPedestrainLightOrig(final int[] waits,int xbRA_loc,int ybRA_loc){
super(xbRA_loc,ybRA_loc);
setWaits(waits);
if(xbRA_loc<ybRA_loc) modiFlag=true;
}
public UKPedestrainLightOrig(final int r_w,final int g_w,final int fg_w,int xbRA_loc,int ybRA_loc){
this(new int[]{r_w,g_w,fg_w},xbRA_loc,ybRA_loc);
}
public void sequenceTo(final Color colour){
do{
if(currentState==Color.red){
for(int i=0;i<redToGreenDelay*2;i++){
WaitAWhile.tenths(redToGreenDelay*10/8);
setGreen(50/redToGreenDelay);
}
upper.initRect();
setGreen();
}else if(currentState==Color.green){
for(int i=0;i<greenToAmberDelay*2;i++){
WaitAWhile.tenths(greenToAmberDelay*10/8);
setGreen(50/greenToAmberDelay);
}
upper.initRect();
setAmber();
setFlashing();
}else if(currentState==Color.yellow){
WaitAWhile.seconds(amberToRedDelay);
unsetFlashing();
setRed();
}else{
}
}while(colour!=currentState);
}
protected void setGreen(int greenDelay){
if(modiFlag==false)
upper.on(currentState,greenDelay,0);
else
upper.on(currentState,0,greenDelay);
}
protected void setFlashing(){
newflashingGreenThread=new SuspendableThread(){
public void run(){
while(true){
if(!checkState())break;
setAmber();
if(!checkState())break;
WaitAWhile.tenths(5);
if(!checkState())break;
upper.off();
if(!checkState())break;
WaitAWhile.tenths(5);
}
}
};
newflashingGreenThread.start();
}
protected void unsetFlashing(){
if(newflashingGreenThread!=null){
newflashingGreenThread.setState(SuspendableThread.STOPPED);
newflashingGreenThread=null;
}
}
public static void main(final String[]args){
JFrame f=new JFrame("TestRectLight");
final UKPedestrainLightOrig li=new UKPedestrainLightOrig(4,4,3,101,36);
final UKPedestrainLightOrig lii=new UKPedestrainLightOrig(3,4,4,36,101);
f.add(li);
f.add(lii);
f.pack();
f.setSize(400,400);
f.setVisible(true);
SuspendableThread lightRunThread=new SuspendableThread(){
public void run(){
while(true){
synchronized(this){
li.sequence();
lii.sequence();
}
}
}
};
lightRunThread.start();
/* finally{
lightThread.setState(SuspendableThread.STOPPED);
lightThread=null;
}*/
}
}