DEF_COMPONENTNAME
LEDClock
DEF_SUPERCLASS
Panel
DEF_SUPERCOMPONENT
Object
DEF_PACKAGE
plugins
time
DEF_ENDLIST
DEF_SUBCOMPONENTLIST
DEF_ENDLIST
DEF_SUBCOMPONENTCLASSLIST
DEF_ENDLIST
DEF_CATEGORY
Time
DEF_BITMAP
ledm.bmp
DEF_THUMBNAIL_UP
dclock.bmp
DEF_THUMBNAIL_DOWN
2-dclock.bmp
DEF_VISUAL
DEF_TOOL
DEF_PANEL
DEF_IMPORTS
java.util.Date
DEF_ENDLIST
DEF_REQUIRES
DEF_ENDLIST
DEF_IMPLEMENTS
Runnable
DEF_ENDLIST
DEF_DECLARATION
// Makes Led clock component.
// Written 6/26/96 by Tony Hartzler
// Declarations.

Thread my_thread;

int width;
int height;

Date current_time;

protected Color bgColor;
protected Color fgColor;
protected boolean military;

protected int x_points[];
protected int y_points[];

protected int dx=5;
protected int dy=10;

protected int digits[][] =
{
  {1,1,1,1,1,1,0},
  {0,0,0,0,1,1,0},
  {1,0,1,1,0,1,1},
  {1,0,0,1,1,1,1},
  {0,1,0,0,1,1,1},
  {1,1,0,1,1,0,1},
  {1,1,1,1,1,0,1},
  {1,0,0,0,1,1,0},
  {1,1,1,1,1,1,1},
  {1,1,0,1,1,1,1},
};
DEF_ENDLIST
DEF_METHOD
void initialize ()
{
   // local variables

   // method body
  x_points = new int[6];
  y_points = new int[6];
  current_time = new Date();
  set_defaults();
  start();
}
DEF_ENDLIST
DEF_METHOD
public void set_defaults ()
{
   // local variables

   // method body
  width = size().width;
  height = size().height;
}
DEF_ENDLIST
DEF_METHOD
public void start ()
{
   // local variables

   // method body
  if (my_thread == null)
    {
	my_thread = new Thread(this);
 	my_thread.start();
   }
}
DEF_ENDLIST
DEF_METHOD
public void stop ()
{
   // local variables

   // method body
  my_thread.stop();
  my_thread = null;
}
DEF_ENDLIST
DEF_METHOD
public void run ()
{
   // local variables

   // method body
  while (my_thread != null)
    {
	repaint();
	try
	{
	  Thread.sleep(1000);
	}
   	catch (InterruptedException e)
	  {
	  }
    } //while
}
DEF_ENDLIST
DEF_METHOD
public void update(Graphics g)
{
   // local variables
   // method body
  g.setColor(bgColor);
  g.fillRect(0,0,width,height);

  current_time = new Date();
  
  int hours = current_time.getHours();
  int minutes = current_time.getMinutes();
  int seconds = current_time.getSeconds();

  if (military == false && hours > 12)
    hours -= 12;

  if (military == false && hours == 0)
	hours = 12;

  String time;
  if (hours < 10)
 	time = "0" + hours;
  else
	time = "" + hours;

  if (minutes < 10)
 	time += ":0" + minutes;
  else
	time += ":" + minutes;

  if (seconds < 10)
 	time += ":0" + seconds;
  else
	time += ":" + seconds;

  g.setColor(fgColor);
  draw_string(time,0,height,width,height,g);  
}
DEF_ENDLIST
DEF_METHOD
public void paint (Graphics g)
{
   // local variables

   // method body
  set_defaults();
  update(g);
}
DEF_ENDLIST
DEF_METHOD
public void draw_string (String string, int x, int y, int w, int h, Graphics g)
{
   // local variables
  int string_length = string.length();
  char char_array[] = new char[string_length];
  string.getChars(0,string_length, char_array,0);
   // method body

 w /= string_length;

  int char_width = (w*7) /8;
  int char_height=(h*7)/8;

  for (int i=0; i<string_length; i++)
    {
 	draw_char(char_array[i], x, y, char_width, char_height,g);
    	x += w;
   }
}
DEF_ENDLIST
DEF_METHOD
private void draw_char (char c, int x, int y, int w, int h, Graphics g)
{
   // local variables

   // method body
  switch(c)
 	{
	  case ':':
	  	g.fillRect(x+2*w/dx, y-(h)/4, w/dx, h/dy);
		g.fillRect(x+2*w/dx, y-(h*3)/4, w/dx, h/dy);
		break;
	  default:
		int index = Character.digit(c, 10);
		for (int i=0; i < 7; i++)
		  if (digits[index][i] == 1)
		    switch (i)
			{
			  case 0: top (x,y-h,w,h/dy,g);break;
			  case 1: left (x,y-h/2,w/dx,h/2,g);break;
			  case 2: left (x,y,w/dx,h/2,g);break;
			  case 3: bottom(x,y,w,h/dy,g);break;
			  case 4: right(x+w,y,w/dx,h/2,g);break;
			  case 5: right(x+w,y-h/2,w/dx,h/2,g);break;
			  case 6: middle(x,y-h/2,w,h/dy,g);break;
			}  
	}
}
DEF_ENDLIST
DEF_METHOD
private void top (int x, int y, int w, int h, Graphics g)
{
   // local variables

   // method body
   x_points[0] = x;
   x_points[1] = x+w;
   x_points[2]=x+(w*7)/8;
   x_points[3] = x+(w/8);
   y_points[0] = y;
   y_points[1] = y;
   y_points[2] = y+h;
   y_points[3] = y+h;
   g.fillPolygon(x_points, y_points,4);

}
DEF_ENDLIST
DEF_METHOD
public void middle (int x, int y, int w, int h, Graphics g)
{
   // local variables

   // method body
   x_points[0] = x;
   x_points[1] = x+(w)/8;
   x_points[2]=x+(w*7)/8;
   x_points[3] = x+w;
   x_points[4] = x+(w*7)/8;
   x_points[5] = x+(w)/8;
   y_points[0] = y;
   y_points[1] = y-h/2;
   y_points[2] = y-h/2;
   y_points[3] = y;
   y_points[4] = y+h/2;
   y_points[5] = y+h/2;
   g.fillPolygon(x_points, y_points,6);

}
DEF_ENDLIST
DEF_METHOD
private void bottom (int x, int y, int w, int h, Graphics g)
{
   // local variables

   // method body
   x_points[0] = x;
   x_points[1] = x+w;
   x_points[2]=x+(w*7)/8;
   x_points[3] = x+(w)/8;
   y_points[0] = y;
   y_points[1] = y;
   y_points[2] = y-h;
   y_points[3] = y-h;
   g.fillPolygon(x_points, y_points, 4);
}
DEF_ENDLIST
DEF_METHOD
private void left (int x, int y, int w, int h, Graphics g)
{
   // local variables

   // method body
   x_points[0] = x;
   x_points[1] = x;
   x_points[2] = x+w;
   x_points[3] = x+w;
   y_points[0] = y;
   y_points[1] = y-h;
   y_points[2] = y-(h*7)/8;
   y_points[3] = y-(h)/8;
   g.fillPolygon(x_points, y_points, 4);
}
DEF_ENDLIST
DEF_METHOD
private void right (int x, int y, int w, int h, Graphics g)
{
   // local variables

   // method body
   x_points[0] = x;
   x_points[1] = x;
   x_points[2] = x-w;
   x_points[3] = x-w;
   y_points[0] = y;
   y_points[1] = y-h;
   y_points[2] = y-(h*7)/8;
   y_points[3] = y-(h)/8;
   g.fillPolygon(x_points, y_points, 4);
}
DEF_ENDLIST
DEF_METHOD
public void setFGColor (Color aParam)
{
   // local variables

   // method body
   fgColor = aParam;
}
DEF_ENDLIST
DEF_METHOD
public Color getFGColor ()
{
   // local variables

   // method body
   return fgColor;
}
DEF_ENDLIST
DEF_METHOD
public void setBGColor (Color aParam)
{
   // local variables

   // method body
   bgColor = aParam;
}
DEF_ENDLIST
DEF_METHOD
public Color getBGColor ()
{
   // local variables

   // method body
   return bgColor;
}
DEF_ENDLIST
DEF_METHOD
public void setMilitary (boolean aParam)
{
   // local variables

   // method body
   military = aParam;
}
DEF_ENDLIST
DEF_METHOD
public boolean getMilitary ()
{
   // local variables

   // method body
   return military;
}
DEF_ENDLIST
DEF_PROPERTY
Foreground Color
Color
setFGColor(AVALUE);
AVALUE=getFGColor();
Color.green
DEF_ENDLIST
DEF_PROPERTY
Background Color
Color
setBGColor(AVALUE);
AVALUE=getBGColor();
Color.black
DEF_ENDLIST
DEF_PROPERTY
Military Time
boolean
setMilitary(AVALUE);
AVALUE=getMilitary();
true
DEF_ENDLIST
DEF_PROPERTY
Top
int
move(bounds().x, AVALUE);
AVALUE = bounds().y;
70
DEF_ENDLIST
DEF_PROPERTY
Left
int
move(AVALUE, bounds().y);
AVALUE = bounds().x;
130
DEF_ENDLIST
DEF_PROPERTY
Height
int
resize(bounds().width, AVALUE);
AVALUE = bounds().height;
50
DEF_ENDLIST
DEF_PROPERTY
Width
int
resize(AVALUE, bounds().height);
AVALUE = bounds().width;
165
DEF_ENDLIST
DEF_ENDCOMPONENT
