Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.openide.awt;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EventListener;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Action;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.openide.awt.ContextAction.StatefulMonitor;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.Utilities;
import org.openide.util.WeakListeners;
/**
* Enabler, which will work against a certain property on a target object. It attaches to the object when it
* changes, and monitors its property's state using either {@link PropertyChangeListener} or {@link ChangeListener}.
* If the monitored property's state changes, it fires a change to alert the owner Action.
*
* @param data type
*/
class PropertyMonitor implements ContextAction.StatefulMonitor, PropertyChangeListener, ChangeListener {
private static final Logger LOG = Logger.getLogger(PropertyMonitor.class.getName());
static final String KEY_CHECKED_VALUE = "Value"; // NOI18N
static final String KEY_LISTEN_INTERFACE = "ChangeListener"; // NOI18N
static final String KEY_INTERFACE_METHOD = "Method"; // NOI18N
static final String KEY_CUSTOM_CHECK = "ActionProperty"; // NOI18N
static final String KEY_NULL = "Null"; // NOI18N
/**
* Reflection not initialized
*/
private static final int UNINITIALIZED = -1;
/**
* Listeners not supported
*/
private static final int NONE = 0;
/**
* Property change listener registered against specific property name
*/
private static final int PROPERTY_NAME = 1;
/**
* Listener registered using general add method
*/
private static final int PROPERTY_ALL = 2;
/**
* ChangeListener is used,
*/
private static final int CHANGE = 3;
/**
* Custom listener interace.
*/
private static final int CUSTOM = 4;
/**
* Type being monitored, {@link Action} treated specially.
*/
private final Class type;
/**
* The property being monitored
*/
private final String property;
/**
* The value which makes the action selected.
*/
private final Object checkedValue;
private Class valType;
/**
* Reflective access to the property's value
*/
private Method refGetter;
/**
* Reflective access to add listener
*/
private Method refAddListener;
/**
* Reflective access to remove listener
*/
private Method refRemoveListener;
/**
* Detected listener type
*/
private int listenerType = UNINITIALIZED;
/**
* The Weak listener attached to the monitored data
*/
private EventListener weakListener;
/**
* The last data being monitored
*/
private Reference attachedTo;
/**
* Change Listeners added to this monitor.
*/
private List listeners = null;
/**
* Listener interface to listen
*/
private Class listenerInterface;
/**
* Method name to intercept; null for all methods
*/
private final String methodName;
private final StatefulMonitor actionMonitor;
private final Function