/*
 * ShowTextCustomizer.java    1.0 97/08/28
 *
 * Copyright (c) 1997 Netscape Communications Corporation
 *
 * Netscape grants you a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Netscape.
 *
 * This software is provided "AS IS," without a warranty of any kind.
 * See the CDK License Agreement for additional terms and conditions.
 */

import java.beans.*;
import java.awt.*;
import java.awt.event.*;

public class ShowTextCustomizer extends Panel implements Customizer, KeyListener {

    private ShowTextCustom target;
    private TextField textField;
    public Font textFont = new Font("TimesRoman",Font.ITALIC | Font.BOLD,26);
    public Color textColor = new Color(80,80,180);
    public Color backgroundColor = new Color(200,200,255);

    public ShowTextCustomizer() {
        setBackground(backgroundColor);
    	setLayout(null);
    }

    public void setObject(Object obj) {
    	target = (ShowTextCustom) obj;

    	Label textLabel = new Label("Caption:", Label.RIGHT);
    	add(textLabel);
    	textLabel.setBounds(10, 45, 60, 30);

        Label previewLabel = new Label("Preview:", Label.LEFT);
    	add(previewLabel);
    	previewLabel.setBounds(10, 85, 60, 30);

    	textField = new TextField(target.getMessage(), 20);
    	add(textField);
    	textField.setBounds(80, 45, 100, 30);

	    textField.addKeyListener(this);
    }

    public void paint(Graphics g) {
        g.setFont(textFont);
        g.setColor(textColor);
        g.drawString("ShowText Customizer",20,30);

        g.setColor(Color.gray);
    	g.drawString(textField.getText(),23, 145);
        g.setColor(Color.black);
    	g.drawString(textField.getText(),20, 140);
    }

    public Dimension getPreferredSize() {
    	return new Dimension(300, 175);
    }

    public void keyTyped(KeyEvent e) {
        repaint();
    }

    public void keyPressed(KeyEvent e) {
        repaint();
    }

    public void keyReleased(KeyEvent e) {
    	String txt = textField.getText();
    	target.setMessage(txt);
    	support.firePropertyChange("", null, null);
    }

    /**
     * Old method used only for older layout managers
     */
    public Dimension preferredSize() {
	    return getPreferredSize();
    }


    //////////////////////////////////////////////////////
    //
    // Additional Methods for supporting Adding and
    // Removing listeners
    //
    public void addPropertyChangeListener(PropertyChangeListener listener) {
	    support.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
    	support.removePropertyChangeListener(listener);
    }

    private PropertyChangeSupport support = new PropertyChangeSupport(this);

}
