FileDocCategorySizeDatePackage
YesNoDialogCustomizer.javaAPI DocExample4628Mon Sep 22 13:30:32 BST 1997oreilly.beans.yesno

YesNoDialogCustomizer

public class YesNoDialogCustomizer extends Panel implements TextListener, Customizer
This class is a customizer for the YesNoDialog bean. It displays a TextArea and three TextFields where the user can enter the dialog message and the labels for each of the three buttons. It does not allow the dialog title or other resources to be set.

Fields Summary
protected YesNoDialog
bean
protected TextComponent
message
protected TextComponent[]
fields
protected PropertyChangeSupport
listeners
Constructors Summary
Methods Summary
public voidaddPropertyChangeListener(java.beans.PropertyChangeListener l)

      
    listeners.addPropertyChangeListener(l);
  
public java.awt.InsetsgetInsets()

 return new Insets(10, 10, 10, 10); 
public voidremovePropertyChangeListener(java.beans.PropertyChangeListener l)

    listeners.removePropertyChangeListener(l);
  
public voidsetObject(java.lang.Object o)

    bean = (YesNoDialog)o;   // save the object we're customizing

    // Put a label at the top of the panel.
    this.setLayout(new BorderLayout());
    this.add(new Label("Enter the message to appear in the dialog:"), "North");

    // And a big text area below it for entering the dialog message.
    message = new TextArea(bean.getMessage());
    message.addTextListener(this);
    // TextAreas don't know how big they want to be.  You must tell them.
    message.setSize(400, 200);
    this.add(message, "Center");

    // Then add a row of textfields for entering the button labels.
    Panel buttonbox = new Panel();                     // The row container
    buttonbox.setLayout(new GridLayout(1, 0, 25, 10)); // Equally spaced items
    this.add(buttonbox, "South");                      // Put row on bottom

    // Now go create three TextFields to put in this row.  But actually
    // position a Label above each, so create an container for each
    // TextField+Label combination.
    fields = new TextComponent[3];           // Array of TextFields.
    String[] labels = new String[] {         // Labels for each.
      "Yes Button Label", "No Button Label", "Cancel Button Label"};
    String[] values = new String[] {         // Initial values of each.
      bean.getYesLabel(), bean.getNoLabel(), bean.getCancelLabel()};
    for(int i = 0; i < 3; i++) {
      Panel p = new Panel();                 // Create a container.
      p.setLayout(new BorderLayout());       // Give it a BorderLayout.
      p.add(new Label(labels[i]), "North");  // Put a label on the top.
      fields[i] = new TextField(values[i]);  // Create the text field.
      p.add(fields[i], "Center");            // Put it below the label.
      fields[i].addTextListener(this);       // Set the event listener.
      buttonbox.add(p);                      // Add container to row.
    }
  
public voidtextValueChanged(java.awt.event.TextEvent e)

    TextComponent t = (TextComponent)e.getSource();
    String s = t.getText();
    if (t == message) bean.setMessage(s);
    else if (t == fields[0]) bean.setYesLabel(s);
    else if (t == fields[1]) bean.setNoLabel(s);
    else if (t == fields[2]) bean.setCancelLabel(s);
    listeners.firePropertyChange(null, null, null);