1 package com.calipso.reportgenerator.userinterface; 2 import java.util.*; 3 import java.awt.*; 4 5 public class ColorConditionManager implements Cloneable { 6 private Hashtable valuesMetricConditions; 7 8 11 public ColorConditionManager() { 12 init(); 13 } 14 15 18 private void init() { 19 if (valuesMetricConditions == null) { 20 valuesMetricConditions = new Hashtable(); 21 } 22 } 23 24 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 45 public Collection getConditionsFor(String metricName) { 46 return (Collection) valuesMetricConditions.get(metricName); 47 } 48 49 56 public ColorCondition getColor(Object value, String 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 77 public Hashtable getValuesMetricConditions() { 78 return valuesMetricConditions; 79 } 80 81 86 protected Object clone() throws CloneNotSupportedException { 87 ColorConditionManager colorConditionManager = new ColorConditionManager(); 88 return updateColorConditionManeger(colorConditionManager); 89 } 90 91 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 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 123 public void setValuesMetricConditions(Hashtable valuesMetricConditions) { 124 this.valuesMetricConditions = valuesMetricConditions; 125 } 126 127 131 public void clearValues() { 132 valuesMetricConditions.clear(); 133 } 134 } 135 | Popular Tags |