/** * Checks and answers if the specified component is associated with a * warning message in the given validation result. As a prerequisite, * the component must have a <em>message key</em> set. That can * be done using {@link #setMessageKey(JComponent, Object)} or * {@link #setMessageKeys(JComponent, Object[])}.<p> * * <strong>Note:</strong> This method may become slow if invoked for larger * validation results <em>and</em> multiple components. In this case, * it is recommended to use {@link ValidationResult#keyMap()} instead. * The latter iterates once over the validation result and can be used later * to request the severity for multiple components in almost linear time. * * @param comp used to get the association key from * @param result used to lookup the validation messages from * @return true if the given component is associated with a warning message * @throws NullPointerException if the component or validation result * is {@code null} * * @see #hasError(JComponent, ValidationResult) * @see #getMessageKeys(JComponent) */ public static boolean hasWarning(JComponent comp, ValidationResult result) { return result.subResult(getMessageKeys(comp)).hasWarnings(); }
/** * Checks and answers if the specified component is associated with an * error message in the given validation result. As a prerequisite, * the component must have an <em>association key</em> set. That can * be done using {@link #setMessageKey(JComponent, Object)} or * {@link #setMessageKeys(JComponent, Object[])}.<p> * * <strong>Note:</strong> This method may become slow if invoked for larger * validation results <em>and</em> multiple components. In this case, * it is recommended to use {@link ValidationResult#keyMap()} instead. * The latter iterates once over the validation result and can be used later * to request the severity for multiple components in almost linear time. * * @param comp used to get the association key from * @param result used to lookup the validation messages from * @return true if the given component is associated with an error message * @throws NullPointerException if the component or validation result * is {@code null} * * @see #hasWarning(JComponent, ValidationResult) * @see #getMessageKeys(JComponent) */ public static boolean hasError(JComponent comp, ValidationResult result) { return result.subResult(getMessageKeys(comp)).hasErrors(); }
/** * Checks and answers if the specified component is associated with a * warning message in the given validation result. As a prerequisite, * the component must have a <em>message key</em> set. That can * be done using {@link #setMessageKey(JComponent, Object)} or * {@link #setMessageKeys(JComponent, Object[])}.<p> * * <strong>Note:</strong> This method may become slow if invoked for larger * validation results <em>and</em> multiple components. In this case, * it is recommended to use {@link ValidationResult#keyMap()} instead. * The latter iterates once over the validation result and can be used later * to request the severity for multiple components in almost linear time. * * @param comp used to get the association key from * @param result used to lookup the validation messages from * @return true if the given component is associated with a warning message * @throws NullPointerException if the component or validation result * is {@code null} * * @see #hasError(JComponent, ValidationResult) * @see #getMessageKeys(JComponent) */ public static boolean hasWarning(JComponent comp, ValidationResult result) { return result.subResult(getMessageKeys(comp)).hasWarnings(); }
/** * Checks and answers if the specified component is associated with an * error message in the given validation result. As a prerequisite, * the component must have an <em>association key</em> set. That can * be done using {@link #setMessageKey(JComponent, Object)} or * {@link #setMessageKeys(JComponent, Object[])}.<p> * * <strong>Note:</strong> This method may become slow if invoked for larger * validation results <em>and</em> multiple components. In this case, * it is recommended to use {@link ValidationResult#keyMap()} instead. * The latter iterates once over the validation result and can be used later * to request the severity for multiple components in almost linear time. * * @param comp used to get the association key from * @param result used to lookup the validation messages from * @return true if the given component is associated with an error message * @throws NullPointerException if the component or validation result * is {@code null} * * @see #hasWarning(JComponent, ValidationResult) * @see #getMessageKeys(JComponent) */ public static boolean hasError(JComponent comp, ValidationResult result) { return result.subResult(getMessageKeys(comp)).hasErrors(); }
Object[] messageKeys = getMessageKeys(comp); if ((messageKeys == null) || (keyMap == null)) { return null;
Object[] messageKeys = getMessageKeys(comp); if (messageKeys == null || keyMap == null) { return null;
/** * Sets the component background according to the associated * validation result: default, error, warning. * * @param component the component to be visited * @param keyMap maps messages keys to associated validation results */ public void visit(JComponent component, Map<Object, ValidationResult> keyMap) { Object messageKeys = getMessageKeys(component); if (messageKeys == null) { return; } JTextComponent textChild = (JTextComponent) component; ensureCustomBackgroundStored(textChild); ValidationResult result = getAssociatedResult(component, keyMap); if ((result == null) || result.isEmpty()) { restoreBackground(textChild); } else if (result.hasErrors()) { setErrorBackground(textChild); } else if (result.hasWarnings()) { setWarningBackground(textChild); } } }
/** * Sets the component background according to the associated * validation result: default, error, warning. * * @param component the component to be visited * @param keyMap maps messages keys to associated validation results */ @Override public void visit(JComponent component, Map<Object, ValidationResult> keyMap) { Object messageKeys = getMessageKeys(component); if (messageKeys == null) { return; } JTextComponent textChild = (JTextComponent) component; ensureCustomBackgroundStored(textChild); ValidationResult result = getAssociatedResult(component, keyMap); if (result == null || result.isEmpty()) { restoreBackground(textChild); } else if (result.hasErrors()) { setErrorBackground(textChild); } else if (result.hasWarnings()) { setWarningBackground(textChild); } } }