das source browser uses local source method from jalview.bin.Cache and methods refact...
authorjprocter <Jim Procter>
Thu, 4 Dec 2008 10:25:43 +0000 (10:25 +0000)
committerjprocter <Jim Procter>
Thu, 4 Dec 2008 10:25:43 +0000 (10:25 +0000)
src/jalview/gui/DasSourceBrowser.java
src/jalview/gui/FeatureSettings.java

index e336d9a..7237329 100755 (executable)
@@ -53,7 +53,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
 \r
     if (registry.indexOf("/registry/das1/sources/") > -1)\r
     {\r
-      jalview.bin.Cache.setProperty("DAS_REGISTRY_URL", DEFAULT_REGISTRY);\r
+      jalview.bin.Cache.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL, DEFAULT_REGISTRY);\r
       registry = DEFAULT_REGISTRY;\r
     }\r
     return registry;\r
@@ -283,6 +283,19 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
 \r
   public Vector getSelectedSources()\r
   {\r
+    // wait around if we're still loading.\r
+    while (dasSources ==null) {\r
+      if (!loadingDasSources)\r
+      {\r
+        new Thread(this).start();\r
+        try { Thread.sleep(5); } catch (Exception e) {};\r
+        while (loadingDasSources)\r
+        {\r
+          try { Thread.sleep(5); } catch (Exception e) {}; \r
+        };\r
+      }\r
+    }\r
+      \r
     Vector selected = new Vector();\r
     for (int r = 0; r < selectedSources.size(); r++)\r
     {\r
@@ -392,17 +405,19 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
 \r
     JTextField nametf = new JTextField(nickname, 40);\r
     JTextField urltf = new JTextField(url, 40);\r
-\r
+    JCheckBox seqs = new JCheckBox("Sequence Source");\r
+    \r
     JPanel panel = new JPanel(new BorderLayout());\r
     JPanel pane12 = new JPanel(new BorderLayout());\r
     pane12.add(new JLabel("Nickname: "), BorderLayout.CENTER);\r
     pane12.add(nametf, BorderLayout.EAST);\r
     panel.add(pane12, BorderLayout.NORTH);\r
     pane12 = new JPanel(new BorderLayout());\r
-    pane12.add(new JLabel("URL: "), BorderLayout.CENTER);\r
+    pane12.add(new JLabel("URL: "), BorderLayout.NORTH);\r
+    pane12.add(seqs, BorderLayout.SOUTH);\r
     pane12.add(urltf, BorderLayout.EAST);\r
     panel.add(pane12, BorderLayout.SOUTH);\r
-\r
+    \r
     int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,\r
             panel, "Enter Nickname & URL of Local DAS Source",\r
             JOptionPane.OK_CANCEL_OPTION);\r
@@ -421,7 +436,10 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
 \r
     local.setUrl(urltf.getText());\r
     local.setNickname(nametf.getText());\r
-\r
+    if (seqs.isSelected())\r
+    {\r
+      local.setCapabilities(new String[] {"sequence"});\r
+    }\r
     if (localSources == null)\r
     {\r
       localSources = new Hashtable();\r
@@ -561,7 +579,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
     {\r
       return;\r
     }\r
-\r
+    // note - we add all das sources to list so they can be filtered for the standard fetchDbRefs function\r
     int size = dasSources != null ? dasSources.length : 0;\r
     int lsize = localSources.size();\r
 \r
@@ -704,25 +722,18 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
     {\r
       selectedSources.addElement(st.nextToken());\r
     }\r
-\r
-    String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");\r
-    if (local != null)\r
+    \r
+    Vector _localSources = jalview.bin.Cache.getLocalDasSources();\r
+    if (_localSources!=null)\r
     {\r
-      if (localSources == null)\r
+      if (localSources==null)\r
       {\r
         localSources = new Hashtable();\r
       }\r
-\r
-      st = new StringTokenizer(local, "\t");\r
-      while (st.hasMoreTokens())\r
+      Enumeration sources = _localSources.elements();\r
+      while (sources.hasMoreElements())\r
       {\r
-        String token = st.nextToken();\r
-        int bar = token.indexOf("|");\r
-        Das1Source source = new Das1Source();\r
-\r
-        source.setUrl(token.substring(bar + 1));\r
-        source.setNickname(token.substring(0, bar));\r
-\r
+        Das1Source source = (Das1Source) sources.nextElement();\r
         localSources.put(source.getNickname(), source);\r
       }\r
     }\r
@@ -733,15 +744,19 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
     registryURL.setText(DEFAULT_REGISTRY);\r
   }\r
 \r
+  /**\r
+   * set the DAS source settings in the given jalview properties.\r
+   * @param properties\r
+   */\r
   public void saveProperties(Properties properties)\r
   {\r
     if (registryURL.getText() == null || registryURL.getText().length() < 1)\r
     {\r
-      properties.remove("DAS_REGISTRY_URL");\r
+      properties.remove(jalview.bin.Cache.DAS_REGISTRY_URL);\r
     }\r
     else\r
     {\r
-      properties.setProperty("DAS_REGISTRY_URL", registryURL.getText());\r
+      properties.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL, registryURL.getText());\r
     }\r
 \r
     StringBuffer sb = new StringBuffer();\r
@@ -753,7 +768,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
       }\r
     }\r
 \r
-    properties.setProperty("DAS_ACTIVE_SOURCE", sb.toString());\r
+    properties.setProperty(jalview.bin.Cache.DAS_ACTIVE_SOURCE, sb.toString());\r
 \r
     if (localSources != null)\r
     {\r
@@ -763,10 +778,11 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
       {\r
         String token = en.nextElement().toString();\r
         sb.append(token + "|"\r
+                +(((DasSource) localSources.get(token)).hasCapability("sequence") ? "sequence:" : "")\r
                 + ((DasSource) localSources.get(token)).getUrl() + "\t");\r
       }\r
 \r
-      properties.setProperty("DAS_LOCAL_SOURCE", sb.toString());\r
+      properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE, sb.toString());\r
     }\r
 \r
   }\r
@@ -847,4 +863,49 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
       }\r
     }\r
   }\r
+\r
+  public void initDasSources()\r
+  {\r
+\r
+    Thread thr = new Thread(new Runnable()\r
+    {\r
+      public void run()\r
+      {\r
+        // this actually initialises the das source list\r
+        paintComponent(null); // yuk\r
+      }\r
+    });\r
+    thr.start();\r
+    while (loadingDasSources\r
+            || dasSources == null)\r
+    {\r
+      try\r
+      {\r
+        Thread.sleep(10);\r
+      } catch (Exception e)\r
+      {\r
+      }\r
+      ;\r
+    }\r
+  }\r
+\r
+  public Vector resolveSourceNicknames(Vector sources)\r
+  {\r
+\r
+    Vector resolved = new Vector();\r
+    if (sources != null)\r
+    {\r
+      for (int i = 0; i < dasSources.length; i++)\r
+      {\r
+        if (sources.contains(dasSources[i].getNickname()))\r
+        {\r
+          if (!resolved.contains(dasSources[i]))\r
+          {\r
+            resolved.addElement(dasSources[i]);\r
+          }\r
+        }\r
+      }\r
+    }\r
+    return resolved;\r
+  }\r
 }\r
index 632ad00..255340e 100755 (executable)
@@ -850,6 +850,30 @@ public class FeatureSettings extends JPanel
   }
 
   /**
+   * blocking call to initialise the das source browser
+   */
+  public void initDasSources()
+  {
+    dassourceBrowser.initDasSources();
+  }
+  /**
+   * examine the current list of das sources and return any matching the given nicknames in sources 
+   * @param sources Vector of Strings to resolve to DAS source nicknames.
+   * @return sources that are present in source list.
+   */
+  public Vector resolveSourceNicknames(Vector sources)
+  {
+    return dassourceBrowser.resolveSourceNicknames(sources);
+  }
+  /**
+   * get currently selected das sources. ensure you have called initDasSources before calling this.
+   * @return vector of selected das source nicknames
+   */
+  public Vector getSelectedSources()
+  {
+    return dassourceBrowser.getSelectedSources();
+  }
+  /**
    * properly initialise DAS fetcher and then initiate a new thread to fetch
    * features from the named sources (rather than any turned on by default)
    * 
@@ -857,40 +881,8 @@ public class FeatureSettings extends JPanel
    */
   public void fetchDasFeatures(Vector sources)
   {
-    Thread thr = new Thread(new Runnable()
-    {
-      public void run()
-      {
-        // this actually initialises the das source list
-        dassourceBrowser.paintComponent(null); // yuk
-      }
-    });
-    thr.start();
-    while (dassourceBrowser.loadingDasSources
-            || dassourceBrowser.dasSources == null)
-    {
-      try
-      {
-        Thread.sleep(10);
-      } catch (Exception e)
-      {
-      }
-      ;
-    }
-    Vector resolved = new Vector();
-    if (sources != null)
-    {
-      for (int i = 0; i < dassourceBrowser.dasSources.length; i++)
-      {
-        if (sources.contains(dassourceBrowser.dasSources[i].getNickname()))
-        {
-          if (!resolved.contains(dassourceBrowser.dasSources[i]))
-          {
-            resolved.addElement(dassourceBrowser.dasSources[i]);
-          }
-        }
-      }
-    }
+    initDasSources();
+    Vector resolved = resolveSourceNicknames(sources);
     if (resolved.size() == 0)
     {
       resolved = dassourceBrowser.getSelectedSources();