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 speed_filter_label;
49 JLabel accel_filter_label;
51 AltosFilterListener filter_listener;
52 AltosShapeListener shape_listener;
54 static final int max_rows = 14;
56 public void units_changed(boolean imperial_units) {
57 if (this.imperial_units != null) {
58 this.imperial_units.setSelected(imperial_units);
62 class GraphElement implements ActionListener {
63 AltosUIGrapher grapher;
67 public void actionPerformed(ActionEvent ae) {
68 grapher.set_enable(enable.isSelected());
71 GraphElement (String name, AltosUIGrapher grapher, boolean enabled) {
73 this.grapher = grapher;
74 enable = new JCheckBox(name, enabled);
75 grapher.set_enable(enabled);
76 enable.addActionListener(this);
80 LinkedList<GraphElement> elements = new LinkedList<GraphElement>();
82 public void add(String name, AltosUIGrapher grapher, boolean enabled) {
84 GraphElement e = new GraphElement(name, grapher, enabled);
85 GridBagConstraints c = new GridBagConstraints();
90 c = new GridBagConstraints();
91 c.gridx = x; c.gridy = y;
92 c.fill = GridBagConstraints.HORIZONTAL;
93 c.anchor = GridBagConstraints.CENTER;
105 public void stateChanged(ChangeEvent e) {
106 JSlider filter = (JSlider) e.getSource();
107 if (!filter.getValueIsAdjusting()) {
108 double speed_value = (int) speed_filter.getValue() / 1000.0;
109 double accel_value = (int) accel_filter.getValue() / 1000.0;
110 if (filter_listener != null) {
111 filter_listener.filter_changed(speed_value, accel_value);
116 public void set_shapes_visible(boolean visible) {
117 System.out.printf("set shapes %b\n", visible);
118 if (shape_listener != null)
119 shape_listener.set_shapes_visible(visible);
122 public void register_shape_listener(AltosShapeListener shape_listener) {
123 this.shape_listener = shape_listener;
126 public void add_units() {
127 /* Imperial units setting */
130 imperial_units = new JCheckBox("Imperial Units", AltosUIPreferences.imperial_units());
131 imperial_units.addActionListener(new ActionListener() {
132 public void actionPerformed(ActionEvent e) {
133 JCheckBox item = (JCheckBox) e.getSource();
134 boolean enabled = item.isSelected();
135 AltosUIPreferences.set_imperial_units(enabled);
138 imperial_units.setToolTipText("Use Imperial units instead of metric");
139 GridBagConstraints c = new GridBagConstraints();
140 c.gridx = 0; c.gridy = 1000;
141 c.fill = GridBagConstraints.NONE;
142 c.anchor = GridBagConstraints.LINE_START;
144 add(imperial_units, c);
146 show_shapes = new JCheckBox("Show Markers", false);
147 show_shapes.addActionListener(new ActionListener() {
148 public void actionPerformed(ActionEvent e) {
149 JCheckBox item = (JCheckBox) e.getSource();
150 boolean enabled = item.isSelected();
151 set_shapes_visible(enabled);
154 show_shapes.setToolTipText("Show marker Use Imperial units instead of metric");
155 c = new GridBagConstraints();
156 c.gridx = 0; c.gridy = 1001;
157 c.fill = GridBagConstraints.NONE;
158 c.anchor = GridBagConstraints.LINE_START;
163 speed_filter_label = new JLabel("Speed Filter(ms)");
164 c = new GridBagConstraints();
165 c.gridx = 0; c.gridy = 1002;
166 c.fill = GridBagConstraints.NONE;
167 c.anchor = GridBagConstraints.LINE_START;
169 add(speed_filter_label, c);
171 speed_filter = new JSlider(JSlider.HORIZONTAL, 0, 10000, (int) (filter_listener.speed_filter() * 1000.0));
172 Hashtable<Integer,JLabel> label_table = new Hashtable<Integer,JLabel>();
173 for (int i = 0; i <= 10000; i += 5000) {
174 label_table.put(new Integer(i), new JLabel(String.format("%d", i)));
176 speed_filter.setPaintTicks(true);
177 speed_filter.setMajorTickSpacing(1000);
178 speed_filter.setMinorTickSpacing(250);
179 speed_filter.setLabelTable(label_table);
180 speed_filter.setPaintTrack(false);
181 speed_filter.setSnapToTicks(true);
182 speed_filter.setPaintLabels(true);
183 speed_filter.addChangeListener(this);
185 c = new GridBagConstraints();
186 c.gridx = 1; c.gridy = 1002;
187 c.gridwidth = 1000; c.gridheight = 1;
188 c.fill = GridBagConstraints.BOTH;
189 c.anchor = GridBagConstraints.LINE_START;
191 add(speed_filter, c);
193 accel_filter_label = new JLabel("Acceleration Filter(ms)");
194 c = new GridBagConstraints();
195 c.gridx = 0; c.gridy = 1003;
196 c.fill = GridBagConstraints.NONE;
197 c.anchor = GridBagConstraints.LINE_START;
199 add(accel_filter_label, c);
201 accel_filter = new JSlider(JSlider.HORIZONTAL, 0, 10000, (int) (filter_listener.accel_filter() * 1000.0));
202 accel_filter.setPaintTicks(true);
203 accel_filter.setMajorTickSpacing(1000);
204 accel_filter.setMinorTickSpacing(250);
205 accel_filter.setLabelTable(label_table);
206 accel_filter.setPaintTrack(false);
207 accel_filter.setSnapToTicks(true);
208 accel_filter.setPaintLabels(true);
209 accel_filter.addChangeListener(this);
211 c = new GridBagConstraints();
212 c.gridx = 1; c.gridy = 1003;
213 c.gridwidth = 1000; c.gridheight = 1;
214 c.fill = GridBagConstraints.BOTH;
215 c.anchor = GridBagConstraints.LINE_START;
217 add(accel_filter, c);
220 public AltosUIEnable(AltosFilterListener filter_listener) {
221 this.filter_listener = filter_listener;
222 il = new Insets(4,4,4,4);
223 ir = new Insets(4,4,4,4);
226 setLayout(new GridBagLayout());