1 6 7 20 package org.wings.text; 21 22 import org.wings.SFormattedTextField; 23 import org.wings.script.JavaScriptListener; 24 25 import java.util.Iterator ; 26 import java.util.Vector ; 27 import java.text.ParseException ; 28 29 32 public abstract class SAbstractFormatter { 33 34 private Vector textFields = null; 35 private Vector jScripts = null; 36 37 38 public SAbstractFormatter() { 39 textFields = new Vector (); 40 jScripts = new Vector (); 41 } 42 43 44 49 public void install(SFormattedTextField textField) { 50 boolean b = false; 51 if (textField != null) { 52 for (Iterator i = textFields.iterator(); i.hasNext();) { 53 if (i.next() == textField) { 54 return; 55 } 56 } textFields.add(textField); 58 if (textField.getActionListeners().length > 0) { 59 b = true; 60 } 61 62 JavaScriptListener jScriptListener = generateJavaScript(textField, b); 63 64 textField.addScriptListener(jScriptListener); 65 66 jScripts.add(jScriptListener); 67 } 68 } 69 70 73 public void uninstall(SFormattedTextField textField) { 74 if (textField != null) { 75 for (int i = 0; i < textFields.size(); i++) { 76 if (textFields.get(i) == textField) { 77 textField.removeScriptListener((JavaScriptListener) jScripts.get(i)); 78 jScripts.remove(i); 79 textFields.remove(i); 80 } 81 } 82 } 83 } 84 85 86 91 public void updateFormatter() { 92 if (textFields.size() > 0) { 93 Vector tempJScripts = new Vector (); 94 for (int i = 0; i < textFields.size(); i++) { 95 SFormattedTextField tf = (SFormattedTextField) textFields.get(i); 96 tf.removeScriptListener((JavaScriptListener) jScripts.get(i)); 97 boolean b = false; 98 if (tf.getActionListeners().length > 0) { 99 b = true; 100 } 101 102 JavaScriptListener jl = generateJavaScript(tf, b); 103 tf.addScriptListener(jl); 105 tempJScripts.add(jl); 106 107 } 108 jScripts = tempJScripts; 109 } 110 111 115 } 116 117 public abstract JavaScriptListener generateJavaScript(SFormattedTextField field, boolean actionListener); 118 119 123 public abstract Object stringToValue(String text) throws ParseException ; 124 125 129 public abstract String valueToString(Object value) throws ParseException ; 130 } 131 | Popular Tags |