From 82a69777c67128192b50bbf77ace0a6525f49cac Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 28 May 2014 20:24:04 -0700 Subject: telegps: Add preferences dialog Signed-off-by: Keith Packard --- telegps/TeleGPSPreferences.java | 150 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 telegps/TeleGPSPreferences.java (limited to 'telegps/TeleGPSPreferences.java') diff --git a/telegps/TeleGPSPreferences.java b/telegps/TeleGPSPreferences.java new file mode 100644 index 00000000..534cf550 --- /dev/null +++ b/telegps/TeleGPSPreferences.java @@ -0,0 +1,150 @@ +/* + * Copyright © 2010 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.telegps; + +import java.awt.*; +import java.awt.event.*; +import java.beans.*; +import javax.swing.*; +import javax.swing.event.*; +import org.altusmetrum.altosuilib_2.*; + +public class TeleGPSPreferences + extends AltosUIConfigure + implements DocumentListener +{ + AltosVoice voice; + + public JTextField callsign_value; + public JComboBox position_value; + + /* DocumentListener interface methods */ + public void insertUpdate(DocumentEvent e) { + changedUpdate(e); + } + + public void removeUpdate(DocumentEvent e) { + changedUpdate(e); + } + + public void changedUpdate(DocumentEvent e) { + if (callsign_value != null) + AltosUIPreferences.set_callsign(callsign_value.getText()); + } + + public void add_voice() { + + /* Voice settings */ + pane.add(new JLabel("Voice"), constraints(0, 1)); + + JRadioButton enable_voice = new JRadioButton("Enable", AltosUIPreferences.voice()); + enable_voice.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + JRadioButton item = (JRadioButton) e.getSource(); + boolean enabled = item.isSelected(); + AltosUIPreferences.set_voice(enabled); + if (enabled) + voice.speak_always("Enable voice."); + else + voice.speak_always("Disable voice."); + } + }); + pane.add(enable_voice, constraints(1, 1)); + enable_voice.setToolTipText("Enable/Disable all audio in-flight announcements"); + + JButton test_voice = new JButton("Test Voice"); + test_voice.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + voice.speak("That's one small step for man; one giant leap for mankind."); + } + }); + pane.add(test_voice, constraints(2, 1)); + test_voice.setToolTipText("Play a stock audio clip to check volume"); + row++; + } + + public void add_callsign() { + /* Callsign setting */ + pane.add(new JLabel("Callsign"), constraints(0, 1)); + + callsign_value = new JTextField(AltosUIPreferences.callsign()); + callsign_value.getDocument().addDocumentListener(this); + callsign_value.setToolTipText("Callsign sent in packet mode"); + pane.add(callsign_value, constraints(1, 2, GridBagConstraints.BOTH)); + row++; + } + + public void add_bluetooth() { + JButton manage_bluetooth = new JButton("Manage Bluetooth"); + manage_bluetooth.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + AltosBTManage.show(owner, AltosBTKnown.bt_known()); + } + }); + pane.add(manage_bluetooth, constraints(0, 2)); + /* in the same row as add_frequencies, so don't bump row */ + } + + public void add_frequencies() { + JButton manage_frequencies = new JButton("Manage Frequencies"); + manage_frequencies.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + AltosConfigFreqUI.show(owner); + } + }); + manage_frequencies.setToolTipText("Configure which values are shown in frequency menus"); + pane.add(manage_frequencies, constraints(2, 1)); + row++; + } + + final static String[] position_names = { + "Top left", + "Top", + "Top right", + "Left", + "Center", + "Right", + "Bottom left", + "Bottom", + "Bottom right", + }; + + public void add_position() { + pane.add(new JLabel ("Menu position"), constraints(0, 1)); + + position_value = new JComboBox(position_names); + position_value.setMaximumRowCount(position_names.length); + int position = AltosUIPreferences.position(); + position_value.setSelectedIndex(position); + position_value.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + int position = position_value.getSelectedIndex(); + AltosUIPreferences.set_position(position); + } + }); + pane.add(position_value, constraints(1, 2, GridBagConstraints.BOTH)); + position_value.setToolTipText("Position of main AltosUI window"); + row++; + } + + public TeleGPSPreferences(JFrame owner, AltosVoice voice) { + super(owner); + + this.voice = voice; + } +} -- cgit v1.2.3 From bfbabfa60f3cedd994f693867bce56aad05be02a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 13 Jun 2014 22:04:57 -0700 Subject: telegps: Allow TeleGPS preferences to have a custom title and label Don't just inherit the AltosUI ones Signed-off-by: Keith Packard --- altosuilib/AltosUIConfigure.java | 10 +++++++--- telegps/TeleGPSPreferences.java | 32 +------------------------------- 2 files changed, 8 insertions(+), 34 deletions(-) (limited to 'telegps/TeleGPSPreferences.java') diff --git a/altosuilib/AltosUIConfigure.java b/altosuilib/AltosUIConfigure.java index ae7626de..920ed8e2 100644 --- a/altosuilib/AltosUIConfigure.java +++ b/altosuilib/AltosUIConfigure.java @@ -229,8 +229,8 @@ public class AltosUIConfigure public void add_frequencies() { } - public AltosUIConfigure(JFrame in_owner) { - super(in_owner, "Configure AltosUI", false); + public AltosUIConfigure(JFrame in_owner, String name, String label) { + super(in_owner, name, false); owner = in_owner; pane = getContentPane(); @@ -239,7 +239,7 @@ public class AltosUIConfigure row = 0; /* Nice label at the top */ - pane.add(new JLabel ("Configure AltOS UI"), + pane.add(new JLabel (label), constraints(0, 3)); row++; @@ -271,4 +271,8 @@ public class AltosUIConfigure setLocationRelativeTo(owner); setVisible(true); } + + public AltosUIConfigure(JFrame in_owner) { + this(in_owner, "Configure AltosUI", "Configure AltOS UI"); + } } diff --git a/telegps/TeleGPSPreferences.java b/telegps/TeleGPSPreferences.java index 534cf550..8bd371f4 100644 --- a/telegps/TeleGPSPreferences.java +++ b/telegps/TeleGPSPreferences.java @@ -112,38 +112,8 @@ public class TeleGPSPreferences row++; } - final static String[] position_names = { - "Top left", - "Top", - "Top right", - "Left", - "Center", - "Right", - "Bottom left", - "Bottom", - "Bottom right", - }; - - public void add_position() { - pane.add(new JLabel ("Menu position"), constraints(0, 1)); - - position_value = new JComboBox(position_names); - position_value.setMaximumRowCount(position_names.length); - int position = AltosUIPreferences.position(); - position_value.setSelectedIndex(position); - position_value.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - int position = position_value.getSelectedIndex(); - AltosUIPreferences.set_position(position); - } - }); - pane.add(position_value, constraints(1, 2, GridBagConstraints.BOTH)); - position_value.setToolTipText("Position of main AltosUI window"); - row++; - } - public TeleGPSPreferences(JFrame owner, AltosVoice voice) { - super(owner); + super(owner, "TeleGPS Preferences", "Configure TeleGPS"); this.voice = voice; } -- cgit v1.2.3