diff options
| -rw-r--r-- | icon/micropeak-128.png | bin | 0 -> 4394 bytes | |||
| -rw-r--r-- | icon/micropeak-16.png | bin | 0 -> 534 bytes | |||
| -rw-r--r-- | icon/micropeak-256.png | bin | 0 -> 8055 bytes | |||
| -rw-r--r-- | icon/micropeak-32.png | bin | 0 -> 1072 bytes | |||
| -rw-r--r-- | icon/micropeak-48.png | bin | 0 -> 1662 bytes | |||
| -rw-r--r-- | icon/micropeak-64.png | bin | 0 -> 2240 bytes | |||
| -rw-r--r-- | micropeak/Makefile.am | 24 | ||||
| -rw-r--r-- | micropeak/MicroFontListener.java | 22 | ||||
| -rw-r--r-- | micropeak/MicroFrame.java | 74 | ||||
| -rw-r--r-- | micropeak/MicroPeak.java | 2 | ||||
| -rw-r--r-- | micropeak/MicroPreferences.java | 221 | ||||
| -rw-r--r-- | micropeak/MicroPreferencesBackend.java | 101 | ||||
| -rw-r--r-- | micropeak/MicroSerial.java | 5 | ||||
| -rw-r--r-- | micropeak/MicroUIListener.java | 22 | 
14 files changed, 469 insertions, 2 deletions
| diff --git a/icon/micropeak-128.png b/icon/micropeak-128.pngBinary files differ new file mode 100644 index 00000000..f045dc6a --- /dev/null +++ b/icon/micropeak-128.png diff --git a/icon/micropeak-16.png b/icon/micropeak-16.pngBinary files differ new file mode 100644 index 00000000..d8140802 --- /dev/null +++ b/icon/micropeak-16.png diff --git a/icon/micropeak-256.png b/icon/micropeak-256.pngBinary files differ new file mode 100644 index 00000000..b96d4706 --- /dev/null +++ b/icon/micropeak-256.png diff --git a/icon/micropeak-32.png b/icon/micropeak-32.pngBinary files differ new file mode 100644 index 00000000..d34c5c12 --- /dev/null +++ b/icon/micropeak-32.png diff --git a/icon/micropeak-48.png b/icon/micropeak-48.pngBinary files differ new file mode 100644 index 00000000..86dc4f7f --- /dev/null +++ b/icon/micropeak-48.png diff --git a/icon/micropeak-64.png b/icon/micropeak-64.pngBinary files differ new file mode 100644 index 00000000..6ca7c2eb --- /dev/null +++ b/icon/micropeak-64.png diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index 32be9070..2cfd2ad3 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -10,9 +10,14 @@ micropeakdir=$(datadir)/java  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= \ @@ -33,6 +38,25 @@ LIBALTOS= \  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: diff --git a/micropeak/MicroFontListener.java b/micropeak/MicroFontListener.java new file mode 100644 index 00000000..a902584c --- /dev/null +++ b/micropeak/MicroFontListener.java @@ -0,0 +1,22 @@ +/* + * 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); +} diff --git a/micropeak/MicroFrame.java b/micropeak/MicroFrame.java new file mode 100644 index 00000000..a9b9a37a --- /dev/null +++ b/micropeak/MicroFrame.java @@ -0,0 +1,74 @@ +/* + * 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(); +	} +} diff --git a/micropeak/MicroPeak.java b/micropeak/MicroPeak.java index cd09c475..c9074348 100644 --- a/micropeak/MicroPeak.java +++ b/micropeak/MicroPeak.java @@ -25,7 +25,7 @@ import java.util.concurrent.*;  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; diff --git a/micropeak/MicroPreferences.java b/micropeak/MicroPreferences.java new file mode 100644 index 00000000..70c2557c --- /dev/null +++ b/micropeak/MicroPreferences.java @@ -0,0 +1,221 @@ +/* + * 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; +		} +	} + +} diff --git a/micropeak/MicroPreferencesBackend.java b/micropeak/MicroPreferencesBackend.java new file mode 100644 index 00000000..7d92f6be --- /dev/null +++ b/micropeak/MicroPreferencesBackend.java @@ -0,0 +1,101 @@ +/* + * 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(); +	} +} diff --git a/micropeak/MicroSerial.java b/micropeak/MicroSerial.java index afe55532..8546276e 100644 --- a/micropeak/MicroSerial.java +++ b/micropeak/MicroSerial.java @@ -24,7 +24,10 @@ public class MicroSerial extends InputStream {  	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() { diff --git a/micropeak/MicroUIListener.java b/micropeak/MicroUIListener.java new file mode 100644 index 00000000..9aed8dae --- /dev/null +++ b/micropeak/MicroUIListener.java @@ -0,0 +1,22 @@ +/* + * 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); +} | 
