boolean for internal copies
[jalview.git] / src / jalview / gui / DasSourceBrowser.java
index 0f4cf5f..58580eb 100755 (executable)
@@ -1,6 +1,6 @@
 /*\r
  * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Copyright (C) 2006 AM Waterhouse, J Procter, 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
@@ -41,19 +41,32 @@ public class DasSourceBrowser extends GDasSourceBrowser
 \r
   Vector selectedSources;\r
 \r
+  public static String DEFAULT_REGISTRY = "http://www.dasregistry.org/das1/sources/";\r
+\r
+  boolean loadingDasSources = false;\r
+\r
+\r
   public DasSourceBrowser()\r
   {\r
-    registryURL.setText(jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",\r
-        "http://www.spice-3d.org/dasregistry/das1/sources") );\r
+    String registry = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",\r
+        DEFAULT_REGISTRY);\r
+\r
+    if(registry.indexOf("/registry/das1/sources/")>-1)\r
+    {\r
+      jalview.bin.Cache.setProperty("DAS_REGISTRY_URL", DEFAULT_REGISTRY);\r
+      registry = DEFAULT_REGISTRY;\r
+    }\r
+\r
+    registryURL.setText( registry );\r
 \r
     setSelectedFromProperties();\r
 \r
     displayFullDetails(null);\r
     table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r
 \r
-    capabilities.addListSelectionListener(this);\r
-    coords1.addListSelectionListener(this);\r
-    coords2.addListSelectionListener(this);\r
+    filter1.addListSelectionListener(this);\r
+    filter2.addListSelectionListener(this);\r
+    filter3.addListSelectionListener(this);\r
 \r
     //Ask to be notified of selection changes.\r
     ListSelectionModel rowSM = table.getSelectionModel();\r
@@ -61,10 +74,6 @@ public class DasSourceBrowser extends GDasSourceBrowser
     {\r
       public void valueChanged(ListSelectionEvent e)\r
       {\r
-        //Ignore extra messages.\r
-        if (e.getValueIsAdjusting())\r
-          return;\r
-\r
         ListSelectionModel lsm = (ListSelectionModel) e.getSource();\r
         if (!lsm.isSelectionEmpty())\r
         {\r
@@ -84,15 +93,19 @@ public class DasSourceBrowser extends GDasSourceBrowser
           }\r
         });\r
 \r
-    if(dasSources==null)\r
+    if(dasSources!=null)\r
     {\r
-    Thread worker = new Thread(this);\r
-    worker.start();\r
-    }\r
-    else\r
-     {\r
        init();\r
-     }\r
+    }\r
+  }\r
+\r
+  public void paintComponent(java.awt.Graphics g)\r
+  {\r
+    if (dasSources == null && !loadingDasSources)\r
+    {\r
+      Thread worker = new Thread(this);\r
+      worker.start();\r
+    }\r
   }\r
 \r
   void init()\r
@@ -240,6 +253,8 @@ public class DasSourceBrowser extends GDasSourceBrowser
 \r
   public void run()\r
   {\r
+    loadingDasSources = true;\r
+\r
     addLocal.setVisible(false);\r
     refresh.setVisible(false);\r
     progressBar.setVisible(true);\r
@@ -250,6 +265,28 @@ public class DasSourceBrowser extends GDasSourceBrowser
     appendLocalSources();\r
 \r
     init();\r
+\r
+    loadingDasSources = false;\r
+\r
+  }\r
+\r
+  public Vector getSelectedSources()\r
+  {\r
+    Vector selected = new Vector();\r
+    for (int r = 0; r < selectedSources.size(); r++)\r
+    {\r
+        for (int i = 0; i < dasSources.length; i++)\r
+        {\r
+          if (dasSources[i].getNickname().equals(\r
+              selectedSources.elementAt(r)))\r
+          {\r
+            selected.addElement(dasSources[i]);\r
+            break;\r
+          }\r
+        }\r
+    }\r
+\r
+    return selected;\r
   }\r
 \r
   public DasSource[] getDASSource()\r
@@ -273,49 +310,51 @@ public class DasSourceBrowser extends GDasSourceBrowser
 \r
   private void setCapabilities(DasSource[] sources)\r
   {\r
-    Vector vcapabilities = new Vector();\r
-    Vector vcoords = new Vector();\r
-    Vector vcoords2 = new Vector();\r
+    Vector authority = new Vector();\r
+    Vector type = new Vector();\r
+    Vector label = new Vector();\r
 \r
-    vcapabilities.addElement("All");\r
-    vcoords.addElement("All");\r
-    vcoords2.addElement("All");\r
+    authority.addElement("Any");\r
+    type.addElement("Any");\r
+    label.addElement("Any");\r
 \r
     for (int i = 0; i < sources.length; i++)\r
     {\r
       DasSource ds = sources[i];\r
-      String[] scap = ds.getCapabilities();\r
-      for (int s = 0; s < scap.length; s++)\r
-      {\r
-        if (!vcapabilities.contains(scap[s]))\r
-        {\r
-          vcapabilities.addElement(scap[s]);\r
-        }\r
-      }\r
 \r
       DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
 \r
       for (int j = 0; j < dcs.length; j++)\r
       {\r
-        if (!vcoords.contains(dcs[j].getCategory()))\r
-          vcoords.addElement(dcs[j].getCategory());\r
+        if (!type.contains(dcs[j].getCategory()))\r
+          type.addElement(dcs[j].getCategory());\r
 \r
-        if (!vcoords2.contains(dcs[j].getName()))\r
-          vcoords2.addElement(dcs[j].getName());\r
+        if (!authority.contains(dcs[j].getName()))\r
+          authority.addElement(dcs[j].getName());\r
       }\r
+\r
+      String[] slabels = ds.getLabels();\r
+      for (int s = 0; s < slabels.length; s++)\r
+      {\r
+        if (!label.contains(slabels[s]))\r
+        {\r
+          label.addElement(slabels[s]);\r
+        }\r
+      }\r
+\r
     }\r
 \r
-    capabilities.setListData(vcapabilities);\r
-    coords1.setListData(vcoords);\r
-    coords2.setListData(vcoords2);\r
+    filter1.setListData(authority);\r
+    filter2.setListData(type);\r
+    filter3.setListData(label);\r
 \r
     javax.swing.SwingUtilities.invokeLater(new Runnable()\r
     {\r
       public void run()\r
       {\r
-        capabilities.setSelectedIndex(0);\r
-        coords1.setSelectedIndex(0);\r
-        coords2.setSelectedIndex(0);\r
+        filter1.setSelectedIndex(0);\r
+        filter2.setSelectedIndex(0);\r
+        filter3.setSelectedIndex(0);\r
       }\r
     });\r
   }\r
@@ -527,44 +566,70 @@ public class DasSourceBrowser extends GDasSourceBrowser
         index++;\r
       }\r
 \r
-         dasSources = tmp;\r
+      dasSources = tmp;\r
 \r
-         refreshTableData(data);\r
+      refreshTableData(data);\r
   }\r
 \r
   public void valueChanged(ListSelectionEvent evt)\r
   {\r
     //Called when the MainTable selection changes\r
-    if (evt.getValueIsAdjusting())\r
+    if (evt.getValueIsAdjusting() )\r
     {\r
       return;\r
     }\r
 \r
+\r
     displayFullDetails(null);\r
 \r
     // Filter the displayed data sources\r
     int dSize = dasSources.length;\r
+\r
+\r
     ArrayList names = new ArrayList();\r
     ArrayList selected = new ArrayList();\r
     DasSource ds;\r
 \r
-    // capabilities.get\r
+    //The features filter is not visible, but we must still\r
+    //filter the das source list here.\r
+    //July 2006 - only 6 sources fo not serve features\r
+    Object [] dummyFeatureList = new Object[]{"features"};\r
+\r
     for (int i = 0; i < dSize; i++)\r
     {\r
       ds = dasSources[i];\r
+      DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
 \r
-      if (!selectedInList(capabilities, ds.getCapabilities()))\r
+      if (dcs.length == 0 && ds.getCapabilities().length == 0\r
+          && filter1.getSelectedIndex() == 0\r
+          && filter2.getSelectedIndex() == 0\r
+          && filter3.getSelectedIndex() == 0)\r
+      {\r
+        //THIS IS A FIX FOR LOCAL SOURCES WHICH DO NOT\r
+        //HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT\r
+        //IS ADDED FROM THE REGISTRY\r
+        names.add(ds.getNickname());\r
+        selected.add(new Boolean(\r
+              selectedSources.contains(ds.getNickname())));\r
+        continue;\r
+      }\r
+\r
+\r
+      if (!selectedInList(dummyFeatureList, ds.getCapabilities())\r
+      ||  !selectedInList(filter3.getSelectedValues(),\r
+                          ds.getLabels()))\r
       {\r
         continue;\r
       }\r
 \r
-      DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
       for (int j = 0; j < dcs.length; j++)\r
       {\r
-        if (selectedInList(coords1, new String[]\r
-                           {dcs[j].getCategory()})\r
-            && selectedInList(coords2, new String[]\r
-                              {dcs[j].getName()}))\r
+        if (   selectedInList(filter1.getSelectedValues(),\r
+                           new String[]\r
+                           {dcs[j].getName()})\r
+            && selectedInList(filter2.getSelectedValues(),\r
+                              new String[]\r
+                              {dcs[j].getCategory()}))\r
         {\r
           names.add(ds.getNickname());\r
           selected.add(new Boolean(\r
@@ -585,12 +650,11 @@ public class DasSourceBrowser extends GDasSourceBrowser
     refreshTableData(data);\r
   }\r
 \r
-  boolean selectedInList(JList list, String[] items)\r
+  boolean selectedInList(Object [] selection, String[] items)\r
   {\r
-    Object[] selection = list.getSelectedValues();\r
     for (int i = 0; i < selection.length; i++)\r
     {\r
-      if (selection[i].equals("All"))\r
+      if (selection[i].equals("Any") )\r
         return true;\r
 \r
       for (int j = 0; j < items.length; j++)\r
@@ -634,9 +698,17 @@ public class DasSourceBrowser extends GDasSourceBrowser
      }\r
   }\r
 \r
-  void saveProperties(Properties properties)\r
+  public void reset_actionPerformed(ActionEvent e)\r
   {\r
-    properties.setProperty("DAS_REGISTRY_URL", registryURL.getText());\r
+    registryURL.setText(DEFAULT_REGISTRY);\r
+  }\r
+\r
+  public void saveProperties(Properties properties)\r
+  {\r
+    if (registryURL.getText() == null || registryURL.getText().length() < 1)\r
+      properties.remove("DAS_REGISTRY_URL");\r
+    else\r
+      properties.setProperty("DAS_REGISTRY_URL", registryURL.getText());\r
 \r
     StringBuffer sb = new StringBuffer();\r
     for(int r=0; r<table.getModel().getRowCount(); r++)\r