package com.oreilly.javaxp.junit;
import java.awt.*;
/**
* @author Eric M. Burke
* @version $Id: UtilComponent.java,v 1.1 2002/11/16 20:03:31 jepc Exp $
*/
public class UtilComponent {
public static final int ADD_MODE = 1;
public static final int RECORD_AVAILABLE_MODE = 2;
public static final int NO_RECORD_AVAILABLE_MODE = 3;
public static final int KEY_FIELD = 100;
public static final int REQUIRED_FIELD = 101;
public static final int READONLY_FIELD = 102;
public static final int NORMAL_FIELD = 103;
public static final Color FIELD_NORMAL_BACKGROUND = Color.WHITE;
public static final Color FIELD_ERROR_BACKGROUND = Color.PINK;
public static final Color FIELD_REQUIRED_BACKGROUND = Color.CYAN;
public static final Color FIELD_DISABLED_BACKGROUND = Color.GRAY;
public static Color getFieldBackground(
int screenMode,
int fieldType,
boolean valid,
boolean requiredConditionMet) {
if (fieldType == READONLY_FIELD
|| screenMode == NO_RECORD_AVAILABLE_MODE
|| (fieldType == KEY_FIELD && screenMode != ADD_MODE)) {
return FIELD_DISABLED_BACKGROUND;
}
if (!valid) {
return FIELD_ERROR_BACKGROUND;
}
if ((fieldType == KEY_FIELD || fieldType == REQUIRED_FIELD)
&& !requiredConditionMet) {
return FIELD_REQUIRED_BACKGROUND;
}
return FIELD_NORMAL_BACKGROUND;
}
public static String colorToString(Color color) {
if (color == null) {
return "null";
}
if (color.equals(FIELD_DISABLED_BACKGROUND)) {
return "FIELD_DISABLED_BACKGROUND";
}
if (color.equals(FIELD_ERROR_BACKGROUND)) {
return "FIELD_ERROR_BACKGROUND";
}
if (color.equals(FIELD_REQUIRED_BACKGROUND)) {
return "FIELD_REQUIRED_BACKGROUND";
}
if (color.equals(FIELD_NORMAL_BACKGROUND)) {
return "FIELD_NORMAL_BACKGROUND";
}
return color.toString();
}
}
|