Changed average values to always be floating-point

This commit is contained in:
nifi 2010-10-14 06:31:38 +00:00
parent 0d7f895744
commit a5fe4ae1c3

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: NodeInfoPanel.java,v 1.9 2010/10/13 22:55:14 nifi Exp $ * $Id: NodeInfoPanel.java,v 1.10 2010/10/14 06:31:38 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 6 sep 2010 * Created : 6 sep 2010
* Updated : $Date: 2010/10/13 22:55:14 $ * Updated : $Date: 2010/10/14 06:31:38 $
* $Revision: 1.9 $ * $Revision: 1.10 $
*/ */
package se.sics.contiki.collect.gui; package se.sics.contiki.collect.gui;
@ -93,17 +93,17 @@ public class NodeInfoPanel extends JPanel implements Visualizer, Configurable {
return node; return node;
} }
}, },
new TableData("Packets", "Packets Received", Integer.class) { new TableData("Packets", "Packets Received", Number.class) {
public Object getValue(Node node) { public Object getValue(Node node) {
return node.getSensorDataAggregator().getPacketCount(); return node.getSensorDataAggregator().getPacketCount();
} }
}, },
new TableData("Duplicates", "Duplicate Packets Received", Integer.class) { new TableData("Duplicates", "Duplicate Packets Received", Number.class) {
public Object getValue(Node node) { public Object getValue(Node node) {
return node.getSensorDataAggregator().getDuplicateCount(); return node.getSensorDataAggregator().getDuplicateCount();
} }
}, },
new TableData("Estimated Lost", "Estimated Lost Packets", Integer.class) { new TableData("Estimated Lost", "Estimated Lost Packets", Number.class) {
public Object getValue(Node node) { public Object getValue(Node node) {
return node.getSensorDataAggregator().getEstimatedLostCount(); return node.getSensorDataAggregator().getEstimatedLostCount();
} }
@ -123,13 +123,13 @@ public class NodeInfoPanel extends JPanel implements Visualizer, Configurable {
return node.getSensorDataAggregator().getAverageValue(SensorData.BEST_NEIGHBOR_ETX); return node.getSensorDataAggregator().getAverageValue(SensorData.BEST_NEIGHBOR_ETX);
} }
}, },
new TableData("Next Hop Changes", "Next Hop Change Count", Integer.class) { new TableData("Next Hop Changes", "Next Hop Change Count", Number.class) {
public Object getValue(Node node) { public Object getValue(Node node) {
return node.getSensorDataAggregator().getNextHopChangeCount(); return node.getSensorDataAggregator().getNextHopChangeCount();
} }
}, },
new TableData("Restarts", "Estimated Node Restart Count", Integer.class) { new TableData("Restarts", "Estimated Node Restart Count", Number.class) {
public Object getValue(Node node) { public Object getValue(Node node) {
return node.getSensorDataAggregator().getEstimatedRestarts(); return node.getSensorDataAggregator().getEstimatedRestarts();
} }
@ -256,15 +256,35 @@ public class NodeInfoPanel extends JPanel implements Visualizer, Configurable {
public void setValue(Object value) { public void setValue(Object value) {
if (value == null) { if (value == null) {
setText(null); setText(null);
} else {
double v = ((Number) value).doubleValue() + 0.0005;
int dec = ((int)(v * 1000)) % 1000;
setText((long)v + "." + (dec > 99 ? "" : "0") + (dec > 9 ? "" : "0") + dec);
} }
double v = ((Number) value).doubleValue() + 0.0005;
int dec = ((int)(v * 1000)) % 1000;
setText((long)v + "." + (dec > 99 ? "" : "0") + (dec > 9 ? "" : "0") + dec);
} }
}; };
renderer.setHorizontalAlignment(JLabel.RIGHT); renderer.setHorizontalAlignment(JLabel.RIGHT);
table.setDefaultRenderer(Double.class, renderer); table.setDefaultRenderer(Double.class, renderer);
// Add renderer for mixed integers and doubles
renderer = new DefaultTableCellRenderer() {
private static final long serialVersionUID = 1L;
public void setValue(Object value) {
if (value == null) {
setText(null);
} else if (value instanceof Integer) {
setText(value.toString());
} else {
double v = ((Number) value).doubleValue() + 0.0005;
int dec = ((int)(v * 1000)) % 1000;
setText((long)v + "." + (dec > 99 ? "" : "0") + (dec > 9 ? "" : "0") + dec);
}
}
};
renderer.setHorizontalAlignment(JLabel.RIGHT);
table.setDefaultRenderer(Number.class, renderer);
table.setFillsViewportHeight(true); table.setFillsViewportHeight(true);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
for (int i = 0, n = table.getColumnCount(); i < n; i++) { for (int i = 0, n = table.getColumnCount(); i < n; i++) {
@ -549,7 +569,8 @@ public class NodeInfoPanel extends JPanel implements Visualizer, Configurable {
return tmp; return tmp;
} }
if (dataClass == Integer.class || dataClass == Long.class || dataClass == Double.class) { if (dataClass == Long.class || dataClass == Double.class
|| dataClass == Number.class) {
double average = 0.0; double average = 0.0;
if (nodes != null && nodes.length > 0) { if (nodes != null && nodes.length > 0) {
int count = 0; int count = 0;
@ -563,9 +584,7 @@ public class NodeInfoPanel extends JPanel implements Visualizer, Configurable {
average = average / count; average = average / count;
} }
} }
if (dataClass == Integer.class) { if (dataClass == Long.class) {
tmp = (int) (average + 0.5);
} else if (dataClass == Long.class) {
tmp = (long) (average + 0.5); tmp = (long) (average + 0.5);
} else { } else {
tmp = average; tmp = average;