JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / src / jalview / gui / FeatureSettings.java
old mode 100755 (executable)
new mode 100644 (file)
index 5598af2..a2d0559
@@ -1,46 +1,96 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
- * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
+ * Copyright (C) 2015 The Jalview Authors
  * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This file is part of Jalview.
  * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
  * 
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
 package jalview.gui;
 
-import java.io.*;
-import java.util.*;
-
-import java.awt.*;
-import java.awt.event.*;
-import java.awt.geom.AffineTransform;
-import java.awt.image.BufferedImage;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-
-import javax.swing.*;
-import javax.swing.event.*;
-import javax.swing.table.*;
-
-import jalview.analysis.AlignmentSorter;
+import jalview.api.FeatureSettingsControllerI;
 import jalview.bin.Cache;
-import jalview.commands.OrderCommand;
-import jalview.datamodel.*;
-import jalview.io.*;
+import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceI;
+import jalview.gui.Help.HelpId;
+import jalview.io.JalviewFileChooser;
 import jalview.schemes.AnnotationColourGradient;
 import jalview.schemes.GraduatedColor;
-
-public class FeatureSettings extends JPanel
+import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
+import jalview.ws.dbsources.das.api.jalviewSourceI;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.GridLayout;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionAdapter;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.help.HelpSetException;
+import javax.swing.AbstractCellEditor;
+import javax.swing.BorderFactory;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JColorChooser;
+import javax.swing.JDialog;
+import javax.swing.JInternalFrame;
+import javax.swing.JLabel;
+import javax.swing.JLayeredPane;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JScrollPane;
+import javax.swing.JSlider;
+import javax.swing.JTabbedPane;
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.table.TableCellEditor;
+import javax.swing.table.TableCellRenderer;
+
+public class FeatureSettings extends JPanel implements
+        FeatureSettingsControllerI
 {
   DasSourceBrowser dassourceBrowser;
 
@@ -56,6 +106,8 @@ public class FeatureSettings extends JPanel
 
   Object[][] originalData;
 
+  private float originalTransparency;
+
   final JInternalFrame frame;
 
   JScrollPane scrollPane = new JScrollPane();
@@ -72,8 +124,9 @@ public class FeatureSettings extends JPanel
   {
     this.af = af;
     fr = af.getFeatureRenderer();
-
-    transparency.setMaximum(100 - (int) (fr.transparency * 100));
+    // allow transparency to be recovered
+    transparency.setMaximum(100 - (int) ((originalTransparency = fr
+            .getTransparency()) * 100));
 
     try
     {
@@ -83,7 +136,22 @@ public class FeatureSettings extends JPanel
       ex.printStackTrace();
     }
 
-    table = new JTable();
+    table = new JTable()
+    {
+      @Override
+      public String getToolTipText(MouseEvent e)
+      {
+        if (table.columnAtPoint(e.getPoint()) == 0)
+        {
+          /*
+           * Tooltip for feature name only
+           */
+          return JvSwingUtils.wrapTooltip(true, MessageManager
+                  .getString("label.feature_settings_click_drag"));
+        }
+        return null;
+      }
+    };
     table.getTableHeader().setFont(new Font("Verdana", Font.PLAIN, 12));
     table.setFont(new Font("Verdana", Font.PLAIN, 12));
     table.setDefaultRenderer(Color.class, new ColorRenderer());
@@ -99,11 +167,31 @@ public class FeatureSettings extends JPanel
       public void mousePressed(MouseEvent evt)
       {
         selectedRow = table.rowAtPoint(evt.getPoint());
-        if (javax.swing.SwingUtilities.isRightMouseButton(evt))
+        if (SwingUtilities.isRightMouseButton(evt))
         {
           popupSort(selectedRow, (String) table.getValueAt(selectedRow, 0),
-                  table.getValueAt(selectedRow, 1), fr.minmax, evt.getX(),
-                  evt.getY());
+                  table.getValueAt(selectedRow, 1), fr.getMinMax(),
+                  evt.getX(), evt.getY());
+        }
+        else if (evt.getClickCount() == 2)
+        {
+          fr.ap.alignFrame.avc.markColumnsContainingFeatures(
+                  evt.isAltDown(), evt.isShiftDown() || evt.isMetaDown(),
+                  evt.isMetaDown(),
+                  (String) table.getValueAt(selectedRow, 0));
+        }
+      }
+
+      // isPopupTrigger fires on mouseReleased on Mac
+      @Override
+      public void mouseReleased(MouseEvent evt)
+      {
+        selectedRow = table.rowAtPoint(evt.getPoint());
+        if (evt.isPopupTrigger())
+        {
+          popupSort(selectedRow, (String) table.getValueAt(selectedRow, 0),
+                  table.getValueAt(selectedRow, 1), fr.getMinMax(),
+                  evt.getX(), evt.getY());
         }
       }
     });
@@ -132,19 +220,19 @@ public class FeatureSettings extends JPanel
         }
       }
     });
-
+    // table.setToolTipText(JvSwingUtils.wrapTooltip(true,
+    // MessageManager.getString("label.feature_settings_click_drag")));
     scrollPane.setViewportView(table);
 
-    dassourceBrowser = new DasSourceBrowser();
+    dassourceBrowser = new DasSourceBrowser(this);
     dasSettingsPane.add(dassourceBrowser, BorderLayout.CENTER);
 
-    if (af.getViewport().featuresDisplayed == null
-            || fr.renderOrder == null)
+    if (af.getViewport().isShowSequenceFeatures() || !fr.hasRenderOrder())
     {
       fr.findAllFeatures(true); // display everything!
     }
 
-    setTableData();
+    discoverAllFeatureData();
     final PropertyChangeListener change;
     final FeatureSettings fs = this;
     fr.addPropertyChangeListener(change = new PropertyChangeListener()
@@ -164,24 +252,38 @@ public class FeatureSettings extends JPanel
 
     frame = new JInternalFrame();
     frame.setContentPane(this);
-    Desktop.addInternalFrame(frame, "Sequence Feature Settings", 400, 450);
-    frame
-            .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
-            {
-              public void internalFrameClosed(
-                      javax.swing.event.InternalFrameEvent evt)
-              {
-                fr.removePropertyChangeListener(change);
-              };
-            });
+    if (new jalview.util.Platform().isAMac())
+    {
+      Desktop.addInternalFrame(frame,
+              MessageManager.getString("label.sequence_feature_settings"),
+              475, 480);
+    }
+    else
+    {
+      Desktop.addInternalFrame(frame,
+              MessageManager.getString("label.sequence_feature_settings"),
+              400, 450);
+    }
+
+    frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
+    {
+      public void internalFrameClosed(
+              javax.swing.event.InternalFrameEvent evt)
+      {
+        fr.removePropertyChangeListener(change);
+        dassourceBrowser.fs = null;
+      };
+    });
     frame.setLayer(JLayeredPane.PALETTE_LAYER);
   }
 
   protected void popupSort(final int selectedRow, final String type,
           final Object typeCol, final Hashtable minmax, int x, int y)
   {
-    JPopupMenu men = new JPopupMenu("Settings for " + type);
-    JMenuItem scr = new JMenuItem("Sort by Score");
+    JPopupMenu men = new JPopupMenu(MessageManager.formatMessage(
+            "label.settings_for_param", new String[] { type }));
+    JMenuItem scr = new JMenuItem(
+            MessageManager.getString("label.sort_by_score"));
     men.add(scr);
     final FeatureSettings me = this;
     scr.addActionListener(new ActionListener()
@@ -189,19 +291,18 @@ public class FeatureSettings extends JPanel
 
       public void actionPerformed(ActionEvent e)
       {
-        me.sortByScore(new String[]
-        { type });
+        me.af.avc.sortAlignmentByFeatureScore(new String[] { type });
       }
 
     });
-    JMenuItem dens = new JMenuItem("Sort by Density");
+    JMenuItem dens = new JMenuItem(
+            MessageManager.getString("label.sort_by_density"));
     dens.addActionListener(new ActionListener()
     {
 
       public void actionPerformed(ActionEvent e)
       {
-        me.sortByDens(new String[]
-        { type });
+        me.af.avc.sortAlignmentByFeatureDensity(new String[] { type });
       }
 
     });
@@ -273,8 +374,9 @@ public class FeatureSettings extends JPanel
                 // probably the color chooser!
                 table.setValueAt(colorChooser.getColor(), selectedRow, 1);
                 table.validate();
-                me.updateFeatureRenderer(((FeatureTableModel) table
-                        .getModel()).getData(), false);
+                me.updateFeatureRenderer(
+                        ((FeatureTableModel) table.getModel()).getData(),
+                        false);
               }
             }
           }
@@ -282,6 +384,32 @@ public class FeatureSettings extends JPanel
         });
       }
     }
+    JMenuItem selCols = new JMenuItem(
+            MessageManager.getString("label.select_columns_containing"));
+    selCols.addActionListener(new ActionListener()
+    {
+
+      @Override
+      public void actionPerformed(ActionEvent arg0)
+      {
+        fr.ap.alignFrame.avc.markColumnsContainingFeatures(false, false,
+                false, type);
+      }
+    });
+    JMenuItem clearCols = new JMenuItem(
+            MessageManager.getString("label.select_columns_not_containing"));
+    clearCols.addActionListener(new ActionListener()
+    {
+
+      @Override
+      public void actionPerformed(ActionEvent arg0)
+      {
+        fr.ap.alignFrame.avc.markColumnsContainingFeatures(true, false,
+                false, type);
+      }
+    });
+    men.add(selCols);
+    men.add(clearCols);
     men.show(table, x, y);
   }
 
@@ -295,27 +423,22 @@ public class FeatureSettings extends JPanel
    */
   Hashtable typeWidth = null;
 
-  synchronized public void setTableData()
+  @Override
+  synchronized public void discoverAllFeatureData()
   {
-    if (fr.featureGroups == null)
-    {
-      fr.featureGroups = new Hashtable();
-    }
     Vector allFeatures = new Vector();
     Vector allGroups = new Vector();
     SequenceFeature[] tmpfeatures;
     String group;
-    for (int i = 0; i < af.getViewport().alignment.getHeight(); i++)
+    for (int i = 0; i < af.getViewport().getAlignment().getHeight(); i++)
     {
-      if (af.getViewport().alignment.getSequenceAt(i).getDatasetSequence()
-              .getSequenceFeatures() == null)
+      tmpfeatures = af.getViewport().getAlignment().getSequenceAt(i)
+              .getSequenceFeatures();
+      if (tmpfeatures == null)
       {
         continue;
       }
 
-      tmpfeatures = af.getViewport().alignment.getSequenceAt(i)
-              .getDatasetSequence().getSequenceFeatures();
-
       int index = 0;
       while (index < tmpfeatures.length)
       {
@@ -331,10 +454,7 @@ public class FeatureSettings extends JPanel
           if (!allGroups.contains(group))
           {
             allGroups.addElement(group);
-            if (group != null)
-            {
-              checkGroupState(group);
-            }
+            checkGroupState(group);
           }
         }
 
@@ -352,21 +472,14 @@ public class FeatureSettings extends JPanel
   }
 
   /**
+   * Synchronise gui group list and check visibility of group
    * 
    * @param group
-   * @return true if group has been seen before and is already added to set.
+   * @return true if group is visible
    */
   private boolean checkGroupState(String group)
   {
-    boolean visible;
-    if (fr.featureGroups.containsKey(group))
-    {
-      visible = ((Boolean) fr.featureGroups.get(group)).booleanValue();
-    }
-    else
-    {
-      visible = true; // new group is always made visible
-    }
+    boolean visible = fr.checkGroupVisibility(group, true);
 
     if (groupPanel == null)
     {
@@ -387,10 +500,8 @@ public class FeatureSettings extends JPanel
     if (alreadyAdded)
     {
 
-      return true;
+      return visible;
     }
-
-    fr.featureGroups.put(group, new Boolean(visible));
     final String grp = group;
     final JCheckBox check = new JCheckBox(group, visible);
     check.setFont(new Font("Serif", Font.BOLD, 12));
@@ -398,20 +509,18 @@ public class FeatureSettings extends JPanel
     {
       public void itemStateChanged(ItemEvent evt)
       {
-        fr.featureGroups.put(check.getText(), new Boolean(check
-                .isSelected()));
-        af.alignPanel.seqPanel.seqCanvas.repaint();
+        fr.setGroupVisibility(check.getText(), check.isSelected());
+        af.alignPanel.getSeqPanel().seqCanvas.repaint();
         if (af.alignPanel.overviewPanel != null)
         {
           af.alignPanel.overviewPanel.updateOverviewImage();
         }
 
-        resetTable(new String[]
-        { grp });
+        resetTable(new String[] { grp });
       }
     });
     groupPanel.add(check);
-    return false;
+    return visible;
   }
 
   boolean resettingTable = false;
@@ -434,11 +543,11 @@ public class FeatureSettings extends JPanel
     // Find out which features should be visible depending on which groups
     // are selected / deselected
     // and recompute average width ordering
-    for (int i = 0; i < af.getViewport().alignment.getHeight(); i++)
+    for (int i = 0; i < af.getViewport().getAlignment().getHeight(); i++)
     {
 
-      tmpfeatures = af.getViewport().alignment.getSequenceAt(i)
-              .getDatasetSequence().getSequenceFeatures();
+      tmpfeatures = af.getViewport().getAlignment().getSequenceAt(i)
+              .getSequenceFeatures();
       if (tmpfeatures == null)
       {
         continue;
@@ -455,11 +564,8 @@ public class FeatureSettings extends JPanel
           continue;
         }
 
-        if (group == null || fr.featureGroups.get(group) == null
-                || ((Boolean) fr.featureGroups.get(group)).booleanValue())
+        if (group == null || checkGroupState(group))
         {
-          if (group != null)
-            checkGroupState(group);
           type = tmpfeatures[index].getType();
           if (!visibleChecks.contains(type))
           {
@@ -494,17 +600,20 @@ public class FeatureSettings extends JPanel
     Object[][] data = new Object[fSize][3];
     int dataIndex = 0;
 
-    if (fr.renderOrder != null)
+    if (fr.hasRenderOrder())
     {
       if (!handlingUpdate)
+      {
         fr.findAllFeatures(groupChanged != null); // prod to update
-      // colourschemes. but don't
-      // affect display
-      // First add the checks in the previous render order,
-      // in case the window has been closed and reopened
-      for (int ro = fr.renderOrder.length - 1; ro > -1; ro--)
+        // colourschemes. but don't
+        // affect display
+        // First add the checks in the previous render order,
+        // in case the window has been closed and reopened
+      }
+      List<String> frl = fr.getRenderOrder();
+      for (int ro = frl.size() - 1; ro > -1; ro--)
       {
-        type = fr.renderOrder[ro];
+        type = frl.get(ro);
 
         if (!visibleChecks.contains(type))
         {
@@ -513,8 +622,8 @@ public class FeatureSettings extends JPanel
 
         data[dataIndex][0] = type;
         data[dataIndex][1] = fr.getFeatureStyle(type);
-        data[dataIndex][2] = new Boolean(af.getViewport().featuresDisplayed
-                .containsKey(type));
+        data[dataIndex][2] = new Boolean(af.getViewport()
+                .getFeaturesDisplayed().isVisible(type));
         dataIndex++;
         visibleChecks.removeElement(type);
       }
@@ -532,7 +641,7 @@ public class FeatureSettings extends JPanel
       if (data[dataIndex][1] == null)
       {
         // "Colour has been updated in another view!!"
-        fr.renderOrder = null;
+        fr.clearRenderOrder();
         return;
       }
 
@@ -554,8 +663,8 @@ public class FeatureSettings extends JPanel
 
     if (groupPanel != null)
     {
-      groupPanel.setLayout(new GridLayout(fr.featureGroups.size() / 4 + 1,
-              4));
+      groupPanel.setLayout(new GridLayout(
+              fr.getFeatureGroupsSize() / 4 + 1, 4));
 
       groupPanel.validate();
       bigPanel.add(groupPanel, BorderLayout.NORTH);
@@ -578,23 +687,31 @@ public class FeatureSettings extends JPanel
     {
       order[i] = fr.getOrder(data[i][0].toString());
       if (order[i] < 0)
+      {
         order[i] = fr.setOrder(data[i][0].toString(), i / order.length);
+      }
       if (i > 1)
+      {
         sort = sort || order[i - 1] > order[i];
+      }
     }
     if (sort)
+    {
       jalview.util.QuickSort.sort(order, data);
+    }
   }
 
   void load()
   {
-    JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
-            .getProperty("LAST_DIRECTORY"), new String[]
-    { "fc" }, new String[]
-    { "Sequence Feature Colours" }, "Sequence Feature Colours");
+    JalviewFileChooser chooser = new JalviewFileChooser(
+            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
+            new String[] { "fc" },
+            new String[] { "Sequence Feature Colours" },
+            "Sequence Feature Colours");
     chooser.setFileView(new jalview.io.JalviewFileView());
-    chooser.setDialogTitle("Load Feature Colours");
-    chooser.setToolTipText("Load");
+    chooser.setDialogTitle(MessageManager
+            .getString("label.load_feature_colours"));
+    chooser.setToolTipText(MessageManager.getString("action.load"));
 
     int value = chooser.showOpenDialog(this);
 
@@ -608,28 +725,27 @@ public class FeatureSettings extends JPanel
                 file), "UTF-8");
 
         jalview.schemabinding.version2.JalviewUserColours jucs = new jalview.schemabinding.version2.JalviewUserColours();
-        jucs = (jalview.schemabinding.version2.JalviewUserColours) jucs.unmarshal(in);
-        
+        jucs = jucs.unmarshal(in);
+
         for (int i = jucs.getColourCount() - 1; i >= 0; i--)
         {
           String name;
           jalview.schemabinding.version2.Colour newcol = jucs.getColour(i);
           if (newcol.hasMax())
           {
-            Color mincol=null,maxcol=null;
-            try {
-              mincol = new Color(
-                      Integer.parseInt(newcol.getMinRGB(), 16));
-              maxcol = new Color(
-                      Integer.parseInt(newcol.getRGB(), 16));
-              
+            Color mincol = null, maxcol = null;
+            try
+            {
+              mincol = new Color(Integer.parseInt(newcol.getMinRGB(), 16));
+              maxcol = new Color(Integer.parseInt(newcol.getRGB(), 16));
+
             } catch (Exception e)
             {
-              Cache.log.warn("Couldn't parse out graduated feature color.",e);
+              Cache.log.warn("Couldn't parse out graduated feature color.",
+                      e);
             }
-            GraduatedColor gcol = 
-              new GraduatedColor(mincol,maxcol, 
-                  newcol.getMin(),newcol.getMax());
+            GraduatedColor gcol = new GraduatedColor(mincol, maxcol,
+                    newcol.getMin(), newcol.getMax());
             if (newcol.hasAutoScale())
             {
               gcol.setAutoScaled(newcol.getAutoScale());
@@ -643,24 +759,28 @@ public class FeatureSettings extends JPanel
               gcol.setThresh(newcol.getThreshold());
               gcol.setThreshType(AnnotationColourGradient.NO_THRESHOLD); // default
             }
-            if (newcol.getThreshType().length()>0)
+            if (newcol.getThreshType().length() > 0)
             {
               String ttyp = newcol.getThreshType();
-              if (ttyp.equalsIgnoreCase("NONE")) {
+              if (ttyp.equalsIgnoreCase("NONE"))
+              {
                 gcol.setThreshType(AnnotationColourGradient.NO_THRESHOLD);
               }
               if (ttyp.equalsIgnoreCase("ABOVE"))
               {
                 gcol.setThreshType(AnnotationColourGradient.ABOVE_THRESHOLD);
               }
-              if (ttyp.equalsIgnoreCase("BELOW")){
+              if (ttyp.equalsIgnoreCase("BELOW"))
+              {
                 gcol.setThreshType(AnnotationColourGradient.BELOW_THRESHOLD);
-              } 
+              }
             }
             fr.setColour(name = newcol.getName(), gcol);
-          } else {
+          }
+          else
+          {
             fr.setColour(name = jucs.getColour(i).getName(), new Color(
-                  Integer.parseInt(jucs.getColour(i).getRGB(), 16)));
+                    Integer.parseInt(jucs.getColour(i).getRGB(), 16)));
           }
           fr.setOrder(name, (i == 0) ? 0 : i / jucs.getColourCount());
         }
@@ -682,13 +802,15 @@ public class FeatureSettings extends JPanel
 
   void save()
   {
-    JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
-            .getProperty("LAST_DIRECTORY"), new String[]
-    { "fc" }, new String[]
-    { "Sequence Feature Colours" }, "Sequence Feature Colours");
+    JalviewFileChooser chooser = new JalviewFileChooser(
+            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
+            new String[] { "fc" },
+            new String[] { "Sequence Feature Colours" },
+            "Sequence Feature Colours");
     chooser.setFileView(new jalview.io.JalviewFileView());
-    chooser.setDialogTitle("Save Feature Colour Scheme");
-    chooser.setToolTipText("Save");
+    chooser.setDialogTitle(MessageManager
+            .getString("label.save_feature_colours"));
+    chooser.setToolTipText(MessageManager.getString("action.save"));
 
     int value = chooser.showSaveDialog(this);
 
@@ -702,13 +824,14 @@ public class FeatureSettings extends JPanel
         PrintWriter out = new PrintWriter(new OutputStreamWriter(
                 new FileOutputStream(choice), "UTF-8"));
 
-        Enumeration e = fr.featureColours.keys();
-        float[] sortOrder = new float[fr.featureColours.size()];
-        String[] sortTypes = new String[fr.featureColours.size()];
+        Set fr_colours = fr.getAllFeatureColours();
+        Iterator e = fr_colours.iterator();
+        float[] sortOrder = new float[fr_colours.size()];
+        String[] sortTypes = new String[fr_colours.size()];
         int i = 0;
-        while (e.hasMoreElements())
+        while (e.hasNext())
         {
-          sortTypes[i] = e.nextElement().toString();
+          sortTypes[i] = e.next().toString();
           sortOrder[i] = fr.getOrder(sortTypes[i]);
           i++;
         }
@@ -770,7 +893,9 @@ public class FeatureSettings extends JPanel
   public void orderByAvWidth()
   {
     if (table == null || table.getModel() == null)
+    {
       return;
+    }
     Object[][] data = ((FeatureTableModel) table.getModel()).getData();
     float[] width = new float[data.length];
     float[] awidth;
@@ -792,7 +917,9 @@ public class FeatureSettings extends JPanel
         width[i] = 0;
       }
       if (max < width[i])
+      {
         max = width[i];
+      }
     }
     boolean sort = false;
     for (int i = 0; i < width.length; i++)
@@ -812,11 +939,15 @@ public class FeatureSettings extends JPanel
         fr.setOrder(data[i][0].toString(), width[i]); // store for later
       }
       if (i > 0)
+      {
         sort = sort || width[i - 1] > width[i];
+      }
     }
     if (sort)
+    {
       jalview.util.QuickSort.sort(width, data);
-    // update global priority order
+      // update global priority order
+    }
 
     updateFeatureRenderer(data, false);
     table.repaint();
@@ -884,7 +1015,9 @@ public class FeatureSettings extends JPanel
 
   JButton sortByDens = new JButton();
 
-  JPanel transbuttons = new JPanel(new GridLayout(4, 1));
+  JButton help = new JButton();
+
+  JPanel transbuttons = new JPanel(new GridLayout(5, 1));
 
   private void jbInit() throws Exception
   {
@@ -892,8 +1025,8 @@ public class FeatureSettings extends JPanel
     settingsPane.setLayout(borderLayout2);
     dasSettingsPane.setLayout(borderLayout3);
     bigPanel.setLayout(borderLayout4);
-    invert.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
-    invert.setText("Invert Selection");
+    invert.setFont(JvSwingUtils.getLabelFont());
+    invert.setText(MessageManager.getString("label.invert_selection"));
     invert.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -901,8 +1034,8 @@ public class FeatureSettings extends JPanel
         invertSelection();
       }
     });
-    optimizeOrder.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
-    optimizeOrder.setText("Optimise Order");
+    optimizeOrder.setFont(JvSwingUtils.getLabelFont());
+    optimizeOrder.setText(MessageManager.getString("label.optimise_order"));
     optimizeOrder.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -910,36 +1043,69 @@ public class FeatureSettings extends JPanel
         orderByAvWidth();
       }
     });
-    sortByScore.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
-    sortByScore.setText("Seq sort by Score");
+    sortByScore.setFont(JvSwingUtils.getLabelFont());
+    sortByScore
+            .setText(MessageManager.getString("label.seq_sort_by_score"));
     sortByScore.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
       {
-        sortByScore(null);
+        af.avc.sortAlignmentByFeatureScore(null);
       }
     });
-    sortByDens.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
-    sortByDens.setText("Seq Sort by density");
+    sortByDens.setFont(JvSwingUtils.getLabelFont());
+    sortByDens.setText(MessageManager
+            .getString("label.sequence_sort_by_density"));
     sortByDens.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
       {
-        sortByDens(null);
+        af.avc.sortAlignmentByFeatureDensity(null);
       }
     });
-    cancel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
-    cancel.setText("Cancel");
+    help.setFont(JvSwingUtils.getLabelFont());
+    help.setText(MessageManager.getString("action.help"));
+    help.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        try
+        {
+          Help.showHelpWindow(HelpId.SequenceFeatureSettings);
+        } catch (HelpSetException e1)
+        {
+          e1.printStackTrace();
+        }
+      }
+    });
+    help.setFont(JvSwingUtils.getLabelFont());
+    help.setText(MessageManager.getString("action.help"));
+    help.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        try
+        {
+          Help.showHelpWindow(HelpId.SequenceFeatureSettings);
+        } catch (HelpSetException e1)
+        {
+          e1.printStackTrace();
+        }
+      }
+    });
+    cancel.setFont(JvSwingUtils.getLabelFont());
+    cancel.setText(MessageManager.getString("action.cancel"));
     cancel.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
       {
+        fr.setTransparency(originalTransparency);
         updateFeatureRenderer(originalData);
         close();
       }
     });
-    ok.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
-    ok.setText("OK");
+    ok.setFont(JvSwingUtils.getLabelFont());
+    ok.setText(MessageManager.getString("action.ok"));
     ok.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -947,8 +1113,8 @@ public class FeatureSettings extends JPanel
         close();
       }
     });
-    loadColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
-    loadColours.setText("Load Colours");
+    loadColours.setFont(JvSwingUtils.getLabelFont());
+    loadColours.setText(MessageManager.getString("label.load_colours"));
     loadColours.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -956,8 +1122,8 @@ public class FeatureSettings extends JPanel
         load();
       }
     });
-    saveColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
-    saveColours.setText("Save Colours");
+    saveColours.setFont(JvSwingUtils.getLabelFont());
+    saveColours.setText(MessageManager.getString("label.save_colours"));
     saveColours.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -969,13 +1135,15 @@ public class FeatureSettings extends JPanel
     {
       public void stateChanged(ChangeEvent evt)
       {
-        fr.setTransparency((float) (100 - transparency.getValue()) / 100f);
+        fr.setTransparency((100 - transparency.getValue()) / 100f);
         af.alignPanel.paintAlignment(true);
       }
     });
 
     transparency.setMaximum(70);
-    fetchDAS.setText("Fetch DAS Features");
+    transparency.setToolTipText(MessageManager
+            .getString("label.transparency_tip"));
+    fetchDAS.setText(MessageManager.getString("label.fetch_das_features"));
     fetchDAS.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -983,7 +1151,7 @@ public class FeatureSettings extends JPanel
         fetchDAS_actionPerformed(e);
       }
     });
-    saveDAS.setText("Save as default");
+    saveDAS.setText(MessageManager.getString("action.save_as_default"));
     saveDAS.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -994,7 +1162,7 @@ public class FeatureSettings extends JPanel
     dasButtonPanel.setBorder(BorderFactory.createEtchedBorder());
     dasSettingsPane.setBorder(null);
     cancelDAS.setEnabled(false);
-    cancelDAS.setText("Cancel Fetch");
+    cancelDAS.setText(MessageManager.getString("action.cancel_fetch"));
     cancelDAS.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -1003,13 +1171,18 @@ public class FeatureSettings extends JPanel
       }
     });
     this.add(tabbedPane, java.awt.BorderLayout.CENTER);
-    tabbedPane.addTab("Feature Settings", settingsPane);
-    tabbedPane.addTab("DAS Settings", dasSettingsPane);
+    tabbedPane.addTab(MessageManager.getString("label.feature_settings"),
+            settingsPane);
+    tabbedPane.addTab(MessageManager.getString("label.das_settings"),
+            dasSettingsPane);
     bigPanel.add(transPanel, java.awt.BorderLayout.SOUTH);
     transbuttons.add(optimizeOrder);
     transbuttons.add(invert);
     transbuttons.add(sortByScore);
     transbuttons.add(sortByDens);
+    transbuttons.add(help);
+    JPanel sliderPanel = new JPanel();
+    sliderPanel.add(transparency);
     transPanel.add(transparency);
     transPanel.add(transbuttons);
     buttonPanel.add(ok);
@@ -1025,122 +1198,11 @@ public class FeatureSettings extends JPanel
     settingsPane.add(buttonPanel, java.awt.BorderLayout.SOUTH);
   }
 
-  protected void sortByDens(String[] typ)
-  {
-    sortBy(typ, "Sort by Density", AlignmentSorter.FEATURE_DENSITY);
-  }
-
-  protected void sortBy(String[] typ, String methodText, final String method)
-  {
-    if (typ == null)
-    {
-      typ = getDisplayedFeatureTypes();
-    }
-    String gps[] = null;
-    gps = getDisplayedFeatureGroups();
-    if (typ != null)
-    {
-      for (int i = 0; i < typ.length; i++)
-      {
-        System.err.println("Sorting on Types:" + typ[i]);
-      }
-    }
-    if (gps != null)
-    {
-
-      for (int i = 0; i < gps.length; i++)
-      {
-        System.err.println("Sorting on groups:" + gps[i]);
-      }
-    }
-    AlignmentPanel alignPanel = af.alignPanel;
-    AlignmentI al = alignPanel.av.getAlignment();
-
-    int start, stop;
-    SequenceGroup sg = alignPanel.av.getSelectionGroup();
-    if (sg != null)
-    {
-      start = sg.getStartRes();
-      stop = sg.getEndRes();
-    }
-    else
-    {
-      start = 0;
-      stop = al.getWidth();
-    }
-    SequenceI[] oldOrder = al.getSequencesArray();
-    AlignmentSorter.sortByFeature(typ, gps, start, stop, al, method);
-    af.addHistoryItem(new OrderCommand(methodText, oldOrder, alignPanel.av
-            .getAlignment()));
-    alignPanel.paintAlignment(true);
-
-  }
-
-  protected void sortByScore(String[] typ)
-  {
-    sortBy(typ, "Sort by Feature Score", AlignmentSorter.FEATURE_SCORE);
-  }
-
-  private String[] getDisplayedFeatureTypes()
-  {
-    String[] typ = null;
-    if (fr != null)
-    {
-      synchronized (fr.renderOrder)
-      {
-        typ = new String[fr.renderOrder.length];
-        System.arraycopy(fr.renderOrder, 0, typ, 0, typ.length);
-        for (int i = 0; i < typ.length; i++)
-        {
-          if (af.viewport.featuresDisplayed.get(typ[i]) == null)
-          {
-            typ[i] = null;
-          }
-        }
-      }
-    }
-    return typ;
-  }
-
-  private String[] getDisplayedFeatureGroups()
-  {
-    String[] gps = null;
-    if (fr != null)
-    {
-
-      if (fr.featureGroups != null)
-      {
-        Enumeration en = fr.featureGroups.keys();
-        gps = new String[fr.featureColours.size()];
-        int g = 0;
-        boolean valid = false;
-        while (en.hasMoreElements())
-        {
-          String gp = (String) en.nextElement();
-          Boolean on = (Boolean) fr.featureGroups.get(gp);
-          if (on != null && on.booleanValue())
-          {
-            valid = true;
-            gps[g++] = gp;
-          }
-        }
-        while (g < gps.length)
-        {
-          gps[g++] = null;
-        }
-        if (!valid)
-        {
-          return null;
-        }
-      }
-    }
-    return gps;
-  }
-
   public void fetchDAS_actionPerformed(ActionEvent e)
   {
     fetchDAS.setEnabled(false);
     cancelDAS.setEnabled(true);
+    dassourceBrowser.setGuiEnabled(false);
     Vector selectedSources = dassourceBrowser.getSelectedSources();
     doDasFeatureFetch(selectedSources, true, true);
   }
@@ -1152,12 +1214,12 @@ public class FeatureSettings extends JPanel
    * @param checkDbRefs
    * @param promptFetchDbRefs
    */
-  private void doDasFeatureFetch(Vector selectedSources,
+  private void doDasFeatureFetch(List<jalviewSourceI> selectedSources,
           boolean checkDbRefs, boolean promptFetchDbRefs)
   {
     SequenceI[] dataset, seqs;
     int iSize;
-    AlignViewport vp = af.getViewport();
+    AlignmentViewport vp = af.getViewport();
     if (vp.getSelectionGroup() != null
             && vp.getSelectionGroup().getSize() > 0)
     {
@@ -1200,9 +1262,9 @@ public class FeatureSettings extends JPanel
    *          Vector of Strings to resolve to DAS source nicknames.
    * @return sources that are present in source list.
    */
-  public Vector resolveSourceNicknames(Vector sources)
+  public List<jalviewSourceI> resolveSourceNicknames(Vector sources)
   {
-    return dassourceBrowser.resolveSourceNicknames(sources);
+    return dassourceBrowser.sourceRegistry.resolveSourceNicknames(sources);
   }
 
   /**
@@ -1228,14 +1290,15 @@ public class FeatureSettings extends JPanel
   public void fetchDasFeatures(Vector sources, boolean block)
   {
     initDasSources();
-    Vector resolved = resolveSourceNicknames(sources);
+    List<jalviewSourceI> resolved = dassourceBrowser.sourceRegistry
+            .resolveSourceNicknames(sources);
     if (resolved.size() == 0)
     {
       resolved = dassourceBrowser.getSelectedSources();
     }
     if (resolved.size() > 0)
     {
-      final Vector dassources = resolved;
+      final List<jalviewSourceI> dassources = resolved;
       fetchDAS.setEnabled(false);
       // cancelDAS.setEnabled(true); doDasFetch does this.
       Runnable fetcher = new Runnable()
@@ -1268,6 +1331,8 @@ public class FeatureSettings extends JPanel
   {
     fetchDAS.setEnabled(true);
     cancelDAS.setEnabled(false);
+    dassourceBrowser.setGuiEnabled(true);
+
   }
 
   public void cancelDAS_actionPerformed(ActionEvent e)
@@ -1276,18 +1341,21 @@ public class FeatureSettings extends JPanel
     {
       dasFeatureFetcher.cancel();
     }
-    fetchDAS.setEnabled(true);
-    cancelDAS.setEnabled(false);
+    complete();
   }
 
   public void noDasSourceActive()
   {
     complete();
-    JOptionPane.showInternalConfirmDialog(Desktop.desktop,
-            "No das sources were selected.\n"
-                    + "Please select some sources and\n" + " try again.",
-            "No Sources Selected", JOptionPane.DEFAULT_OPTION,
-            JOptionPane.INFORMATION_MESSAGE);
+    JOptionPane
+            .showInternalConfirmDialog(
+                    Desktop.desktop,
+                    MessageManager
+                            .getString("label.no_das_sources_selected_warn"),
+                    MessageManager
+                            .getString("label.no_das_sources_selected_title"),
+                    JOptionPane.DEFAULT_OPTION,
+                    JOptionPane.INFORMATION_MESSAGE);
   }
 
   // ///////////////////////////////////////////////////////////////////////
@@ -1300,8 +1368,10 @@ public class FeatureSettings extends JPanel
       this.data = data;
     }
 
-    private String[] columnNames =
-    { "Feature Type", "Colour", "Display" };
+    private String[] columnNames = {
+        MessageManager.getString("label.feature_type"),
+        MessageManager.getString("action.colour"),
+        MessageManager.getString("label.display") };
 
     private Object[][] data;
 
@@ -1370,6 +1440,8 @@ public class FeatureSettings extends JPanel
     public ColorRenderer()
     {
       setOpaque(true); // MUST do this for background to show up.
+      setHorizontalTextPosition(SwingConstants.CENTER);
+      setVerticalTextPosition(SwingConstants.CENTER);
     }
 
     public Component getTableCellRendererComponent(JTable table,
@@ -1451,22 +1523,28 @@ public class FeatureSettings extends JPanel
   public static void renderGraduatedColor(JLabel comp, GraduatedColor gcol,
           int w, int h)
   {
-
+    boolean thr = false;
     String tt = "";
     String tx = "";
     if (gcol.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD)
     {
-      tx += "> ";
+      thr = true;
+      tx += ">";
       tt += "Thresholded (Above " + gcol.getThresh() + ") ";
     }
     if (gcol.getThreshType() == AnnotationColourGradient.BELOW_THRESHOLD)
     {
-      tx += "< ";
+      thr = true;
+      tx += "<";
       tt += "Thresholded (Below " + gcol.getThresh() + ") ";
     }
     if (gcol.isColourByLabel())
     {
       tt = "Coloured by label text. " + tt;
+      if (thr)
+      {
+        tx += " ";
+      }
       tx += "Label";
       comp.setIcon(null);
     }
@@ -1474,14 +1552,15 @@ public class FeatureSettings extends JPanel
     {
       Color newColor = gcol.getMaxColor();
       comp.setBackground(newColor);
-      System.err.println("Width is " + w / 2);
-      Icon ficon = new FeatureIcon(gcol, comp.getBackground(), w / 2, h);
+      // System.err.println("Width is " + w / 2);
+      Icon ficon = new FeatureIcon(gcol, comp.getBackground(), w, h, thr);
       comp.setIcon(ficon);
       // tt+="RGB value: Max (" + newColor.getRed() + ", "
       // + newColor.getGreen() + ", " + newColor.getBlue()
       // + ")\nMin (" + minCol.getRed() + ", " + minCol.getGreen()
       // + ", " + minCol.getBlue() + ")");
     }
+    comp.setHorizontalAlignment(SwingConstants.CENTER);
     comp.setText(tx);
     if (tt.length() > 0)
     {
@@ -1503,14 +1582,31 @@ class FeatureIcon implements Icon
 
   Color backg;
 
+  boolean midspace = false;
+
   int width = 50, height = 20;
 
-  FeatureIcon(GraduatedColor gfc, Color bg, int w, int h)
+  int s1, e1; // start and end of midpoint band for thresholded symbol
+
+  Color mpcolour = Color.white;
+
+  FeatureIcon(GraduatedColor gfc, Color bg, int w, int h, boolean mspace)
   {
     gcol = gfc;
     backg = bg;
     width = w;
     height = h;
+    midspace = mspace;
+    if (midspace)
+    {
+      s1 = width / 3;
+      e1 = s1 * 2;
+    }
+    else
+    {
+      s1 = width / 2;
+      e1 = s1;
+    }
   }
 
   public int getIconWidth()
@@ -1540,14 +1636,21 @@ class FeatureIcon implements Icon
       // width/g.getFontMetrics().stringWidth("Label"),
       // height/g.getFontMetrics().getHeight())));
 
-      g.drawString("Label", 0, 0);
+      g.drawString(MessageManager.getString("label.label"), 0, 0);
 
     }
     else
     {
       Color minCol = gcol.getMinColor();
       g.setColor(minCol);
-      g.fillRect(0, 0, width, height);
+      g.fillRect(0, 0, s1, height);
+      if (midspace)
+      {
+        g.setColor(Color.white);
+        g.fillRect(s1, 0, e1 - s1, height);
+      }
+      g.setColor(gcol.getMaxColor());
+      g.fillRect(0, e1, width - e1, height);
     }
   }
 }