
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import java.beans.*;
import javax.swing.SwingContainer;
import java.util.Arrays;


public class StaticOrNot {

    // ========== test bean (annotations must be ignored!) ==========

    public class TestClass {

        private int    value;
        private double other;

        public void setValue(int v) { value = v; }
        public  int getValue()      { return value; }


        public   void setOther(double o) { other = o; }
        public double getOther()         { return other; }

        public void addActionListener(ActionListener l) {}
        public void removeActionListener(ActionListener l) {}

        public void addMouseListener(MouseListener l) {}
        public void removeMouseListener(MouseListener l) {}
    }

    // ========== user-defined bean info ==========

    public static class TestClassBeanInfo extends SimpleBeanInfo {

        private static final int iOther = 0;
        private static final int iValue = 1;

        private static final int iAction = 0;
        private static final int iMouse  = 1;


        @Override
        public BeanDescriptor getBeanDescriptor() {

            BeanDescriptor bd = new BeanDescriptor(TestClass.class, null);
            bd.setShortDescription("user-defined-description");
            bd.setValue("isContainer", true);
            bd.setValue("containerDelegate", "user-defined-delegate");

            return bd;
        }

        @Override
        public PropertyDescriptor[] getPropertyDescriptors() {

            PropertyDescriptor[] p = new PropertyDescriptor[2];

            try {

                // value
                PropertyDescriptor pdValue = new PropertyDescriptor(
                    "value", TestClass.class, "getValue", "setValue");
                pdValue.setBound(true);
                pdValue.setConstrained(true);
                pdValue.setExpert(true);
                pdValue.setHidden(true);
                pdValue.setPreferred(true);
                pdValue.setValue("required", true);
                pdValue.setValue("visualUpdate", true);
                pdValue.setShortDescription("user-defined-value");
                p[iValue] = pdValue;

                // other
                PropertyDescriptor pdOther = new PropertyDescriptor(
                        "other", TestClass.class, "getOther", "setOther");
                pdOther.setBound(false);
                pdOther.setConstrained(false);
                pdOther.setExpert(false);
                pdOther.setHidden(false);
                pdOther.setPreferred(false);
                pdOther.setValue("required", false);
                pdOther.setValue("visualUpdate", false);
                pdOther.setShortDescription("user-defined-other");
                p[iOther] = pdOther;

            } catch(IntrospectionException e) {
                e.printStackTrace();
            }

            return p;
        }

        @Override
        public EventSetDescriptor[] getEventSetDescriptors() {
            EventSetDescriptor[] es = new EventSetDescriptor[2];
            try {
                es[iAction] = new EventSetDescriptor(
                        TestClass.class,
                        "actionListener",
                        java.awt.event.ActionListener.class,
                        new String[] {"actionPerformed"},
                        "addActionListener",
                        "removeActionListener");
                es[iMouse] = new EventSetDescriptor(
                        TestClass.class,
                        "mouseListener",
                        java.awt.event.MouseListener.class,
                        new String[] {"mouseClicked", "mousePressed", "mouseReleased", "mouseEntered", "mouseExited"},
                        "addMouseListener",
                        "removeMouseListener");
            } catch(IntrospectionException e) {
                e.printStackTrace();
            }
            return es;
        }

        @Override
        public MethodDescriptor[] getMethodDescriptors() {
            MethodDescriptor[] m = new MethodDescriptor[0];
            return m;
        }

        @Override
        public int getDefaultPropertyIndex() { return iValue; } // default: value

        @Override
        public int getDefaultEventIndex() { return iAction; } // default: action

        @Override
        public java.awt.Image getIcon(int iconKind) { return null; }
    }



    // ========== test ==========

    public static void main(String[] args) throws Exception {

        BeanInfo i = Introspector.getBeanInfo(TestClass.class, Object.class);
        BeanDescriptor bd = i.getBeanDescriptor();

        System.out.println("description: " + bd.getShortDescription());
        System.out.println("default property index: " + i.getDefaultPropertyIndex());
        System.out.println("default event index: " + i.getDefaultEventIndex());

        System.out.println("isContainer: " + i.getBeanDescriptor().getValue("isContainer"));
        System.out.println("containerDelegate" +
            i.getBeanDescriptor().getValue("containerDelegate"));
        System.out.println("");

        System.out.println("property descriptors:");
        System.out.println("");
        PropertyDescriptor[] pds = i.getPropertyDescriptors();
        for (PropertyDescriptor pd: pds) {
            System.out.println("---" + pd.getName() + "---");
            System.out.println("isBound: " + pd.isBound());
            System.out.println("isConstrained: " + pd.isConstrained());
            System.out.println("isExpert: " + pd.isExpert());
            System.out.println("isHidden: " + pd.isHidden());
            System.out.println("isPreferred: " + pd.isPreferred());
            System.out.println("required: " + pd.getValue("required"));
            System.out.println("visualUpdate: " + pd.getValue("visualUpdate"));
        }
    }
}
