1// BEGIN LICENSE BLOCK
2// Version: CMPL 1.1
3//
4// The contents of this file are subject to the Cisco-style Mozilla Public
5// License Version 1.1 (the "License"); you may not use this file except
6// in compliance with the License.  You may obtain a copy of the License
7// at www.eclipse-clp.org/license.
8//
9// Software distributed under the License is distributed on an "AS IS"
10// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11// the License for the specific language governing rights and limitations
12// under the License.
13//
14// The Original Code is  The ECLiPSe Constraint Logic Programming System.
15// The Initial Developer of the Original Code is  Cisco Systems, Inc.
16// Portions created by the Initial Developer are
17// Copyright (C) 2006 Cisco Systems, Inc.  All Rights Reserved.
18//
19// Contributor(s):
20//
21// END LICENSE BLOCK
22
23package com.parctechnologies.eclipse.visualisation;
24
25import com.parctechnologies.eclipse.*;
26import java.beans.*;
27
28/**
29 * This class represents the concept of "interest spec" on the Java side.
30 * Any viewer monitoring a viewable has its own interest spec. An
31 * interest spec is a specification of how the viewer preferres to be sent
32 * updates. The two components at the moment are the change condition (i.e. the
33 * waking condition for sending updates) and the view granularity (i.e. whether
34 * to see propagation steps separately or not).
35 */
36public class InterestSpec implements CompoundTerm
37{
38  private String name;
39  private CompoundTerm changeCondition;
40  private Atom viewGranularity;
41  private PropertyChangeSupport propertyChangeSupport;
42  private Viewable viewable;
43
44  static final CompoundTerm DEFAULT_CHANGE_CONDITION =
45    new CompoundTermImpl("change_condition",
46                         new Atom("suspend"),
47                         new Atom("suspend"),
48                         new Atom("constrained"));
49
50  static final Atom DEFAULT_VIEW_GRANULARITY =
51    new Atom("fine");
52
53  public InterestSpec(String name, Viewable viewable)
54  {
55    this(name, DEFAULT_CHANGE_CONDITION, DEFAULT_VIEW_GRANULARITY, viewable);
56  }
57
58  public InterestSpec(String name, CompoundTerm changeCondition,
59                      Atom viewGranularity, Viewable viewable)
60  {
61    this.viewable = viewable;
62    this.name = name;
63    setChangeCondition(changeCondition);
64    this.viewGranularity = viewGranularity;
65    this.propertyChangeSupport = new PropertyChangeSupport(this);
66  }
67
68  public Viewable getViewable()
69  {
70    return(viewable);
71  }
72
73  public PropertyChangeSupport getPropertyChangeSupport()
74  {
75    return(propertyChangeSupport);
76  }
77
78  public String getName()
79  {
80    return(name);
81  }
82
83  public CompoundTerm getChangeCondition()
84  {
85    return(changeCondition);
86  }
87
88  public void setChangeCondition(CompoundTerm changeCondition)
89  {
90    this.changeCondition = changeCondition;
91  }
92
93  public Atom getViewGranularity()
94  {
95    return(viewGranularity);
96  }
97
98  public void setViewGranularity(Atom newViewGranularity)
99  {
100    Object oldViewGranularity;
101    if(!viewGranularity.equals(newViewGranularity))
102    {
103      oldViewGranularity = viewGranularity;
104      viewGranularity = newViewGranularity;
105      propertyChangeSupport.
106        firePropertyChange("viewGranularity",
107                           oldViewGranularity, newViewGranularity);
108    }
109  }
110
111  public String functor()
112  {
113    return("interest_spec");
114  }
115
116  public int arity()
117  {
118    return(3);
119  }
120
121  public Object arg(int index)
122  {
123    switch(index)
124    {
125      case 1:
126        return new Atom(name);
127      case 2:
128        return changeCondition;
129      case 3:
130        return viewGranularity;
131      default:
132        throw new IllegalArgumentException("Argument index must be between 1 and "+
133                                           arity()+" inclusive.");
134    }
135  }
136
137}
138