JAL-1075 better layout and info box for source browser
authorjprocter <jprocter@compbio.dundee.ac.uk>
Thu, 10 May 2012 13:41:52 +0000 (14:41 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Thu, 10 May 2012 13:41:52 +0000 (14:41 +0100)
src/jalview/gui/JDatabaseTree.java

index 385d1bd..708e19e 100644 (file)
@@ -22,6 +22,8 @@ import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTree;
 import javax.swing.JViewport;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
 import javax.swing.tree.DefaultMutableTreeNode;
 import javax.swing.tree.DefaultTreeCellRenderer;
 import javax.swing.tree.DefaultTreeModel;
@@ -56,9 +58,12 @@ public class JDatabaseTree extends JalviewDialog
 
   private jalview.ws.SequenceFetcher sfetcher;
 
+  private JLabel dbstatus;
+
   public JDatabaseTree(jalview.ws.SequenceFetcher sfetch)
   {
-    super();
+    initDialogFrame(this, true, false, "Select Database Retrieval Source",
+            650, 490);
     /*
      * Dynamically generated database list will need a translation function from
      * internal source to externally distinct names. UNIPROT and UP_NAME are
@@ -84,8 +89,11 @@ public class JDatabaseTree extends JalviewDialog
         {
           tn.add(new DefaultMutableTreeNode(dbp, false));
           ht.put(dbp.getDbName(), dbp.getDbName());
-        } else {
-          System.err.println("dupe ig for : "+dbs[i]+" \t"+dbp.getDbName());
+        }
+        else
+        {
+          System.err.println("dupe ig for : " + dbs[i] + " \t"
+                  + dbp.getDbName());
         }
       }
     }
@@ -103,28 +111,44 @@ public class JDatabaseTree extends JalviewDialog
       }
       root.add(tn);
     }
-    initDialogFrame(this, true, false, "Select Database Retrieval Source",
-            400, 300);
     svp = new JScrollPane();
-    //svp.setAutoscrolls(true);
+    // svp.setAutoscrolls(true);
     dbviews = new JTree(new DefaultTreeModel(root, false));
     dbviews.setCellRenderer(new DbTreeRenderer(this));
 
     dbviews.getSelectionModel().setSelectionMode(
             TreeSelectionModel.SINGLE_TREE_SELECTION);
     svp.getViewport().setView(dbviews);
-    svp.getViewport().setMinimumSize(new Dimension(300,250));
-    //svp.setSize(300,250);
-//    JPanel panel=new JPanel();
-//    panel.setSize(new Dimension(350,220));
-//    panel.add(svp);
-    
-    add(svp, BorderLayout.NORTH);
-    JPanel j = new JPanel(new FlowLayout());
-    j.setPreferredSize(new Dimension(300,50));
+    // svp.getViewport().setMinimumSize(new Dimension(300,200));
+    // svp.setSize(300,250);
+    // JPanel panel=new JPanel();
+    // panel.setSize(new Dimension(350,220));
+    // panel.add(svp);
+    dbviews.addTreeSelectionListener(new TreeSelectionListener()
+    {
+
+      @Override
+      public void valueChanged(TreeSelectionEvent arg0)
+      {
+        _setSelectionState();
+      }
+    });
+    JPanel jc = new JPanel(new BorderLayout()), j = new JPanel(
+            new FlowLayout());
+    jc.add(svp, BorderLayout.CENTER);
+
+    java.awt.Font f;
+    // TODO: make the panel resize and fit this in
+    dbstatus = new JLabel(" "); // set the height correctly for layout
+    dbstatus.setFont(f = JvSwingUtils.getLabelFont(false, true));
+    dbstatus.setSize(new Dimension(290, 50));
+    jc.add(dbstatus, BorderLayout.SOUTH);
+    jc.validate();
+    // j.setPreferredSize(new Dimension(300,50));
+    add(jc, BorderLayout.CENTER);
     j.add(ok);
     j.add(cancel);
-    add(j, BorderLayout.CENTER);
+    add(j, BorderLayout.SOUTH);
     validate();
   }
 
@@ -240,9 +264,32 @@ public class JDatabaseTree extends JalviewDialog
         }
       }
     }
+    updateDbStatus(srcs);
     selection = srcs;
   }
 
+  private void updateDbStatus(List<DbSourceProxy> srcs)
+  {
+    int x = 0;
+    for (DbSourceProxy dbs : srcs)
+    {
+      String tq = dbs.getTestQuery();
+      if (tq != null && tq.trim().length()>0 && dbs.isValidReference(tq))
+      {
+        x++;
+      }
+    }
+
+    dbstatus.setText("Selected "
+            + srcs.size()
+            + " database"
+            + (srcs.size() == 1 ? "" : "s")
+            + " to fetch from"
+            + (srcs.size() > 0 ? " with " + x + " test quer"
+                    + (x == 1 ? "y" : "ies")  : "."));
+    dbstatus.invalidate();
+  }
+
   public String getSelectedItem()
   {
     if (hasSelection())