JAL-3438 spotless for 2.11.2.0
[jalview.git] / src / jalview / appletgui / AlignFrame.java
index f28a906..2a2fc70 100644 (file)
@@ -95,6 +95,7 @@ import java.awt.Menu;
 import java.awt.MenuBar;
 import java.awt.MenuItem;
 import java.awt.Panel;
+import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.FocusEvent;
@@ -106,6 +107,7 @@ import java.awt.event.KeyListener;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.net.URLEncoder;
 import java.util.Arrays;
@@ -343,7 +345,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     createAlignFrameWindow(embedded);
     validate();
     alignPanel.adjustAnnotationHeight();
-    alignPanel.paintAlignment(true);
+    alignPanel.paintAlignment(true, true);
   }
 
   public AlignViewport getAlignViewport()
@@ -415,8 +417,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       {
         viewport.featureSettings.refreshTable();
       }
-      alignPanel.paintAlignment(true);
-      statusBar.setText(MessageManager
+      alignPanel.paintAlignment(true, true);
+      setStatus(MessageManager
               .getString("label.successfully_added_features_alignment"));
     }
     return featuresFile;
@@ -574,8 +576,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
     case KeyEvent.VK_F2:
       viewport.cursorMode = !viewport.cursorMode;
-      statusBar.setText(MessageManager
-              .formatMessage("label.keyboard_editing_mode", new String[]
+      setStatus(MessageManager.formatMessage("label.keyboard_editing_mode",
+              new String[]
               { (viewport.cursorMode ? "on" : "off") }));
       if (viewport.cursorMode)
       {
@@ -691,7 +693,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       break;
 
     }
-    alignPanel.paintAlignment(true);
+    // TODO: repaint flags set only if the keystroke warrants it
+    alignPanel.paintAlignment(true, true);
   }
 
   /**
@@ -917,7 +920,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {
       applyAutoAnnotationSettings_actionPerformed();
     }
-    alignPanel.paintAlignment(true);
+    // TODO: repaint flags set only if warranted
+    alignPanel.paintAlignment(true, true);
   }
 
   /**
@@ -1094,7 +1098,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     else if (source == invertColSel)
     {
       viewport.invertColumnSelection();
-      alignPanel.paintAlignment(true);
+      alignPanel.paintAlignment(false, false);
       viewport.sendSelection();
     }
     else if (source == remove2LeftMenuItem)
@@ -1128,34 +1132,34 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     else if (source == showColumns)
     {
       viewport.showAllHiddenColumns();
-      alignPanel.paintAlignment(true);
+      alignPanel.paintAlignment(true, true);
       viewport.sendSelection();
     }
     else if (source == showSeqs)
     {
       viewport.showAllHiddenSeqs();
-      alignPanel.paintAlignment(true);
+      alignPanel.paintAlignment(true, true);
       // uncomment if we want to slave sequence selections in split frame
       // viewport.sendSelection();
     }
     else if (source == hideColumns)
     {
       viewport.hideSelectedColumns();
-      alignPanel.paintAlignment(true);
+      alignPanel.paintAlignment(true, true);
       viewport.sendSelection();
     }
     else if (source == hideSequences
             && viewport.getSelectionGroup() != null)
     {
       viewport.hideAllSelectedSeqs();
-      alignPanel.paintAlignment(true);
+      alignPanel.paintAlignment(true, true);
       // uncomment if we want to slave sequence selections in split frame
       // viewport.sendSelection();
     }
     else if (source == hideAllButSelection)
     {
       toggleHiddenRegions(false, false);
-      alignPanel.paintAlignment(true);
+      alignPanel.paintAlignment(true, true);
       viewport.sendSelection();
     }
     else if (source == hideAllSelection)
@@ -1164,14 +1168,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       viewport.expandColSelection(sg, false);
       viewport.hideAllSelectedSeqs();
       viewport.hideSelectedColumns();
-      alignPanel.paintAlignment(true);
+      alignPanel.paintAlignment(true, true);
       viewport.sendSelection();
     }
     else if (source == showAllHidden)
     {
       viewport.showAllHiddenColumns();
       viewport.showAllHiddenSeqs();
-      alignPanel.paintAlignment(true);
+      alignPanel.paintAlignment(true, true);
       viewport.sendSelection();
     }
     else if (source == showGroupConsensus)
@@ -1200,7 +1204,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     }
     else if (source == featureSettings)
     {
-      new FeatureSettings(alignPanel);
+      showFeatureSettingsUI();
     }
     else if (source == alProperties)
     {
@@ -1443,15 +1447,15 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     FeaturesFile formatter = new FeaturesFile();
     if (format.equalsIgnoreCase("Jalview"))
     {
-      features = formatter.printJalviewFormat(viewport.getAlignment()
-              .getSequencesArray(), getDisplayedFeatureCols(),
-              getDisplayedFeatureGroups(), true);
+      features = formatter.printJalviewFormat(
+              viewport.getAlignment().getSequencesArray(),
+              alignPanel.getFeatureRenderer(), true, false);
     }
     else
     {
-      features = formatter.printGffFormat(viewport.getAlignment()
-              .getSequencesArray(), getDisplayedFeatureCols(),
-              getDisplayedFeatureGroups(), true);
+      features = formatter.printGffFormat(
+              viewport.getAlignment().getSequencesArray(),
+              alignPanel.getFeatureRenderer(), true, false);
     }
 
     if (displayTextbox)
@@ -1568,7 +1572,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     try
     {
       new URL(url);
-      url = URLEncoder.encode(url);
+      url = URLEncoder.encode(url, "UTF-8");
     }
     /*
      * When we finally deprecate 1.1 compatibility, we can start to use
@@ -1580,6 +1584,12 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     catch (java.net.MalformedURLException ex)
     {
       url = viewport.applet.getCodeBase() + url;
+    } catch (UnsupportedEncodingException ex)
+    {
+      System.err.println(
+              "WARNING = IMPLEMENTATION ERROR - UNSUPPORTED ENCODING EXCEPTION FOR "
+                      + url);
+      ex.printStackTrace();
     }
     return url;
   }
@@ -1601,10 +1611,12 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {
       System.exit(0);
     }
-    else
+
+    viewport = null;
+    if (alignPanel != null && alignPanel.overviewPanel != null)
     {
+      alignPanel.overviewPanel.dispose();
     }
-    viewport = null;
     alignPanel = null;
     this.dispose();
   }
@@ -1781,7 +1793,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     }
     viewport.getAlignment().moveSelectedSequencesByOne(sg,
             up ? null : viewport.getHiddenRepSequences(), up);
-    alignPanel.paintAlignment(true);
+    alignPanel.paintAlignment(true, false);
 
     /*
      * Also move cDNA/protein complement sequences
@@ -1793,7 +1805,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
               viewport, complement);
       complement.getAlignment().moveSelectedSequencesByOne(mappedSelection,
               up ? null : complement.getHiddenRepSequences(), up);
-      getSplitFrame().getComplement(this).alignPanel.paintAlignment(true);
+      getSplitFrame().getComplement(this).alignPanel.paintAlignment(true,
+              false);
     }
   }
 
@@ -2000,13 +2013,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   {
     try
     {
-
       if (copiedSequences == null)
       {
         return;
       }
 
-      StringTokenizer st = new StringTokenizer(copiedSequences.toString());
+      StringTokenizer st = new StringTokenizer(copiedSequences.toString(),
+              "\t");
       Vector seqs = new Vector();
       while (st.hasMoreElements())
       {
@@ -2067,7 +2080,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
             seqs, 0, viewport.getAlignment().getWidth(),
             viewport.getAlignment()));
 
-    viewport.getRanges().setEndSeq(viewport.getAlignment().getHeight());
+    viewport.getRanges().setEndSeq(viewport.getAlignment().getHeight() - 1); // BH
+                                                                             // 2019.04.18
     viewport.getAlignment().getWidth();
     viewport.firePropertyChange("alignment", null,
             viewport.getAlignment().getSequences());
@@ -2219,7 +2233,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {
       PaintRefresher.Refresh(this, viewport.getSequenceSetId());
       alignPanel.updateAnnotation();
-      alignPanel.paintAlignment(true);
+      alignPanel.paintAlignment(true, true);
     }
   }
 
@@ -2256,7 +2270,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     // JAL-2034 - should delegate to
     // alignPanel to decide if overview needs
     // updating.
-    alignPanel.paintAlignment(false);
+    alignPanel.paintAlignment(false, false);
     PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
     viewport.sendSelection();
   }
@@ -2276,7 +2290,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     // JAL-2034 - should delegate to
     // alignPanel to decide if overview needs
     // updating.
-    alignPanel.paintAlignment(false);
+    alignPanel.paintAlignment(false, false);
     PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
     viewport.sendSelection();
   }
@@ -2296,7 +2310,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   public void invertColSel_actionPerformed()
   {
     viewport.invertColumnSelection();
-    alignPanel.paintAlignment(true);
+    alignPanel.paintAlignment(true, false);
     PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
     viewport.sendSelection();
   }
@@ -2343,8 +2357,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
                 column, al);
       }
 
-      statusBar.setText(MessageManager
-              .formatMessage("label.removed_columns", new String[]
+      setStatus(MessageManager.formatMessage("label.removed_columns",
+              new String[]
               { Integer.valueOf(trimRegion.getSize()).toString() }));
       addHistoryItem(trimRegion);
 
@@ -2387,8 +2401,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
     addHistoryItem(removeGapCols);
 
-    statusBar.setText(MessageManager
-            .formatMessage("label.removed_empty_columns", new String[]
+    setStatus(MessageManager.formatMessage("label.removed_empty_columns",
+            new String[]
             { Integer.valueOf(removeGapCols.getSize()).toString() }));
 
     // This is to maintain viewport position on first residue
@@ -2588,19 +2602,19 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   {
     viewport.setShowJVSuffix(seqLimits.getState());
     alignPanel.fontChanged();
-    alignPanel.paintAlignment(true);
+    alignPanel.paintAlignment(true, false);
   }
 
   protected void colourTextMenuItem_actionPerformed()
   {
     viewport.setColourText(colourTextMenuItem.getState());
-    alignPanel.paintAlignment(true);
+    alignPanel.paintAlignment(false, false);
   }
 
   protected void displayNonconservedMenuItem_actionPerformed()
   {
     viewport.setShowUnconserved(displayNonconservedMenuItem.getState());
-    alignPanel.paintAlignment(true);
+    alignPanel.paintAlignment(false, false);
   }
 
   protected void wrapMenuItem_actionPerformed()
@@ -2610,7 +2624,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     scaleAbove.setEnabled(wrapMenuItem.getState());
     scaleLeft.setEnabled(wrapMenuItem.getState());
     scaleRight.setEnabled(wrapMenuItem.getState());
-    alignPanel.paintAlignment(true);
+    alignPanel.paintAlignment(true, false);
   }
 
   public void overviewMenuItem_actionPerformed()
@@ -2653,7 +2667,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   {
     viewport.setGlobalColourScheme(cs);
 
-    alignPanel.paintAlignment(true);
+    alignPanel.paintAlignment(true, true);
   }
 
   protected void modifyPID_actionPerformed()
@@ -2728,7 +2742,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
     addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
             viewport.getAlignment()));
-    alignPanel.paintAlignment(true);
+    alignPanel.paintAlignment(true, false);
   }
 
   public void sortIDMenuItem_actionPerformed()
@@ -2737,7 +2751,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     AlignmentSorter.sortByID(viewport.getAlignment());
     addHistoryItem(
             new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
-    alignPanel.paintAlignment(true);
+    alignPanel.paintAlignment(true, false);
   }
 
   public void sortLengthMenuItem_actionPerformed()
@@ -2746,7 +2760,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     AlignmentSorter.sortByLength(viewport.getAlignment());
     addHistoryItem(new OrderCommand("Length Sort", oldOrder,
             viewport.getAlignment()));
-    alignPanel.paintAlignment(true);
+    alignPanel.paintAlignment(true, false);
   }
 
   public void sortGroupMenuItem_actionPerformed()
@@ -2755,7 +2769,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     AlignmentSorter.sortByGroup(viewport.getAlignment());
     addHistoryItem(new OrderCommand("Group Sort", oldOrder,
             viewport.getAlignment()));
-    alignPanel.paintAlignment(true);
+    alignPanel.paintAlignment(true, false);
 
   }
 
@@ -2795,7 +2809,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
           current.insertCharAt(Width - 1, viewport.getGapCharacter());
         }
       }
-      alignPanel.paintAlignment(true);
+      alignPanel.paintAlignment(false, false);
     }
 
     if ((viewport.getSelectionGroup() != null
@@ -2859,7 +2873,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
           current.insertCharAt(Width - 1, viewport.getGapCharacter());
         }
       }
-      alignPanel.paintAlignment(true);
+      alignPanel.paintAlignment(false, false);
 
     }
 
@@ -2912,7 +2926,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     addHistoryItem(new OrderCommand(MessageManager
             .formatMessage("label.order_by_params", new String[]
             { title }), oldOrder, viewport.getAlignment()));
-    alignPanel.paintAlignment(true);
+    alignPanel.paintAlignment(true, false);
   }
 
   /**
@@ -2970,7 +2984,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       addHistoryItem(new OrderCommand(undoname, oldOrder,
               viewport.getAlignment()));
     }
-    alignPanel.paintAlignment(true);
+    alignPanel.paintAlignment(true, false);
     return true;
   }
 
@@ -3506,17 +3520,17 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     hydrophobicityColour.setLabel(
             MessageManager.getString("label.colourScheme_hydrophobic"));
     hydrophobicityColour.addActionListener(this);
-    helixColour.setLabel(MessageManager
-            .getString("label.colourScheme_helix_propensity"));
+    helixColour.setLabel(
+            MessageManager.getString("label.colourScheme_helixpropensity"));
     helixColour.addActionListener(this);
     strandColour.setLabel(MessageManager
-            .getString("label.colourScheme_strand_propensity"));
+            .getString("label.colourScheme_strandpropensity"));
     strandColour.addActionListener(this);
     turnColour.setLabel(
-            MessageManager.getString("label.colourScheme_turn_propensity"));
+            MessageManager.getString("label.colourScheme_turnpropensity"));
     turnColour.addActionListener(this);
     buriedColour.setLabel(
-            MessageManager.getString("label.colourScheme_buried_index"));
+            MessageManager.getString("label.colourScheme_buriedindex"));
     buriedColour.addActionListener(this);
     purinePyrimidineColour.setLabel(MessageManager
             .getString("label.colourScheme_purine/pyrimidine"));
@@ -3525,19 +3539,19 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     // .getString("label.rna_interaction"));
     // RNAInteractionColour.addActionListener(this);
     RNAHelixColour.setLabel(
-            MessageManager.getString("label.colourScheme_rna_helices"));
+            MessageManager.getString("label.colourScheme_rnahelices"));
     RNAHelixColour.addActionListener(this);
     userDefinedColour
             .setLabel(MessageManager.getString("action.user_defined"));
     userDefinedColour.addActionListener(this);
     PIDColour.setLabel(
-            MessageManager.getString("label.colourScheme_%_identity"));
+            MessageManager.getString("label.colourScheme_%identity"));
     PIDColour.addActionListener(this);
     BLOSUM62Colour.setLabel(
             MessageManager.getString("label.colourScheme_blosum62"));
     BLOSUM62Colour.addActionListener(this);
     tcoffeeColour.setLabel(
-            MessageManager.getString("label.colourScheme_t-coffee_scores"));
+            MessageManager.getString("label.colourScheme_t-coffeescores"));
     // it will be enabled only if a score file is provided
     tcoffeeColour.setEnabled(false);
     tcoffeeColour.addActionListener(this);
@@ -3809,7 +3823,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
      */
     statusBar.setBackground(Color.white);
     statusBar.setFont(new java.awt.Font("Verdana", 0, 11));
-    statusBar.setText(MessageManager.getString("label.status_bar"));
+    setStatus(MessageManager.getString("label.status_bar"));
     this.add(statusBar, BorderLayout.SOUTH);
   }
 
@@ -3949,7 +3963,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
    * without an additional javascript library to exchange messages between the
    * distinct applets. See http://issues.jalview.org/browse/JAL-621
    * 
-   * @param viewer
+   * @param jmolViewer
    *          JmolViewer instance
    * @param sequenceIds
    *          - sequence Ids to search for associations
@@ -4137,7 +4151,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {
       // register the association(s) and quit, don't create any windows.
       if (StructureSelectionManager.getStructureSelectionManager(applet)
-              .setMapping(seqs, chains, pdb.getFile(), protocol) == null)
+              .setMapping(seqs, chains, pdb.getFile(), protocol,
+                      null) == null)
       {
         System.err.println("Failed to map " + pdb.getFile() + " ("
                 + protocol + ") to any sequences");
@@ -4177,7 +4192,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     }
     else
     {
-      new MCview.AppletPDBViewer(pdb, seqs, chains, alignPanel, protocol);
+      new mc_view.AppletPDBViewer(pdb, seqs, chains, alignPanel, protocol);
     }
 
   }
@@ -4325,4 +4340,24 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     return alignPanel.av.featureSettings;
   }
 
+  @Override
+  public FeatureSettingsControllerI showFeatureSettingsUI()
+  {
+    return new FeatureSettings(alignPanel);
+  }
+
+  private Rectangle fs_bounds = null;
+
+  @Override
+  public void setFeatureSettingsGeometry(Rectangle bounds)
+  {
+    fs_bounds = bounds;
+  }
+
+  @Override
+  public Rectangle getFeatureSettingsGeometry()
+  {
+    return fs_bounds;
+  }
+
 }