FileDocCategorySizeDatePackage
YesNoPanelCustomizer.javaAPI DocExample4997Sat Jan 24 10:44:38 GMT 2004je3.beans

YesNoPanelCustomizer

public class YesNoPanelCustomizer extends JComponent implements DocumentListener, Customizer
This class is a customizer for the YesNoPanel bean. It displays a JTextArea and three JTextFields where the user can enter the main message and the labels for each of the three buttons. It does not allow the alignment property to be set.

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

        
	listeners.addPropertyChangeListener(l);
    
public voidchangedUpdate(javax.swing.event.DocumentEvent e)

 update(e); 
public java.awt.InsetsgetInsets()

 return new Insets(10, 10, 10, 10); 
public voidinsertUpdate(javax.swing.event.DocumentEvent e)

 update(e); 
public voidremovePropertyChangeListener(java.beans.PropertyChangeListener l)

	listeners.removePropertyChangeListener(l);
    
public voidremoveUpdate(javax.swing.event.DocumentEvent e)

 update(e); 
public voidsetObject(java.lang.Object o)

	bean = (YesNoPanel)o;   // save the object we're customizing
	
	// Put a label at the top of the panel.
	this.setLayout(new BorderLayout());
	this.add(new JLabel("Enter the message to appear in the panel:"),
		 BorderLayout.NORTH);
	
	// And a big text area below it for entering the message.
	message = new JTextArea(bean.getMessageText(), 5, 35);
	message.getDocument().addDocumentListener(this);
	this.add(new JScrollPane(message), "Center");
	
	// Then add a row of textfields for entering the button labels.
	JPanel buttonbox = new JPanel();                   // The row container
	buttonbox.setLayout(new GridLayout(1, 0, 25, 10)); // Equally spaced
	this.add(buttonbox, BorderLayout.SOUTH);           // Put row on bottom
	
	// Now go create three JTextFields to put in this row.  But actually
	// position a JLabel above each, so create an container for each
	// JTextField+JLabel combination.
	fields = new JTextField[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++) {
	    JPanel p = new JPanel();               // Create a container.
	    p.setLayout(new BorderLayout());       // Give it a BorderLayout.
	    p.add(new JLabel(labels[i]), "North"); // Put a label on the top.
	    fields[i] = new JTextField(values[i]); // Create the text field.
	    p.add(fields[i], "Center");            // Put it below the label.
	    buttonbox.add(p);                      // Add container to row.
	    // register listener for the JTextField
	    fields[i].getDocument().addDocumentListener(this);
	}
    
voidupdate(javax.swing.event.DocumentEvent e)

	Document doc = e.getDocument();     // What document was updated?
	if (doc == message.getDocument())   
	    bean.setMessageText(message.getText());
	else if (doc == fields[0].getDocument())
	    bean.setYesLabel(fields[0].getText());
	else if (doc == fields[1].getDocument())
	    bean.setNoLabel(fields[1].getText());
	else if (doc == fields[2].getDocument())
	    bean.setCancelLabel(fields[2].getText());
	listeners.firePropertyChange(null, null, null);