sunw.demo.misc
Class Voter

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

public class Voter
extends java.awt.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, Serialized Form

Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
Voter()
          Construct a Voter that, by default, vetos all proposed PropertyChange events.
 
Method Summary
 java.awt.Dimension getPreferredSize()
           
 boolean getVetoAll()
          If true, veto all proposed changes, otherwise accept them.
 void paint(java.awt.Graphics g)
           
 void setVetoAll(boolean x)
          If true, veto all proposed changes, otherwise accept them.
 void vetoableChange(java.beans.PropertyChangeEvent x)
          The PropertyChangeEvent handler method.
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Voter

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

setVetoAll

public void setVetoAll(boolean x)
If true, veto all proposed changes, otherwise accept them.
See Also:
getVetoAll(), vetoableChange(java.beans.PropertyChangeEvent)

getVetoAll

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

vetoableChange

public void vetoableChange(java.beans.PropertyChangeEvent x)
                    throws java.beans.PropertyVetoException
The PropertyChangeEvent handler method. By default this method throws a PropertyVetoException, which vetos the proposed change defined by the PropertyChangeEvent.
Throws:
java.beans.PropertyVetoException - if the vetoAll is true
See Also:
setVetoAll(boolean)

getPreferredSize

public java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class java.awt.Component

paint

public void paint(java.awt.Graphics g)
Overrides:
paint in class java.awt.Component