Example usage for java.util Observable addObserver

List of usage examples for java.util Observable addObserver

Introduction

In this page you can find the example usage for java.util Observable addObserver.

Prototype

public synchronized void addObserver(Observer o) 

Source Link

Document

Adds an observer to the set of observers for this object, provided that it is not the same as some observer already in the set.

Usage

From source file:ca.sfu.federation.viewer.propertysheet.PointPropertySheet.java

private void setValues() {
    // target/*from   ww w . j  av  a2  s .c o m*/
    this.target = (Point) Application.getContext().getViewState(ApplicationContext.VIEWER_SELECTION);
    // set field values
    this.lblINamedObject.setText(this.target.getName());
    this.jtfClass.setText(this.target.getClass().toString());
    this.jtfName.setText(this.target.getName());
    this.jtfCanonicalName.setText(this.target.getCanonicalName());
    this.jtfParentContext.setText(this.target.getContext().getName());
    try {
        BeanProxy proxy = new BeanProxy(this.target);
        Double x = (Double) proxy.get("x");
        Double y = (Double) proxy.get("y");
        Double z = (Double) proxy.get("z");
        this.jtfX.setText(String.valueOf(x));
        this.jtfY.setText(String.valueOf(y));
        this.jtfZ.setText(String.valueOf(z));
    } catch (Exception ex) {
        String stack = ExceptionUtils.getFullStackTrace(ex);
        logger.log(Level.WARNING, "{0}", stack);
    }

    List<Method> methods = this.target.getUpdateMethods();
    ArrayList<String> methodNameList = new ArrayList<String>();
    Iterator<Method> it = methods.iterator();
    while (it.hasNext()) {
        Method method = it.next();
        methodNameList.add(method.getName());
    }
    DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel(methodNameList.toArray());
    jcbUpdateMethod.setModel(comboBoxModel);
    String selected = this.target.getUpdateMethodName();
    jcbUpdateMethod.setSelectedItem(selected);

    // build the input panel
    this.buildUpdateMethodInputsPanel();

    // listen for changes on the target
    if (this.target instanceof Observable) {
        Observable o = (Observable) this.target;
        o.addObserver(this);
    }
}

From source file:ca.sfu.federation.model.Scenario.java

/**
 * Add a transactional element to the context.
 * @param Named Named object/*  ww  w. ja  va 2  s.  c o m*/
 * @throws DuplicateObjectException An object with the same name already exists in the context.
 */
public void add(INamed Named) throws IllegalArgumentException {
    if (!this.transactional.containsKey(Named.getName())) {
        // put the object in the local store
        this.transactional.put(Named.getName(), Named);
        // set the object context to this scenario
        Named.setContext(this);
        // listen for changes on the object
        if (Named instanceof Observable) {
            Observable o = (Observable) Named;
            o.addObserver(this);
        }
    } else {
        throw new IllegalArgumentException(
                "An object identified by the same name already exists in the Context.");
    }
    // generate change event
    this.setChanged();
    this.notifyObservers(Integer.valueOf(ApplicationContext.EVENT_ELEMENT_ADD));
}

From source file:ca.sfu.federation.model.Scenario.java

/**
 * Add an INamed as a Contextual Element of the Scenario.
 *
 * @param Named INamed to add as a Contextual object.
 * @throws DuplicateObjectException An object by the same name already exists in this Scenario.
 *//*w ww.  j av a 2s  .  c om*/
public void addContextual(INamed Named) throws IllegalArgumentException {
    if (!this.contextual.containsKey(Named.getName())) {
        // add to list of contextual elements
        this.contextual.put(Named.getName(), Named);
        // listen for changes on the object
        // TODO: we should listen for changes on the object's parent context instead!
        // in this situation, we will receive an update from the object before it has been updated _in context_
        if (Named instanceof Observable) {
            Observable o = (Observable) Named;
            o.addObserver(this);
        }
    } else {
        throw new IllegalArgumentException(
                "An object identified by the same name already exists in the Context.");
    }
    // generate change event
    this.setChanged();
    this.notifyObservers(Integer.valueOf(ApplicationContext.EVENT_ELEMENT_ADD));
}