diff options
Diffstat (limited to 'altosuilib')
23 files changed, 871 insertions, 38 deletions
diff --git a/altosuilib/AltosDevice.java b/altosuilib/AltosDevice.java index 69b025ba..2461df1b 100644 --- a/altosuilib/AltosDevice.java +++ b/altosuilib/AltosDevice.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altosuilib; +package org.altusmetrum.altosuilib_1; import libaltosJNI.*; diff --git a/altosuilib/AltosDeviceDialog.java b/altosuilib/AltosDeviceDialog.java index cde545a7..73bc0b2f 100644 --- a/altosuilib/AltosDeviceDialog.java +++ b/altosuilib/AltosDeviceDialog.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altosuilib; +package org.altusmetrum.altosuilib_1; import javax.swing.*; import java.awt.*; diff --git a/altosuilib/AltosFontListener.java b/altosuilib/AltosFontListener.java index ef543264..da903352 100644 --- a/altosuilib/AltosFontListener.java +++ b/altosuilib/AltosFontListener.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altosuilib; +package org.altusmetrum.altosuilib_1; public interface AltosFontListener { void font_size_changed(int font_size); diff --git a/altosuilib/AltosUnitsListener.java b/altosuilib/AltosPositionListener.java index 22c66cd4..e75d2de5 100644 --- a/altosuilib/AltosUnitsListener.java +++ b/altosuilib/AltosPositionListener.java @@ -1,5 +1,5 @@ /* - * Copyright © 2012 Keith Packard <keithp@keithp.com> + * Copyright © 2013 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 @@ -15,8 +15,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altosuilib; +package org.altusmetrum.altosuilib_1; -public interface AltosUnitsListener { - public void units_changed(); +public interface AltosPositionListener { + public void position_changed(int position); } diff --git a/altosuilib/AltosUIAxis.java b/altosuilib/AltosUIAxis.java new file mode 100644 index 00000000..867b0384 --- /dev/null +++ b/altosuilib/AltosUIAxis.java @@ -0,0 +1,94 @@ +/* + * Copyright © 2013 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.altosuilib_1; + +import java.io.*; +import java.util.ArrayList; + +import java.awt.*; +import javax.swing.*; +import org.altusmetrum.altoslib_1.*; + +import org.jfree.ui.*; +import org.jfree.chart.*; +import org.jfree.chart.plot.*; +import org.jfree.chart.axis.*; +import org.jfree.chart.renderer.*; +import org.jfree.chart.renderer.xy.*; +import org.jfree.chart.labels.*; +import org.jfree.data.xy.*; +import org.jfree.data.*; + +public class AltosUIAxis extends NumberAxis { + String label; + AltosUnits units; + Color color; + int ref; + int visible; + int index; + + public final static int axis_integer = 1; + public final static int axis_include_zero = 2; + + public final static int axis_default = axis_include_zero; + + public void set_units() { + setLabel(String.format("%s (%s)", label, units.show_units())); + } + + public void set_enable(boolean enable) { + if (enable) { + visible++; + if (visible > ref) + System.out.printf("too many visible\n"); + } else { + visible--; + if (visible < 0) + System.out.printf("too few visible\n"); + } + setVisible(visible > 0); + if (enable) + autoAdjustRange(); + } + + public void ref(boolean enable) { + ++ref; + if (enable) { + ++visible; + setVisible(visible > 0); + } + } + + public AltosUIAxis(String label, AltosUnits units, Color color, int index, int flags) { + this.label = label; + this.units = units; + this.index = index; + this.visible = 0; + this.ref = 0; + setLabelPaint(color); + setTickLabelPaint(color); + setVisible(false); + if ((flags & axis_integer) != 0) + setStandardTickUnits(NumberAxis.createIntegerTickUnits()); + setAutoRangeIncludesZero((flags & axis_include_zero) != 0); + } + + public AltosUIAxis(String label, AltosUnits units, Color color, int index) { + this(label, units, color, index, axis_default); + } +} diff --git a/altosuilib/AltosUIConfigure.java b/altosuilib/AltosUIConfigure.java index 6c9a841e..9e72e403 100644 --- a/altosuilib/AltosUIConfigure.java +++ b/altosuilib/AltosUIConfigure.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altosuilib; +package org.altusmetrum.altosuilib_1; import java.awt.*; import java.awt.event.*; @@ -202,9 +202,10 @@ public class AltosUIConfigure row++; } - public void add_serial_debug() { - GridBagConstraints c = new GridBagConstraints(); + public void add_position () { + } + public void add_serial_debug() { /* Serial debug setting */ pane.add(new JLabel("Serial Debug"), constraints(0, 1)); @@ -217,12 +218,8 @@ public class AltosUIConfigure } }); serial_debug.setToolTipText("Enable/Disable USB I/O getting sent to the console"); - c.gridx = 1; - c.gridy = row++; - c.gridwidth = 3; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.WEST; - pane.add(serial_debug, c); + pane.add(serial_debug, constraints(1,2)); + row++; } public void add_bluetooth() { @@ -253,8 +250,10 @@ public class AltosUIConfigure add_log_dir(); add_callsign(); add_units(); + add_serial_debug(); add_font_size(); add_look_and_feel(); + add_position(); add_bluetooth(); add_frequencies(); diff --git a/altosuilib/AltosUIDataMissing.java b/altosuilib/AltosUIDataMissing.java new file mode 100644 index 00000000..c7b01859 --- /dev/null +++ b/altosuilib/AltosUIDataMissing.java @@ -0,0 +1,25 @@ +/* + * Copyright © 2013 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.altosuilib_1; + +public class AltosUIDataMissing extends Exception { + public int id; + public AltosUIDataMissing(int id) { + this.id = id; + } +}
\ No newline at end of file diff --git a/altosuilib/AltosUIDataPoint.java b/altosuilib/AltosUIDataPoint.java new file mode 100644 index 00000000..d3020410 --- /dev/null +++ b/altosuilib/AltosUIDataPoint.java @@ -0,0 +1,25 @@ +/* + * Copyright © 2013 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.altosuilib_1; + +public interface AltosUIDataPoint { + public abstract double x() throws AltosUIDataMissing; + public abstract double y(int index) throws AltosUIDataMissing; + public abstract int id(int index) throws AltosUIDataMissing; + public abstract String id_name(int index) throws AltosUIDataMissing; +} diff --git a/altosuilib/AltosUIDataSet.java b/altosuilib/AltosUIDataSet.java new file mode 100644 index 00000000..6f23ef9a --- /dev/null +++ b/altosuilib/AltosUIDataSet.java @@ -0,0 +1,23 @@ +/* + * Copyright © 2013 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.altosuilib_1; + +public interface AltosUIDataSet { + public abstract String name(); + public abstract Iterable<AltosUIDataPoint> dataPoints(); +} diff --git a/altosuilib/AltosUIDialog.java b/altosuilib/AltosUIDialog.java index c0c33ba6..e1e699a7 100644 --- a/altosuilib/AltosUIDialog.java +++ b/altosuilib/AltosUIDialog.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altosuilib; +package org.altusmetrum.altosuilib_1; import java.awt.*; import java.awt.event.*; diff --git a/altosuilib/AltosUIEnable.java b/altosuilib/AltosUIEnable.java new file mode 100644 index 00000000..55486dea --- /dev/null +++ b/altosuilib/AltosUIEnable.java @@ -0,0 +1,121 @@ +/* + * Copyright © 2013 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.altosuilib_1; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.io.*; +import java.util.concurrent.*; +import java.util.*; +import org.altusmetrum.altoslib_1.*; + +import org.jfree.ui.*; +import org.jfree.chart.*; +import org.jfree.chart.plot.*; +import org.jfree.chart.axis.*; +import org.jfree.chart.renderer.*; +import org.jfree.chart.renderer.xy.*; +import org.jfree.chart.labels.*; +import org.jfree.data.xy.*; +import org.jfree.data.*; + +public class AltosUIEnable extends Container { + + Insets il, ir; + int y; + + class GraphElement implements ActionListener { + AltosUIGrapher grapher; + JLabel label; + JRadioButton enable; + String name; + + public void actionPerformed(ActionEvent ae) { + grapher.set_enable(enable.isSelected()); + } + + GraphElement (String name, AltosUIGrapher grapher, boolean enabled) { + this.name = name; + this.grapher = grapher; + label = new JLabel(name); + enable = new JRadioButton("Enable", enabled); + grapher.set_enable(enabled); + enable.addActionListener(this); + } + } + + public void add(String name, AltosUIGrapher grapher, boolean enabled) { + + GraphElement e = new GraphElement(name, grapher, enabled); + + /* Add label */ + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; c.gridy = y; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + add(e.label, c); + + /* Add radio button */ + c = new GridBagConstraints(); + c.gridx = 1; c.gridy = y; + c.fill = GridBagConstraints.HORIZONTAL; + c.anchor = GridBagConstraints.CENTER; + c.insets = ir; + add(e.enable, c); + + /* Next row */ + y++; + } + + public void add_units() { + /* Imperial units setting */ + /* Add label */ + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 1000; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + add(new JLabel("Imperial Units"), c); + + JRadioButton imperial_units = new JRadioButton("Enable", AltosUIPreferences.imperial_units()); + imperial_units.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + JRadioButton item = (JRadioButton) e.getSource(); + boolean enabled = item.isSelected(); + AltosUIPreferences.set_imperial_units(enabled); + } + }); + imperial_units.setToolTipText("Use Imperial units instead of metric"); + c = new GridBagConstraints(); + c.gridx = 1; c.gridy = 1000; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.LINE_START; + c.insets = il; + add(imperial_units, c); + } + + public AltosUIEnable() { + il = new Insets(4,4,4,4); + ir = new Insets(4,4,4,4); + y = 0; + setLayout(new GridBagLayout()); + add_units(); + } +} diff --git a/altosuilib/AltosUIFrame.java b/altosuilib/AltosUIFrame.java index 409aea2e..3fc99910 100644 --- a/altosuilib/AltosUIFrame.java +++ b/altosuilib/AltosUIFrame.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altosuilib; +package org.altusmetrum.altosuilib_1; import java.awt.*; import java.awt.event.*; @@ -28,7 +28,7 @@ class AltosUIFrameListener extends WindowAdapter { } } -public class AltosUIFrame extends JFrame implements AltosUIListener { +public class AltosUIFrame extends JFrame implements AltosUIListener, AltosPositionListener { public void ui_changed(String look_and_feel) { SwingUtilities.updateComponentTreeUI(this); @@ -66,17 +66,108 @@ public class AltosUIFrame extends JFrame implements AltosUIListener { setIconImages(icons); } + private boolean location_by_platform = true; - public AltosUIFrame() { + public void setLocationByPlatform(boolean lbp) { + location_by_platform = lbp; + super.setLocationByPlatform(lbp); + } + + public void setSize() { + /* Smash sizes around so that the window comes up in the right shape */ + Insets i = getInsets(); + Dimension ps = rootPane.getPreferredSize(); + ps.width += i.left + i.right; + ps.height += i.top + i.bottom; + setPreferredSize(ps); + setSize(ps); + } + + public void setPosition (int position) { + Insets i = getInsets(); + Dimension ps = getSize(); + + /* Stick the window in the desired location on the screen */ + setLocationByPlatform(false); + GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + GraphicsConfiguration gc = gd.getDefaultConfiguration(); + Rectangle r = gc.getBounds(); + + /* compute X position */ + int x = 0; + int y = 0; + switch (position) { + case AltosUILib.position_top_left: + case AltosUILib.position_left: + case AltosUILib.position_bottom_left: + x = 0; + break; + case AltosUILib.position_top: + case AltosUILib.position_center: + case AltosUILib.position_bottom: + x = (r.width - ps.width) / 2; + break; + case AltosUILib.position_top_right: + case AltosUILib.position_right: + case AltosUILib.position_bottom_right: + x = r.width - ps.width + i.right; + break; + } + + /* compute Y position */ + switch (position) { + case AltosUILib.position_top_left: + case AltosUILib.position_top: + case AltosUILib.position_top_right: + y = 0; + break; + case AltosUILib.position_left: + case AltosUILib.position_center: + case AltosUILib.position_right: + y = (r.height - ps.height) / 2; + break; + case AltosUILib.position_bottom_left: + case AltosUILib.position_bottom: + case AltosUILib.position_bottom_right: + y = r.height - ps.height + i.bottom; + break; + } + setLocation(x, y); + } + + int position; + + public void position_changed(int position) { + this.position = position; + if (!location_by_platform) + setPosition(position); + } + + public void setVisible (boolean visible) { + if (visible) + setLocationByPlatform(location_by_platform); + super.setVisible(visible); + if (visible) { + setSize(); + if (!location_by_platform) + setPosition(position); + } + } + + void init() { AltosUIPreferences.register_ui_listener(this); + AltosUIPreferences.register_position_listener(this); + position = AltosUIPreferences.position(); addWindowListener(new AltosUIFrameListener()); set_icon(); } + public AltosUIFrame() { + init(); + } + public AltosUIFrame(String name) { super(name); - AltosUIPreferences.register_ui_listener(this); - addWindowListener(new AltosUIFrameListener()); - set_icon(); + init(); } } diff --git a/altosuilib/AltosUIGraph.java b/altosuilib/AltosUIGraph.java new file mode 100644 index 00000000..5c589c02 --- /dev/null +++ b/altosuilib/AltosUIGraph.java @@ -0,0 +1,155 @@ +/* + * Copyright © 2012 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.altosuilib_1; + +import java.io.*; +import java.util.ArrayList; + +import java.awt.*; +import javax.swing.*; +import org.altusmetrum.altoslib_1.*; + +import org.jfree.ui.*; +import org.jfree.chart.*; +import org.jfree.chart.plot.*; +import org.jfree.chart.axis.*; +import org.jfree.chart.renderer.*; +import org.jfree.chart.renderer.xy.*; +import org.jfree.chart.labels.*; +import org.jfree.data.xy.*; +import org.jfree.data.*; + +public class AltosUIGraph implements AltosUnitsListener { + + XYPlot plot; + JFreeChart chart; + public ChartPanel panel; + NumberAxis xAxis; + AltosUIEnable enable; + ArrayList<AltosUIGrapher> graphers; + AltosUIDataSet dataSet; + int axis_index; + int series_index; + + static final private Color gridline_color = new Color(0, 0, 0); + static final private Color border_color = new Color(255, 255, 255); + static final private Color background_color = new Color(255, 255, 255); + + public JPanel panel() { + return panel; + } + + public AltosUIAxis newAxis(String label, AltosUnits units, Color color, int flags) { + AltosUIAxis axis = new AltosUIAxis(label, units, color, axis_index++, flags); + plot.setRangeAxis(axis.index, axis); + return axis; + } + + public AltosUIAxis newAxis(String label, AltosUnits units, Color color) { + return newAxis(label, units, color, AltosUIAxis.axis_default); + } + + public void addSeries(String label, int fetch, AltosUnits units, Color color, + boolean enabled, AltosUIAxis axis) { + AltosUISeries series = new AltosUISeries(label, fetch, units, color, enabled, axis); + XYSeriesCollection dataset = new XYSeriesCollection(series); + + series.renderer.setPlot(plot); + plot.setDataset(series_index, dataset); + plot.setRenderer(series_index, series.renderer); + plot.mapDatasetToRangeAxis(series_index, axis.index); + if (enable != null) + enable.add(label, series, enabled); + this.graphers.add(series); + series_index++; + } + + public void addSeries(String label, int fetch, AltosUnits units, Color color) { + addSeries(label, fetch, units, color, true, newAxis(label, units, color)); + } + + public void addMarker(String label, int fetch, Color color) { + AltosUIMarker marker = new AltosUIMarker(fetch, color, plot); + if (enable != null) + enable.add(label, marker, true); + this.graphers.add(marker); + } + + public void resetData() { + for (AltosUIGrapher g : graphers) + g.clear(); + if (dataSet != null) { + for (AltosUIDataPoint dataPoint : dataSet.dataPoints()) + for (AltosUIGrapher g : graphers) + g.add(dataPoint); + } + } + + public void units_changed(boolean imperial_units) { + for (AltosUIGrapher g : graphers) + g.set_units(); + resetData(); + } + + public void setName (String name) { + chart.setTitle(name); + } + + public void setDataSet (AltosUIDataSet dataSet) { + this.dataSet = dataSet; + resetData(); + if (dataSet != null) + setName(dataSet.name()); + } + + public AltosUIGraph(AltosUIEnable enable) { + + this.enable = enable; + this.graphers = new ArrayList<AltosUIGrapher>(); + this.series_index = 0; + this.axis_index = 0; + + xAxis = new NumberAxis("Time (s)"); + + xAxis.setAutoRangeIncludesZero(true); + + plot = new XYPlot(); + plot.setDomainAxis(xAxis); + plot.setOrientation(PlotOrientation.VERTICAL); + plot.setDomainPannable(true); + plot.setRangePannable(true); + + chart = new JFreeChart("Flight", JFreeChart.DEFAULT_TITLE_FONT, + plot, true); + + ChartUtilities.applyCurrentTheme(chart); + + plot.setDomainGridlinePaint(gridline_color); + plot.setRangeGridlinePaint(gridline_color); + plot.setBackgroundPaint(background_color); + plot.setBackgroundAlpha((float) 1); + + chart.setBackgroundPaint(background_color); + chart.setBorderPaint(border_color); + panel = new ChartPanel(chart); + panel.setMouseWheelEnabled(true); + panel.setPreferredSize(new java.awt.Dimension(800, 500)); + + AltosPreferences.register_units_listener(this); + } +}
\ No newline at end of file diff --git a/altosuilib/AltosUIGrapher.java b/altosuilib/AltosUIGrapher.java new file mode 100644 index 00000000..c627fec5 --- /dev/null +++ b/altosuilib/AltosUIGrapher.java @@ -0,0 +1,46 @@ +/* + * Copyright © 2013 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.altosuilib_1; + +import java.io.*; +import java.util.ArrayList; + +import java.awt.*; +import javax.swing.*; +import org.altusmetrum.altoslib_1.*; + +import org.jfree.ui.*; +import org.jfree.chart.*; +import org.jfree.chart.plot.*; +import org.jfree.chart.axis.*; +import org.jfree.chart.renderer.*; +import org.jfree.chart.renderer.xy.*; +import org.jfree.chart.labels.*; +import org.jfree.data.xy.*; +import org.jfree.data.*; + +interface AltosUIGrapher { + + public abstract void set_units(); + + public abstract void clear(); + + public abstract void add(AltosUIDataPoint dataPoint); + + public abstract void set_enable(boolean enable); +} diff --git a/altosuilib/AltosUILib.java b/altosuilib/AltosUILib.java index 5d5f9aaa..1b121405 100644 --- a/altosuilib/AltosUILib.java +++ b/altosuilib/AltosUILib.java @@ -15,12 +15,12 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altosuilib; +package org.altusmetrum.altosuilib_1; import java.awt.*; import libaltosJNI.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosUILib extends AltosLib { @@ -36,7 +36,17 @@ public class AltosUILib extends AltosLib { final public static int font_size_medium = 2; final public static int font_size_large = 3; - static void set_fonts(int size) { + final public static int position_top_left = 0; + final public static int position_top = 1; + final public static int position_top_right = 2; + final public static int position_left = 3; + final public static int position_center = 4; + final public static int position_right = 5; + final public static int position_bottom_left = 6; + final public static int position_bottom = 7; + final public static int position_bottom_right = 8; + + public static void set_fonts(int size) { int brief_size; int table_size; int status_size; @@ -66,7 +76,7 @@ public class AltosUILib extends AltosLib { table_value_font = new Font("Monospaced", Font.PLAIN, table_size); } - static final int text_width = 20; + static public final int text_width = 20; static public boolean initialized = false; static public boolean loaded_library = false; diff --git a/altosuilib/AltosUIListener.java b/altosuilib/AltosUIListener.java index f4127f58..450dc0bf 100644 --- a/altosuilib/AltosUIListener.java +++ b/altosuilib/AltosUIListener.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altosuilib; +package org.altusmetrum.altosuilib_1; public interface AltosUIListener { public void ui_changed(String look_and_feel); diff --git a/altosuilib/AltosUIMarker.java b/altosuilib/AltosUIMarker.java new file mode 100644 index 00000000..e2eb9028 --- /dev/null +++ b/altosuilib/AltosUIMarker.java @@ -0,0 +1,106 @@ +/* + * Copyright © 2013 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.altosuilib_1; + +import java.io.*; +import java.util.ArrayList; + +import java.awt.*; +import javax.swing.*; +import org.altusmetrum.altoslib_1.*; + +import org.jfree.ui.*; +import org.jfree.chart.*; +import org.jfree.chart.plot.*; +import org.jfree.chart.axis.*; +import org.jfree.chart.renderer.*; +import org.jfree.chart.renderer.xy.*; +import org.jfree.chart.labels.*; +import org.jfree.data.xy.*; +import org.jfree.data.*; + +public class AltosUIMarker implements AltosUIGrapher { + ArrayList<ValueMarker> markers; + int last_id; + XYPlot plot; + boolean enabled; + int fetch; + Color color; + + private void remove_markers() { + for (ValueMarker marker : markers) + plot.removeDomainMarker(marker); + } + + private void add_markers() { + for (ValueMarker marker : markers) + plot.addDomainMarker(marker); + } + + public void set_units() { + } + + public void set_enable(boolean enable) { + if (enabled == enable) + return; + if (enable) + add_markers(); + else + remove_markers(); + enabled = enable; + } + + public void clear() { + if (enabled) + remove_markers(); + markers = new ArrayList<ValueMarker>(); + } + + public void add(AltosUIDataPoint dataPoint) { + try { + int id = dataPoint.id(fetch); + if (id < 0) + return; + if (id == last_id) + return; + ValueMarker marker = new ValueMarker(dataPoint.x()); + marker.setLabel(dataPoint.id_name(fetch)); + marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); + marker.setLabelTextAnchor(TextAnchor.TOP_LEFT); + marker.setPaint(color); + if (enabled) + plot.addDomainMarker(marker); + markers.add(marker); + last_id = id; + } catch (AltosUIDataMissing m) { + } + } + + public AltosUIMarker (int fetch, Color color, XYPlot plot, boolean enable) { + markers = new ArrayList<ValueMarker>(); + last_id = -1; + this.fetch = fetch; + this.color = color; + this.plot = plot; + this.enabled = enable; + } + + public AltosUIMarker (int fetch, Color color, XYPlot plot) { + this(fetch, color, plot, true); + } +}
\ No newline at end of file diff --git a/altosuilib/AltosUIPreferences.java b/altosuilib/AltosUIPreferences.java index 485cb582..49321bce 100644 --- a/altosuilib/AltosUIPreferences.java +++ b/altosuilib/AltosUIPreferences.java @@ -15,13 +15,13 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altosuilib; +package org.altusmetrum.altosuilib_1; import java.io.*; import java.util.*; import java.awt.Component; import javax.swing.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; public class AltosUIPreferences extends AltosPreferences { @@ -31,6 +31,9 @@ public class AltosUIPreferences extends AltosPreferences { /* Look&Feel preference name */ final static String lookAndFeelPreference = "LOOK-AND-FEEL"; + /* Window position preference name */ + final static String positionPreference = "POSITION"; + /* UI Component to pop dialogs up */ static Component component; @@ -45,6 +48,10 @@ public class AltosUIPreferences extends AltosPreferences { /* Serial debug */ public static boolean serial_debug; + static LinkedList<AltosPositionListener> position_listeners; + + public static int position = AltosUILib.position_top_left; + public static void init() { AltosPreferences.init(new AltosUIPreferencesBackend()); @@ -56,7 +63,11 @@ public class AltosUIPreferences extends AltosPreferences { ui_listeners = new LinkedList<AltosUIListener>(); serial_debug = backend.getBoolean(serialDebugPreference, false); + AltosLink.set_debug(serial_debug); + + position = backend.getInt(positionPreference, AltosUILib.position_top_left); + position_listeners = new LinkedList<AltosPositionListener>(); } static { init(); } @@ -177,4 +188,31 @@ public class AltosUIPreferences extends AltosPreferences { } } + public static void register_position_listener(AltosPositionListener l) { + synchronized(backend) { + position_listeners.add(l); + } + } + + public static void unregister_position_listener(AltosPositionListener l) { + synchronized (backend) { + position_listeners.remove(l); + } + } + + public static void set_position(int new_position) { + synchronized (backend) { + position = new_position; + backend.putInt(positionPreference, position); + flush_preferences(); + for (AltosPositionListener l : position_listeners) + l.position_changed(position); + } + } + + public static int position() { + synchronized (backend) { + return position; + } + } } diff --git a/altosuilib/AltosUIPreferencesBackend.java b/altosuilib/AltosUIPreferencesBackend.java index c6c05e55..8a5386c3 100644 --- a/altosuilib/AltosUIPreferencesBackend.java +++ b/altosuilib/AltosUIPreferencesBackend.java @@ -15,11 +15,11 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altosuilib; +package org.altusmetrum.altosuilib_1; import java.io.File; import java.util.prefs.*; -import org.altusmetrum.AltosLib.*; +import org.altusmetrum.altoslib_1.*; import javax.swing.filechooser.FileSystemView; public class AltosUIPreferencesBackend implements AltosPreferencesBackend { diff --git a/altosuilib/AltosUISeries.java b/altosuilib/AltosUISeries.java new file mode 100644 index 00000000..ac09a3cc --- /dev/null +++ b/altosuilib/AltosUISeries.java @@ -0,0 +1,91 @@ +/* + * Copyright © 2013 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.altosuilib_1; + +import java.io.*; +import java.util.ArrayList; + +import java.awt.*; +import javax.swing.*; +import org.altusmetrum.altoslib_1.*; + +import org.jfree.ui.*; +import org.jfree.chart.*; +import org.jfree.chart.plot.*; +import org.jfree.chart.axis.*; +import org.jfree.chart.renderer.*; +import org.jfree.chart.renderer.xy.*; +import org.jfree.chart.labels.*; +import org.jfree.data.xy.*; +import org.jfree.data.*; + +public class AltosUISeries extends XYSeries implements AltosUIGrapher { + AltosUIAxis axis; + String label; + AltosUnits units; + Color color; + XYItemRenderer renderer; + int fetch; + boolean enable; + + public void set_units() { + axis.set_units(); + StandardXYToolTipGenerator ttg; + + String example = units.graph_format(4); + + ttg = new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})", + units.show_units()), + new java.text.DecimalFormat(example), + new java.text.DecimalFormat(example)); + renderer.setBaseToolTipGenerator(ttg); + } + + public void set_enable(boolean enable) { + if (this.enable != enable) { + this.enable = enable; + renderer.setSeriesVisible(0, enable); + axis.set_enable(enable); + } + } + + public void add(AltosUIDataPoint dataPoint) { + try { + super.add(dataPoint.x(), units.value(dataPoint.y(fetch))); + } catch (AltosUIDataMissing dm) { + } + } + + public AltosUISeries (String label, int fetch, AltosUnits units, Color color, + boolean enable, AltosUIAxis axis) { + super(label); + this.label = label; + this.fetch = fetch; + this.units = units; + this.color = color; + this.enable = enable; + this.axis = axis; + + axis.ref(this.enable); + + renderer = new XYLineAndShapeRenderer(true, false); + renderer.setSeriesPaint(0, color); + renderer.setSeriesVisible(0, enable); + set_units(); + } +} diff --git a/altosuilib/AltosUIVersion.java.in b/altosuilib/AltosUIVersion.java.in index 6fb3b38b..169cca1b 100644 --- a/altosuilib/AltosUIVersion.java.in +++ b/altosuilib/AltosUIVersion.java.in @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altosuilib; +package org.altusmetrum.altosuilib_1; public class AltosUIVersion { public final static String version = "@VERSION@"; diff --git a/altosuilib/AltosUSBDevice.java b/altosuilib/AltosUSBDevice.java index bab16fb0..a5496597 100644 --- a/altosuilib/AltosUSBDevice.java +++ b/altosuilib/AltosUSBDevice.java @@ -15,7 +15,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altosuilib; +package org.altusmetrum.altosuilib_1; import java.util.*; import libaltosJNI.*; diff --git a/altosuilib/Makefile.am b/altosuilib/Makefile.am index da5fb848..0cd2aaea 100644 --- a/altosuilib/Makefile.am +++ b/altosuilib/Makefile.am @@ -9,21 +9,30 @@ SRC=. altosuilibdir = $(datadir)/java altosuilib_JAVA = \ - AltosUIConfigure.java \ AltosDevice.java \ AltosDeviceDialog.java \ - AltosUSBDevice.java \ AltosFontListener.java \ + AltosPositionListener.java \ + AltosUIConfigure.java \ + AltosUIAxis.java \ + AltosUIDataMissing.java \ + AltosUIDataPoint.java \ + AltosUIDataSet.java \ + AltosUIGraph.java \ + AltosUIGrapher.java \ AltosUIDialog.java \ + AltosUIEnable.java \ AltosUIFrame.java \ AltosUILib.java \ AltosUIListener.java \ + AltosUIMarker.java \ AltosUIPreferencesBackend.java \ AltosUIPreferences.java \ + AltosUISeries.java \ AltosUIVersion.java \ - AltosUnitsListener.java + AltosUSBDevice.java -JAR=altosuilib.jar +JAR=altosuilib_$(ALTOSUILIB_VERSION).jar all-local: $(JAR) |
