Package de.reuse

Source Code of de.reuse.MVContextImplementation

package de.reuse;

import javax.swing.event.SwingPropertyChangeSupport;
import java.beans.PropertyChangeListener;
import java.util.Set;

/**
* Created by IntelliJ IDEA.
* User: saturn
* Date: 2004-5-3
* Time: 19:36:33
* To change this template use File | Settings | File Templates.
*/
public class MVContextImplementation implements MVContext {

    protected SwingPropertyChangeSupport changeSupport;

    protected GroupTreeMap groupMap = new GroupTreeMap();

    public Set getValue(String key){
        return groupMap.get(key);
    }

    public void addValue(String key, Object value) {
        if ((key == null) || (value == null)) return;

        if (groupMap.constains(key, value)) return;

        groupMap.add(key, value);

        fireContextChange(key, null, value);
    }

    public void removeValue(String key, Object value) {
        if ((key == null) || (value == null)) return;

        if (!groupMap.constains(key, value)) return;

        groupMap.remove(key, value);

        fireContextChange(key, value, null);
    }

    protected void fireContextChange(String propertyName, Object oldValue, Object newValue) {
        if (changeSupport == null ||
                (oldValue != null && newValue != null && oldValue.equals(newValue))) {
            return;
        }
        changeSupport.firePropertyChange(propertyName, oldValue, newValue);
    }

    public synchronized void addContextChangeListener(PropertyChangeListener listener) {
        if (changeSupport == null) {
            changeSupport = new SwingPropertyChangeSupport(this);
        }
        changeSupport.addPropertyChangeListener(listener);
    }

    public synchronized void addContextChangeListener(String propertyName, PropertyChangeListener listener) {
        if (changeSupport == null) {
            changeSupport = new SwingPropertyChangeSupport(this);
        }
        changeSupport.addPropertyChangeListener(propertyName, listener);
    }

    public synchronized void removeContextChangeListener(PropertyChangeListener listener) {
        if (changeSupport == null) {
            return;
        }
        changeSupport.removePropertyChangeListener(listener);
    }

    public synchronized void removeContextChangeListener(String propertyName, PropertyChangeListener listener) {
        if (changeSupport == null) {
            return;
        }
        changeSupport.removePropertyChangeListener(propertyName, listener);
    }

}
TOP

Related Classes of de.reuse.MVContextImplementation

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.