/** @author David Culyba */
public class EventCriteriaManager {
  public void addCondition(ManipulationEventCriteria condition) {
    if (!this.manipulationConditions.contains(condition)) {
      this.manipulationConditions.add(condition);
    }
  }

  public void removeCondition(ManipulationEventCriteria condition) {
    this.manipulationConditions.remove(condition);
  }

  public void setTargetTransformable(
      edu.cmu.cs.dennisc.scenegraph.AbstractTransformable transformable) {
    this.targetTransformable = transformable;
  }

  public boolean matches(ManipulationEvent event) {
    if ((this.targetTransformable == null)
        || (event.getTarget() == null)
        || (this.targetTransformable == event.getTarget())) {
      for (ManipulationEventCriteria condition : this.manipulationConditions) {
        if (condition.matches(event)) {
          return true;
        }
      }
    }
    return false;
  }

  private final java.util.List<ManipulationEventCriteria> manipulationConditions =
      edu.cmu.cs.dennisc.java.util.Lists.newCopyOnWriteArrayList();
  private edu.cmu.cs.dennisc.scenegraph.AbstractTransformable targetTransformable;
}
Example #2
0
  public class SwingModel {
    private java.awt.Color value;

    private final java.util.List<javax.swing.event.ChangeListener> changeListeners =
        edu.cmu.cs.dennisc.java.util.Lists.newCopyOnWriteArrayList();

    public SwingModel(java.awt.Color initialValue) {
      this.value = initialValue;
    }

    public java.awt.Color getValue() {
      return this.value;
    }

    public void setValue(java.awt.Color nextValue, java.awt.event.MouseEvent e) {
      if (this.value.equals(nextValue)) {
        // pass
      } else {
        this.value = nextValue;
        IsAdjusting isAdjusting;
        if (e != null) {
          isAdjusting =
              e.getID() != java.awt.event.MouseEvent.MOUSE_RELEASED
                  ? IsAdjusting.TRUE
                  : IsAdjusting.FALSE;
        } else {
          isAdjusting = IsAdjusting.FALSE;
        }

        // todo
        isAdjusting = IsAdjusting.FALSE;

        org.lgna.croquet.triggers.Trigger trigger;
        if (e != null) {
          trigger = org.lgna.croquet.triggers.MouseEventTrigger.createUserInstance(e);
        } else {
          trigger = org.lgna.croquet.triggers.NullTrigger.createUserInstance();
        }
        changeValueFromSwing(this.value, isAdjusting, trigger);
        if (this.changeListeners.size() > 0) {
          Object source = e != null ? e.getSource() : this;
          javax.swing.event.ChangeEvent changeEvent = new javax.swing.event.ChangeEvent(source);
          for (javax.swing.event.ChangeListener changeListener : this.changeListeners) {
            changeListener.stateChanged(changeEvent);
          }
        }
      }
    }

    public void addChangeListener(javax.swing.event.ChangeListener changeListener) {
      this.changeListeners.add(changeListener);
    }

    public void removeChangeListener(javax.swing.event.ChangeListener changeListener) {
      this.changeListeners.remove(changeListener);
    }
  }