BarMeter

The BarMeter may be displayed either horizontal or vertical and supports two different textures (filled or lined).

Besides the standard methods like setValue or setBounds, the BarMeter provides some specific configuration options. These are listed in table 3.

MethodDescription
BarMeter(int x, int y, int width, int height, int min, int max, boolean orientation, int style)Creates a new BarMeter at the desired location and with the specified dimensions. The values min and max define the range of values to be displayed. The parameter style specifies the used texture(FILL_LINE or FILL_SOLID). orientation configures the BarMeters' alignment (possible values are ORIENTATION_HORIZONTAL and ORIENTATION_VERTICAL).
setCaption(String captionMin, String captionMax)Adds a caption to the BarMeter. The passed Strings will be displayed at the beginning and at the end of the bar.
setNumericDisplay(int digits, int decimals, String unit)This method configures the alphanumeric display of measured values. Parameter digits defines the total number of displayed digits, decimals specifies the number of decimals included in digits. Example: digits=4 and decimals=3 will display values in form of x,xxx. If decimals=0, no decimal point will be displayed (useful if the measured value shall be displayed in a different range of values). The parameter unit holds the unit of the displayed values (e.g. "V").
setValue(int value)Passes a new value to the BarMeter, which thereupon will be updated. If value exceeds the range of values, it will be replaced by the according value for min or max.
Table 3: Methods of class jcontrol.ui.vole.meter.BarMeter

The following program listing 3 is called VoleBarMeterExample and demonstrates the usage of the BarMeter. You may download the archive VoleBarMeterExample.zip and open the contained JControl/IDE project file. If you start the project in the simulator you will get a picture like the one shown in figure 3.

Figure 3: The VoleBarMeterExample

1    import jcontrol.lang.Math;
2    import jcontrol.lang.ThreadExt;
3    import jcontrol.ui.vole.Frame;
4    import jcontrol.ui.vole.meter.BarMeter;
5    
6    /**
7     * <p>This example demonstrates how to use the
8     * components BarMeter and Thermometer within
9     * the GUI framework JControl/Vole.</p>
10     *
11     * <p>(C) DOMOLOGIC Home Automation GmbH 2003-2005</p>
12     */
13    public class VoleBarMeterExample extends Frame {
14     
15      /**
16       * Draw two BarMeters and a Thermometer
17       */
18      public VoleBarMeterExample() {
19        // create a vertical BarMeter with solid fill and inscriptions
20        BarMeter bm1 = new BarMeter(5, 0, 30, 35, 0, 20,
21                                    BarMeter.ORIENTATION_VERTICAL,
22                                    BarMeter.FILL_SOLID);
23        bm1.setCaption("Min", "Max");
24        this.add(bm1);
25       
26        // create a horizontal BarMeter with line-style fill
27        BarMeter bm2 = new BarMeter(5, 40, 100, 20, 0, 100,
28                                    BarMeter.ORIENTATION_HORIZONTAL,
29                                    BarMeter.FILL_LINE);
30        bm2.setCaption("0", "20");
31        bm2.setNumericDisplay(5, 0, "%");
32        this.add(bm2);
33       
34        // make the frame visible
35        show();
36       
37        // generate random values
38        for (;;) {
39          bm1.setValue(Math.rnd(20));
40          bm2.setValue(Math.rnd(100));
41         
42          try { ThreadExt.sleep(1000); } catch (InterruptedException e) {}
43        }
44      }
45    
46      /**
47       * Start the example
48       */
49      public static void main(String[] args) {
50        new VoleBarMeterExample();
51      }
52    }
Listing 3: VoleBarMeterExample.java