package org.greenstone.applet.GsdlCollageApplet;

import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;
import java.util.*;

/** 
 *  @author Katrina Edgar */
public class Display extends Thread {
    
    GsdlCollageApplet app_ = null;

     public Display(GsdlCollageApplet app) {
	super("Display");
	app_ = app;

	System.err.println("@@@@ Someone called new Display()");
	
    }

    // Do we even use this class? If so, maybe a separate stopRunning() method is better
    // As I'm not sure if there needs to be synchronisation done around app_.isStopping()?    
    /** Runs display thread by repeatedly calling the next frame,
     *  waiting for a specified delay period between calls */
    public void run() {
	try {

	    System.err.println("Started display thread.");

	    Thread curr_thread = Thread.currentThread();
	    
	    while (!app_.isStopping() && curr_thread == this) {
		app_.repaint();
		// can't make it zero or it hogs the whole processor
		Thread.sleep(100);
		curr_thread = Thread.currentThread();
	    }

	    if(app_.isStopping() && app_.verbosity() >= 3) {
		System.err.println("*** Display.run() thread has been told to stop.");
	    }
	    System.err.println("Stopped display thread.");
	    
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }
}
