package W3C.PICS;
import java.awt.*;
import java.util.StringTokenizer;
/**
 * The dialog box displaying the information of a rating service
 */

class ServiceInfoBox extends Dialog {

//    public ServiceInfoBox(Frame parent,String name,String description,String ratingsystem,String ratingservice) {

    public ServiceInfoBox(Frame parent,String name,String description,String ratingsystem,String ratingservice) {

	    super(parent, "Rating Service Info", true);

        //Break the string into lines
        String s="";
        StringTokenizer st=new StringTokenizer(description," ");
        int i=1;
        int line=50;
        while (st.hasMoreTokens())
        {
         if (s.length()>i*line)
           { s+="\n";
             i++;
           }
          s+=st.nextToken()+ " ";
        }

	    description=s;
	    //{{INIT_CONTROLS
        setLayout(null);
        addNotify();
        resize(insets().left + insets().right + 500, insets().top + insets().bottom + 245);
        ratingsystemlabel=new Label("Rating System", Label.RIGHT);
        ratingsystemlabel.setFont(new Font("Dialog",Font.PLAIN,10));
        add(ratingsystemlabel);
        ratingsystemlabel.reshape(insets().left + 15,insets().top + 136,105,20);
        ratingservicelabel=new Label("Rating Service", Label.RIGHT);
        ratingservicelabel.setFont(new Font("Dialog",Font.PLAIN,10));
        add(ratingservicelabel);
        ratingservicelabel.reshape(insets().left + 15,insets().top + 156,105,20);
        ratingsystemfield=new Label(ratingsystem);
        add(ratingsystemfield);
        ratingsystemfield.reshape(insets().left + 138,insets().top + 136,312,13);
        ratingservicefield=new Label(ratingservice);
        add(ratingservicefield);
        ratingservicefield.reshape(insets().left + 138,insets().top + 156,312,13);
        namefield=new Label(name, Label.CENTER);
        add(namefield);
        namefield.reshape(insets().left + 18,insets().top + 7,420,19);
        button1=new Button("OK");
        add(button1);
        button1.reshape(insets().left + 187,insets().top + 188,78,26);
        edit1=new MultiLineLabel(description);
//        edit1.setEditable(false);
        add(edit1);
        edit1.reshape(insets().left + 20,insets().top + 33,450,100);
        //}}

       setResizable(false);
    }

    public synchronized void show() {
    	Rectangle bounds = getParent().bounds();
    	Rectangle abounds = bounds();

    	move(bounds.x + (bounds.width - abounds.width)/ 2,
    	     bounds.y + (bounds.height - abounds.height)/2);

    	super.show();
    }

    public synchronized void wakeUp() {
    	notify();
    }

    public boolean handleEvent(Event event) {

    	if (event.id == Event.WINDOW_DESTROY) {
    	    hide();
    	    return true;
    	}

    	return super.handleEvent(event);
    }

    public boolean action(Event evt, Object arg)
    {
     if (arg.equals("OK")) clickedOKButton();
        else return false;
     return true;

    }

    //{{DECLARE_CONTROLS
    Label ratingsystemlabel;
    Label ratingservicelabel;
    Label ratingsystemfield;
    Label ratingservicefield;
    Label namefield;
    Button button1;
    MultiLineLabel edit1;
    //}}

    public void clickedOKButton() {
	handleEvent(new Event(this, Event.WINDOW_DESTROY, null));
    }

}


