From 120727a429d0c0e0c87cfc9d200515190bd8e736 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Mon, 10 Mar 2008 13:23:45 +0100 Subject: [PATCH] Sort mote views numerically when ordered by TOS --- src/remote/gui/RenderableTreeNode.java | 21 ++++++++++++++++++--- .../gui/treeorderings/OrderingsAllMotesView.java | 14 ++++++++------ .../treeorderings/OrderingsControlledMotesView.java | 14 ++++++++------ 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/remote/gui/RenderableTreeNode.java b/src/remote/gui/RenderableTreeNode.java index c095bac..21996fe 100644 --- a/src/remote/gui/RenderableTreeNode.java +++ b/src/remote/gui/RenderableTreeNode.java @@ -2,17 +2,32 @@ package remote.gui; import java.awt.Component; -public abstract class RenderableTreeNode implements Comparable{ +public abstract class RenderableTreeNode implements Comparable +{ private Comparable compareKey; + private boolean numeric; + private int intValue; - protected RenderableTreeNode(Comparable compareKey) { + protected RenderableTreeNode(Comparable compareKey, boolean numeric) + { super(); this.compareKey = compareKey; + if (numeric && compareKey instanceof String) { + this.intValue = Integer.parseInt((String) compareKey); + this.numeric = numeric; + } } - public int compareTo(Object arg0) { + public int compareTo(Object arg0) + { + if (!(arg0 instanceof RenderableTreeNode)) + return 0; + RenderableTreeNode o = (RenderableTreeNode)arg0; + if (this.numeric == true && o.numeric == true) + return this.intValue - o.intValue; + return this.compareKey.compareTo(o.compareKey); } diff --git a/src/remote/gui/treeorderings/OrderingsAllMotesView.java b/src/remote/gui/treeorderings/OrderingsAllMotesView.java index af0c15d..b1596c7 100644 --- a/src/remote/gui/treeorderings/OrderingsAllMotesView.java +++ b/src/remote/gui/treeorderings/OrderingsAllMotesView.java @@ -20,8 +20,8 @@ public class OrderingsAllMotesView { private static class MoteNodeRenderer extends RenderableTreeNode { JPanel mote = new JPanel(); - protected MoteNodeRenderer(Comparable key, TableRow row) { - super(key); + protected MoteNodeRenderer(Comparable key, TableRow row, boolean numeric) { + super(key, numeric); mote.setBackground(new Color(0, true)); ImageIcon moteicon = IconResources.MOTE; ImageIcon usageicon = null; @@ -75,13 +75,15 @@ public class OrderingsAllMotesView { } private static class RenderableOrdering extends SimpleTableRowOrdering { + boolean numeric; - public RenderableOrdering(String key, String name, boolean total) { + public RenderableOrdering(String key, String name, boolean total, boolean numeric) { super(key, name, total); + this.numeric = numeric; } public Comparable getKey(TableRow row) { - return new MoteNodeRenderer(super.getKey(row), row); + return new MoteNodeRenderer(super.getKey(row), row, numeric); } }; @@ -95,10 +97,10 @@ public class OrderingsAllMotesView { = new SimpleTableRowOrdering("room", "room", false);**/ public static TableRowOrdering BY_TOS - = new RenderableOrdering("tosaddress","TOS",true); + = new RenderableOrdering("tosaddress", "TOS", true, true); public static TableRowOrdering BY_MAC - = new RenderableOrdering("macaddress","MAC",true); + = new RenderableOrdering("macaddress", "MAC", true, true); /**public static TableRowOrdering BY_MOTE_ID = new RenderableOrdering("mote_id","mote_id",true);**/ diff --git a/src/remote/gui/treeorderings/OrderingsControlledMotesView.java b/src/remote/gui/treeorderings/OrderingsControlledMotesView.java index 300d8a0..a7941dd 100644 --- a/src/remote/gui/treeorderings/OrderingsControlledMotesView.java +++ b/src/remote/gui/treeorderings/OrderingsControlledMotesView.java @@ -29,8 +29,8 @@ public class OrderingsControlledMotesView { private MoteControlRow row = null; - public MoteControlNodeRenderer(Comparable key, MoteControlRow row) { - super(key); + public MoteControlNodeRenderer(Comparable key, MoteControlRow row, boolean numeric) { + super(key, numeric); this.row = row; panel.setBackground(new Color(0, true)); @@ -123,22 +123,24 @@ public class OrderingsControlledMotesView { }; private static class RenderableOrdering extends SimpleTableRowOrdering { + boolean numeric; - public RenderableOrdering(String key, String name, boolean total) + public RenderableOrdering(String key, String name, boolean total, boolean numeric) { super(key,name,total); + this.numeric = numeric; } public Comparable getKey(TableRow row) { - return new MoteControlNodeRenderer(super.getKey(row),(MoteControlRow)row); + return new MoteControlNodeRenderer(super.getKey(row), (MoteControlRow) row, numeric); } }; public static TableRowOrdering BY_STATUS = new SimpleTableRowOrdering("status","status",false); - public static TableRowOrdering BY_MAC = new RenderableOrdering("macaddress", "MAC",true); + public static TableRowOrdering BY_MAC = new RenderableOrdering("macaddress", "MAC", true, false); - public static TableRowOrdering BY_TOS = new RenderableOrdering("tosaddress", "TOS",true); + public static TableRowOrdering BY_TOS = new RenderableOrdering("tosaddress", "TOS", true, true); public static TableRowOrdering[] orderings = { BY_TOS, BY_MAC,BY_STATUS }; -- 2.11.4.GIT