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_3;
22 import org.altusmetrum.altoslib_5.*;
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);
65 for (int i = 0; i < n; i++)
66 values[i].setText(s[i]);
69 public void show(String format, double value) {
70 show(String.format(format, value));
73 public void show(String format, int value) {
74 show(String.format(format, value));
77 public void show(String format1, double value1, String format2, double value2) {
78 show(String.format(format1, value1), String.format(format2, value2));
81 public void show(String format1, int value1, String format2, int value2) {
82 show(String.format(format1, value1), String.format(format2, value2));
87 lights.setVisible(false);
88 label.setVisible(false);
89 for (int i = 0; i < values.length; i++)
90 values[i].setVisible(false);
93 public void font_size_changed(int font_size) {
94 label.setFont(AltosUILib.label_font);
95 for (int i = 0; i < values.length; i++)
96 values[i].setFont(AltosUILib.value_font);
99 public void units_changed(boolean imperial_units) {
102 public void set_label(String text) {
106 public void remove(Container container) {
108 container.remove(lights);
109 container.remove(label);
110 for (int i = 0; i < values.length; i++)
111 container.remove(values[i]);
114 public AltosUIIndicator (Container container, int x, int y, int label_width, String text, int number_values, boolean has_lights, int value_width, int value_space) {
115 GridBagLayout layout = (GridBagLayout)(container.getLayout());
117 GridBagConstraints c = new GridBagConstraints();
121 lights = new AltosLights();
122 c.gridx = x; c.gridy = y;
123 c.anchor = GridBagConstraints.CENTER;
124 c.fill = GridBagConstraints.VERTICAL;
126 layout.setConstraints(lights, c);
127 container.add(lights);
130 label = new JLabel(text);
131 label.setFont(AltosUILib.label_font);
132 label.setHorizontalAlignment(SwingConstants.LEFT);
133 c.gridx = x + 1; c.gridy = y;
134 c.gridwidth = label_width;
135 c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
136 c.anchor = GridBagConstraints.WEST;
137 c.fill = GridBagConstraints.VERTICAL;
139 layout.setConstraints(label, c);
140 container.add(label);
142 values = new JTextField[number_values];
143 for (int i = 0; i < values.length; i++) {
144 values[i] = new JTextField(AltosUILib.text_width);
145 values[i].setEditable(false);
146 values[i].setFont(AltosUILib.value_font);
147 values[i].setHorizontalAlignment(SwingConstants.RIGHT);
148 c.gridx = 1 + label_width + x + i * value_space; c.gridy = y;
149 c.anchor = GridBagConstraints.WEST;
150 c.fill = GridBagConstraints.BOTH;
152 c.gridwidth = value_width;
153 layout.setConstraints(values[i], c);
154 container.add(values[i]);
158 public AltosUIIndicator (Container container, int x, int y, int label_width, String text, int number_values, boolean has_lights, int value_width) {
159 this(container, x, y, label_width, text, number_values, has_lights, value_width, 1);
162 public AltosUIIndicator (Container container, int x, int y, String text, int number_values, boolean has_lights, int value_width) {
163 this(container, x, y, 1, text, number_values, has_lights, value_width);
166 public AltosUIIndicator (Container container, int y, String text, int number_values, boolean has_lights, int value_width) {
167 this(container, 0, y, text, number_values, has_lights, value_width);
170 public AltosUIIndicator (Container container, int y, String text, int number_values, boolean has_lights) {
171 this(container, 0, y, text, number_values, has_lights, 1);
174 public AltosUIIndicator (Container container, int y, String text, int number_values) {
175 this(container, 0, y, text, number_values, false, 1);
178 public AltosUIIndicator (Container container, int y, String text) {
179 this(container, 0, y, text, 1, false, 1);