]> git.gag.com Git - fw/altos/blob - telegps/TeleGPSPreferences.java
altos/easymotor-v2: Use same init order as easymini
[fw/altos] / telegps / TeleGPSPreferences.java
1 /*
2  * Copyright © 2010 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.telegps;
20
21 import java.awt.*;
22 import java.awt.event.*;
23 import java.beans.*;
24 import javax.swing.*;
25 import javax.swing.event.*;
26 import org.altusmetrum.altosuilib_14.*;
27
28 public class TeleGPSPreferences
29         extends AltosUIConfigure
30         implements DocumentListener
31 {
32         AltosVoice      voice;
33
34         public JTextField       callsign_value;
35         public JComboBox<String>        position_value;
36
37         /* DocumentListener interface methods */
38         public void insertUpdate(DocumentEvent e) {
39                 changedUpdate(e);
40         }
41
42         public void removeUpdate(DocumentEvent e) {
43                 changedUpdate(e);
44         }
45
46         public void changedUpdate(DocumentEvent e) {
47                 if (callsign_value != null)
48                         AltosUIPreferences.set_callsign(callsign_value.getText());
49         }
50
51         public void add_voice() {
52
53                 /* Voice settings */
54                 pane.add(new JLabel("Voice"), constraints(0, 1));
55
56                 JRadioButton enable_voice = new JRadioButton("Enable", AltosUIPreferences.voice());
57                 enable_voice.addActionListener(new ActionListener() {
58                                 public void actionPerformed(ActionEvent e) {
59                                         JRadioButton item = (JRadioButton) e.getSource();
60                                         boolean enabled = item.isSelected();
61                                         AltosUIPreferences.set_voice(enabled);
62                                         if (enabled)
63                                                 voice.speak_always("Enable voice.");
64                                         else
65                                                 voice.speak_always("Disable voice.");
66                                 }
67                         });
68                 pane.add(enable_voice, constraints(1, 1));
69                 enable_voice.setToolTipText("Enable/Disable all audio in-flight announcements");
70
71                 JButton test_voice = new JButton("Test Voice");
72                 test_voice.addActionListener(new ActionListener() {
73                                 public void actionPerformed(ActionEvent e) {
74                                         voice.speak("That's one small step for man; one giant leap for mankind.");
75                                 }
76                         });
77                 pane.add(test_voice, constraints(2, 1));
78                 test_voice.setToolTipText("Play a stock audio clip to check volume");
79                 row++;
80         }
81
82         public void add_callsign() {
83                 /* Callsign setting */
84                 pane.add(new JLabel("Callsign"), constraints(0, 1));
85
86                 callsign_value = new JTextField(AltosUIPreferences.callsign());
87                 callsign_value.getDocument().addDocumentListener(this);
88                 callsign_value.setToolTipText("Callsign sent in packet mode");
89                 pane.add(callsign_value, constraints(1, 2, GridBagConstraints.BOTH));
90                 row++;
91         }
92
93         public void add_bluetooth() {
94                 JButton manage_bluetooth = new JButton("Manage Bluetooth");
95                 manage_bluetooth.addActionListener(new ActionListener() {
96                                 public void actionPerformed(ActionEvent e) {
97                                         AltosBTManage.show(owner, AltosBTKnown.bt_known());
98                                 }
99                         });
100                 pane.add(manage_bluetooth, constraints(0, 2));
101                 /* in the same row as add_frequencies, so don't bump row */
102         }
103
104         public void add_frequencies() {
105                 JButton manage_frequencies = new JButton("Manage Frequencies");
106                 manage_frequencies.addActionListener(new ActionListener() {
107                                 public void actionPerformed(ActionEvent e) {
108                                         AltosConfigFreqUI.show(owner);
109                                 }
110                         });
111                 manage_frequencies.setToolTipText("Configure which values are shown in frequency menus");
112                 pane.add(manage_frequencies, constraints(2, 1));
113                 row++;
114         }
115
116         public TeleGPSPreferences(JFrame owner, AltosVoice voice) {
117                 super(owner, "TeleGPS Preferences", "Configure TeleGPS");
118
119                 this.voice = voice;
120         }
121 }