From 382c54a0d052c8975b57c995ef83bc8934bde242 Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Fri, 14 Sep 2012 13:09:58 +1200 Subject: altosui: remove un-used imports Signed-off-by: Mike Beattie --- altosui/AltosUIPreferences.java | 4 ---- 1 file changed, 4 deletions(-) (limited to 'altosui/AltosUIPreferences.java') diff --git a/altosui/AltosUIPreferences.java b/altosui/AltosUIPreferences.java index 8f1e45d9..a026d123 100644 --- a/altosui/AltosUIPreferences.java +++ b/altosui/AltosUIPreferences.java @@ -19,12 +19,8 @@ package altosui; import java.io.*; import java.util.*; -import java.text.*; -import java.util.prefs.*; -import java.util.concurrent.LinkedBlockingQueue; import java.awt.Component; import javax.swing.*; -import javax.swing.filechooser.FileSystemView; import org.altusmetrum.AltosLib.*; public class AltosUIPreferences extends AltosPreferences { -- cgit v1.2.3 From ec036e8fe057f4b641ba9ee17d6dce2689816047 Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Fri, 14 Sep 2012 00:25:49 +1200 Subject: altoslib/altosui: begin moving preferences "backend" into interface Signed-off-by: Mike Beattie --- altoslib/AltosPreferences.java | 130 +++++++++++++++------------------ altoslib/AltosPreferencesBackend.java | 38 ++++++++++ altosui/AltosUIPreferences.java | 30 ++++---- altosui/AltosUIPreferencesBackend.java | 84 +++++++++++++++++++++ 4 files changed, 194 insertions(+), 88 deletions(-) create mode 100644 altoslib/AltosPreferencesBackend.java create mode 100644 altosui/AltosUIPreferencesBackend.java (limited to 'altosui/AltosUIPreferences.java') diff --git a/altoslib/AltosPreferences.java b/altoslib/AltosPreferences.java index 0e7b2bd3..ef30f8e9 100644 --- a/altoslib/AltosPreferences.java +++ b/altoslib/AltosPreferences.java @@ -19,11 +19,10 @@ package org.altusmetrum.AltosLib; import java.io.*; import java.util.*; -import java.util.prefs.*; import javax.swing.filechooser.FileSystemView; public class AltosPreferences { - public static Preferences preferences; + public static AltosPreferencesBackend backend = null; /* logdir preference name */ public final static String logdirPreference = "LOGDIR"; @@ -100,13 +99,10 @@ public class AltosPreferences { public static AltosFrequency[] load_common_frequencies() { AltosFrequency[] frequencies = null; boolean existing = false; - try { - existing = preferences.nodeExists(common_frequencies_node_name); - } catch (BackingStoreException be) { - existing = false; - } + existing = backend.nodeExists(common_frequencies_node_name); + if (existing) { - Preferences node = preferences.node(common_frequencies_node_name); + AltosPreferencesBackend node = backend.node(common_frequencies_node_name); int count = node.getInt(frequency_count, 0); frequencies = new AltosFrequency[count]; @@ -115,7 +111,7 @@ public class AltosPreferences { String description; frequency = node.getDouble(String.format(frequency_format, i), 0.0); - description = node.get(String.format(description_format, i), null); + description = node.getString(String.format(description_format, i), null); frequencies[i] = new AltosFrequency(frequency, description); } } else { @@ -129,12 +125,12 @@ public class AltosPreferences { } public static void save_common_frequencies(AltosFrequency[] frequencies) { - Preferences node = preferences.node(common_frequencies_node_name); + AltosPreferencesBackend node = backend.node(common_frequencies_node_name); node.putInt(frequency_count, frequencies.length); for (int i = 0; i < frequencies.length; i++) { node.putDouble(String.format(frequency_format, i), frequencies[i].frequency); - node.put(String.format(description_format, i), frequencies[i].description); + node.putString(String.format(description_format, i), frequencies[i].description); } } public static int launcher_serial; @@ -142,10 +138,10 @@ public class AltosPreferences { public static int launcher_channel; public static void init() { - preferences = Preferences.userRoot().node("/org/altusmetrum/altosui"); + //preferences = Preferences.userRoot().node("/org/altusmetrum/altosui"); /* Initialize logdir from preferences */ - String logdir_string = preferences.get(logdirPreference, null); + String logdir_string = backend.getString(logdirPreference, null); if (logdir_string != null) logdir = new File(logdir_string); else { @@ -162,17 +158,17 @@ public class AltosPreferences { telemetries = new Hashtable(); - voice = preferences.getBoolean(voicePreference, true); + voice = backend.getBoolean(voicePreference, true); - callsign = preferences.get(callsignPreference,"N0CALL"); + callsign = backend.getString(callsignPreference,"N0CALL"); - scanning_telemetry = preferences.getInt(scanningTelemetryPreference,(1 << AltosLib.ao_telemetry_standard)); + scanning_telemetry = backend.getInt(scanningTelemetryPreference,(1 << AltosLib.ao_telemetry_standard)); - launcher_serial = preferences.getInt(launcherSerialPreference, 0); + launcher_serial = backend.getInt(launcherSerialPreference, 0); - launcher_channel = preferences.getInt(launcherChannelPreference, 0); + launcher_channel = backend.getInt(launcherChannelPreference, 0); - String firmwaredir_string = preferences.get(firmwaredirPreference, null); + String firmwaredir_string = backend.getString(firmwaredirPreference, null); if (firmwaredir_string != null) firmwaredir = new File(firmwaredir_string); else @@ -180,65 +176,53 @@ public class AltosPreferences { common_frequencies = load_common_frequencies(); - AltosConvert.imperial_units = preferences.getBoolean(unitsPreference, false); + AltosConvert.imperial_units = backend.getBoolean(unitsPreference, false); } static { init(); } public static void flush_preferences() { - try { - preferences.flush(); - } catch (BackingStoreException ee) { -/* - if (component != null) - JOptionPane.showMessageDialog(component, - preferences.absolutePath(), - "Cannot save prefernces", - JOptionPane.ERROR_MESSAGE); - else -*/ - System.err.printf("Cannot save preferences\n"); - } + backend.flush(); } public static void set_logdir(File new_logdir) { - synchronized (preferences) { + synchronized (backend) { logdir = new_logdir; mapdir = new File(logdir, "maps"); if (!mapdir.exists()) mapdir.mkdirs(); - preferences.put(logdirPreference, logdir.getPath()); + backend.putString(logdirPreference, logdir.getPath()); flush_preferences(); } } public static File logdir() { - synchronized (preferences) { + synchronized (backend) { return logdir; } } public static File mapdir() { - synchronized (preferences) { + synchronized (backend) { return mapdir; } } public static void set_frequency(int serial, double new_frequency) { - synchronized (preferences) { + synchronized (backend) { frequencies.put(serial, new_frequency); - preferences.putDouble(String.format(frequencyPreferenceFormat, serial), new_frequency); + backend.putDouble(String.format(frequencyPreferenceFormat, serial), new_frequency); flush_preferences(); } } public static double frequency(int serial) { - synchronized (preferences) { + synchronized (backend) { if (frequencies.containsKey(serial)) return frequencies.get(serial); - double frequency = preferences.getDouble(String.format(frequencyPreferenceFormat, serial), 0); + double frequency = backend.getDouble(String.format(frequencyPreferenceFormat, serial), 0); if (frequency == 0.0) { - int channel = preferences.getInt(String.format(channelPreferenceFormat, serial), 0); + int channel = backend.getInt(String.format(channelPreferenceFormat, serial), 0); frequency = AltosConvert.radio_channel_to_frequency(channel); } frequencies.put(serial, frequency); @@ -247,122 +231,122 @@ public class AltosPreferences { } public static void set_telemetry(int serial, int new_telemetry) { - synchronized (preferences) { + synchronized (backend) { telemetries.put(serial, new_telemetry); - preferences.putInt(String.format(telemetryPreferenceFormat, serial), new_telemetry); + backend.putInt(String.format(telemetryPreferenceFormat, serial), new_telemetry); flush_preferences(); } } public static int telemetry(int serial) { - synchronized (preferences) { + synchronized (backend) { if (telemetries.containsKey(serial)) return telemetries.get(serial); - int telemetry = preferences.getInt(String.format(telemetryPreferenceFormat, serial), - AltosLib.ao_telemetry_standard); + int telemetry = backend.getInt(String.format(telemetryPreferenceFormat, serial), + AltosLib.ao_telemetry_standard); telemetries.put(serial, telemetry); return telemetry; } } public static void set_scanning_telemetry(int new_scanning_telemetry) { - synchronized (preferences) { + synchronized (backend) { scanning_telemetry = new_scanning_telemetry; - preferences.putInt(scanningTelemetryPreference, scanning_telemetry); + backend.putInt(scanningTelemetryPreference, scanning_telemetry); flush_preferences(); } } public static int scanning_telemetry() { - synchronized (preferences) { + synchronized (backend) { return scanning_telemetry; } } public static void set_voice(boolean new_voice) { - synchronized (preferences) { + synchronized (backend) { voice = new_voice; - preferences.putBoolean(voicePreference, voice); + backend.putBoolean(voicePreference, voice); flush_preferences(); } } public static boolean voice() { - synchronized (preferences) { + synchronized (backend) { return voice; } } public static void set_callsign(String new_callsign) { - synchronized(preferences) { + synchronized(backend) { callsign = new_callsign; - preferences.put(callsignPreference, callsign); + backend.putString(callsignPreference, callsign); flush_preferences(); } } public static String callsign() { - synchronized(preferences) { + synchronized(backend) { return callsign; } } public static void set_firmwaredir(File new_firmwaredir) { - synchronized (preferences) { + synchronized (backend) { firmwaredir = new_firmwaredir; - preferences.put(firmwaredirPreference, firmwaredir.getPath()); + backend.putString(firmwaredirPreference, firmwaredir.getPath()); flush_preferences(); } } public static File firmwaredir() { - synchronized (preferences) { + synchronized (backend) { return firmwaredir; } } public static void set_launcher_serial(int new_launcher_serial) { - synchronized (preferences) { + synchronized (backend) { launcher_serial = new_launcher_serial; - preferences.putInt(launcherSerialPreference, launcher_serial); + backend.putInt(launcherSerialPreference, launcher_serial); flush_preferences(); } } public static int launcher_serial() { - synchronized (preferences) { + synchronized (backend) { return launcher_serial; } } public static void set_launcher_channel(int new_launcher_channel) { - synchronized (preferences) { + synchronized (backend) { launcher_channel = new_launcher_channel; - preferences.putInt(launcherChannelPreference, launcher_channel); + backend.putInt(launcherChannelPreference, launcher_channel); flush_preferences(); } } public static int launcher_channel() { - synchronized (preferences) { + synchronized (backend) { return launcher_channel; } } - public static Preferences bt_devices() { - synchronized (preferences) { - return preferences.node("bt_devices"); + public static AltosPreferencesBackend bt_devices() { + synchronized (backend) { + return backend.node("bt_devices"); } } public static AltosFrequency[] common_frequencies() { - synchronized (preferences) { + synchronized (backend) { return common_frequencies; } } public static void set_common_frequencies(AltosFrequency[] frequencies) { - synchronized(preferences) { + synchronized(backend) { common_frequencies = frequencies; save_common_frequencies(frequencies); flush_preferences(); @@ -388,15 +372,15 @@ public class AltosPreferences { } public static boolean imperial_units() { - synchronized(preferences) { + synchronized(backend) { return AltosConvert.imperial_units; } } public static void set_imperial_units(boolean imperial_units) { - synchronized (preferences) { + synchronized (backend) { AltosConvert.imperial_units = imperial_units; - preferences.putBoolean(unitsPreference, imperial_units); + backend.putBoolean(unitsPreference, imperial_units); flush_preferences(); } } diff --git a/altoslib/AltosPreferencesBackend.java b/altoslib/AltosPreferencesBackend.java new file mode 100644 index 00000000..a8cfb31b --- /dev/null +++ b/altoslib/AltosPreferencesBackend.java @@ -0,0 +1,38 @@ +/* + * Copyright © 2010 Mike Beattie + * + * 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.AltosLib; + +public interface AltosPreferencesBackend { + + public String getString(String key, String def); + public void putString(String key, String value); + + public int getInt(String key, int def); + public void putInt(String key, int value); + + public double getDouble(String key, double def); + public void putDouble(String key, double value); + + public boolean getBoolean(String key, boolean def); + public void putBoolean(String key, boolean value); + + public boolean nodeExists(String key); + public AltosPreferencesBackend node(String key); + + public void flush(); +} diff --git a/altosui/AltosUIPreferences.java b/altosui/AltosUIPreferences.java index a026d123..03e8e129 100644 --- a/altosui/AltosUIPreferences.java +++ b/altosui/AltosUIPreferences.java @@ -48,12 +48,12 @@ public class AltosUIPreferences extends AltosPreferences { public static void init() { font_listeners = new LinkedList(); - font_size = preferences.getInt(fontSizePreference, Altos.font_size_medium); + font_size = backend.getInt(fontSizePreference, Altos.font_size_medium); Altos.set_fonts(font_size); - look_and_feel = preferences.get(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName()); + look_and_feel = backend.getString(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName()); ui_listeners = new LinkedList(); - serial_debug = preferences.getBoolean(serialDebugPreference, false); + serial_debug = backend.getBoolean(serialDebugPreference, false); AltosLink.set_debug(serial_debug); } @@ -107,9 +107,9 @@ public class AltosUIPreferences extends AltosPreferences { } public static void set_font_size(int new_font_size) { - synchronized (preferences) { + synchronized (backend) { font_size = new_font_size; - preferences.putInt(fontSizePreference, font_size); + backend.putInt(fontSizePreference, font_size); flush_preferences(); Altos.set_fonts(font_size); for (AltosFontListener l : font_listeners) @@ -118,13 +118,13 @@ public class AltosUIPreferences extends AltosPreferences { } public static void register_font_listener(AltosFontListener l) { - synchronized (preferences) { + synchronized (backend) { font_listeners.add(l); } } public static void unregister_font_listener(AltosFontListener l) { - synchronized (preferences) { + synchronized (backend) { font_listeners.remove(l); } } @@ -134,9 +134,9 @@ public class AltosUIPreferences extends AltosPreferences { UIManager.setLookAndFeel(new_look_and_feel); } catch (Exception e) { } - synchronized(preferences) { + synchronized(backend) { look_and_feel = new_look_and_feel; - preferences.put(lookAndFeelPreference, look_and_feel); + backend.putString(lookAndFeelPreference, look_and_feel); flush_preferences(); for (AltosUIListener l : ui_listeners) l.ui_changed(look_and_feel); @@ -150,21 +150,21 @@ public class AltosUIPreferences extends AltosPreferences { } public static void register_ui_listener(AltosUIListener l) { - synchronized(preferences) { + synchronized(backend) { ui_listeners.add(l); } } public static void unregister_ui_listener(AltosUIListener l) { - synchronized (preferences) { + synchronized (backend) { ui_listeners.remove(l); } } public static void set_serial_debug(boolean new_serial_debug) { - AltosLink.set_debug(new_serial_debug); - synchronized (preferences) { + AltosLink.set_debug(serial_debug); + synchronized (backend) { serial_debug = new_serial_debug; - preferences.putBoolean(serialDebugPreference, serial_debug); + backend.putBoolean(serialDebugPreference, serial_debug); flush_preferences(); } } @@ -175,4 +175,4 @@ public class AltosUIPreferences extends AltosPreferences { } } -} \ No newline at end of file +} diff --git a/altosui/AltosUIPreferencesBackend.java b/altosui/AltosUIPreferencesBackend.java new file mode 100644 index 00000000..16844f37 --- /dev/null +++ b/altosui/AltosUIPreferencesBackend.java @@ -0,0 +1,84 @@ +/* + * Copyright © 2012 Mike Beattie + * + * 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 altosui; + +import java.text.*; +import java.util.prefs.*; +import org.altusmetrum.AltosLib.*; + +public class AltosUIPreferencesBackend implements AltosPreferencesBackend { + + private Preferences _preferences = null; + + public AltosUIPreferencesBackend() { + _preferences = Preferences.userRoot().node("/org/altusmetrum/altosui"); + } + + public AltosUIPreferencesBackend(Preferences in_preferences) { + _preferences = in_preferences; + } + + public String getString(String key, String def) { + return _preferences.get(key, def) + } + public void putString(String key, String value) { + _preferences.put(key, value); + } + + public int getInt(String key, int def) { + return _preferences.getInt(key, def); + } + public void putInt(String key, int value) { + _preferences.putInt(key, value); + } + + public double getDouble(String key, double def) { + return _preferences.getDouble(key, def); + } + public void putDouble(String key, double value) { + _preferences.putDouble(key, value); + } + + public boolean getBoolean(String key, boolean def) { + return _preferences.getBoolean(key, def); + } + public void putBoolean(String key, boolean value) { + _preferences.putBoolean(key, value); + } + + public boolean nodeExists(String key) { + try { + return _preferences.nodeExists(key); + } catch (BackingStoreException be) { + return false; + } + } + + public AltosPreferencesBackend node(String key) { + return new AltosUIPreferencesBackend(_preferences.node(key)); + } + + public void flush() { + try { + _preferences.flush(); + } catch (BackingStoreException ee) { + System.err.printf("Cannot save preferences\n"); + } + } + +} \ No newline at end of file -- cgit v1.2.3 From 67b618409a0d34fff26cac6025bc159ff92ede9c Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Fri, 14 Sep 2012 00:40:16 +1200 Subject: altosui: add missing methods for Backend, fix BT code. Signed-off-by: Mike Beattie --- altosui/AltosBTKnown.java | 6 +++--- altosui/AltosUIPreferences.java | 6 +++--- altosui/AltosUIPreferencesBackend.java | 8 ++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'altosui/AltosUIPreferences.java') diff --git a/altosui/AltosBTKnown.java b/altosui/AltosBTKnown.java index 74cc6838..7e5e9533 100644 --- a/altosui/AltosBTKnown.java +++ b/altosui/AltosBTKnown.java @@ -21,14 +21,14 @@ import java.util.prefs.*; public class AltosBTKnown implements Iterable { LinkedList devices = new LinkedList(); - Preferences bt_pref = AltosUIPreferences.bt_devices(); + AltosPreferencesBackend bt_pref = AltosUIPreferences.bt_devices(); private String get_address(String name) { - return bt_pref.get(name, ""); + return bt_pref.getString(name, ""); } private void set_address(String name, String addr) { - bt_pref.put(name, addr); + bt_pref.putString(name, addr); } private void remove(String name) { diff --git a/altosui/AltosUIPreferences.java b/altosui/AltosUIPreferences.java index 03e8e129..6e4c9097 100644 --- a/altosui/AltosUIPreferences.java +++ b/altosui/AltosUIPreferences.java @@ -98,7 +98,7 @@ public class AltosUIPreferences extends AltosPreferences { } } public static int font_size() { - synchronized (preferences) { + synchronized (backend) { return font_size; } } @@ -144,7 +144,7 @@ public class AltosUIPreferences extends AltosPreferences { } public static String look_and_feel() { - synchronized (preferences) { + synchronized (backend) { return look_and_feel; } } @@ -170,7 +170,7 @@ public class AltosUIPreferences extends AltosPreferences { } public static boolean serial_debug() { - synchronized (preferences) { + synchronized (backend) { return serial_debug; } } diff --git a/altosui/AltosUIPreferencesBackend.java b/altosui/AltosUIPreferencesBackend.java index 16844f37..2b2769c2 100644 --- a/altosui/AltosUIPreferencesBackend.java +++ b/altosui/AltosUIPreferencesBackend.java @@ -73,6 +73,14 @@ public class AltosUIPreferencesBackend implements AltosPreferencesBackend { return new AltosUIPreferencesBackend(_preferences.node(key)); } + public String[] keys() { + return _preferences.keys(); + } + + public void remove(String key) { + _preferences.remove(key); + } + public void flush() { try { _preferences.flush(); -- cgit v1.2.3 From 08345b8909922f2ff8f9ed8b4497b9cbea6b26e9 Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Fri, 14 Sep 2012 00:53:56 +1200 Subject: altosui/altoslib: Add call to …Preferences.init() with backend object, remove static init() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mike Beattie --- altoslib/AltosPreferences.java | 6 ++---- altosui/AltosUI.java | 1 + altosui/AltosUIPreferences.java | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'altosui/AltosUIPreferences.java') diff --git a/altoslib/AltosPreferences.java b/altoslib/AltosPreferences.java index ef30f8e9..a82ea3f6 100644 --- a/altoslib/AltosPreferences.java +++ b/altoslib/AltosPreferences.java @@ -137,8 +137,8 @@ public class AltosPreferences { public static int launcher_channel; - public static void init() { - //preferences = Preferences.userRoot().node("/org/altusmetrum/altosui"); + public static void init(AltosPreferencesBackend in_backend) { + backend = in_backend; /* Initialize logdir from preferences */ String logdir_string = backend.getString(logdirPreference, null); @@ -179,8 +179,6 @@ public class AltosPreferences { AltosConvert.imperial_units = backend.getBoolean(unitsPreference, false); } - static { init(); } - public static void flush_preferences() { backend.flush(); } diff --git a/altosui/AltosUI.java b/altosui/AltosUI.java index b5cbefe7..52b6b128 100644 --- a/altosui/AltosUI.java +++ b/altosui/AltosUI.java @@ -98,6 +98,7 @@ public class AltosUI extends AltosFrame { load_library(null); + AltosUIPreferences.init(new AltosUIPreferencesBackend()); AltosUIPreferences.set_component(this); pane = getContentPane(); diff --git a/altosui/AltosUIPreferences.java b/altosui/AltosUIPreferences.java index 6e4c9097..c1087dd6 100644 --- a/altosui/AltosUIPreferences.java +++ b/altosui/AltosUIPreferences.java @@ -45,7 +45,9 @@ public class AltosUIPreferences extends AltosPreferences { /* Serial debug */ static boolean serial_debug; - public static void init() { + public static void init(AltosUIPreferencesBackend in_backend) { + super(in_backend); + font_listeners = new LinkedList(); font_size = backend.getInt(fontSizePreference, Altos.font_size_medium); @@ -57,8 +59,6 @@ public class AltosUIPreferences extends AltosPreferences { AltosLink.set_debug(serial_debug); } - static { init(); } - static void set_component(Component in_component) { component = in_component; } -- cgit v1.2.3 From 26c83bc0981036651a89c29771b2ad52c8fb0396 Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Fri, 14 Sep 2012 01:03:53 +1200 Subject: altosui/altoslib: bug fixes, update Makefile.am Signed-off-by: Mike Beattie --- altosui/AltosUIPreferences.java | 2 +- altosui/AltosUIPreferencesBackend.java | 4 ++-- altosui/Makefile.am | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'altosui/AltosUIPreferences.java') diff --git a/altosui/AltosUIPreferences.java b/altosui/AltosUIPreferences.java index c1087dd6..4ef9384d 100644 --- a/altosui/AltosUIPreferences.java +++ b/altosui/AltosUIPreferences.java @@ -46,7 +46,7 @@ public class AltosUIPreferences extends AltosPreferences { static boolean serial_debug; public static void init(AltosUIPreferencesBackend in_backend) { - super(in_backend); + AltosPreferences.init(in_backend); font_listeners = new LinkedList(); diff --git a/altosui/AltosUIPreferencesBackend.java b/altosui/AltosUIPreferencesBackend.java index 2b2769c2..69485ba4 100644 --- a/altosui/AltosUIPreferencesBackend.java +++ b/altosui/AltosUIPreferencesBackend.java @@ -34,7 +34,7 @@ public class AltosUIPreferencesBackend implements AltosPreferencesBackend { } public String getString(String key, String def) { - return _preferences.get(key, def) + return _preferences.get(key, def); } public void putString(String key, String value) { _preferences.put(key, value); @@ -89,4 +89,4 @@ public class AltosUIPreferencesBackend implements AltosPreferencesBackend { } } -} \ No newline at end of file +} diff --git a/altosui/Makefile.am b/altosui/Makefile.am index 6010df58..9f03ceb6 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -65,6 +65,7 @@ altosui_JAVA = \ AltosLights.java \ AltosPad.java \ AltosUIPreferences.java \ + AltosUIPreferencesBackend.java \ AltosRomconfig.java \ AltosRomconfigUI.java \ AltosScanUI.java \ @@ -338,4 +339,4 @@ $(WINDOWS_DIST): $(WINDOWS_FILES) altos-windows.nsi makensis -Oaltos-windows.log "-XOutFile $@" "-DVERSION=$(VERSION)" altos-windows.nsi publish: - scp launch-sites.txt gag.com:public_html \ No newline at end of file + scp launch-sites.txt gag.com:public_html -- cgit v1.2.3 From f985ea055d935b10ae9ae8441fe808ba2c13c99e Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Fri, 14 Sep 2012 01:27:22 +1200 Subject: altosui: revert AltosUIPreferences init() method Signed-off-by: Mike Beattie --- altosui/AltosUI.java | 1 - altosui/AltosUIPreferences.java | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'altosui/AltosUIPreferences.java') diff --git a/altosui/AltosUI.java b/altosui/AltosUI.java index 52b6b128..b5cbefe7 100644 --- a/altosui/AltosUI.java +++ b/altosui/AltosUI.java @@ -98,7 +98,6 @@ public class AltosUI extends AltosFrame { load_library(null); - AltosUIPreferences.init(new AltosUIPreferencesBackend()); AltosUIPreferences.set_component(this); pane = getContentPane(); diff --git a/altosui/AltosUIPreferences.java b/altosui/AltosUIPreferences.java index 4ef9384d..a28c07b0 100644 --- a/altosui/AltosUIPreferences.java +++ b/altosui/AltosUIPreferences.java @@ -45,8 +45,8 @@ public class AltosUIPreferences extends AltosPreferences { /* Serial debug */ static boolean serial_debug; - public static void init(AltosUIPreferencesBackend in_backend) { - AltosPreferences.init(in_backend); + public static void init() { + AltosPreferences.init(new AltosUIPreferencesBackend()); font_listeners = new LinkedList(); @@ -59,6 +59,8 @@ public class AltosUIPreferences extends AltosPreferences { AltosLink.set_debug(serial_debug); } + static { init(); } + static void set_component(Component in_component) { component = in_component; } -- cgit v1.2.3 From 23b0c2fe95dbfaa4a8ce603b56b75d12d2c17d8c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 18 Oct 2012 16:19:38 -0700 Subject: altosui: Re-add a couple of "unused" values The values in these calls aren't needed, but the side-effects are, so add them back in. Signed-off-by: Keith Packard --- altosui/AltosFlashUI.java | 2 +- altosui/AltosSiteMap.java | 2 +- altosui/AltosUIPreferences.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'altosui/AltosUIPreferences.java') diff --git a/altosui/AltosFlashUI.java b/altosui/AltosFlashUI.java index f8c24b16..3ccfa76c 100644 --- a/altosui/AltosFlashUI.java +++ b/altosui/AltosFlashUI.java @@ -286,7 +286,7 @@ public class AltosFlashUI if (!select_source_file()) return; build_dialog(); - //flash_task f = new flash_task(this); + flash_task f = new flash_task(this); } static void show(JFrame frame) { diff --git a/altosui/AltosSiteMap.java b/altosui/AltosSiteMap.java index 3ea4d0fd..4e939b88 100644 --- a/altosui/AltosSiteMap.java +++ b/altosui/AltosSiteMap.java @@ -421,7 +421,7 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { public AltosSiteMap(int in_radius) { radius = in_radius; - //GrabNDrag scroller = new GrabNDrag(comp); + GrabNDrag scroller = new GrabNDrag(comp); comp.setLayout(layout); diff --git a/altosui/AltosUIPreferences.java b/altosui/AltosUIPreferences.java index a28c07b0..f6ee7e06 100644 --- a/altosui/AltosUIPreferences.java +++ b/altosui/AltosUIPreferences.java @@ -163,7 +163,7 @@ public class AltosUIPreferences extends AltosPreferences { } } public static void set_serial_debug(boolean new_serial_debug) { - AltosLink.set_debug(serial_debug); + AltosLink.set_debug(new_serial_debug); synchronized (backend) { serial_debug = new_serial_debug; backend.putBoolean(serialDebugPreference, serial_debug); -- cgit v1.2.3 From ae09bd641a86970763380f3028f987ffcb791020 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 2 Jan 2013 09:33:36 -0800 Subject: altosui: Use shared AltosFontListener class Signed-off-by: Keith Packard --- altosui/AltosFlightUI.java | 1 + altosui/AltosFontListener.java | 22 ---------------------- altosui/AltosUIPreferences.java | 1 + altosui/Makefile.am | 1 - 4 files changed, 2 insertions(+), 23 deletions(-) delete mode 100644 altosui/AltosFontListener.java (limited to 'altosui/AltosUIPreferences.java') diff --git a/altosui/AltosFlightUI.java b/altosui/AltosFlightUI.java index 43df705e..604ea658 100644 --- a/altosui/AltosFlightUI.java +++ b/altosui/AltosFlightUI.java @@ -22,6 +22,7 @@ import java.awt.event.*; import javax.swing.*; import java.util.concurrent.*; import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altosuilib.*; public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, AltosFontListener { AltosVoice voice; diff --git a/altosui/AltosFontListener.java b/altosui/AltosFontListener.java deleted file mode 100644 index 0dda0f29..00000000 --- a/altosui/AltosFontListener.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright © 2011 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 altosui; - -public interface AltosFontListener { - void font_size_changed(int font_size); -} diff --git a/altosui/AltosUIPreferences.java b/altosui/AltosUIPreferences.java index f6ee7e06..9c56d031 100644 --- a/altosui/AltosUIPreferences.java +++ b/altosui/AltosUIPreferences.java @@ -22,6 +22,7 @@ import java.util.*; import java.awt.Component; import javax.swing.*; import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altosuilib.*; public class AltosUIPreferences extends AltosPreferences { diff --git a/altosui/Makefile.am b/altosui/Makefile.am index 593eeb0a..1bd98c1c 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -50,7 +50,6 @@ altosui_JAVA = \ AltosFlightStatus.java \ AltosFlightStatusUpdate.java \ AltosFlightUI.java \ - AltosFontListener.java \ AltosFreqList.java \ AltosHexfile.java \ Altos.java \ -- cgit v1.2.3 From cf03ab3383b679e6617e8ab7004be91e5a727562 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 20 Jan 2013 15:39:53 -0800 Subject: altosui: Remove duplicate AltosUIPreferences.java This lives in altosuilib now. Several files needed imports of altosuilib added as a result. Signed-off-by: Keith Packard --- altosui/AltosDataChooser.java | 1 + altosui/AltosFreqList.java | 1 + altosui/AltosSiteMap.java | 1 + altosui/AltosUIPreferences.java | 181 ---------------------------------------- altosui/AltosVoice.java | 1 + altosui/Makefile.am | 1 - 6 files changed, 4 insertions(+), 182 deletions(-) delete mode 100644 altosui/AltosUIPreferences.java (limited to 'altosui/AltosUIPreferences.java') diff --git a/altosui/AltosDataChooser.java b/altosui/AltosDataChooser.java index a8a2ca49..242af9ad 100644 --- a/altosui/AltosDataChooser.java +++ b/altosui/AltosDataChooser.java @@ -21,6 +21,7 @@ import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.io.*; import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altosuilib.*; public class AltosDataChooser extends JFileChooser { JFrame frame; diff --git a/altosui/AltosFreqList.java b/altosui/AltosFreqList.java index 4edf088c..cc1f07ef 100644 --- a/altosui/AltosFreqList.java +++ b/altosui/AltosFreqList.java @@ -19,6 +19,7 @@ package altosui; import javax.swing.*; import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altosuilib.*; public class AltosFreqList extends JComboBox { diff --git a/altosui/AltosSiteMap.java b/altosui/AltosSiteMap.java index 4e939b88..144d506d 100644 --- a/altosui/AltosSiteMap.java +++ b/altosui/AltosSiteMap.java @@ -24,6 +24,7 @@ import java.lang.Math; import java.awt.geom.Point2D; import java.util.concurrent.*; import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altosuilib.*; public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay { // preferred vertical step in a tile in naut. miles diff --git a/altosui/AltosUIPreferences.java b/altosui/AltosUIPreferences.java deleted file mode 100644 index 9c56d031..00000000 --- a/altosui/AltosUIPreferences.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright © 2011 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 altosui; - -import java.io.*; -import java.util.*; -import java.awt.Component; -import javax.swing.*; -import org.altusmetrum.AltosLib.*; -import org.altusmetrum.altosuilib.*; - -public class AltosUIPreferences extends AltosPreferences { - - /* font size preferences name */ - final static String fontSizePreference = "FONT-SIZE"; - - /* Look&Feel preference name */ - final static String lookAndFeelPreference = "LOOK-AND-FEEL"; - - /* UI Component to pop dialogs up */ - static Component component; - - static LinkedList font_listeners; - - static int font_size = Altos.font_size_medium; - - static LinkedList ui_listeners; - - static String look_and_feel = null; - - /* Serial debug */ - static boolean serial_debug; - - public static void init() { - AltosPreferences.init(new AltosUIPreferencesBackend()); - - font_listeners = new LinkedList(); - - font_size = backend.getInt(fontSizePreference, Altos.font_size_medium); - Altos.set_fonts(font_size); - look_and_feel = backend.getString(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName()); - - ui_listeners = new LinkedList(); - serial_debug = backend.getBoolean(serialDebugPreference, false); - AltosLink.set_debug(serial_debug); - } - - static { init(); } - - static void set_component(Component in_component) { - component = in_component; - } - - private static boolean check_dir(File dir) { - if (!dir.exists()) { - if (!dir.mkdirs()) { - JOptionPane.showMessageDialog(component, - dir.getName(), - "Cannot create directory", - JOptionPane.ERROR_MESSAGE); - return false; - } - } else if (!dir.isDirectory()) { - JOptionPane.showMessageDialog(component, - dir.getName(), - "Is not a directory", - JOptionPane.ERROR_MESSAGE); - return false; - } - return true; - } - - /* Configure the log directory. This is where all telemetry and eeprom files - * will be written to, and where replay will look for telemetry files - */ - public static void ConfigureLog() { - JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile()); - - logdir_chooser.setDialogTitle("Configure Data Logging Directory"); - logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - - if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) { - File dir = logdir_chooser.getSelectedFile(); - if (check_dir(dir)) - set_logdir(dir); - } - } - public static int font_size() { - synchronized (backend) { - return font_size; - } - } - - static void set_fonts() { - } - - public static void set_font_size(int new_font_size) { - synchronized (backend) { - font_size = new_font_size; - backend.putInt(fontSizePreference, font_size); - flush_preferences(); - Altos.set_fonts(font_size); - for (AltosFontListener l : font_listeners) - l.font_size_changed(font_size); - } - } - - public static void register_font_listener(AltosFontListener l) { - synchronized (backend) { - font_listeners.add(l); - } - } - - public static void unregister_font_listener(AltosFontListener l) { - synchronized (backend) { - font_listeners.remove(l); - } - } - - public static void set_look_and_feel(String new_look_and_feel) { - try { - UIManager.setLookAndFeel(new_look_and_feel); - } catch (Exception e) { - } - synchronized(backend) { - look_and_feel = new_look_and_feel; - backend.putString(lookAndFeelPreference, look_and_feel); - flush_preferences(); - for (AltosUIListener l : ui_listeners) - l.ui_changed(look_and_feel); - } - } - - public static String look_and_feel() { - synchronized (backend) { - return look_and_feel; - } - } - - public static void register_ui_listener(AltosUIListener l) { - synchronized(backend) { - ui_listeners.add(l); - } - } - - public static void unregister_ui_listener(AltosUIListener l) { - synchronized (backend) { - ui_listeners.remove(l); - } - } - public static void set_serial_debug(boolean new_serial_debug) { - AltosLink.set_debug(new_serial_debug); - synchronized (backend) { - serial_debug = new_serial_debug; - backend.putBoolean(serialDebugPreference, serial_debug); - flush_preferences(); - } - } - - public static boolean serial_debug() { - synchronized (backend) { - return serial_debug; - } - } - -} diff --git a/altosui/AltosVoice.java b/altosui/AltosVoice.java index f84c1122..775c13d5 100644 --- a/altosui/AltosVoice.java +++ b/altosui/AltosVoice.java @@ -20,6 +20,7 @@ package altosui; import com.sun.speech.freetts.Voice; import com.sun.speech.freetts.VoiceManager; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.altosuilib.*; public class AltosVoice implements Runnable { VoiceManager voice_manager; diff --git a/altosui/Makefile.am b/altosui/Makefile.am index 7d000f7b..f5b83ce7 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -62,7 +62,6 @@ altosui_JAVA = \ AltosLed.java \ AltosLights.java \ AltosPad.java \ - AltosUIPreferences.java \ AltosUIPreferencesBackend.java \ AltosRomconfig.java \ AltosRomconfigUI.java \ -- cgit v1.2.3