
import java.beans.*;
import javax.swing.*;
import java.lang.reflect.Method;


public class Test {

    private static class Listener implements PropertyChangeListener {

        @Override
        public void propertyChange(PropertyChangeEvent e) {
            System.out.println("\n>>> LISTENER: " + e.getPropertyName() + " changed");
        }
    }

    private final Listener LISTENER = new Listener();


    private void checkIfBound(Class<?> c, String name, Class<?> argType)
            throws NoSuchMethodException {

        Method m = c.getMethod(name, argType);
        if (m.isAnnotationPresent(BeanProperty.class)) {
            BeanProperty p = (BeanProperty) m.getAnnotation(BeanProperty.class);
            System.out.println("\nsetter " + name + ", bound = " +
                p.bound() + ":\n" + p.toString());
        } else {
            System.out.println("not @BeanProperty!");
        }
    }

    private void run() throws NoSuchMethodException {

        JButton b = new JButton();
        b.addPropertyChangeListener(LISTENER);
        //checkIfBound(b.getClass(), "setText", String.class);
        b.setText("text"); // check that the listener works

        checkIfBound(b.getClass(), "setAlignmentX", float.class);
        b.setAlignmentX(0.3f);
        b.setAlignmentX(0.9f);

        checkIfBound(b.getClass(), "setAlignmentY", float.class);
        b.setAlignmentY(0.f);
        b.setAlignmentY(0.1f);
        b.setAlignmentY(0.8f);

        JRadioButton rb = new JRadioButton();
        rb.addPropertyChangeListener(LISTENER);
        rb.setText("text");  // check that the listener works

        checkIfBound(rb.getClass(), "setAlignmentY", float.class);
        rb.setAlignmentY(0.f);
        rb.setAlignmentY(0.5f);
        rb.setAlignmentY(0.7f);
    }

    public static void main(String[] args) throws NoSuchMethodException {

        (new Test()).run();
    }
}
