All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sunw.demo.misc.Voter

java.lang.Object
   |
   +----java.awt.Component
           |
           +----sunw.demo.misc.Voter

public class Voter
extends Component
A simple Java Bean that handles constrained property PropertyChange events by unconditionally vetoing or accepting all proposed changes. It can be used with the JellyBean, which fires vetoable PropertyChange events, to demonstrate constratined properties. It's easy to experiment with connecting constratined properties to Voter objects with the BeanBox. To do so programatically one would write:
 import sunw.demo.jelly.JellyBean;
 import sunw.demo.misc.Voter;
 import java.beans.*;
 public class DemoVoter
 {
   JellyBean bean = new JellyBean(); 
   Voter voter = new Voter();
   VetoableChangeAdapter adapter = new VetoableChangeAdapter();
   DemoVoter()
   {
     bean.addVetoableChangeListener(adapter);
     try {
       bean.setPriceInCents(123); 
     }
     catch (PropertyVetoException e) {
       System.err.println("Vetoed: " + e);
     }
   }
   class VetoableChangeAdapter implements VetoableChangeListener 
   {
     public void vetoableChange(PropertyChangeEvent e)
       throws PropertyVetoException
     {
       voter.vetoableChange(e);
     }
   }
   public static void main(String[] argv)
   {
     new DemoVoter();
   }
 }
 
In the example above the nested adapter calls Voter.vetoable change each time a constrained bean property is set. In this case the constrained property is "priceInCents".

See Also:
JellyBean

Constructor Index

 o Voter()
Construct a Voter that, by default, vetos all proposed PropertyChange events.

Method Index

 o getPreferredSize()
 o getVetoAll()
If true, veto all proposed changes, otherwise accept them.
 o paint(Graphics)
 o setVetoAll(boolean)
If true, veto all proposed changes, otherwise accept them.
 o vetoableChange(PropertyChangeEvent)
The PropertyChangeEvent handler method.

Constructors

 o Voter
 public Voter()
Construct a Voter that, by default, vetos all proposed PropertyChange events.

Methods

 o setVetoAll
 public void setVetoAll(boolean x)
If true, veto all proposed changes, otherwise accept them.

See Also:
getVetoAll, vetoableChange
 o getVetoAll
 public boolean getVetoAll()
If true, veto all proposed changes, otherwise accept them.

See Also:
setVetoAll
 o vetoableChange
 public void vetoableChange(PropertyChangeEvent x) throws PropertyVetoException
The PropertyChangeEvent handler method. By default this method throws a PropertyVetoException, which vetos the proposed change defined by the PropertyChangeEvent.

Throws: PropertyVetoException
if the vetoAll is true
See Also:
setVetoAll
 o getPreferredSize
 public Dimension getPreferredSize()
Overrides:
getPreferredSize in class Component
 o paint
 public void paint(Graphics g)
Overrides:
paint in class Component

All Packages  Class Hierarchy  This Package  Previous  Next  Index