Switch from GPLv2 to GPLv2+
[fw/altos] / altosuilib / AltosFlightStatsTable.java
index ec106cf1f0e973156a55a4183ed5e591b8716f84..2f46f231cbc0221dc9ffb1a3520f854eeb23bbb5 100644 (file)
@@ -3,7 +3,8 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altosuilib_2;
+package org.altusmetrum.altosuilib_11;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_4.*;
+import java.util.*;
+import org.altusmetrum.altoslib_11.*;
 
-public class AltosFlightStatsTable extends JComponent {
+public class AltosFlightStatsTable extends JComponent implements AltosFontListener {
        GridBagLayout   layout;
 
-       class FlightStat {
+       LinkedList<FlightStat> flight_stats = new LinkedList<FlightStat>();
+
+       class FlightStat implements AltosFontListener {
                JLabel          label;
-               JTextField      value;
+               JTextField[]    value;
+
+               public void font_size_changed(int font_size) {
+                       label.setFont(AltosUILib.label_font);
+                       for (int i = 0; i < value.length; i++)
+                               value[i].setFont(AltosUILib.value_font);
+               }
 
                public FlightStat(GridBagLayout layout, int y, String label_text, String ... values) {
                        GridBagConstraints      c = new GridBagConstraints();
@@ -43,21 +53,29 @@ public class AltosFlightStatsTable extends JComponent {
                        layout.setConstraints(label, c);
                        add(label);
 
+                       value = new JTextField[values.length];
                        for (int j = 0; j < values.length; j++) {
-                               value = new JTextField(values[j]);
-                               value.setFont(AltosUILib.value_font);
-                               value.setHorizontalAlignment(SwingConstants.RIGHT);
+                               value[j] = new JTextField(values[j]);
+                               value[j].setEditable(false);
+                               value[j].setFont(AltosUILib.value_font);
+                               value[j].setHorizontalAlignment(SwingConstants.RIGHT);
                                c.gridx = j+1; c.gridy = y;
                                c.anchor = GridBagConstraints.EAST;
                                c.fill = GridBagConstraints.BOTH;
                                c.weightx = 1;
-                               layout.setConstraints(value, c);
-                               add(value);
+                               layout.setConstraints(value[j], c);
+                               add(value[j]);
                        }
+                       flight_stats.add(this);
                }
 
        }
 
+       public void font_size_changed(int font_size) {
+               for (FlightStat f : flight_stats)
+                       f.font_size_changed(font_size);
+       }
+
        static String pos(double p, String pos, String neg) {
                String  h = pos;
                if (p < 0) {
@@ -100,18 +118,18 @@ public class AltosFlightStatsTable extends JComponent {
                }
                new FlightStat(layout, y++, "Maximum speed",
                               String.format("%5.0f m/s", stats.max_speed),
-                              String.format("%5.0f mph", AltosConvert.meters_to_mph(stats.max_speed)),
+                              String.format("%5.0f fps", AltosConvert.mps_to_fps(stats.max_speed)),
                               String.format("Mach %4.1f", AltosConvert.meters_to_mach(stats.max_speed)));
-               if (stats.max_acceleration != AltosLib.MISSING) {
+               if (stats.max_acceleration != AltosLib.MISSING)
                        new FlightStat(layout, y++, "Maximum boost acceleration",
                                       String.format("%5.0f m/s²", stats.max_acceleration),
                                       String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.max_acceleration)),
                                       String.format("%5.0f G", AltosConvert.meters_to_g(stats.max_acceleration)));
+               if (stats.state_accel[AltosLib.ao_flight_boost] != AltosLib.MISSING)
                        new FlightStat(layout, y++, "Average boost acceleration",
                                       String.format("%5.0f m/s²", stats.state_accel[AltosLib.ao_flight_boost]),
                                       String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.state_accel[AltosLib.ao_flight_boost])),
                                       String.format("%5.0f G", AltosConvert.meters_to_g(stats.state_accel[AltosLib.ao_flight_boost])));
-               }
                if (stats.state_speed[AltosLib.ao_flight_drogue] != AltosLib.MISSING)
                        new FlightStat(layout, y++, "Drogue descent rate",
                                       String.format("%5.0f m/s", stats.state_speed[AltosLib.ao_flight_drogue]),
@@ -147,5 +165,4 @@ public class AltosFlightStatsTable extends JComponent {
                                       pos(stats.lon,"E","W"));
                }
        }
-
 }