Example usage for java.awt Component addPropertyChangeListener

List of usage examples for java.awt Component addPropertyChangeListener

Introduction

In this page you can find the example usage for java.awt Component addPropertyChangeListener.

Prototype

public void addPropertyChangeListener(PropertyChangeListener listener) 

Source Link

Document

Adds a PropertyChangeListener to the listener list.

Usage

From source file:com.mac.tarchan.desktop.event.EventQuery.java

/**
 * ???????????????/*from  w w  w.j  av a 2  s. c om*/
 * ????????
 * 
 * @param target ?
 * @param action ?????????????
 * @param property ???????????? 
 * @return ??
 * @see TextListener#textValueChanged(java.awt.event.TextEvent)
 * @see ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
 * @see PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
 * @see ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
 */
public EventQuery change(Object target, String action, String property) {
    TextListener textValueChanged = EventHandler.create(TextListener.class, target, action, property,
            "textValueChanged");
    ListSelectionListener valueChanged = EventHandler.create(ListSelectionListener.class, target, action,
            property, "valueChanged");
    PropertyChangeListener propertyChange = EventHandler.create(PropertyChangeListener.class, target, action,
            property, "propertyChange");
    ChangeListener stateChanged = EventHandler.create(ChangeListener.class, target, action, property,
            "stateChanged");
    for (Component child : list) {
        if (TextComponent.class.isInstance(child)) {
            TextComponent.class.cast(child).addTextListener(textValueChanged);
        } else if (JTable.class.isInstance(child)) {
            JTable.class.cast(child).getSelectionModel().addListSelectionListener(valueChanged);
        } else if (JTabbedPane.class.isInstance(child)) {
            JTabbedPane.class.cast(child).addChangeListener(stateChanged);
        } else {
            child.addPropertyChangeListener(propertyChange);
        }
    }

    return this;
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Registers common component changes//from w  w  w.j  a v a  2 s  .c  om
 * @param function receives an instance of javaQuery with the changed view selected, as well as the
 * following arguments:
 * <ol>
 * <li>{@link changeEvent} to define the type of event that was triggered
 * <li>The associated event
 * </ol>
 * @return
 * @see changeEvent
 */
public $ change(final Function function) {
    for (final Component component : views) {
        component.addInputMethodListener(new InputMethodListener() {

            @Override
            public void caretPositionChanged(InputMethodEvent event) {
                function.invoke($.with(component), ChangeEvent.INPUT_CARET_POSITION_CHANGED, event);
            }

            @Override
            public void inputMethodTextChanged(InputMethodEvent event) {
                function.invoke($.with(component), ChangeEvent.INPUT_METHOD_TEXT_CHANGED, event);
            }

        });

        component.addHierarchyBoundsListener(new HierarchyBoundsListener() {

            @Override
            public void ancestorMoved(HierarchyEvent event) {
                function.invoke($.with(component), ChangeEvent.HIERARCHY_ANCESTOR_MOVED, event);
            }

            @Override
            public void ancestorResized(HierarchyEvent event) {
                function.invoke($.with(component), ChangeEvent.HIERARCHY_ANCENSTOR_RESIZED, event);
            }

        });

        component.addHierarchyListener(new HierarchyListener() {

            @Override
            public void hierarchyChanged(HierarchyEvent event) {
                function.invoke($.with(component), ChangeEvent.HIERARCHY_CHANGED, event);
            }

        });

        component.addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                function.invoke($.with(component), ChangeEvent.PROPERTY_CHANGED, event);
            }
        });

        component.addComponentListener(new ComponentListener() {

            @Override
            public void componentHidden(ComponentEvent event) {
                function.invoke($.with(component), ChangeEvent.COMPONENT_HIDDEN, event);
            }

            @Override
            public void componentMoved(ComponentEvent event) {
                function.invoke($.with(component), ChangeEvent.COMPONENT_MOVED, event);
            }

            @Override
            public void componentResized(ComponentEvent event) {
                function.invoke($.with(component), ChangeEvent.COMPONENT_RESIZED, event);
            }

            @Override
            public void componentShown(ComponentEvent event) {
                function.invoke($.with(component), ChangeEvent.COMPONENT_SHOWN, event);
            }

        });

        if (component instanceof Container) {
            ((Container) component).addContainerListener(new ContainerListener() {

                @Override
                public void componentAdded(ContainerEvent event) {
                    function.invoke($.with(component), ChangeEvent.COMPONENT_ADDED, event);
                }

                @Override
                public void componentRemoved(ContainerEvent event) {
                    function.invoke($.with(component), ChangeEvent.COMPONENT_REMOVED, event);
                }

            });
        }
    }
    return this;
}