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; version 2 of the License.
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.
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.
18 package org.altusmetrum.altosuilib_2;
22 import org.altusmetrum.altoslib_4.*;
24 public abstract class AltosUIIndicator implements AltosFontListener, AltosUnitsListener {
32 abstract public void show(AltosState state, AltosListenerState listener_state);
34 public void set_lights(boolean on) {
38 public void setVisible(boolean visible) {
40 lights.setVisible(visible);
41 label.setVisible(visible);
42 for (int i = 0; i < values.length; i++)
43 values[i].setVisible(visible);
47 for (int i = 0; i < values.length; i++)
48 values[i].setText("");
55 lights.setVisible(true);
56 label.setVisible(true);
57 for (int i = 0; i < values.length; i++)
58 values[i].setVisible(true);
61 public void show(String... s) {
62 int n = Math.min(s.length, values.length);
64 for (int i = 0; i < n; i++)
65 values[i].setText(s[i]);
68 public void show(String format, double value) {
69 show(String.format(format, value));
72 public void show(String format, int value) {
73 show(String.format(format, value));
76 public void show(String format1, double value1, String format2, double value2) {
77 show(String.format(format1, value1), String.format(format2, value2));
80 public void show(String format1, int value1, String format2, int value2) {
81 show(String.format(format1, value1), String.format(format2, value2));
86 lights.setVisible(false);
87 label.setVisible(false);
88 for (int i = 0; i < values.length; i++)
89 values[i].setVisible(false);
92 public void font_size_changed(int font_size) {
93 label.setFont(AltosUILib.label_font);
94 for (int i = 0; i < values.length; i++)
95 values[i].setFont(AltosUILib.value_font);
98 public void units_changed(boolean imperial_units) {
101 public void set_label(String text) {
105 public AltosUIIndicator (Container container, int y, String text, int number_values, boolean has_lights, int value_width) {
106 GridBagLayout layout = (GridBagLayout)(container.getLayout());
108 GridBagConstraints c = new GridBagConstraints();
112 lights = new AltosLights();
113 c.gridx = 0; c.gridy = y;
114 c.anchor = GridBagConstraints.CENTER;
115 c.fill = GridBagConstraints.VERTICAL;
117 layout.setConstraints(lights, c);
118 container.add(lights);
121 label = new JLabel(text);
122 label.setFont(AltosUILib.label_font);
123 label.setHorizontalAlignment(SwingConstants.LEFT);
124 c.gridx = 1; c.gridy = y;
125 c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
126 c.anchor = GridBagConstraints.WEST;
127 c.fill = GridBagConstraints.VERTICAL;
129 layout.setConstraints(label, c);
130 container.add(label);
132 values = new JTextField[number_values];
133 for (int i = 0; i < values.length; i++) {
134 values[i] = new JTextField(AltosUILib.text_width);
135 values[i].setEditable(false);
136 values[i].setFont(AltosUILib.value_font);
137 values[i].setHorizontalAlignment(SwingConstants.RIGHT);
138 c.gridx = 2 + i; c.gridy = y;
139 c.anchor = GridBagConstraints.WEST;
140 c.fill = GridBagConstraints.BOTH;
142 c.gridwidth = value_width;
143 layout.setConstraints(values[i], c);
144 container.add(values[i]);
148 public AltosUIIndicator (Container container, int y, String text) {
149 this(container, y, text, 1, false, 1);
152 public AltosUIIndicator (Container container, int y, String text, int number_values) {
153 this(container, y, text, number_values, false, 1);
156 public AltosUIIndicator (Container container, int y, String text, int number_values, boolean has_lights) {
157 this(container, y, text, number_values, has_lights, 1);