+ progressNote("PCTB: Waiting ...");
+ debuglog("pctb finish...");
+ donepctb = finishUpload(in);
+ debuglog("pctb done.");
+ }
+ setProgress(99);
+
+ String summary;
+ if ((uploadToPCTB && !donepctb) ||
+ (uploadToYarrg && !doneyarrg)) {
+ summary= "trouble";
+ } else if (unknownPCTBcommods != 0) {
+ summary= "PCTB lacks "+unknownPCTBcommods+" commod(s)";
+ } else if (donepctb || doneyarrg) {
+ summary= "Done " + islandName;
+ } else {
+ summary= "uploaded nowhere!";
+ }
+ final String summary_final = summary;
+ new UIX() { public void body() {
+ resultSummary.setText(summary_final);
+ }}.exec("resultSummary.setText");
+
+ debuglog("done.");
+ }
+
+ /*
+ * UPLOAD HELPER FUNCTIONS FOR EXTRACTING SPECIFIC UI DATA
+ */
+
+ private ArrayList<ArrayList<String>> getData(AccessibleTable table) {
+ // Gets the offer data out of the table and returns it as an ArrayList
+
+ on_ui_thread();
+ ArrayList<ArrayList<String>> data = new ArrayList<ArrayList<String>>();
+ for (int i = 0; i < table.getAccessibleRowCount(); i++) {
+ ArrayList<String> row = new ArrayList<String>();
+ for (int j = 0; j < table.getAccessibleColumnCount(); j++) {
+ row.add(table.getAccessibleAt(i, j)
+ .getAccessibleContext().getAccessibleName());
+ }
+ data.add(row);
+ }
+ return data;
+ }
+
+ public AccessibleTable findMarketTable() {
+ // Return the table containing market data if it exists, otherwise null.
+ on_ui_thread();
+
+ Accessible node1 = window;
+ Accessible node = descendNodes(node1,new int[] {0,1,0,0,0,0,1,0,0,1,0,0});
+ // commod market
+ // commod market: {0,1,0,0,0,0,1,0,0,1,0} {0,1,0,0,0,0,1,0,1,0,0,1,0,0})
+ // debuglog(node);
+ if (!(node instanceof JTable)) {
+ node = descendNodes(node1,new int[] {0,1,0,0,0,0,1,0,1,0,0,1,0,0});
+ // commod market
+ }
+ if (!(node instanceof JTable)) return null;
+ AccessibleTable table = node.getAccessibleContext().getAccessibleTable();
+ // debuglog(table);
+ return table;
+ }
+
+ private boolean isDisplayAll() {
+ // Returns true iff the "Display:" menu on the commodities
+ // interface in YPP is set to "All"
+ on_ui_thread();
+
+ Accessible button = descendNodes(window,new int[] {0,1,0,0,0,0,1,0,0,0,1});
+ if(!(button instanceof JButton)) {
+ button = descendNodes(window,new int[] {0,1,0,0,0,0,1,0,1,0,0,0,1});
+ }
+ String display = button.getAccessibleContext().getAccessibleName();
+ if(!display.equals("All")) {
+ return false;
+ }
+ return true;
+ }
+
+ /*
+ * FUNCTIONS AND CALLBACKS FOR FINDING ISLAND AND OCEAN
+ */
+
+ private void getOcean() {
+ // Finds the ocean name from the window title.
+ // Stores it in the global oceanName
+ on_ui_thread();
+
+ oceanName = null;
+ AccessibleContext topwindow = window.getAccessibleContext();
+ oceanName = topwindow.getAccessibleName()
+ .replaceAll(".*on the (\\w+) ocean", "$1");
+ }
+
+ private void getIsland() {
+ // Tries to find the island name. Either:
+ // (a) sets the islandName global
+ // or
+ // (b) sets latch to a new CountDownLatch, and arranges that
+ // at some point later, islandName will be set and the latch
+ // decremented to zero
+ on_ui_thread();
+
+ // If the league tracker is there, we can skip the faff
+ // and ask for its tooltip, since we're on a boat
+
+ 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();
+ latch = null;
+ } catch (NullPointerException e) {
+ // evidently we're actually on an island
+
+ islandName = null;
+ AccessibleContext chatArea =
+ descendNodes(window,new int[] {0,1,0,0,0,2,0,0,2})
+ .getAccessibleContext();
+ // attach the property change listener to the outer sunshine
+ // panel if the "ahoy" tab is not active, otherwise attach it to
+ // the scroll panel in the "ahoy" tab.
+ if(!"com.threerings.piracy.client.AttentionListPanel".
+ equals(descendNodes(window,new int[] {0,1,0,0,2,2,0})
+ .getClass().getCanonicalName())) {
+ sidePanel = descendNodes(window,new int[] {0,1,0,0,2,2})
+ .getAccessibleContext();
+ } else {
+ sidePanel = descendNodes(window,new int[] {0,1,0,0,2,2,0,0,0})
+ .getAccessibleContext();
+ }
+ sidePanel.addPropertyChangeListener(changeListener);
+ latch = new java.util.concurrent.CountDownLatch(1);
+ // make the Players Online ("/who") panel appear
+ AccessibleEditableText chat = chatArea.getAccessibleEditableText();
+ chat.setTextContents("/w");
+ int c = chatArea.getAccessibleAction().getAccessibleActionCount();
+ for(int i=0;i<c;i++) {
+ if("notify-field-accept".equals(chatArea.getAccessibleAction()
+ .getAccessibleActionDescription(i))) {
+ chatArea.getAccessibleAction().doAccessibleAction(i);
+ }
+ }