/** * Binds an event listener to a specific method on a specific object. * * @param <L> the event listener type * @param target the target object * @param methodName the name of the method to be called * @param eventSource the object which is generating events (JButton, JList, etc.) * @param listenerType the listener interface (ActionListener.class, SelectionListener.class, etc.) * @param eventTypes the event types (method names) from the listener interface (if none specified, all will be * supported) */ public static <L> void bindEventsToMethod(final Object target, final String methodName, final Object eventSource, final Class<L> listenerType, final String... eventTypes) { final L listener = listenerType.cast(Proxy.newProxyInstance(target.getClass().getClassLoader(), new Class[] { listenerType }, new EventBindingInvocationHandler(target, methodName, eventTypes))); addEventListener(eventSource, listenerType, listener); }
/** * Handles a method invocation on the proxy object. * * @param proxy the proxy instance * @param method the method to be invoked * @param parameters the parameters for the method invocation * @return the result of the method call * @throws Throwable if an error occurs */ @Override public Object invoke(final Object proxy, final Method method, final Object[] parameters) throws Throwable { if (eventTypes.isEmpty() || eventTypes.contains(method.getName())) { if (hasMatchingParametersMethod(method)) { return MethodUtils.invokeMethod(target, methodName, parameters); } return MethodUtils.invokeMethod(target, methodName); } return null; }
/** * Handles a method invocation on the proxy object. * * @param proxy the proxy instance * @param method the method to be invoked * @param parameters the parameters for the method invocation * @return the result of the method call * @throws Throwable if an error occurs */ @Override public Object invoke(final Object proxy, final Method method, final Object[] parameters) throws Throwable { if (eventTypes.isEmpty() || eventTypes.contains(method.getName())) { if (hasMatchingParametersMethod(method)) { return MethodUtils.invokeMethod(target, methodName, parameters); } return MethodUtils.invokeMethod(target, methodName); } return null; }
/** * Handles a method invocation on the proxy object. * * @param proxy the proxy instance * @param method the method to be invoked * @param parameters the parameters for the method invocation * @return the result of the method call * @throws Throwable if an error occurs */ @Override public Object invoke(final Object proxy, final Method method, final Object[] parameters) throws Throwable { if (eventTypes.isEmpty() || eventTypes.contains(method.getName())) { if (hasMatchingParametersMethod(method)) { return MethodUtils.invokeMethod(target, methodName, parameters); } return MethodUtils.invokeMethod(target, methodName); } return null; }
/** * Binds an event listener to a specific method on a specific object. * * @param <L> the event listener type * @param target the target object * @param methodName the name of the method to be called * @param eventSource the object which is generating events (JButton, JList, etc.) * @param listenerType the listener interface (ActionListener.class, SelectionListener.class, etc.) * @param eventTypes the event types (method names) from the listener interface (if none specified, all will be * supported) */ public static <L> void bindEventsToMethod(final Object target, final String methodName, final Object eventSource, final Class<L> listenerType, final String... eventTypes) { final L listener = listenerType.cast(Proxy.newProxyInstance(target.getClass().getClassLoader(), new Class[] { listenerType }, new EventBindingInvocationHandler(target, methodName, eventTypes))); addEventListener(eventSource, listenerType, listener); }
/** * Binds an event listener to a specific method on a specific object. * * @param <L> the event listener type * @param target the target object * @param methodName the name of the method to be called * @param eventSource the object which is generating events (JButton, JList, etc.) * @param listenerType the listener interface (ActionListener.class, SelectionListener.class, etc.) * @param eventTypes the event types (method names) from the listener interface (if none specified, all will be * supported) */ public static <L> void bindEventsToMethod(final Object target, final String methodName, final Object eventSource, final Class<L> listenerType, final String... eventTypes) { final L listener = listenerType.cast(Proxy.newProxyInstance(target.getClass().getClassLoader(), new Class[] { listenerType }, new EventBindingInvocationHandler(target, methodName, eventTypes))); addEventListener(eventSource, listenerType, listener); }
/** * Handles a method invocation on the proxy object. * * @param proxy the proxy instance * @param method the method to be invoked * @param parameters the parameters for the method invocation * @return the result of the method call * @throws Throwable if an error occurs */ @Override public Object invoke(final Object proxy, final Method method, final Object[] parameters) throws Throwable { if (eventTypes.isEmpty() || eventTypes.contains(method.getName())) { if (hasMatchingParametersMethod(method)) { return MethodUtils.invokeMethod(target, methodName, parameters); } return MethodUtils.invokeMethod(target, methodName); } return null; }
/** * Binds an event listener to a specific method on a specific object. * * @param <L> the event listener type * @param target the target object * @param methodName the name of the method to be called * @param eventSource the object which is generating events (JButton, JList, etc.) * @param listenerType the listener interface (ActionListener.class, SelectionListener.class, etc.) * @param eventTypes the event types (method names) from the listener interface (if none specified, all will be * supported) */ public static <L> void bindEventsToMethod(final Object target, final String methodName, final Object eventSource, final Class<L> listenerType, final String... eventTypes) { final L listener = listenerType.cast(Proxy.newProxyInstance(target.getClass().getClassLoader(), new Class[] { listenerType }, new EventBindingInvocationHandler(target, methodName, eventTypes))); addEventListener(eventSource, listenerType, listener); }