package examples.zac.update;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;

/**
 * Used by the ZAC-driven applet in this example.
 *
 * @author                    Copyright (c) 1998-2000 by BEA Systems, Inc.
 *                            All Rights Reserved.
 */
public class TextDialog extends Dialog implements ActionListener, WindowListener {
  
  TextArea tf;
  Button ok;
  
  public void setText(String s) {
    tf.setText(s);
  }
  
  public void appendText(String s) {
    tf.append(s);
  }
  
  public TextDialog(Frame f, String title) {
    super(f, title, false);
    GridBagLayout gb = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    setLayout(gb);
    gbc.insets = new Insets(5,5,5,5);
    
    tf = new TextArea("", 15, 15, TextArea.SCROLLBARS_BOTH);
    tf.setEditable( false);
    tf.setBackground(Color.white);
    gbc.gridx = gbc.gridy = 0;
    gbc.weightx = gbc.weighty = 1.0;
    gbc.fill = gbc.BOTH;
    gbc.gridwidth = gbc.REMAINDER;
    gbc.gridheight = gbc.RELATIVE;
    add(tf, gbc);
    gbc.gridy++;
    gbc.gridheight = gbc.REMAINDER;
    gbc.fill =gbc.HORIZONTAL;
    gbc.weighty = 0.1;
    ok = new Button("OK");
    ok.addActionListener(this);
    Panel pan = new Panel();
    pan.add(ok);
    add(pan, gbc);
    //	pack();
    setSize(400, 400);
    addWindowListener(this);
    /* front & center */
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension sz = getSize();
    Point p = new Point(0,0);
    p.x = (screen.width - sz.width)/2;
    p.y = (screen.height - sz.height)/2;
    setLocation(p);
  }
  
  public void actionPerformed(ActionEvent ev) {
    if (ev.getSource() == ok) {
      setVisible(false);
      dispose();
    }
  }
  
  /** WindowListener methods */
  public void windowActivated(WindowEvent e) {}
  public void windowClosed(WindowEvent e) {}
  public void windowClosing(WindowEvent e) {
    setVisible(false);
    dispose();
  }
  public void windowDeactivated(WindowEvent e) {}
  public void windowDeiconified(WindowEvent e) {}
  public void windowIconified(WindowEvent e) {}
  public void windowOpened(WindowEvent e) {}
}

