2 * Copyright © 2013 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;
22 import java.awt.event.*;
24 import javax.swing.event.*;
26 import java.util.concurrent.*;
28 import org.altusmetrum.altoslib_14.*;
30 import org.jfree.ui.*;
31 import org.jfree.chart.*;
32 import org.jfree.chart.plot.*;
33 import org.jfree.chart.axis.*;
34 import org.jfree.chart.renderer.*;
35 import org.jfree.chart.renderer.xy.*;
36 import org.jfree.chart.labels.*;
37 import org.jfree.data.xy.*;
38 import org.jfree.data.*;
40 public class AltosUIEnable extends Container implements ChangeListener {
45 JCheckBox imperial_units;
46 JCheckBox show_shapes;
47 JLabel line_width_label;
49 JLabel speed_filter_label;
51 JLabel accel_filter_label;
53 AltosFilterListener filter_listener;
54 AltosShapeListener shape_listener;
56 static final int max_rows = 14;
58 public void units_changed(boolean imperial_units) {
59 if (this.imperial_units != null) {
60 this.imperial_units.setSelected(imperial_units);
64 class GraphElement implements ActionListener {
65 AltosUIGrapher grapher;
69 public void actionPerformed(ActionEvent ae) {
70 grapher.set_enable(enable.isSelected());
73 GraphElement (String name, AltosUIGrapher grapher, boolean enabled) {
75 this.grapher = grapher;
76 enable = new JCheckBox(name, enabled);
77 grapher.set_enable(enabled);
78 enable.addActionListener(this);
82 LinkedList<GraphElement> elements = new LinkedList<GraphElement>();
84 public void add(String name, AltosUIGrapher grapher, boolean enabled) {
86 GraphElement e = new GraphElement(name, grapher, enabled);
87 GridBagConstraints c = new GridBagConstraints();
92 c = new GridBagConstraints();
93 c.gridx = x; c.gridy = y;
94 c.fill = GridBagConstraints.HORIZONTAL;
95 c.anchor = GridBagConstraints.CENTER;
107 public void stateChanged(ChangeEvent e) {
108 JSlider filter = (JSlider) e.getSource();
109 if (!filter.getValueIsAdjusting()) {
110 double speed_value = (int) speed_filter.getValue() / 1000.0;
111 double accel_value = (int) accel_filter.getValue() / 1000.0;
112 if (filter_listener != null) {
113 filter_listener.filter_changed(speed_value, accel_value);
118 public void set_shapes_visible(boolean visible) {
119 if (shape_listener != null)
120 shape_listener.set_shapes_visible(visible);
123 public void set_line_width(float width) {
124 if (shape_listener != null)
125 shape_listener.set_line_width(width);
128 public void register_shape_listener(AltosShapeListener shape_listener) {
129 this.shape_listener = shape_listener;
132 public void add_units() {
133 /* Imperial units setting */
136 imperial_units = new JCheckBox("Imperial Units", AltosUIPreferences.imperial_units());
137 imperial_units.addActionListener(new ActionListener() {
138 public void actionPerformed(ActionEvent e) {
139 JCheckBox item = (JCheckBox) e.getSource();
140 boolean enabled = item.isSelected();
141 AltosUIPreferences.set_imperial_units(enabled);
144 imperial_units.setToolTipText("Use Imperial units instead of metric");
145 GridBagConstraints c = new GridBagConstraints();
146 c.gridx = 0; c.gridy = 1000;
147 c.fill = GridBagConstraints.NONE;
148 c.anchor = GridBagConstraints.LINE_START;
150 add(imperial_units, c);
152 show_shapes = new JCheckBox("Show Markers", false);
153 show_shapes.addActionListener(new ActionListener() {
154 public void actionPerformed(ActionEvent e) {
155 JCheckBox item = (JCheckBox) e.getSource();
156 boolean enabled = item.isSelected();
157 set_shapes_visible(enabled);
160 show_shapes.setToolTipText("Show marker Use Imperial units instead of metric");
161 c = new GridBagConstraints();
162 c.gridx = 0; c.gridy = 1001;
163 c.fill = GridBagConstraints.NONE;
164 c.anchor = GridBagConstraints.LINE_START;
169 line_width_label = new JLabel("Line Width");
170 c = new GridBagConstraints();
171 c.gridx = 1; c.gridy = 1001;
172 c.fill = GridBagConstraints.NONE;
173 c.anchor = GridBagConstraints.LINE_START;
175 add(line_width_label, c);
177 line_width = new JSpinner();
178 line_width.setValue(1);
179 line_width.addChangeListener(new ChangeListener() {
180 public void stateChanged(ChangeEvent e) {
181 int w = (Integer) line_width.getValue();
184 line_width.setValue(w);
189 c = new GridBagConstraints();
190 c.gridx = 2; c.gridy = 1001;
191 c.fill = GridBagConstraints.NONE;
192 c.anchor = GridBagConstraints.LINE_START;
196 speed_filter_label = new JLabel("Speed Filter(ms)");
197 c = new GridBagConstraints();
198 c.gridx = 0; c.gridy = 1002;
199 c.fill = GridBagConstraints.NONE;
200 c.anchor = GridBagConstraints.LINE_START;
202 add(speed_filter_label, c);
204 speed_filter = new JSlider(JSlider.HORIZONTAL, 0, 10000, (int) (filter_listener.speed_filter() * 1000.0));
205 Hashtable<Integer,JLabel> label_table = new Hashtable<Integer,JLabel>();
206 for (int i = 0; i <= 10000; i += 5000) {
207 label_table.put(i, new JLabel(String.format("%d", i)));
209 speed_filter.setPaintTicks(true);
210 speed_filter.setMajorTickSpacing(1000);
211 speed_filter.setMinorTickSpacing(250);
212 speed_filter.setLabelTable(label_table);
213 speed_filter.setPaintTrack(false);
214 speed_filter.setSnapToTicks(true);
215 speed_filter.setPaintLabels(true);
216 speed_filter.addChangeListener(this);
218 c = new GridBagConstraints();
219 c.gridx = 1; c.gridy = 1002;
220 c.gridwidth = 1000; c.gridheight = 1;
221 c.fill = GridBagConstraints.BOTH;
222 c.anchor = GridBagConstraints.LINE_START;
224 add(speed_filter, c);
226 accel_filter_label = new JLabel("Acceleration Filter(ms)");
227 c = new GridBagConstraints();
228 c.gridx = 0; c.gridy = 1003;
229 c.fill = GridBagConstraints.NONE;
230 c.anchor = GridBagConstraints.LINE_START;
232 add(accel_filter_label, c);
234 accel_filter = new JSlider(JSlider.HORIZONTAL, 0, 10000, (int) (filter_listener.accel_filter() * 1000.0));
235 accel_filter.setPaintTicks(true);
236 accel_filter.setMajorTickSpacing(1000);
237 accel_filter.setMinorTickSpacing(250);
238 accel_filter.setLabelTable(label_table);
239 accel_filter.setPaintTrack(false);
240 accel_filter.setSnapToTicks(true);
241 accel_filter.setPaintLabels(true);
242 accel_filter.addChangeListener(this);
244 c = new GridBagConstraints();
245 c.gridx = 1; c.gridy = 1003;
246 c.gridwidth = 1000; c.gridheight = 1;
247 c.fill = GridBagConstraints.BOTH;
248 c.anchor = GridBagConstraints.LINE_START;
250 add(accel_filter, c);
253 public AltosUIEnable(AltosFilterListener filter_listener) {
254 this.filter_listener = filter_listener;
255 il = new Insets(4,4,4,4);
256 ir = new Insets(4,4,4,4);
259 setLayout(new GridBagLayout());