1 33 34 package com.icesoft.faces.context.effects; 35 36 import java.text.DecimalFormat ; 37 import java.text.NumberFormat ; 38 import java.util.*; 39 40 43 public class EffectsArguments { 44 45 private Map map = new HashMap(); 46 private List parameter = new ArrayList(); 47 private NumberFormat floatFormat = NumberFormat.getNumberInstance(Locale.US); 48 private String options = null; 49 50 public EffectsArguments(){ 51 floatFormat.setGroupingUsed(false); 52 } 53 54 55 public void setParameter(int i, float f) { 56 addParameter(i, floatFormat.format(f)); 57 } 58 59 public void addParameter(int i, String value) { 60 if (i == parameter.size()) { 61 parameter.add(i, value); 62 } else { 63 parameter.set(i, value); 64 } 65 } 66 67 public void add(String argument, String value) { 68 if (value == null) { 69 return; 70 } 71 map.put(argument, "'" + value + "'"); 72 } 73 74 public void setOptions(String value){ 75 options = value; 76 } 77 78 public void add(String argument, float value) { 79 map.put(argument, floatFormat.format(value)); 80 } 81 82 public void addFunction(String argument, String function) { 83 map.put(argument, function); 84 } 85 86 public void add(String arg, boolean value) { 87 88 map.put(arg, value + ""); 89 } 90 91 public boolean isEmpty() { 92 return map.isEmpty(); 93 } 94 95 96 public String toString() { 97 if(options != null){ 98 options = options.replace(')', ' '); 100 options = options.replace('}', ' '); 101 } 102 StringBuffer sb = new StringBuffer (",{"); 103 Iterator iter = parameter.iterator(); 104 if (iter.hasNext()) { 105 sb.append(", "); 106 } 107 while (iter.hasNext()) { 108 String value = (String ) iter.next(); 109 sb.append("'").append(value).append("'"); 110 if (iter.hasNext()) { 111 sb.append(","); 112 } 113 } 114 if (map.isEmpty()) { 115 if(options != null){ 116 return ",{ " +options + "})"; 117 } 118 return ");"; 119 } 120 121 iter = map.keySet().iterator(); 122 while (iter.hasNext()) { 123 String arg = (String ) iter.next(); 124 String value = (String ) map.get(arg); 125 sb.append(arg).append(":").append(value); 126 if (iter.hasNext()) { 127 sb.append(","); 128 } 129 } 130 if(options != null){ 131 sb.append(",").append(options); 132 } 133 sb.append("});"); 134 135 return sb.toString(); 136 } 137 } 138 | Popular Tags |