package W3C.PICS;

import java.awt.*;
import java.util.*;
/**
 *  The dialog box for displaying the content of a single label
 * @see W3C.PICS.SingleLabel
 */
public class SingleLabelDialog extends Dialog {

    public SingleLabelDialog(Frame parent,SingleLabel SL) {

	    super(parent, "Label", true);

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

	    //{{INIT_CONTROLS
        addNotify();
        resize(insets().left + insets().right + 477, insets().top + insets().bottom + 318);
        rlist=new List();
        add(rlist);
        rlist.reshape(insets().left + 110,insets().top + 66,248,88);
        label1=new Label("By", Label.RIGHT);
        add(label1);
        label1.reshape(insets().left + 36,insets().top + 8,90,16);
        label2=new Label("For", Label.RIGHT);
        add(label2);
        label2.reshape(insets().left + 36,insets().top + 32,90,16);
        ByLabel=new Label("");
        add(ByLabel);
        ByLabel.reshape(insets().left + 144,insets().top + 8,252,16);
        ForLabel=new Label("");
        add(ForLabel);
        ForLabel.reshape(insets().left + 144,insets().top + 32,252,16);
        OKButton=new Button("OK");
        add(OKButton);
        OKButton.reshape(insets().left + 180,insets().top + 244,117,32);
//        plabel=new Label("");
//        add(plabel);
//        plabel.reshape(insets().left + 32,insets().top + 170,420,66);
        //}}
        pmlabel=new MultiLineLabel(s,MultiLineLabel.CENTER);
        add(pmlabel);
        pmlabel.reshape(insets().left + 32,insets().top + 170,420,66);


        ByLabel.setText(SL.getBy());
        ForLabel.setText(SL.getFor());

        Vector ratinglist=SL.getRatingList();
        for (int j=0;j<ratinglist.size();j++)
         {
            rlist.addItem(((Rating)ratinglist.elementAt(j)).getListString());
         }
        rlist.setFont(new Font("Courier",Font.PLAIN,13));

    	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.ACTION_EVENT && event.target == OKButton) {
    	    	clickedOKButton();
    	    	return true;
    	}
    	else

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

    //{{DECLARE_CONTROLS
    List rlist;
    Label label1;
    Label label2;
    Label ByLabel;
    Label ForLabel;
    Button OKButton;
    Label plabel;
    //}}
    MultiLineLabel pmlabel;

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

    }
}


