039d83e09d9c0600be32403d17efb50a86ea9441
[fw/altos] / altosuilib / AltosUIFlightTab.java
1 /*
2  * Copyright © 2014 Keith Packard <keithp@keithp.com>
3  *
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; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package org.altusmetrum.altosuilib_2;
19
20 import java.util.*;
21 import java.awt.*;
22 import java.awt.event.*;
23 import javax.swing.*;
24 import org.altusmetrum.altoslib_4.*;
25
26 public abstract class AltosUIFlightTab extends JComponent implements AltosFlightDisplay, HierarchyListener {
27         public GridBagLayout    layout;
28
29         AltosState              last_state;
30         AltosListenerState      last_listener_state;
31
32         LinkedList<AltosUIIndicator>    indicators = new LinkedList<AltosUIIndicator>();
33
34         public void add (AltosUIIndicator indicator) {
35                 indicators.add(indicator);
36         }
37
38         public void remove(AltosUIIndicator indicator) {
39                 indicators.remove(indicator);
40         }
41
42         public void reset() {
43                 for (AltosUIIndicator i : indicators)
44                         i.reset();
45         }
46
47         public void font_size_changed(int font_size) {
48                 for (AltosUIIndicator i : indicators)
49                         i.font_size_changed(font_size);
50         }
51
52         public void units_changed(boolean imperial_units) {
53                 for (AltosUIIndicator i : indicators)
54                         i.units_changed(imperial_units);
55         }
56
57         public void show(AltosState state, AltosListenerState listener_state) {
58                 if (!isShowing()) {
59                         last_state = state;
60                         last_listener_state = listener_state;
61                         return;
62                 }
63
64                 for (AltosUIIndicator i : indicators)
65                         i.show(state, listener_state);
66         }
67
68         public void hierarchyChanged(HierarchyEvent e) {
69                 if (last_state != null && isShowing()) {
70                         AltosState              state = last_state;
71                         AltosListenerState      listener_state = last_listener_state;
72
73                         last_state = null;
74                         last_listener_state = null;
75                         show(state, listener_state);
76                 }
77         }
78
79         abstract public String getName();
80
81         public AltosUIFlightTab() {
82                 layout = new GridBagLayout();
83
84                 setLayout(layout);
85
86                 addHierarchyListener(this);
87         }
88 }