View Javadoc

1   package org.informagen.echo.app;
2   
3   
4   import nextapp.echo.app.Component;
5   import nextapp.echo.app.Color;
6   import nextapp.echo.app.Extent;
7   
8   import java.lang.Number;
9   
10  import java.util.ArrayList;
11  import java.util.Collections;
12  import java.util.List;
13  
14  
15  /**
16   * 
17   */
18  
19  public class CapacityBar extends Component {
20      
21      // Properties
22      public static final String PROPERTY_WIDTH = "width";
23      public static final String PROPERTY_HEIGHT = "height";
24      public static final String PROPERTY_SHOW_TICKS = "showTicks";
25      public static final String PROPERTY_REFLECTIVITY = "reflectivity";
26      public static final String PROPERTY_CORNER_RADIUS = "cornerRadius";
27      
28      // Values
29      public static final String PROPERTY_TICK_SPACING = "tickSpacing";
30      public static final String PROPERTY_COLORS = "colors";
31      public static final String PROPERTY_VALUES = "values";
32  
33      private Extent width = new Extent(460, Extent.PX);
34      private Extent height = new Extent(18, Extent.PX);
35      private boolean showTicks = true;
36      private double reflectivity = 0.75;
37      private double cornerRadius = 1.0;
38      
39      private Number tickSpacing = null;
40  
41      private List<Color> colors = Collections.EMPTY_LIST;
42      private List<Number> values = Collections.EMPTY_LIST;
43  
44      public CapacityBar() {
45          super();
46      }
47  
48  
49      public CapacityBar(int height, int width) {
50          super();
51          
52          setHeight(height);
53          setWidth(width);
54      }
55  
56      //-----------------------------------------------------------------------------------------
57      
58      /**
59       * Set the width 
60       * 
61       * @param width the width in pixels
62      */
63         
64      public void setWidth(int width) {
65          setWidth(new Extent(width, Extent.PX));
66      }
67  
68      public void setWidth(Extent width) {
69          Extent oldWidth = this.width;
70          this.width = width;
71          firePropertyChange(PROPERTY_WIDTH, oldWidth, width);
72      }
73  
74      /**
75       * Get the width
76       * 
77       * @returns Extent the width
78      */
79         
80      public Extent getWidth() {
81          return width;
82      }
83  
84      //-----------------------------------------------------------------------------------------
85  
86      /**
87       * Set the height 
88       * 
89       * @param height the height in pixels
90      */
91         
92      public void setHeight(int height) {
93          setHeight(new Extent(height, Extent.PX));
94      }
95  
96      public void setHeight(Extent height) {
97          Extent oldHeight = this.height;
98          this.height = height;
99          firePropertyChange(PROPERTY_HEIGHT, oldHeight, height);
100     }
101 
102 
103     /**
104      * Get the height
105      * 
106      * @returns Extent the height
107     */
108        
109     public Extent getHeight() {
110         return height;
111     }
112 
113     //-----------------------------------------------------------------------------------------
114 
115     /**
116      * Set showTicks 
117      * 
118      * @param showTicks show/hide the tick marks along the capacity bar
119     */
120        
121     public void setShowTicks(boolean showTicks) {
122         Boolean oldShowTicks = this.showTicks ? Boolean.TRUE : Boolean.FALSE;
123         this.showTicks = showTicks;
124         firePropertyChange(PROPERTY_SHOW_TICKS, oldShowTicks, showTicks ? Boolean.TRUE : Boolean.FALSE);
125     }
126 
127 
128     /**
129      * Are the ticks shown or hidden
130      * 
131      * @returns boolean the value of showTicks
132     */
133        
134     public boolean isShowTicks() {
135         return showTicks;
136     }
137 
138     //-----------------------------------------------------------------------------------------
139 
140     /**
141      * Set reflectivity of the relfected image 
142      * 
143      * @param reflectivity the level of the reflectivity, .001 is solid, 1.0 is transparent
144     */
145        
146     public void setReflectivity(double reflectivity) {
147         Double oldValue = new Double(this.reflectivity);
148         
149         // Keep in range 0.001 to 1.0
150         reflectivity = Math.max(reflectivity, 0.001);
151         reflectivity = Math.min(reflectivity, 1.00);
152         
153         this.reflectivity = reflectivity;
154         firePropertyChange(PROPERTY_REFLECTIVITY, oldValue, new Double(reflectivity));
155     }
156 
157 
158     /**
159      * Are the ticks shown or hidden
160      * 
161      * @returns double the reflectivity of the reflected image, .001 is transparent, 1.0 is solid
162     */
163        
164     public double getReflectivity() {
165         return reflectivity;
166     }
167 
168     //-----------------------------------------------------------------------------------------
169 
170     /**
171      * Set the corner radius of the capacity bar 
172      * 
173      * @param corner radius, .001 is square, 1.0 is round
174     */
175        
176     public void setCornerRadius(double cornerRadius) {
177         Double oldCornerRadius = new Double(this.cornerRadius);
178         
179         // Keep in range 0.001 to 1.0
180         cornerRadius = Math.max(cornerRadius, 0.001);
181         cornerRadius = Math.min(cornerRadius, 1.00);
182         
183         this.cornerRadius = cornerRadius;
184         firePropertyChange(PROPERTY_CORNER_RADIUS, oldCornerRadius, new Double(cornerRadius));
185     }
186 
187 
188     /**
189      * Are the ticks shown or hidden
190      * 
191      * @returns double the opacity of the reflected image, .001 is solid, 1.0 is transparent
192     */
193        
194     public double getCornerRadius() {
195         return cornerRadius;
196     }
197 
198     //-----------------------------------------------------------------------------------------
199 
200     /**
201      * Set the tick spacing of the capacity bar 
202      * 
203      * @param tickSpacing 
204     */
205        
206     public void setTickSpacing(Number tickSpacing) {
207         Number oldTickSpacing = this.tickSpacing;
208         
209         this.tickSpacing = tickSpacing;
210         firePropertyChange(PROPERTY_TICK_SPACING, oldTickSpacing, tickSpacing);
211     }
212 
213 
214     /**
215      * Spacing of the ticks
216      * 
217      * @returns Number  
218     */
219        
220     public Number getTickSpacing() {
221         return tickSpacing;
222     }
223 
224     //-----------------------------------------------------------------------------------------
225 
226     /**
227      * Set the list of colors  
228      * 
229      * @param colors the list of colors to use and reuse across the bar
230      */
231        
232     public void setColors(List<Color> colors) {
233         List oldColors = this.colors;
234         
235         this.colors = colors;
236         firePropertyChange(PROPERTY_COLORS, oldColors, colors);
237     }
238 
239 
240     /**
241      * The list of colors to use and reuse across the bar
242      * 
243      * @returns List<colors> the list of colors to use and reuse across the bar
244      */
245        
246     public List<Color> getColors() {
247         return colors;
248     }
249 
250     //-----------------------------------------------------------------------------------------
251 
252     /**
253      * Set the list of values  
254      * 
255      * @param values the list of values to use across the bar
256      */
257        
258     public void setValues(List<Number> values) {
259         List oldValues = this.values;
260         
261         this.values = values;
262         firePropertyChange(PROPERTY_VALUES, oldValues, values);
263     }
264 
265 
266     /**
267      * The list of values to use across the bar
268      * 
269      * @returns List<Number> the list of values to use across the bar
270      */
271        
272     public List<Number> getValues() {
273         return values;
274     }
275 
276 
277 
278 }
279