KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > table > span > SpanConfigSupport


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.jpivot.table.span;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.List JavaDoc;
17
18 /**
19  * Created on 29.10.2002
20  *
21  * @author av
22  */

23 public class SpanConfigSupport implements SpanConfig {
24   
25   int defaultDirection = SpanConfig.NO_SPAN;
26   List JavaDoc clsList = new ArrayList JavaDoc();
27   List JavaDoc dirList = new ArrayList JavaDoc();
28   
29   /**
30    * sets the span direction for a specific class. The direction will be
31    * applied to all span, whose getObject() returns an instance of clazz.
32    * <p>
33    * The order is significant, its the order that chooseDirection will use
34    * to test. So you *must* call setDirection with a more specific class
35    * before the less specific, e.g. after setDirection(Object.class) no
36    * other classes will be recognized, because every class is assignable to
37    * object.
38    */

39   public void setDirection(Class JavaDoc clazz, int direction) {
40      clsList.add(clazz);
41      dirList.add(new Integer JavaDoc(direction));
42   }
43
44   /**
45    * returns the direction for span. The class of the spans object will
46    * be tested against
47    */

48   public int chooseSpanDirection(Span span) {
49     Object JavaDoc obj = span.getObject();
50     if (obj == null)
51       return defaultDirection;
52     Class JavaDoc clazz = obj.getClass();
53     int N = clsList.size();
54     for (int i = 0; i < N; i++) {
55       Class JavaDoc c = (Class JavaDoc)clsList.get(i);
56       if (c.isAssignableFrom(clazz))
57         return ((Integer JavaDoc)dirList.get(i)).intValue();
58     }
59     // use default
60
return defaultDirection;
61   }
62
63   /**
64    * Returns the defaultDirection.
65    * @return int
66    */

67   public int getDefaultDirection() {
68     return defaultDirection;
69   }
70
71   /**
72    * Sets the defaultDirection.
73    * @param defaultDirection The defaultDirection to set
74    */

75   public void setDefaultDirection(int defaultDirection) {
76     this.defaultDirection = defaultDirection;
77   }
78
79   /**
80    * returns true, if the objects returned by getObject() are equal.
81    */

82   public boolean equals(Span span1, Span span2) {
83     return span1.getObject().equals(span2.getObject());
84   }
85
86 }
87
Popular Tags