diff options
Diffstat (limited to 'altosui/AltosAscent.java')
| -rw-r--r-- | altosui/AltosAscent.java | 428 | 
1 files changed, 92 insertions, 336 deletions
diff --git a/altosui/AltosAscent.java b/altosui/AltosAscent.java index 3f74fdd1..3bc80406 100644 --- a/altosui/AltosAscent.java +++ b/altosui/AltosAscent.java @@ -17,385 +17,151 @@  package altosui; +import java.util.*;  import java.awt.*; +import java.awt.event.*;  import javax.swing.*; -import org.altusmetrum.altoslib_3.*; +import org.altusmetrum.altoslib_4.*; +import org.altusmetrum.altosuilib_2.*; -public class AltosAscent extends JComponent implements AltosFlightDisplay { -	GridBagLayout	layout; -	JLabel			cur, max; +public class AltosAscent extends AltosUIFlightTab { +	JLabel	cur, max; -	public class AscentStatus { -		JLabel		label; -		JTextField	value; -		AltosLights	lights; +	class Height extends AltosUIUnitsIndicator { -		void show() { -			value.setVisible(true); -			lights.setVisible(true); -			label.setVisible(true); -		} - -		void hide() { -			value.setVisible(false); -			lights.setVisible(false); -			label.setVisible(false); -		} - -		void show(AltosState state, AltosListenerState listener_state) {} - -		void show(String s) { -			show(); -			value.setText(s); -		} -		 -		void show(AltosUnits units, double v) { -			show(units.show(8, v)); -		} - -		void show(String format, double v) { -			show(String.format(format, v)); -		} - -		void reset() { -			value.setText(""); -			lights.set(false); -		} - -		void set_font() { -			label.setFont(Altos.label_font); -			value.setFont(Altos.value_font); +		public double value(AltosState state, int i) { +			if (i == 0) +				return state.height(); +			else +				return state.max_height();  		} -		public AscentStatus (GridBagLayout layout, int y, String text) { -			GridBagConstraints	c = new GridBagConstraints(); -			c.weighty = 1; - -			lights = new AltosLights(); -			c.gridx = 0; c.gridy = y; -			c.anchor = GridBagConstraints.CENTER; -			c.fill = GridBagConstraints.VERTICAL; -			c.weightx = 0; -			layout.setConstraints(lights, c); -			add(lights); - -			label = new JLabel(text); -			label.setFont(Altos.label_font); -			label.setHorizontalAlignment(SwingConstants.LEFT); -			c.gridx = 1; c.gridy = y; -			c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); -			c.anchor = GridBagConstraints.WEST; -			c.fill = GridBagConstraints.VERTICAL; -			c.weightx = 0; -			layout.setConstraints(label, c); -			add(label); - -			value = new JTextField(Altos.text_width); -			value.setFont(Altos.value_font); -			value.setHorizontalAlignment(SwingConstants.RIGHT); -			c.gridx = 2; c.gridy = y; -			c.gridwidth = 2; -			c.anchor = GridBagConstraints.WEST; -			c.fill = GridBagConstraints.BOTH; -			c.weightx = 1; -			layout.setConstraints(value, c); -			add(value); - +		public Height(Container container, int y) { +			super(container, y, AltosConvert.height, "Height", 2, false, 1);  		}  	} -	public class AscentValue { -		JLabel		label; -		JTextField	value; -		void show(AltosState state, AltosListenerState listener_state) {} - -		void reset() { -			value.setText(""); +	class Speed extends AltosUIUnitsIndicator { +		public double value(AltosState state, int i) { +			if (i == 0) +				return state.speed(); +			else +				return state.max_speed();  		} -		void show() { -			label.setVisible(true); -			value.setVisible(true); +		public Speed(Container container, int y) { +			super(container, y, AltosConvert.speed, "Speed", 2, false, 1);  		} +	} -		void show(String s) { -			show(); -			value.setText(s); -		} -		 -		void show(AltosUnits units, double v) { -			show(units.show(8, v)); -		} +	class Accel extends AltosUIUnitsIndicator { +		public boolean hide(double v) { return v == AltosLib.MISSING; } -		void show(String format, double v) { -			show(String.format(format, v)); -		} - -		void hide() { -			label.setVisible(false); -			value.setVisible(false); -		} -		void set_font() { -			label.setFont(Altos.label_font); -			value.setFont(Altos.value_font); +		public double value(AltosState state, int i) { +			if (i == 0) +				return state.acceleration(); +			else +				return state.max_acceleration();  		} -		public AscentValue (GridBagLayout layout, int y, String text) { -			GridBagConstraints	c = new GridBagConstraints(); -			c.weighty = 1; - -			label = new JLabel(text); -			label.setFont(Altos.label_font); -			label.setHorizontalAlignment(SwingConstants.LEFT); -			c.gridx = 1; c.gridy = y; -			c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); -			c.anchor = GridBagConstraints.WEST; -			c.fill = GridBagConstraints.VERTICAL; -			c.weightx = 0; -			layout.setConstraints(label, c); -			add(label); - -			value = new JTextField(Altos.text_width); -			value.setFont(Altos.value_font); -			value.setHorizontalAlignment(SwingConstants.RIGHT); -			c.gridx = 2; c.gridy = y; -			c.anchor = GridBagConstraints.WEST; -			c.fill = GridBagConstraints.BOTH; -			c.gridwidth = 2; -			c.weightx = 1; -			layout.setConstraints(value, c); -			add(value); +		public Accel(Container container, int y) { +			super(container, y, AltosConvert.accel, "Acceleration", 2, false, 1);  		}  	} -	public class AscentValueHold { -		JLabel		label; -		JTextField	value; -		JTextField	max_value; -		double		max; +	class Orient extends AltosUIUnitsIndicator { -		void show(AltosState state, AltosListenerState listener_state) {} +		public boolean hide(double v) { return v == AltosLib.MISSING; } -		void reset() { -			value.setText(""); -			max_value.setText(""); -			max = AltosLib.MISSING; +		public double value(AltosState state, int i) { +			if (i == 0) +				return state.orient(); +			else +				return state.max_orient();  		} -		void set_font() { -			label.setFont(Altos.label_font); -			value.setFont(Altos.value_font); -			max_value.setFont(Altos.value_font); +		public Orient(Container container, int y) { +			super(container, y, AltosConvert.orient, "Tilt Angle", 2, false, 1);  		} -		void show(AltosUnits units, double v) { -			if (v == AltosLib.MISSING) { -				value.setText("Missing"); -				max_value.setText("Missing"); -			} else { -				value.setText(units.show(8, v)); -				if (v > max || max == AltosLib.MISSING) { -					max_value.setText(units.show(8, v)); -					max = v; -				} -			} -		} -		public AscentValueHold (GridBagLayout layout, int y, String text) { -			GridBagConstraints	c = new GridBagConstraints(); -			c.weighty = 1; - -			label = new JLabel(text); -			label.setFont(Altos.label_font); -			label.setHorizontalAlignment(SwingConstants.LEFT); -			c.gridx = 1; c.gridy = y; -			c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); -			c.anchor = GridBagConstraints.WEST; -			c.fill = GridBagConstraints.VERTICAL; -			c.weightx = 0; -			layout.setConstraints(label, c); -			add(label); - -			value = new JTextField(Altos.text_width); -			value.setFont(Altos.value_font); -			value.setHorizontalAlignment(SwingConstants.RIGHT); -			c.gridx = 2; c.gridy = y; -			c.anchor = GridBagConstraints.EAST; -			c.fill = GridBagConstraints.BOTH; -			c.weightx = 1; -			layout.setConstraints(value, c); -			add(value); - -			max_value = new JTextField(Altos.text_width); -			max_value.setFont(Altos.value_font); -			max_value.setHorizontalAlignment(SwingConstants.RIGHT); -			c.gridx = 3; c.gridy = y; -			c.anchor = GridBagConstraints.EAST; -			c.fill = GridBagConstraints.BOTH; -			c.weightx = 1; -			layout.setConstraints(max_value, c); -			add(max_value); -		}  	} +	class Apogee extends AltosUIUnitsIndicator { -	class Height extends AscentValueHold { -		void show (AltosState state, AltosListenerState listener_state) { -			show(AltosConvert.height, state.height()); +		public double value(AltosState state, int i) { +			return state.apogee_voltage;  		} -		public Height (GridBagLayout layout, int y) { -			super (layout, y, "Height"); -		} -	} -	Height	height; +		public boolean good(double v) { return v >= AltosLib.ao_igniter_good; } +		public boolean hide(double v) { return v == AltosLib.MISSING; } -	class Speed extends AscentValueHold { -		void show (AltosState state, AltosListenerState listener_state) { -			show(AltosConvert.speed, state.speed()); -		} -		public Speed (GridBagLayout layout, int y) { -			super (layout, y, "Speed"); +		public Apogee (Container container, int y) { +			super(container, y, AltosConvert.voltage, "Apogee Igniter Voltage", 1, true, 2);  		}  	} -	Speed	speed; - -	class Accel extends AscentValueHold { -		void show (AltosState state, AltosListenerState listener_state) { -			show(AltosConvert.accel, state.acceleration()); +	class Main extends AltosUIUnitsIndicator { +		public double value(AltosState state, int i) { +			return state.main_voltage;  		} -		public Accel (GridBagLayout layout, int y) { -			super (layout, y, "Acceleration"); -		} -	} -	Accel	accel; +		public boolean good(double v) { return v >= AltosLib.ao_igniter_good; } +		public boolean hide(double v) { return v == AltosLib.MISSING; } -	class Orient extends AscentValueHold { -		void show (AltosState state, AltosListenerState listener_state) { -			show(AltosConvert.orient, state.orient()); -		} -		public Orient (GridBagLayout layout, int y) { -			super (layout, y, "Tilt Angle"); +		public Main (Container container, int y) { +			super(container, y, AltosConvert.voltage, "Main Igniter Voltage", 1, true, 2);  		}  	} -	Orient	orient; +	class Lat extends AltosUIUnitsIndicator { -	String pos(double p, String pos, String neg) { -		String	h = pos; -		if (p < 0) { -			h = neg; -			p = -p; +		public boolean hide(AltosState state, int i) { +			return state.gps == null || !state.gps.connected;  		} -		int deg = (int) Math.floor(p); -		double min = (p - Math.floor(p)) * 60.0; -		return String.format("%s %4d° %9.6f", h, deg, min); -	} -	class Apogee extends AscentStatus { -		void show (AltosState state, AltosListenerState listener_state) { -			show("%4.2f V", state.apogee_voltage); - 			lights.set(state.apogee_voltage >= AltosLib.ao_igniter_good); -		} -		public Apogee (GridBagLayout layout, int y) { -			super(layout, y, "Apogee Igniter Voltage"); +		public double value(AltosState state, int i) { +			if (state.gps == null) +				return AltosLib.MISSING; +			if (!state.gps.connected) +				return AltosLib.MISSING; +			return state.gps.lat;  		} -	} -	Apogee apogee; - -	class Main extends AscentStatus { -		void show (AltosState state, AltosListenerState listener_state) { -			show("%4.2f V", state.main_voltage); -			lights.set(state.main_voltage >= AltosLib.ao_igniter_good); -		} -		public Main (GridBagLayout layout, int y) { -			super(layout, y, "Main Igniter Voltage"); +		Lat (Container container, int y) { +			super (container, y, AltosConvert.latitude, "Latitude", 1, false, 2);  		}  	} -	Main main; +	class Lon extends AltosUIUnitsIndicator { -	class Lat extends AscentValue { -		void show (AltosState state, AltosListenerState listener_state) { -			if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING) -				show(pos(state.gps.lat,"N", "S")); -			else -				show("???"); +		public boolean hide(AltosState state, int i) { +			return state.gps == null || !state.gps.connected;  		} -		public Lat (GridBagLayout layout, int y) { -			super (layout, y, "Latitude"); -		} -	} - -	Lat lat; -	class Lon extends AscentValue { -		void show (AltosState state, AltosListenerState listener_state) { -			if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING) -				show(pos(state.gps.lon,"E", "W")); -			else -				show("???"); -		} -		public Lon (GridBagLayout layout, int y) { -			super (layout, y, "Longitude"); +		public double value(AltosState state, int i) { +			if (state.gps == null) +				return AltosLib.MISSING; +			if (!state.gps.connected) +				return AltosLib.MISSING; +			return state.gps.lon;  		} -	} -	Lon lon; - -	public void reset() { -		lat.reset(); -		lon.reset(); -		main.reset(); -		apogee.reset(); -		height.reset(); -		speed.reset(); -		accel.reset(); -		orient.reset(); -	} - -	public void set_font() { -		cur.setFont(Altos.label_font); -		max.setFont(Altos.label_font); -		lat.set_font(); -		lon.set_font(); -		main.set_font(); -		apogee.set_font(); -		height.set_font(); -		speed.set_font(); -		accel.set_font(); -		orient.set_font(); +		Lon (Container container, int y) { +			super (container, y, AltosConvert.longitude, "Longitude", 1, false, 2); +		}  	} -	public void show(AltosState state, AltosListenerState listener_state) { -		if (state.gps != null && state.gps.connected) { -			lat.show(state, listener_state); -			lon.show(state, listener_state); -		} else { -			lat.hide(); -			lon.hide(); -		} -		height.show(state, listener_state); -		if (state.main_voltage != AltosLib.MISSING) -			main.show(state, listener_state); -		else -			main.hide(); -		if (state.apogee_voltage != AltosLib.MISSING) -			apogee.show(state, listener_state); -		else -			apogee.hide(); -		speed.show(state, listener_state); -		accel.show(state, listener_state); -		orient.show(state, listener_state); +	public void font_size_changed(int font_size) { +		super.font_size_changed(font_size); +		cur.setFont(AltosUILib.label_font); +		max.setFont(AltosUILib.label_font);  	}  	public void labels(GridBagLayout layout, int y) {  		GridBagConstraints	c;  		cur = new JLabel("Current"); -		cur.setFont(Altos.label_font); +		cur.setFont(AltosUILib.label_font);  		c = new GridBagConstraints();  		c.gridx = 2; c.gridy = y;  		c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad); @@ -403,7 +169,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {  		add(cur);  		max = new JLabel("Maximum"); -		max.setFont(Altos.label_font); +		max.setFont(AltosUILib.label_font);  		c.gridx = 3; c.gridy = y;  		layout.setConstraints(max, c);  		add(max); @@ -414,25 +180,15 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {  	}  	public AltosAscent() { -		layout = new GridBagLayout(); - -		setLayout(layout); - -		/* Elements in ascent display: -		 * -		 * lat -		 * lon -		 * height -		 */  		int y = 0;  		labels(layout, y++); -		height = new Height(layout, y++); -		speed = new Speed(layout, y++); -		accel = new Accel(layout, y++); -		orient = new Orient(layout, y++); -		lat = new Lat(layout, y++); -		lon = new Lon(layout, y++); -		apogee = new Apogee(layout, y++); -		main = new Main(layout, y++); +		add(new Height(this, y++)); +		add(new Speed(this, y++)); +		add(new Accel(this, y++)); +		add(new Orient(this, y++)); +		add(new Lat(this, y++)); +		add(new Lon(this, y++)); +		add(new Apogee(this, y++)); +		add(new Main(this, y++));  	}  }  | 
