From: Sylvain Papa Date: Fri, 18 Jan 2019 10:20:31 +0000 (+0100) Subject: Country + Origin + RegionView modify X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=d8b03ca81cef363ec5f57e0dbe46d0b47023314d;p=Persons_Comparator.git Country + Origin + RegionView modify --- diff --git a/src/Country.java b/src/Country.java index c663ff0..cb67273 100644 --- a/src/Country.java +++ b/src/Country.java @@ -30,10 +30,18 @@ public class Country { this.lat = lat; } + public double getLat() { + return lat; + } + public void setLng(double lng) { this.lng = lng; } + public double getLng() { + return lng; + } + public int distanceTo(Country country) { if ((this.lat == country.lat) && (this.lng == country.lng)) { return 0; diff --git a/src/Origin.java b/src/Origin.java index 41b5b36..7ea4e53 100644 --- a/src/Origin.java +++ b/src/Origin.java @@ -64,6 +64,8 @@ public class Origin { } public int distanceTo(Origin origin) { + + return 0; } } diff --git a/src/RegionView.java b/src/RegionView.java index 7e5c69f..3c79ea6 100644 --- a/src/RegionView.java +++ b/src/RegionView.java @@ -49,8 +49,37 @@ public class RegionView extends JPanel { } } } + sortTree(top); tree = new JTree(top); - add(tree); + add(new JScrollPane(tree)); + } + + public static DefaultMutableTreeNode sortTree(DefaultMutableTreeNode root) { + { + for (int i = 0; i < root.getChildCount() - 1; i++) { + DefaultMutableTreeNode node = (DefaultMutableTreeNode) root + .getChildAt(i); + String nt = node.getUserObject().toString(); + + for (int j = i + 1; j <= root.getChildCount() - 1; j++) { + DefaultMutableTreeNode prevNode = (DefaultMutableTreeNode) root + .getChildAt(j); + String np = prevNode.getUserObject().toString(); + + System.out.println(nt + " " + np); + if (nt.compareToIgnoreCase(np) > 0) { + + root.insert(node, j); + break; + } + } + if (node.getChildCount() > 0) { + node = sortTree(node); + } + } + + return root; + } } public void setRegionObj(Region regionObj) {