Set version to 1.3.2 in preparation for release
[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; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package org.altusmetrum.altosuilib_1;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import javax.swing.*;
23 import java.io.*;
24 import java.util.concurrent.*;
25 import java.util.*;
26 import org.altusmetrum.altoslib_3.*;
27
28 import org.jfree.ui.*;
29 import org.jfree.chart.*;
30 import org.jfree.chart.plot.*;
31 import org.jfree.chart.axis.*;
32 import org.jfree.chart.renderer.*;
33 import org.jfree.chart.renderer.xy.*;
34 import org.jfree.chart.labels.*;
35 import org.jfree.data.xy.*;
36 import org.jfree.data.*;
37
38 public class AltosUIEnable extends Container {
39
40         Insets  il, ir;
41         int     y;
42         int     x;
43
44         static final int max_rows = 14;
45
46         class GraphElement implements ActionListener {
47                 AltosUIGrapher  grapher;
48                 JRadioButton    enable;
49                 String          name;
50
51                 public void actionPerformed(ActionEvent ae) {
52                         grapher.set_enable(enable.isSelected());
53                 }
54
55                 GraphElement (String name, AltosUIGrapher grapher, boolean enabled) {
56                         this.name = name;
57                         this.grapher = grapher;
58                         enable = new JRadioButton(name, enabled);
59                         grapher.set_enable(enabled);                      
60                         enable.addActionListener(this);
61                 }
62         }
63
64         public void add(String name, AltosUIGrapher grapher, boolean enabled) {
65
66                 GraphElement    e = new GraphElement(name, grapher, enabled);
67                 GridBagConstraints c = new GridBagConstraints();
68
69                 /* Add element */
70                 c = new GridBagConstraints();
71                 c.gridx = x; c.gridy = y;
72                 c.fill = GridBagConstraints.HORIZONTAL;
73                 c.anchor = GridBagConstraints.CENTER;
74                 c.insets = ir;
75                 add(e.enable, c);
76
77                 /* Next row */
78                 y++;
79                 if (y == max_rows) {
80                         x++;
81                         y = 0;
82                 }
83         }
84
85         public void add_units() {
86                 /* Imperial units setting */
87
88                 /* Add label */
89                 JRadioButton imperial_units = new JRadioButton("Imperial Units", AltosUIPreferences.imperial_units());
90                 imperial_units.addActionListener(new ActionListener() {
91                                 public void actionPerformed(ActionEvent e) {
92                                         JRadioButton item = (JRadioButton) e.getSource();
93                                         boolean enabled = item.isSelected();
94                                         AltosUIPreferences.set_imperial_units(enabled);
95                                 }
96                         });
97                 imperial_units.setToolTipText("Use Imperial units instead of metric");
98                 GridBagConstraints c = new GridBagConstraints();
99                 c.gridx = 0; c.gridy = 1000;
100                 c.fill = GridBagConstraints.NONE;
101                 c.anchor = GridBagConstraints.LINE_START;
102                 c.insets = il;
103                 add(imperial_units, c);
104         }
105
106         public AltosUIEnable() {
107                 il = new Insets(4,4,4,4);
108                 ir = new Insets(4,4,4,4);
109                 x = 0;
110                 y = 0;
111                 setLayout(new GridBagLayout());
112                 add_units();
113         }
114 }