Source code: com/webobjects/woextensions/WOThresholdColoredNumber.java
1 /*
2 * WOThresholdColoredNumber.java
3 * © Copyright 2001 Apple Computer, Inc. All rights reserved.
4 * This a modified version.
5 * Original license: http://www.opensource.apple.com/apsl/
6 */
7
8 package com.webobjects.woextensions;
9
10 import com.webobjects.appserver.*;
11
12 public class WOThresholdColoredNumber extends WOComponent
13 {
14 protected Number _threshold;
15 protected String _highColor;
16 protected String _lowColor;
17
18 public WOThresholdColoredNumber(WOContext aContext) {
19 super(aContext);
20 }
21
22 public boolean isStateless() {
23 return true;
24 }
25
26 public void reset() {
27 _invalidateCaches();
28 }
29
30 protected Number numberForBinding(String theBinding) {
31 Object bindingValue = valueForBinding(theBinding);
32 if (bindingValue != null) {
33 if (bindingValue instanceof String) {
34 return (Number) new Long((String) bindingValue);
35 }
36 if (bindingValue instanceof Number) {
37 return (Number) bindingValue;
38 }
39 }
40
41 return new Integer(0);
42 }
43
44 public Number threshold() {
45 if (_threshold==null) {
46 _threshold = numberForBinding("threshold");
47 }
48 return _threshold;
49 }
50
51 public String highColor() {
52 if (null==_highColor) {
53 _highColor = (String)_WOJExtensionsUtil.valueForBindingOrNull("highColor",this);
54 if (null==_highColor) {
55 _highColor = "#00FF00";
56 }
57 }
58 return _highColor;
59 }
60
61 public String lowColor() {
62 if (null==_lowColor) {
63 _lowColor = (String)_WOJExtensionsUtil.valueForBindingOrNull("lowColor",this);
64 if (null==_lowColor) {
65 _lowColor = "#FF0000";
66 }
67 }
68 return _lowColor;
69 }
70
71 public String color() {
72 String aColor = null;
73
74 if (numberForBinding("value").longValue() >= threshold().longValue()) {
75 aColor = highColor();
76 } else {
77 aColor = lowColor();
78 }
79 return aColor;
80 }
81
82 protected void _invalidateCaches() {
83 // ** By setting these to nil, we allow for cycling of the page)
84 _threshold = null;
85 _highColor = null;
86 _lowColor = null;
87 }
88
89 }