2 * Copyright © 2014 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altosuilib_11;
23 import org.altusmetrum.altoslib_11.*;
25 public abstract class AltosUIUnitsIndicator extends AltosUIIndicator {
29 abstract public double value(AltosState state, int i);
30 public double good() { return 0; }
31 public boolean good(double value) { return value != AltosLib.MISSING && value >= good(); }
32 public boolean hide(double value) { return false; }
34 public boolean hide(AltosState state, int i) {
36 return hide(AltosLib.MISSING);
37 return hide(value(state, i));
40 public boolean hide(AltosState state, AltosListenerState listener_state, int i) {
41 return hide(state, i);
44 public double value (AltosState state, AltosListenerState listener_state, int i) {
45 return value(state, i);
48 public double[] last_values;
50 private void show(boolean force, double... v) {
52 for (int i = 0; i < values.length; i++) {
53 if (force || v[i] != last_values[i]) {
57 if (v[i] == AltosLib.MISSING) {
58 value_text = "Missing";
60 value_text = units.show(8, v[i]);
64 last_values[i] = v[i];
65 if (i == 0 && lights != null)
67 values[i].setText(value_text);
74 public void show(double... v) {
78 public void units_changed(boolean imperial_units) {
80 show(true, last_values);
83 public void show (AltosState state, AltosListenerState listener_state) {
84 double[] v = new double[values.length];
87 for (int i = 0; i < values.length; i++) {
89 v[i] = value(state, listener_state, i);
91 v[i] = AltosLib.MISSING;
92 if (hide(state, listener_state, i))
102 public void reset() {
103 for (int i = 0; i < last_values.length; i++)
104 last_values[i] = AltosLib.MISSING;
107 public AltosUIUnitsIndicator (Container container, int x, int y, int label_width, AltosUnits units, String name, int number_values, boolean has_lights, int width) {
108 super(container, x, y, label_width, name, number_values, has_lights, width);
110 last_values = new double[values.length];
111 for (int i = 0; i < last_values.length; i++)
112 last_values[i] = AltosLib.MISSING;
115 public AltosUIUnitsIndicator (Container container, int x, int y, AltosUnits units, String name, int number_values, boolean has_lights, int width) {
116 this(container, x, y, 1, units, name, number_values, has_lights, width);
119 public AltosUIUnitsIndicator (Container container, int y, AltosUnits units, String name, int number_values, boolean has_lights, int width) {
120 this(container, 0, y, units, name, number_values, has_lights, width);
123 public AltosUIUnitsIndicator (Container container, int y, AltosUnits units, String name, int width) {
124 this(container, 0, y, units, name, 1, false, width);
127 public AltosUIUnitsIndicator (Container container, int y, AltosUnits units, String name) {
128 this(container, 0, y, units, name, 1, false, 1);
131 public AltosUIUnitsIndicator (Container container, int x,int y, AltosUnits units, String name) {
132 this(container, x, y, units, name, 1, false, 1);