KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > util > force > AbstractForce


1 package prefuse.util.force;
2
3 /**
4  * Abstract base class for force functions in a force simulation. This
5  * skeletal version provides support for storing and retrieving float-valued
6  * parameters of the force function. Subclasses should use the protected
7  * field <code>params</code> to store parameter values.
8  *
9  * @author <a HREF="http://jheer.org">jeffrey heer</a>
10  */

11 public abstract class AbstractForce implements Force {
12
13     protected float[] params;
14     protected float[] minValues;
15     protected float[] maxValues;
16
17     /**
18      * Initialize this force function. This default implementation does nothing.
19      * Subclasses should override this method with any needed initialization.
20      * @param fsim the encompassing ForceSimulator
21      */

22     public void init(ForceSimulator fsim) {
23         // do nothing.
24
}
25
26     /**
27      * @see prefuse.util.force.Force#getParameterCount()
28      */

29     public int getParameterCount() {
30         return ( params == null ? 0 : params.length );
31     }
32
33     /**
34      * @see prefuse.util.force.Force#getParameter(int)
35      */

36     public float getParameter(int i) {
37         if ( i < 0 || params == null || i >= params.length ) {
38             throw new IndexOutOfBoundsException JavaDoc();
39         } else {
40             return params[i];
41         }
42     }
43     
44     /**
45      * @see prefuse.util.force.Force#getMinValue(int)
46      */

47     public float getMinValue(int i) {
48         if ( i < 0 || params == null || i >= params.length ) {
49             throw new IndexOutOfBoundsException JavaDoc();
50         } else {
51             return minValues[i];
52         }
53     }
54     
55     /**
56      * @see prefuse.util.force.Force#getMaxValue(int)
57      */

58     public float getMaxValue(int i) {
59         if ( i < 0 || params == null || i >= params.length ) {
60             throw new IndexOutOfBoundsException JavaDoc();
61         } else {
62             return maxValues[i];
63         }
64     }
65     
66     /**
67      * @see prefuse.util.force.Force#getParameterName(int)
68      */

69     public String JavaDoc getParameterName(int i) {
70         String JavaDoc[] pnames = getParameterNames();
71         if ( i < 0 || pnames == null || i >= pnames.length ) {
72             throw new IndexOutOfBoundsException JavaDoc();
73         } else {
74             return pnames[i];
75         }
76     }
77
78     /**
79      * @see prefuse.util.force.Force#setParameter(int, float)
80      */

81     public void setParameter(int i, float val) {
82         if ( i < 0 || params == null || i >= params.length ) {
83             throw new IndexOutOfBoundsException JavaDoc();
84         } else {
85             params[i] = val;
86         }
87     }
88     
89     /**
90      * @see prefuse.util.force.Force#setMinValue(int, float)
91      */

92     public void setMinValue(int i, float val) {
93         if ( i < 0 || params == null || i >= params.length ) {
94             throw new IndexOutOfBoundsException JavaDoc();
95         } else {
96             minValues[i] = val;
97         }
98     }
99     
100     /**
101      * @see prefuse.util.force.Force#setMaxValue(int, float)
102      */

103     public void setMaxValue(int i, float val) {
104         if ( i < 0 || params == null || i >= params.length ) {
105             throw new IndexOutOfBoundsException JavaDoc();
106         } else {
107             maxValues[i] = val;
108         }
109     }
110     
111     protected abstract String JavaDoc[] getParameterNames();
112     
113     /**
114      * Returns false.
115      * @see prefuse.util.force.Force#isItemForce()
116      */

117     public boolean isItemForce() {
118         return false;
119     }
120     
121     /**
122      * Returns false.
123      * @see prefuse.util.force.Force#isSpringForce()
124      */

125     public boolean isSpringForce() {
126         return false;
127     }
128     
129     /**
130      * Throws an UnsupportedOperationException.
131      * @see prefuse.util.force.Force#getForce(prefuse.util.force.ForceItem)
132      */

133     public void getForce(ForceItem item) {
134         throw new UnsupportedOperationException JavaDoc(
135             "This class does not support this operation");
136     }
137     
138     /**
139      * Throws an UnsupportedOperationException.
140      * @see prefuse.util.force.Force#getForce(prefuse.util.force.Spring)
141      */

142     public void getForce(Spring spring) {
143         throw new UnsupportedOperationException JavaDoc(
144             "This class does not support this operation");
145     }
146     
147 } // end of abstract class AbstractForce
148
Popular Tags