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_12;
22 import java.awt.event.*;
24 import javax.swing.event.*;
26 import java.util.concurrent.*;
28 import org.altusmetrum.altoslib_12.*;
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(new Integer(1));
179 line_width.addChangeListener(new ChangeListener() {
180 public void stateChanged(ChangeEvent e) {
181 int w = (Integer) line_width.getValue();
184 line_width.setValue(new Integer(w));
186 System.out.printf("line width set to %d\n", w);
190 c = new GridBagConstraints();
191 c.gridx = 2; c.gridy = 1001;
192 c.fill = GridBagConstraints.NONE;
193 c.anchor = GridBagConstraints.LINE_START;
197 speed_filter_label = new JLabel("Speed Filter(ms)");
198 c = new GridBagConstraints();
199 c.gridx = 0; c.gridy = 1002;
200 c.fill = GridBagConstraints.NONE;
201 c.anchor = GridBagConstraints.LINE_START;
203 add(speed_filter_label, c);
205 speed_filter = new JSlider(JSlider.HORIZONTAL, 0, 10000, (int) (filter_listener.speed_filter() * 1000.0));
206 Hashtable<Integer,JLabel> label_table = new Hashtable<Integer,JLabel>();
207 for (int i = 0; i <= 10000; i += 5000) {
208 label_table.put(new Integer(i), new JLabel(String.format("%d", i)));
210 speed_filter.setPaintTicks(true);
211 speed_filter.setMajorTickSpacing(1000);
212 speed_filter.setMinorTickSpacing(250);
213 speed_filter.setLabelTable(label_table);
214 speed_filter.setPaintTrack(false);
215 speed_filter.setSnapToTicks(true);
216 speed_filter.setPaintLabels(true);
217 speed_filter.addChangeListener(this);
219 c = new GridBagConstraints();
220 c.gridx = 1; c.gridy = 1002;
221 c.gridwidth = 1000; c.gridheight = 1;
222 c.fill = GridBagConstraints.BOTH;
223 c.anchor = GridBagConstraints.LINE_START;
225 add(speed_filter, c);
227 accel_filter_label = new JLabel("Acceleration Filter(ms)");
228 c = new GridBagConstraints();
229 c.gridx = 0; c.gridy = 1003;
230 c.fill = GridBagConstraints.NONE;
231 c.anchor = GridBagConstraints.LINE_START;
233 add(accel_filter_label, c);
235 accel_filter = new JSlider(JSlider.HORIZONTAL, 0, 10000, (int) (filter_listener.accel_filter() * 1000.0));
236 accel_filter.setPaintTicks(true);
237 accel_filter.setMajorTickSpacing(1000);
238 accel_filter.setMinorTickSpacing(250);
239 accel_filter.setLabelTable(label_table);
240 accel_filter.setPaintTrack(false);
241 accel_filter.setSnapToTicks(true);
242 accel_filter.setPaintLabels(true);
243 accel_filter.addChangeListener(this);
245 c = new GridBagConstraints();
246 c.gridx = 1; c.gridy = 1003;
247 c.gridwidth = 1000; c.gridheight = 1;
248 c.fill = GridBagConstraints.BOTH;
249 c.anchor = GridBagConstraints.LINE_START;
251 add(accel_filter, c);
254 public AltosUIEnable(AltosFilterListener filter_listener) {
255 this.filter_listener = filter_listener;
256 il = new Insets(4,4,4,4);
257 ir = new Insets(4,4,4,4);
260 setLayout(new GridBagLayout());