0c23fa8d3279bd23f26e9b8249a98ccd4953b045
[fw/altos] / altosuilib / AltosUIEnable.java
1 /*
2  * Copyright © 2013 Keith Packard <keithp@keithp.com>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 package org.altusmetrum.altosuilib_12;
20
21 import java.awt.*;
22 import java.awt.event.*;
23 import javax.swing.*;
24 import java.io.*;
25 import java.util.concurrent.*;
26 import java.util.*;
27 import org.altusmetrum.altoslib_12.*;
28
29 import org.jfree.ui.*;
30 import org.jfree.chart.*;
31 import org.jfree.chart.plot.*;
32 import org.jfree.chart.axis.*;
33 import org.jfree.chart.renderer.*;
34 import org.jfree.chart.renderer.xy.*;
35 import org.jfree.chart.labels.*;
36 import org.jfree.data.xy.*;
37 import org.jfree.data.*;
38
39 public class AltosUIEnable extends Container {
40
41         Insets          il, ir;
42         int             y;
43         int             x;
44         JCheckBox       imperial_units;
45
46         static final int max_rows = 14;
47
48         public void units_changed(boolean imperial_units) {
49                 if (this.imperial_units != null) {
50                         this.imperial_units.setSelected(imperial_units);
51                 }
52         }
53
54         class GraphElement implements ActionListener {
55                 AltosUIGrapher  grapher;
56                 JCheckBox       enable;
57                 String          name;
58
59                 public void actionPerformed(ActionEvent ae) {
60                         grapher.set_enable(enable.isSelected());
61                 }
62
63                 GraphElement (String name, AltosUIGrapher grapher, boolean enabled) {
64                         this.name = name;
65                         this.grapher = grapher;
66                         enable = new JCheckBox(name, enabled);
67                         grapher.set_enable(enabled);
68                         enable.addActionListener(this);
69                 }
70         }
71
72         public void add(String name, AltosUIGrapher grapher, boolean enabled) {
73
74                 GraphElement    e = new GraphElement(name, grapher, enabled);
75                 GridBagConstraints c = new GridBagConstraints();
76
77                 /* Add element */
78                 c = new GridBagConstraints();
79                 c.gridx = x; c.gridy = y;
80                 c.fill = GridBagConstraints.HORIZONTAL;
81                 c.anchor = GridBagConstraints.CENTER;
82                 c.insets = ir;
83                 add(e.enable, c);
84
85                 /* Next row */
86                 y++;
87                 if (y == max_rows) {
88                         x++;
89                         y = 0;
90                 }
91         }
92
93         public void add_units() {
94                 /* Imperial units setting */
95
96                 /* Add label */
97                 imperial_units = new JCheckBox("Imperial Units", AltosUIPreferences.imperial_units());
98                 imperial_units.addActionListener(new ActionListener() {
99                                 public void actionPerformed(ActionEvent e) {
100                                         JCheckBox item = (JCheckBox) e.getSource();
101                                         boolean enabled = item.isSelected();
102                                         AltosUIPreferences.set_imperial_units(enabled);
103                                 }
104                         });
105                 imperial_units.setToolTipText("Use Imperial units instead of metric");
106                 GridBagConstraints c = new GridBagConstraints();
107                 c.gridx = 0; c.gridy = 1000;
108                 c.fill = GridBagConstraints.NONE;
109                 c.anchor = GridBagConstraints.LINE_START;
110                 c.insets = il;
111                 add(imperial_units, c);
112         }
113
114         public AltosUIEnable() {
115                 il = new Insets(4,4,4,4);
116                 ir = new Insets(4,4,4,4);
117                 x = 0;
118                 y = 0;
119                 setLayout(new GridBagLayout());
120                 add_units();
121         }
122 }