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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altosuilib_14;
23 import org.altusmetrum.altoslib_14.*;
25 public abstract class AltosUIIndicator implements AltosFontListener, AltosUnitsListener {
33 abstract public void show(AltosState state, AltosListenerState listener_state);
35 public void set_lights(boolean on) {
39 public void setVisible(boolean visible) {
41 lights.setVisible(visible);
42 label.setVisible(visible);
43 for (int i = 0; i < values.length; i++)
44 values[i].setVisible(visible);
48 for (int i = 0; i < values.length; i++)
49 values[i].setText("");
56 lights.setVisible(true);
57 label.setVisible(true);
58 for (int i = 0; i < values.length; i++)
59 values[i].setVisible(true);
62 public void show(String... s) {
63 int n = Math.min(s.length, values.length);
66 for (int i = 0; i < n; i++)
67 values[i].setText(s[i]);
70 public void show(String format, double value) {
71 show(String.format(format, value));
74 public void show(String format, int value) {
75 show(String.format(format, value));
78 public void show(String format1, double value1, String format2, double value2) {
79 show(String.format(format1, value1), String.format(format2, value2));
82 public void show(String format1, int value1, String format2, int value2) {
83 show(String.format(format1, value1), String.format(format2, value2));
88 lights.setVisible(false);
89 label.setVisible(false);
90 for (int i = 0; i < values.length; i++)
91 values[i].setVisible(false);
94 public void font_size_changed(int font_size) {
95 label.setFont(AltosUILib.label_font);
96 for (int i = 0; i < values.length; i++)
97 values[i].setFont(AltosUILib.value_font);
100 public void units_changed(boolean imperial_units) {
103 public void set_label(String text) {
107 public void remove(Container container) {
109 container.remove(lights);
110 container.remove(label);
111 for (int i = 0; i < values.length; i++)
112 container.remove(values[i]);
115 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) {
116 GridBagLayout layout = (GridBagLayout)(container.getLayout());
118 GridBagConstraints c = new GridBagConstraints();
122 lights = new AltosLights();
123 c.gridx = x; c.gridy = y;
124 c.anchor = GridBagConstraints.CENTER;
125 c.fill = GridBagConstraints.VERTICAL;
127 layout.setConstraints(lights, c);
128 container.add(lights);
131 label = new JLabel(text);
132 label.setFont(AltosUILib.label_font);
133 label.setHorizontalAlignment(SwingConstants.LEFT);
134 c.gridx = x + 1; c.gridy = y;
135 c.gridwidth = label_width;
136 c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
137 c.anchor = GridBagConstraints.WEST;
138 c.fill = GridBagConstraints.VERTICAL;
140 layout.setConstraints(label, c);
141 container.add(label);
143 values = new JTextField[number_values];
144 for (int i = 0; i < values.length; i++) {
145 values[i] = new JTextField(AltosUILib.text_width);
146 values[i].setEditable(false);
147 values[i].setFont(AltosUILib.value_font);
148 values[i].setHorizontalAlignment(SwingConstants.RIGHT);
149 c.gridx = 1 + label_width + x + i * value_space; c.gridy = y;
150 c.anchor = GridBagConstraints.WEST;
151 c.fill = GridBagConstraints.BOTH;
153 c.gridwidth = value_width;
154 layout.setConstraints(values[i], c);
155 container.add(values[i]);
159 public AltosUIIndicator (Container container, int x, int y, int label_width, String text, int number_values, boolean has_lights, int value_width) {
160 this(container, x, y, label_width, text, number_values, has_lights, value_width, 1);
163 public AltosUIIndicator (Container container, int x, int y, String text, int number_values, boolean has_lights, int value_width) {
164 this(container, x, y, 1, text, number_values, has_lights, value_width);
167 public AltosUIIndicator (Container container, int y, String text, int number_values, boolean has_lights, int value_width) {
168 this(container, 0, y, text, number_values, has_lights, value_width);
171 public AltosUIIndicator (Container container, int y, String text, int number_values, boolean has_lights) {
172 this(container, 0, y, text, number_values, has_lights, 1);
175 public AltosUIIndicator (Container container, int y, String text, int number_values) {
176 this(container, 0, y, text, number_values, false, 1);
179 public AltosUIIndicator (Container container, int y, String text) {
180 this(container, 0, y, text, 1, false, 1);