JAL-1645 source formatting and organise imports
[jalview.git] / src / jalview / gui / FeatureSettings.java
index 66bd2fe..6b58b51 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  */
 package jalview.gui;
 
+import jalview.api.FeatureSettingsControllerI;
 import jalview.bin.Cache;
 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;
 import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
 import jalview.ws.dbsources.das.api.jalviewSourceI;
 
 import java.awt.BorderLayout;
@@ -57,6 +60,7 @@ 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;
@@ -85,7 +89,8 @@ import javax.swing.table.AbstractTableModel;
 import javax.swing.table.TableCellEditor;
 import javax.swing.table.TableCellRenderer;
 
-public class FeatureSettings extends JPanel
+public class FeatureSettings extends JPanel implements
+        FeatureSettingsControllerI
 {
   DasSourceBrowser dassourceBrowser;
 
@@ -120,7 +125,8 @@ public class FeatureSettings extends JPanel
     this.af = af;
     fr = af.getFeatureRenderer();
     // allow transparency to be recovered
-    transparency.setMaximum(100 - (int) ((originalTransparency=fr.getTransparency()) * 100));
+    transparency.setMaximum(100 - (int) ((originalTransparency = fr
+            .getTransparency()) * 100));
 
     try
     {
@@ -130,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());
@@ -170,8 +191,7 @@ public class FeatureSettings extends JPanel
         {
           popupSort(selectedRow, (String) table.getValueAt(selectedRow, 0),
                   table.getValueAt(selectedRow, 1), fr.getMinMax(),
-                  evt.getX(),
-                  evt.getY());
+                  evt.getX(), evt.getY());
         }
       }
     });
@@ -200,8 +220,8 @@ public class FeatureSettings extends JPanel
         }
       }
     });
-    table.setToolTipText(JvSwingUtils
-                    .wrapTooltip(true, MessageManager.getString("label.feature_settings_click_drag")));
+    // table.setToolTipText(JvSwingUtils.wrapTooltip(true,
+    // MessageManager.getString("label.feature_settings_click_drag")));
     scrollPane.setViewportView(table);
 
     dassourceBrowser = new DasSourceBrowser(this);
@@ -212,7 +232,7 @@ public class FeatureSettings extends JPanel
       fr.findAllFeatures(true); // display everything!
     }
 
-    setTableData();
+    discoverAllFeatureData();
     final PropertyChangeListener change;
     final FeatureSettings fs = this;
     fr.addPropertyChangeListener(change = new PropertyChangeListener()
@@ -261,8 +281,7 @@ public class FeatureSettings extends JPanel
           final Object typeCol, final Hashtable minmax, int x, int y)
   {
     JPopupMenu men = new JPopupMenu(MessageManager.formatMessage(
-            "label.settings_for_param", new String[]
-            { type }));
+            "label.settings_for_param", new String[] { type }));
     JMenuItem scr = new JMenuItem(
             MessageManager.getString("label.sort_by_score"));
     men.add(scr);
@@ -272,8 +291,7 @@ public class FeatureSettings extends JPanel
 
       public void actionPerformed(ActionEvent e)
       {
-        me.af.avc.sortAlignmentByFeatureScore(new String[]
-        { type });
+        me.af.avc.sortAlignmentByFeatureScore(new String[] { type });
       }
 
     });
@@ -284,8 +302,7 @@ public class FeatureSettings extends JPanel
 
       public void actionPerformed(ActionEvent e)
       {
-        me.af.avc.sortAlignmentByFeatureDensity(new String[]
-        { type });
+        me.af.avc.sortAlignmentByFeatureDensity(new String[] { type });
       }
 
     });
@@ -406,7 +423,8 @@ public class FeatureSettings extends JPanel
    */
   Hashtable typeWidth = null;
 
-  synchronized public void setTableData()
+  @Override
+  synchronized public void discoverAllFeatureData()
   {
     Vector allFeatures = new Vector();
     Vector allGroups = new Vector();
@@ -414,15 +432,13 @@ public class FeatureSettings extends JPanel
     String group;
     for (int i = 0; i < af.getViewport().getAlignment().getHeight(); i++)
     {
-      if (af.getViewport().getAlignment().getSequenceAt(i)
-              .getDatasetSequence().getSequenceFeatures() == null)
+      tmpfeatures = af.getViewport().getAlignment().getSequenceAt(i)
+              .getSequenceFeatures();
+      if (tmpfeatures == null)
       {
         continue;
       }
 
-      tmpfeatures = af.getViewport().getAlignment().getSequenceAt(i)
-              .getDatasetSequence().getSequenceFeatures();
-
       int index = 0;
       while (index < tmpfeatures.length)
       {
@@ -494,14 +510,13 @@ public class FeatureSettings extends JPanel
       public void itemStateChanged(ItemEvent evt)
       {
         fr.setGroupVisibility(check.getText(), check.isSelected());
-        af.alignPanel.seqPanel.seqCanvas.repaint();
+        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);
@@ -532,7 +547,7 @@ public class FeatureSettings extends JPanel
     {
 
       tmpfeatures = af.getViewport().getAlignment().getSequenceAt(i)
-              .getDatasetSequence().getSequenceFeatures();
+              .getSequenceFeatures();
       if (tmpfeatures == null)
       {
         continue;
@@ -689,11 +704,13 @@ public class FeatureSettings extends JPanel
   void load()
   {
     JalviewFileChooser chooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
-            { "fc" }, new String[]
-            { "Sequence Feature Colours" }, "Sequence Feature Colours");
+            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(MessageManager.getString("label.load_feature_colours"));
+    chooser.setDialogTitle(MessageManager
+            .getString("label.load_feature_colours"));
     chooser.setToolTipText(MessageManager.getString("action.load"));
 
     int value = chooser.showOpenDialog(this);
@@ -708,8 +725,7 @@ public class FeatureSettings extends JPanel
                 file), "UTF-8");
 
         jalview.schemabinding.version2.JalviewUserColours jucs = new jalview.schemabinding.version2.JalviewUserColours();
-        jucs = jucs
-                .unmarshal(in);
+        jucs = jucs.unmarshal(in);
 
         for (int i = jucs.getColourCount() - 1; i >= 0; i--)
         {
@@ -787,11 +803,13 @@ 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");
+            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(MessageManager.getString("label.save_feature_colours"));
+    chooser.setDialogTitle(MessageManager
+            .getString("label.save_feature_colours"));
     chooser.setToolTipText(MessageManager.getString("action.save"));
 
     int value = chooser.showSaveDialog(this);
@@ -926,9 +944,9 @@ public class FeatureSettings extends JPanel
       }
     }
     if (sort)
-     {
+    {
       jalview.util.QuickSort.sort(width, data);
-    // update global priority order
+      // update global priority order
     }
 
     updateFeatureRenderer(data, false);
@@ -997,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
   {
@@ -1043,6 +1063,36 @@ public class FeatureSettings extends JPanel
         af.avc.sortAlignmentByFeatureDensity(null);
       }
     });
+    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()
@@ -1091,6 +1141,8 @@ public class FeatureSettings extends JPanel
     });
 
     transparency.setMaximum(70);
+    transparency.setToolTipText(MessageManager
+            .getString("label.transparency_tip"));
     fetchDAS.setText(MessageManager.getString("label.fetch_das_features"));
     fetchDAS.addActionListener(new ActionListener()
     {
@@ -1119,13 +1171,18 @@ public class FeatureSettings extends JPanel
       }
     });
     this.add(tabbedPane, java.awt.BorderLayout.CENTER);
-    tabbedPane.addTab(MessageManager.getString("label.feature_settings"), settingsPane);
-    tabbedPane.addTab(MessageManager.getString("label.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);
@@ -1162,7 +1219,7 @@ public class FeatureSettings extends JPanel
   {
     SequenceI[] dataset, seqs;
     int iSize;
-    AlignViewport vp = af.getViewport();
+    AlignmentViewport vp = af.getViewport();
     if (vp.getSelectionGroup() != null
             && vp.getSelectionGroup().getSize() > 0)
     {
@@ -1311,8 +1368,10 @@ public class FeatureSettings extends JPanel
       this.data = data;
     }
 
-    private String[] columnNames =
-    { MessageManager.getString("label.feature_type"), MessageManager.getString("action.colour"), MessageManager.getString("label.display") };
+    private String[] columnNames = {
+        MessageManager.getString("label.feature_type"),
+        MessageManager.getString("action.colour"),
+        MessageManager.getString("label.display") };
 
     private Object[][] data;