diff options
author | Keith Packard <keithp@keithp.com> | 2014-06-12 14:12:08 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2014-06-12 14:12:08 -0700 |
commit | 8044eb8e23366e91c741060939baff5137f841c7 (patch) | |
tree | 82d8676369d840051b91a462859a3883bb678a80 /altosuilib | |
parent | e00ffe6ab6197ab48ba8ce3cf71a197f7215649f (diff) |
altosui/telegps: Reduce CPU time needed for flight displays
Don't update displays which aren't shown; track hierarchy changes to
trigger display from most recent state data.
Don't update values which haven't changed; remember previous values
and compare with new before updating widget contents.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosuilib')
-rw-r--r-- | altosuilib/AltosInfoTable.java | 25 | ||||
-rw-r--r-- | altosuilib/AltosUIMapView.java | 3 |
2 files changed, 25 insertions, 3 deletions
diff --git a/altosuilib/AltosInfoTable.java b/altosuilib/AltosInfoTable.java index 24a895eb..8ded1bea 100644 --- a/altosuilib/AltosInfoTable.java +++ b/altosuilib/AltosInfoTable.java @@ -18,16 +18,20 @@ package org.altusmetrum.altosuilib_2; import java.awt.*; +import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; import org.altusmetrum.altoslib_4.*; -public class AltosInfoTable extends JTable implements AltosFlightDisplay { +public class AltosInfoTable extends JTable implements AltosFlightDisplay, HierarchyListener { private AltosFlightInfoTableModel model; static final int info_columns = 3; static final int info_rows = 17; + private AltosState last_state; + private AltosListenerState last_listener_state; + int desired_row_height() { FontMetrics infoValueMetrics = getFontMetrics(AltosUILib.table_value_font); return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10; @@ -56,6 +60,7 @@ public class AltosInfoTable extends JTable implements AltosFlightDisplay { super(new AltosFlightInfoTableModel(info_rows, info_columns)); model = (AltosFlightInfoTableModel) getModel(); setFont(AltosUILib.table_value_font); + addHierarchyListener(this); setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS); setShowGrid(true); set_layout(); @@ -71,6 +76,17 @@ public class AltosInfoTable extends JTable implements AltosFlightDisplay { public void units_changed(boolean imperial_units) { } + public void hierarchyChanged(HierarchyEvent e) { + if (last_state != null && isShowing()) { + AltosState state = last_state; + AltosListenerState listener_state = last_listener_state; + + last_state = null; + last_listener_state = null; + show(state, listener_state); + } + } + public Dimension getPreferredScrollableViewportSize() { return getPreferredSize(); } @@ -108,6 +124,13 @@ public class AltosInfoTable extends JTable implements AltosFlightDisplay { } public void show(AltosState state, AltosListenerState listener_state) { + + if (!isShowing()) { + last_state = state; + last_listener_state = listener_state; + return; + } + reset(); if (state != null) { if (state.device_type != AltosLib.MISSING) diff --git a/altosuilib/AltosUIMapView.java b/altosuilib/AltosUIMapView.java index 70198682..efae3767 100644 --- a/altosuilib/AltosUIMapView.java +++ b/altosuilib/AltosUIMapView.java @@ -28,7 +28,7 @@ import java.util.*; import java.util.concurrent.*; import org.altusmetrum.altoslib_4.*; -public class AltosUIMapView extends Canvas implements MouseMotionListener, MouseListener, MouseWheelListener, ComponentListener, AltosUIMapTileListener, AltosUIMapStoreListener { +public class AltosUIMapView extends Component implements MouseMotionListener, MouseListener, MouseWheelListener, ComponentListener, AltosUIMapTileListener, AltosUIMapStoreListener { AltosUIMapPath path = new AltosUIMapPath(); @@ -422,7 +422,6 @@ public class AltosUIMapView extends Canvas implements MouseMotionListener, Mouse } public void paint(Graphics g) { - VolatileImage back_buffer = create_back_buffer(); do { GraphicsConfiguration gc = getGraphicsConfiguration(); |