KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > userinterface > ColorConditionManager


1 package com.calipso.reportgenerator.userinterface;
2 import java.util.*;
3 import java.awt.*;
4
5 public class ColorConditionManager implements Cloneable JavaDoc {
6   private Hashtable valuesMetricConditions;
7
8   /**
9    * Crea un nuevo ColorConditionManager
10    */

11   public ColorConditionManager() {
12     init();
13   }
14
15   /**
16    * inicializa el ColorConditionManager
17    */

18   private void init() {
19     if (valuesMetricConditions == null) {
20       valuesMetricConditions = new Hashtable();
21     }
22   }
23
24   /**
25    * Agrega un nuevo ColorCondition
26    * @param colorCondition
27    */

28   public void put(ColorCondition colorCondition) {
29     Vector condiciones = (Vector) valuesMetricConditions.get(colorCondition.getMetricName());
30     if (condiciones != null) {
31       condiciones.add(colorCondition);
32     }
33     else {
34       condiciones = new Vector();
35       condiciones.add(colorCondition);
36       valuesMetricConditions.put(colorCondition.getMetricName(), condiciones);
37     }
38   }
39
40   /**
41    * Retorna todos los ColorCondition para una matrica
42    * @param metricName
43    * @return
44    */

45   public Collection getConditionsFor(String JavaDoc metricName) {
46     return (Collection) valuesMetricConditions.get(metricName);
47   }
48
49   /**
50    * Retorna un ColorCondiotion donde encuentre una expresion que corresponda con el valor value
51    * @param value
52    * @param metricName
53    * @param defauktColor
54    * @return
55    */

56   public ColorCondition getColor(Object JavaDoc value, String JavaDoc metricName, Color defauktColor) {
57     Collection colorConditions = getConditionsFor(metricName);
58     ColorCondition condition = null;
59     if (colorConditions != null) {
60       for (Iterator iterator = colorConditions.iterator(); iterator.hasNext();) {
61         condition = (ColorCondition) iterator.next();
62         if (condition.matches(value)) {
63           return condition;
64         }else {
65           condition = null;
66         }
67
68       }
69     }
70     return condition;
71   }
72
73   /**
74    *Retorna el diccionario de matricas
75    * @return
76    */

77   public Hashtable getValuesMetricConditions() {
78     return valuesMetricConditions;
79   }
80
81   /**
82    * Colona el ColorConditionManager
83    * @return
84    * @throws CloneNotSupportedException
85    */

86   protected Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
87     ColorConditionManager colorConditionManager = new ColorConditionManager();
88     return updateColorConditionManeger(colorConditionManager);
89   }
90
91   /**
92    * Actualiza el colorConditionManager y lo devuelve
93    * @param manager
94    * @return
95    */

96   private ColorConditionManager updateColorConditionManeger(ColorConditionManager manager) {
97     Iterator iterator = this.getValuesMetricConditions().values().iterator();
98     while (iterator.hasNext()) {
99       Vector collection = (Vector) iterator.next();
100       for (int i = 0; i < collection.size(); i++) {
101         ColorCondition condition = (ColorCondition) collection.elementAt(i);
102         manager.put(condition);
103       }
104     }
105     return manager;
106   }
107
108   /**
109    * Borra un ColorCondition de la lista
110    * @param colorCondition
111    */

112   public void remove(ColorCondition colorCondition) {
113     Vector condiciones = (Vector) valuesMetricConditions.get(colorCondition.getMetricName());
114     if (condiciones != null) {
115       condiciones.remove(colorCondition);
116     }
117   }
118
119   /**
120    * Setea el nuevo diccionario de MetricsConditionons
121    * @param valuesMetricConditions
122    */

123   public void setValuesMetricConditions(Hashtable valuesMetricConditions) {
124     this.valuesMetricConditions = valuesMetricConditions;
125   }
126
127   /**
128    * borra el diccionario valuesMetricConditions
129    *
130    */

131   public void clearValues() {
132     valuesMetricConditions.clear();
133   }
134 }
135
Popular Tags