JAL-1517 update copyright to version 2.8.2
[jalview.git] / src / jalview / gui / FeatureSettings.java
old mode 100755 (executable)
new mode 100644 (file)
index fae5259..daae5a5
@@ -1,29 +1,28 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
- * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
+ * Copyright (C) 2014 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  * 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 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.util.List;
 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;
 
@@ -38,6 +37,8 @@ import jalview.datamodel.*;
 import jalview.io.*;
 import jalview.schemes.AnnotationColourGradient;
 import jalview.schemes.GraduatedColor;
+import jalview.util.MessageManager;
+import jalview.ws.dbsources.das.api.jalviewSourceI;
 
 public class FeatureSettings extends JPanel
 {
@@ -98,12 +99,18 @@ public class FeatureSettings extends JPanel
       public void mousePressed(MouseEvent evt)
       {
         selectedRow = table.rowAtPoint(evt.getPoint());
-        if (javax.swing.SwingUtilities.isRightMouseButton(evt))
+        if (evt.isPopupTrigger())
         {
           popupSort(selectedRow, (String) table.getValueAt(selectedRow, 0),
                   table.getValueAt(selectedRow, 1), fr.minmax, 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));
+        }
       }
     });
 
@@ -131,7 +138,8 @@ public class FeatureSettings extends JPanel
         }
       }
     });
-
+    table.setToolTipText("<html>"+JvSwingUtils
+            .wrapTooltip("Click/drag feature types up or down to change render order.<br/>Double click to select columns containing feature in alignment/current selection<br/>Pressing Alt will select columns outside features rather than inside<br/>Pressing Shift to modify current selection (rather than clear current selection)<br/>Press CTRL or Command/Meta to toggle columns in/outside features<br/>")+"</html>");
     scrollPane.setViewportView(table);
 
     dassourceBrowser = new DasSourceBrowser(this);
@@ -165,11 +173,11 @@ public class FeatureSettings extends JPanel
     frame.setContentPane(this);
     if (new jalview.util.Platform().isAMac())
     {
-      Desktop.addInternalFrame(frame, "Sequence Feature Settings", 475, 480);
+      Desktop.addInternalFrame(frame, MessageManager.getString("label.sequence_feature_settings"), 475, 480);
     }
     else
     {
-      Desktop.addInternalFrame(frame, "Sequence Feature Settings", 400, 450);
+      Desktop.addInternalFrame(frame, MessageManager.getString("label.sequence_feature_settings"), 400, 450);
     }
 
     frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
@@ -187,8 +195,8 @@ public class FeatureSettings extends JPanel
   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()
@@ -201,7 +209,7 @@ public class FeatureSettings extends JPanel
       }
 
     });
-    JMenuItem dens = new JMenuItem("Sort by Density");
+    JMenuItem dens = new JMenuItem(MessageManager.getString("label.sort_by_density"));
     dens.addActionListener(new ActionListener()
     {
 
@@ -290,6 +298,28 @@ 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);
   }
 
@@ -313,15 +343,15 @@ public class FeatureSettings extends JPanel
     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)
+      if (af.getViewport().getAlignment().getSequenceAt(i)
+              .getDatasetSequence().getSequenceFeatures() == null)
       {
         continue;
       }
 
-      tmpfeatures = af.getViewport().alignment.getSequenceAt(i)
+      tmpfeatures = af.getViewport().getAlignment().getSequenceAt(i)
               .getDatasetSequence().getSequenceFeatures();
 
       int index = 0;
@@ -442,10 +472,10 @@ 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)
+      tmpfeatures = af.getViewport().getAlignment().getSequenceAt(i)
               .getDatasetSequence().getSequenceFeatures();
       if (tmpfeatures == null)
       {
@@ -602,7 +632,7 @@ public class FeatureSettings extends JPanel
             { "Sequence Feature Colours" }, "Sequence Feature Colours");
     chooser.setFileView(new jalview.io.JalviewFileView());
     chooser.setDialogTitle("Load Feature Colours");
-    chooser.setToolTipText("Load");
+    chooser.setToolTipText(MessageManager.getString("action.load"));
 
     int value = chooser.showOpenDialog(this);
 
@@ -700,7 +730,7 @@ public class FeatureSettings extends JPanel
             { "Sequence Feature Colours" }, "Sequence Feature Colours");
     chooser.setFileView(new jalview.io.JalviewFileView());
     chooser.setDialogTitle("Save Feature Colour Scheme");
-    chooser.setToolTipText("Save");
+    chooser.setToolTipText(MessageManager.getString("action.save"));
 
     int value = chooser.showSaveDialog(this);
 
@@ -714,13 +744,13 @@ public class FeatureSettings extends JPanel
         PrintWriter out = new PrintWriter(new OutputStreamWriter(
                 new FileOutputStream(choice), "UTF-8"));
 
-        Enumeration e = fr.featureColours.keys();
+        Iterator e = fr.featureColours.keySet().iterator();
         float[] sortOrder = new float[fr.featureColours.size()];
         String[] sortTypes = new String[fr.featureColours.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++;
         }
@@ -905,7 +935,7 @@ public class FeatureSettings extends JPanel
     dasSettingsPane.setLayout(borderLayout3);
     bigPanel.setLayout(borderLayout4);
     invert.setFont(JvSwingUtils.getLabelFont());
-    invert.setText("Invert Selection");
+    invert.setText(MessageManager.getString("label.invert_selection"));
     invert.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -914,7 +944,7 @@ public class FeatureSettings extends JPanel
       }
     });
     optimizeOrder.setFont(JvSwingUtils.getLabelFont());
-    optimizeOrder.setText("Optimise Order");
+    optimizeOrder.setText(MessageManager.getString("label.optimise_order"));
     optimizeOrder.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -923,7 +953,7 @@ public class FeatureSettings extends JPanel
       }
     });
     sortByScore.setFont(JvSwingUtils.getLabelFont());
-    sortByScore.setText("Seq sort by Score");
+    sortByScore.setText(MessageManager.getString("label.seq_sort_by_score"));
     sortByScore.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -932,7 +962,7 @@ public class FeatureSettings extends JPanel
       }
     });
     sortByDens.setFont(JvSwingUtils.getLabelFont());
-    sortByDens.setText("Seq Sort by density");
+    sortByDens.setText(MessageManager.getString("label.sequence_sort_by_density"));
     sortByDens.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -941,7 +971,7 @@ public class FeatureSettings extends JPanel
       }
     });
     cancel.setFont(JvSwingUtils.getLabelFont());
-    cancel.setText("Cancel");
+    cancel.setText(MessageManager.getString("action.cancel"));
     cancel.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -951,7 +981,7 @@ public class FeatureSettings extends JPanel
       }
     });
     ok.setFont(JvSwingUtils.getLabelFont());
-    ok.setText("OK");
+    ok.setText(MessageManager.getString("action.ok"));
     ok.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -960,7 +990,7 @@ public class FeatureSettings extends JPanel
       }
     });
     loadColours.setFont(JvSwingUtils.getLabelFont());
-    loadColours.setText("Load Colours");
+    loadColours.setText(MessageManager.getString("label.load_colours"));
     loadColours.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -969,7 +999,7 @@ public class FeatureSettings extends JPanel
       }
     });
     saveColours.setFont(JvSwingUtils.getLabelFont());
-    saveColours.setText("Save Colours");
+    saveColours.setText(MessageManager.getString("label.save_colours"));
     saveColours.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -987,7 +1017,7 @@ public class FeatureSettings extends JPanel
     });
 
     transparency.setMaximum(70);
-    fetchDAS.setText("Fetch DAS Features");
+    fetchDAS.setText(MessageManager.getString("label.fetch_das_features"));
     fetchDAS.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -995,7 +1025,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)
@@ -1006,7 +1036,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)
@@ -1129,32 +1159,31 @@ public class FeatureSettings extends JPanel
   private String[] getDisplayedFeatureGroups()
   {
     String[] gps = null;
+    ArrayList<String> _gps = new ArrayList<String>();
     if (fr != null)
     {
 
       if (fr.featureGroups != null)
       {
-        Enumeration en = fr.featureGroups.keys();
-        gps = new String[fr.featureColours.size()];
+        Iterator en = fr.featureGroups.keySet().iterator();
         int g = 0;
         boolean valid = false;
-        while (en.hasMoreElements())
+        while (en.hasNext())
         {
-          String gp = (String) en.nextElement();
+          String gp = (String) en.next();
           Boolean on = (Boolean) fr.featureGroups.get(gp);
           if (on != null && on.booleanValue())
           {
             valid = true;
-            gps[g++] = gp;
+            _gps.add(gp);
           }
         }
-        while (g < gps.length)
-        {
-          gps[g++] = null;
-        }
         if (!valid)
         {
           return null;
+        } else {
+          gps = new String[_gps.size()];
+          _gps.toArray(gps);
         }
       }
     }
@@ -1177,7 +1206,7 @@ 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;
@@ -1225,9 +1254,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);
   }
 
   /**
@@ -1253,14 +1282,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()
@@ -1310,9 +1340,8 @@ public class FeatureSettings extends JPanel
   {
     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,
+            MessageManager.getString("label.no_das_sources_selected_warn"),
+            MessageManager.getString("label.no_das_sources_selected_title"), JOptionPane.DEFAULT_OPTION,
             JOptionPane.INFORMATION_MESSAGE);
   }
 
@@ -1592,7 +1621,7 @@ 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