apply version 2.7 copyright
[jalview.git] / src / jalview / gui / DasSourceBrowser.java
index e336d9a..c623530 100755 (executable)
@@ -1,20 +1,19 @@
 /*\r
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)\r
- * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)\r
+ * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle\r
  * \r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
+ * This file is part of Jalview.\r
  * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
+ * Jalview is free software: you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License \r
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\r
  * \r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+ * Jalview is distributed in the hope that it will be useful, but \r
+ * WITHOUT ANY WARRANTY; without even the implied warranty \r
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
+ * PURPOSE.  See the GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.\r
  */\r
 package jalview.gui;\r
 \r
@@ -53,14 +52,16 @@ 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,\r
+              DEFAULT_REGISTRY);\r
       registry = DEFAULT_REGISTRY;\r
     }\r
     return registry;\r
   }\r
 \r
-  public DasSourceBrowser()\r
+  public DasSourceBrowser(FeatureSettings featureSettings)\r
   {\r
+    fs = featureSettings;\r
     String registry = getDasRegistryURL();\r
 \r
     registryURL.setText(registry);\r
@@ -107,6 +108,13 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
     }\r
   }\r
 \r
+  FeatureSettings fs = null;\r
+\r
+  public DasSourceBrowser()\r
+  {\r
+    this(null);\r
+  }\r
+\r
   public void paintComponent(java.awt.Graphics g)\r
   {\r
     if (dasSources == null && !loadingDasSources)\r
@@ -183,11 +191,10 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
       text.append("<font color=\"#0000FF\">URL:</font> "\r
               + dasSources[i].getUrl() + "<br>");\r
 \r
-      text\r
-              .append("<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"\r
-                      + dasSources[i].getAdminemail()\r
-                      + "\">"\r
-                      + dasSources[i].getAdminemail() + "</a>" + "<br>");\r
+      text.append("<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"\r
+              + dasSources[i].getAdminemail()\r
+              + "\">"\r
+              + dasSources[i].getAdminemail() + "</a>" + "<br>");\r
 \r
       text.append("<font color=\"#0000FF\">Registered at:</font> "\r
               + dasSources[i].getRegisterDate() + "<br>");\r
@@ -271,18 +278,56 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
     refresh.setVisible(false);\r
     progressBar.setVisible(true);\r
     progressBar.setIndeterminate(true);\r
+    setParentGuiEnabled(false);\r
     // Refresh the source list.\r
     dasSources = null;\r
     getDASSource();\r
 \r
     init();\r
 \r
+    setParentGuiEnabled(true);\r
     loadingDasSources = false;\r
 \r
   }\r
 \r
+  private void setParentGuiEnabled(boolean b)\r
+  {\r
+    if (fs != null)\r
+    {\r
+      fs.fetchDAS.setEnabled(b);\r
+      fs.saveDAS.setEnabled(b);\r
+    }\r
+  }\r
+\r
   public Vector getSelectedSources()\r
   {\r
+    // wait around if we're still loading.\r
+    while (dasSources == null)\r
+    {\r
+      if (!loadingDasSources)\r
+      {\r
+        new Thread(this).start();\r
+        try\r
+        {\r
+          Thread.sleep(5);\r
+        } catch (Exception e)\r
+        {\r
+        }\r
+        ;\r
+        while (loadingDasSources)\r
+        {\r
+          try\r
+          {\r
+            Thread.sleep(5);\r
+          } catch (Exception e)\r
+          {\r
+          }\r
+          ;\r
+        }\r
+        ;\r
+      }\r
+    }\r
+\r
     Vector selected = new Vector();\r
     for (int r = 0; r < selectedSources.size(); r++)\r
     {\r
@@ -382,24 +427,28 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
   public void amendLocal(boolean newSource)\r
   {\r
     String url = "http://localhost:8080/", nickname = "";\r
-\r
+    boolean seqsrc = false;\r
     if (!newSource)\r
     {\r
       int selectedRow = table.getSelectionModel().getMinSelectionIndex();\r
       nickname = table.getValueAt(selectedRow, 0).toString();\r
       url = ((DasSource) localSources.get(nickname)).getUrl();\r
+      seqsrc = ((DasSource) localSources.get(nickname))\r
+              .hasCapability("sequence");\r
     }\r
 \r
     JTextField nametf = new JTextField(nickname, 40);\r
     JTextField urltf = new JTextField(url, 40);\r
-\r
+    JCheckBox seqs = new JCheckBox("Sequence Source");\r
+    seqs.setSelected(seqsrc);\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
@@ -421,7 +470,11 @@ 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[]\r
+      { "features", "sequence" });\r
+    }\r
     if (localSources == null)\r
     {\r
       localSources = new Hashtable();\r
@@ -535,8 +588,8 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
         {\r
           tmp[index] = dasSources[i];\r
           data[index][0] = dasSources[i].getNickname();\r
-          data[index][1] = new Boolean(selectedSources\r
-                  .contains(dasSources[i].getNickname()));\r
+          data[index][1] = new Boolean(\r
+                  selectedSources.contains(dasSources[i].getNickname()));\r
           index++;\r
         }\r
       }\r
@@ -561,7 +614,8 @@ 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\r
+    // standard fetchDbRefs function\r
     int size = dasSources != null ? dasSources.length : 0;\r
     int lsize = localSources.size();\r
 \r
@@ -635,14 +689,13 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
         // HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT\r
         // IS ADDED FROM THE REGISTRY\r
         names.add(ds.getNickname());\r
-        selected\r
-                .add(new Boolean(selectedSources.contains(ds.getNickname())));\r
+        selected.add(new Boolean(selectedSources.contains(ds.getNickname())));\r
         continue;\r
       }\r
 \r
       if (!selectedInList(dummyFeatureList, ds.getCapabilities())\r
-              || !selectedInList(filter3.getSelectedValues(), ds\r
-                      .getLabels()))\r
+              || !selectedInList(filter3.getSelectedValues(),\r
+                      ds.getLabels()))\r
       {\r
         continue;\r
       }\r
@@ -705,24 +758,17 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
       selectedSources.addElement(st.nextToken());\r
     }\r
 \r
-    String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");\r
-    if (local != null)\r
+    Vector _localSources = jalview.bin.Cache.getLocalDasSources();\r
+    if (_localSources != null)\r
     {\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 +779,21 @@ 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
+   * \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,\r
+              registryURL.getText());\r
     }\r
 \r
     StringBuffer sb = new StringBuffer();\r
@@ -753,7 +805,8 @@ 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,\r
+            sb.toString());\r
 \r
     if (localSources != null)\r
     {\r
@@ -762,11 +815,15 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
       while (en.hasMoreElements())\r
       {\r
         String token = en.nextElement().toString();\r
-        sb.append(token + "|"\r
+        sb.append(token\r
+                + "|"\r
+                + (((DasSource) localSources.get(token))\r
+                        .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,\r
+              sb.toString());\r
     }\r
 \r
   }\r
@@ -847,4 +904,59 @@ 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 || 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
+  /**\r
+   * disable or enable the buttons on the source browser\r
+   * \r
+   * @param b\r
+   */\r
+  public void setGuiEnabled(boolean b)\r
+  {\r
+    refresh.setEnabled(b);\r
+    addLocal.setEnabled(b);\r
+  }\r
 }\r