micropeak_JAVA= \
MicroPeak.java \
MicroData.java \
+ MicroFrame.java \
MicroGraph.java \
MicroSerial.java \
MicroFileChooser.java \
+ MicroPreferences.java \
+ MicroPreferencesBackend.java \
+ MicroFontListener.java \
+ MicroUIListener.java \
MicroUSB.java
JFREECHART_CLASS= \
ALTOSLIB_CLASS=\
AltosLib.jar
+# Icons
+ICONDIR=$(top_srcdir)/icon
+
+JAVA_ICONS=\
+ $(ICONDIR)/micropeak-16.png \
+ $(ICONDIR)/micropeak-32.png \
+ $(ICONDIR)/micropeak-48.png \
+ $(ICONDIR)/micropeak-64.png \
+ $(ICONDIR)/micropeak-128.png \
+ $(ICONDIR)/micropeak-256.png
+
+# icon base names for jar
+ICONJAR= -C $(ICONDIR) micropeak-16.png \
+ -C $(ICONDIR) micropeak-32.png \
+ -C $(ICONDIR) micropeak-48.png \
+ -C $(ICONDIR) micropeak-64.png \
+ -C $(ICONDIR) micropeak-128.png \
+ -C $(ICONDIR) micropeak-256.png
+
all-local: micropeak-test $(JAR)
clean-local:
--- /dev/null
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * 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.micropeak;
+
+public interface MicroFontListener {
+ void font_size_changed(int font_size);
+}
--- /dev/null
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * 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.micropeak;
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import java.util.*;
+
+class MicroFrameListener extends WindowAdapter {
+ public void windowClosing (WindowEvent e) {
+ MicroPreferences.unregister_ui_listener((MicroFrame) e.getWindow());
+ }
+}
+
+public class MicroFrame extends JFrame implements MicroUIListener {
+
+ public void ui_changed(String look_and_feel) {
+ SwingUtilities.updateComponentTreeUI(this);
+ this.pack();
+ }
+
+ static final String[] icon_names = {
+ "/micropeak-16.png",
+ "/micropeak-32.png",
+ "/micropeak-48.png",
+ "/micropeak-64.png",
+ "/micropeak-128.png",
+ "/micropeak-256.png"
+ };
+
+ public void set_icon() {
+ ArrayList<Image> icons = new ArrayList<Image>();
+
+ for (int i = 0; i < icon_names.length; i++) {
+ java.net.URL imgURL = MicroPeak.class.getResource(icon_names[i]);
+ if (imgURL != null)
+ icons.add(new ImageIcon(imgURL).getImage());
+ }
+
+ setIconImages(icons);
+ }
+
+ public MicroFrame() {
+ super();
+ MicroPreferences.set_component(this);
+ MicroPreferences.register_ui_listener(this);
+ addWindowListener(new MicroFrameListener());
+ set_icon();
+ }
+
+ public MicroFrame(String name) {
+ super(name);
+ MicroPreferences.set_component(this);
+ MicroPreferences.register_ui_listener(this);
+ addWindowListener(new MicroFrameListener());
+ set_icon();
+ }
+}
import java.util.*;
import org.altusmetrum.AltosLib.*;
-public class MicroPeak extends JFrame implements ActionListener, ItemListener {
+public class MicroPeak extends MicroFrame implements ActionListener, ItemListener {
File filename;
MicroGraph graph;
--- /dev/null
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * 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.micropeak;
+
+import java.io.*;
+import java.util.*;
+import java.awt.Component;
+import javax.swing.*;
+import java.awt.*;
+import org.altusmetrum.AltosLib.*;
+
+public class MicroPreferences extends AltosPreferences {
+
+ static final int tab_elt_pad = 5;
+
+ static Font label_font;
+ static Font value_font;
+ static Font status_font;
+ static Font table_label_font;
+ static Font table_value_font;
+
+ final static int font_size_small = 1;
+ final static int font_size_medium = 2;
+ final static int font_size_large = 3;
+
+ static void set_fonts(int size) {
+ int brief_size;
+ int table_size;
+ int status_size;
+
+ switch (size) {
+ case font_size_small:
+ brief_size = 16;
+ status_size = 18;
+ table_size = 11;
+ break;
+ default:
+ case font_size_medium:
+ brief_size = 22;
+ status_size = 24;
+ table_size = 14;
+ break;
+ case font_size_large:
+ brief_size = 26;
+ status_size = 30;
+ table_size = 17;
+ break;
+ }
+ label_font = new Font("Dialog", Font.PLAIN, brief_size);
+ value_font = new Font("Monospaced", Font.PLAIN, brief_size);
+ status_font = new Font("SansSerif", Font.BOLD, status_size);
+ table_label_font = new Font("SansSerif", Font.PLAIN, table_size);
+ table_value_font = new Font("Monospaced", Font.PLAIN, table_size);
+ }
+
+ /* 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<MicroFontListener> font_listeners;
+
+ static int font_size = font_size_medium;
+
+ static LinkedList<MicroUIListener> ui_listeners;
+
+ static String look_and_feel = null;
+
+ /* Serial debug */
+ static boolean serial_debug;
+
+ public static void init() {
+ AltosPreferences.init(new MicroPreferencesBackend());
+
+ font_listeners = new LinkedList<MicroFontListener>();
+
+ font_size = backend.getInt(fontSizePreference, font_size_medium);
+ set_fonts(font_size);
+ look_and_feel = backend.getString(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName());
+
+ ui_listeners = new LinkedList<MicroUIListener>();
+ serial_debug = backend.getBoolean(serialDebugPreference, false);
+ }
+
+ 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();
+ set_fonts(font_size);
+ for (MicroFontListener l : font_listeners)
+ l.font_size_changed(font_size);
+ }
+ }
+
+ public static void register_font_listener(MicroFontListener l) {
+ synchronized (backend) {
+ font_listeners.add(l);
+ }
+ }
+
+ public static void unregister_font_listener(MicroFontListener 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 (MicroUIListener 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(MicroUIListener l) {
+ synchronized(backend) {
+ ui_listeners.add(l);
+ }
+ }
+
+ public static void unregister_ui_listener(MicroUIListener l) {
+ synchronized (backend) {
+ ui_listeners.remove(l);
+ }
+ }
+ public static void set_serial_debug(boolean 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;
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright © 2012 Mike Beattie <mike@ethernal.org>
+ *
+ * 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.micropeak;
+
+import java.io.File;
+import java.util.prefs.*;
+import org.altusmetrum.AltosLib.*;
+import javax.swing.filechooser.FileSystemView;
+
+public class MicroPreferencesBackend implements AltosPreferencesBackend {
+
+ private Preferences _preferences = null;
+
+ public MicroPreferencesBackend() {
+ _preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
+ }
+
+ public MicroPreferencesBackend(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 MicroPreferencesBackend(_preferences.node(key));
+ }
+
+ public String[] keys() {
+ try {
+ return _preferences.keys();
+ } catch (BackingStoreException be) {
+ return null;
+ }
+ }
+
+ public void remove(String key) {
+ _preferences.remove(key);
+ }
+
+ public void flush() {
+ try {
+ _preferences.flush();
+ } catch (BackingStoreException ee) {
+ System.err.printf("Cannot save preferences\n");
+ }
+ }
+
+ public File homeDirectory() {
+ /* Use the file system view default directory */
+ return FileSystemView.getFileSystemView().getDefaultDirectory();
+ }
+}
SWIGTYPE_p_altos_file file;
public int read() {
- return libaltos.altos_getchar(file, 0);
+ int c = libaltos.altos_getchar(file, 0);
+ if (MicroPreferences.serial_debug)
+ System.out.printf("%c", c);
+ return c;
}
public void close() {
--- /dev/null
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * 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.micropeak;
+
+public interface MicroUIListener {
+ public void ui_changed(String look_and_feel);
+}