//[skeleton1.
import java.io.*;

/**
 * An encapsulation of a word in a document
 *
 * This is used in an example of event bubbling
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class Word extends AbstractDocumentElement
{
    private Paragraph            parent;    
    private String               style, text;


    /**
     * Explicit Value Constructor
     *
     * @param text   The text of the word
     */
    public Word(String text)
    {
       super();       
       this.text = text;
       style     = null;       
       parent    = null;        
    }


    
    /**
     * Get the parent of this EventHandler
     *
     * @return  The parent
     */
    public EventHandler getParent()
    {
       return parent;       
    }
//]skeleton1.
    

//[handleStyleChange.

    /**
     * Handle a font style change event
     *
     * @param style    The new font style (e.g., Italic)
     */
    protected boolean handleStyleChange(String style)
    {
	this.style = style;
        return true;        
    }
//]handleStyleChange.

//[skeleton2.

    /**
     * Set the parent of this Word
     *
     * Note: In this example, a Word must be in a Paragraph.
     * This could be relaxed.
     */
    public void setParent(Paragraph p)
    {
       parent = p;       
    }
//]skeleton2.
    


    /**
     * Print this Word
     *
     * @param out   The PrintStream to use
     */
    public void print(PrintStream  out)
    {
	out.println("[Style: "+style+"]\t"+ text + " ");
    }

//[skeleton3.
}
//]skeleton3.
