chiark / gitweb /
when looking for the league tracker, cope if it isn't exactly where we expected;...
[jarrg-ian.git] / src / net / chiark / yarrg / MarketUploader.java
index 4a6a0e5cd4f0eec9810a888194e8482721449ff6..2e83678314e59cd04b66ea00bb97f70f1c2f207d 100644 (file)
@@ -260,7 +260,7 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
                    }
                }
 
-               if (prefs.getBoolean("useLiveServers", false)) {
+               if (prefs.getBoolean("useLiveServers", true)) {
                        YARRG_URL = YARRG_LIVE_URL;
                        PCTB_HOST_URL = PCTB_LIVE_HOST_URL;
                } else {
@@ -346,7 +346,10 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
                // If the league tracker is there, we can skip the faff
                // and ask for its tooltip, since we're on a boat
 
-               Accessible leagueTracker = descendNodes(window,new int[] {0,1,0,0,2,1,1,1});
+               Accessible leagueTrackerContainer = descendNodes(window,new int[] {0,1,0,0,2,1});
+               Accessible leagueTrackerItself = descendByClass(leagueTrackerContainer,
+                                                               "com.threerings.yohoho.sea.client.LeagueTracker");
+               Accessible leagueTracker = descend(leagueTrackerItself, 1);
                try {
                        islandName = ((JLabel)leagueTracker).getToolTipText();
                } catch (NullPointerException e) {
@@ -669,7 +672,6 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
        private Accessible descendNodes(Accessible parent, int[] path) {
                for(int i=0;i<path.length;i++) {
                        if (null == (parent = descend(parent, path[i]))) return null;
-                       // if (dtxt!=null) dtxt.println(parent.getClass());
                }
                return parent;
        }
@@ -683,10 +685,39 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
        *       if the child is not found.
        */
        private Accessible descend(Accessible parent, int childNum) {
-               if (childNum >= parent.getAccessibleContext().getAccessibleChildrenCount()) return null;
-               return parent.getAccessibleContext().getAccessibleChild(childNum);
+               if (parent == null) return null;
+               int children = parent.getAccessibleContext().getAccessibleChildrenCount();
+               if (childNum >= children) {
+                   if (dtxt!=null) dtxt.println("DESCEND "+childNum+" > "+children+" NOT FOUND");
+                   return null;
+               }
+               Accessible child = parent.getAccessibleContext().getAccessibleChild(childNum);
+               if (dtxt!=null) dtxt.println("DESCEND "+childNum+" "+child.getClass().getName()+" OK");
+               return child;
        }
-       
+
+       /**
+       *       Descends one level to the child which has the specified class.
+       *       
+       *       @param parent the node with children
+       *       @param classname the name of the class, as a string
+       *       @return the child or <code>null</code> if the child is not found.
+       */
+       private Accessible descendByClass(Accessible parent, String classname) {
+               if (parent == null) return null;
+               AccessibleContext ac = parent.getAccessibleContext();
+               int children = ac.getAccessibleChildrenCount();
+               for (int i=0; i<children; i++) {
+                       Accessible child = ac.getAccessibleChild(i);
+                       if (child.getClass().getName() == classname) {
+                           if (dtxt!=null) dtxt.println("DESCEND CLASS "+classname+" OK");
+                           return child;
+                       }
+               }
+               if (dtxt!=null) dtxt.println("DESCEND CLASS "+classname+" NOT FOUND");
+               return null;
+       }
+
        public static void main(String[] args) {
                new MarketUploader();
        }