1 26 27 package swingwtx.custom.validation; 28 29 import swingwtx.swing.*; 30 31 import java.util.*; 32 33 52 public class ValidationGroup { 53 54 protected ImageIcon pImage = null; 55 protected Vector components = new Vector(); 56 57 58 protected String errorMessage = ""; 59 60 61 public ValidationGroup() { pImage = new ImageIcon(getClass().getResource("/swingwtx/custom/validation/erroricon.gif")); } 62 public ValidationGroup(ImageIcon image) { if (image == null) throw new IllegalArgumentException ("Image can't be null"); pImage = image; } 63 64 public void add(ValidatableComponent c) { c.setValidationGroup(this); components.add(c); } 65 public void remove(ValidatableComponent c) { c.setValidationGroup(null); components.remove(c); } 66 67 public ImageIcon getIcon() { return pImage; } 68 public String getErrorMessage() { return errorMessage; } 69 70 74 public boolean checkValidation() { 75 boolean andCheck = true; 76 for (int i = 0; i < components.size(); i++) { 77 ValidatableComponent c = (ValidatableComponent) components.get(i); 78 c.fireValidation(false); 79 if (!c.isValid()) { 80 errorMessage = c.getErrorMessage(); 81 } 82 andCheck = andCheck && c.isValid(); 83 } 84 return andCheck; 85 } 86 87 90 public void clearErrors() { 91 for (int i = 0; i < components.size(); i++) { 92 ValidatableComponent c = (ValidatableComponent) components.get(i); 93 c.fireValidation(true); 94 } 95 errorMessage = ""; 96 } 97 98 } 99 | Popular Tags |