Merge branch 'feature/JAL-4159_pasimap' into spike/JAL-4159_pasimap_2113_series
[jalview.git] / src / jalview / gui / AlignFrame.java
index ac8ffb9..7116cf3 100644 (file)
@@ -61,6 +61,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Vector;
 
+import javax.swing.AbstractButton;
 import javax.swing.ButtonGroup;
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JComponent;
@@ -71,6 +72,8 @@ import javax.swing.JLayeredPane;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
 import javax.swing.JPanel;
+import javax.swing.JProgressBar;
+import javax.swing.JRadioButtonMenuItem;
 import javax.swing.JScrollPane;
 import javax.swing.SwingUtilities;
 
@@ -82,6 +85,7 @@ import jalview.analysis.Dna;
 import jalview.analysis.GeneticCodeI;
 import jalview.analysis.ParseProperties;
 import jalview.analysis.SequenceIdMatcher;
+import jalview.api.AlignCalcWorkerI;
 import jalview.api.AlignExportSettingsI;
 import jalview.api.AlignViewControllerGuiI;
 import jalview.api.AlignViewControllerI;
@@ -150,6 +154,7 @@ import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemes;
 import jalview.schemes.ResidueColourScheme;
 import jalview.schemes.TCoffeeColourScheme;
+import jalview.util.Constants;
 import jalview.util.HttpUtils;
 import jalview.util.ImageMaker.TYPE;
 import jalview.util.MessageManager;
@@ -157,6 +162,7 @@ import jalview.util.Platform;
 import jalview.util.imagemaker.BitmapImageSizing;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.viewmodel.ViewportRanges;
+import jalview.workers.SecondaryStructureConsensusThread;
 import jalview.ws.DBRefFetcher;
 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
 import jalview.ws.jws1.Discoverer;
@@ -802,6 +808,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       }
       ap.av.updateConservation(ap);
       ap.av.updateConsensus(ap);
+      ap.av.updateSecondaryStructureConsensus(ap);
       ap.av.updateStrucConsensus(ap);
     }
   }
@@ -990,6 +997,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   @Override
+  public JProgressBar getProgressBar(long id)
+  {
+    if (progressBar != null)
+      return progressBar.getProgressBar(id);
+    return null;
+  }
+
+  @Override
   public void registerHandler(final long id,
           final IProgressIndicatorHandler handler)
   {
@@ -3572,8 +3587,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     final OverviewPanel overview = new OverviewPanel(alignPanel, frame,
             showHidden);
     frame.setContentPane(overview);
-    Desktop.addInternalFrame(frame, "", true, frame.getWidth(),
-            frame.getHeight(), true, true);
+
+    alignPanel.setOverviewPanel(overview);
+    alignPanel.setOverviewTitle(this);
+
+    Desktop.addInternalFrame(frame, overview.getTitle(), true,
+            frame.getWidth(), frame.getHeight(), true, true);
     frame.pack();
     frame.setLayer(JLayeredPane.PALETTE_LAYER);
     final AlignmentPanel thePanel = this.alignPanel;
@@ -3593,9 +3612,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       frame.addKeyListener(getKeyListeners()[0]);
     }
 
-    alignPanel.setOverviewPanel(overview);
-    alignPanel.setOverviewTitle(this);
-
     return overview;
   }
 
@@ -4818,7 +4834,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
              * Object[] { String,SequenceI}
              */
             ArrayList<Object[]> filesmatched = new ArrayList<>();
-            ArrayList<Object> filesnotmatched = new ArrayList<>();
+            ArrayList<Object[]> filesnotmatched = new ArrayList<>();
             for (int i = 0; i < files.size(); i++)
             {
               // BH 2018
@@ -4864,9 +4880,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                   }
                   mtch = idm.findAllIdMatches(pdbfn);
                 }
+                FileFormatI type = null;
                 if (mtch != null)
                 {
-                  FileFormatI type;
                   try
                   {
                     type = new IdentifyFile().identify(file, protocol);
@@ -4882,7 +4898,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                 }
                 // File wasn't named like one of the sequences or wasn't a PDB
                 // file.
-                filesnotmatched.add(file);
+                filesnotmatched.add(new Object[] { file, protocol, type });
               }
             }
             int assocfiles = 0;
@@ -4936,7 +4952,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                  */
                 for (Object[] o : filesmatched)
                 {
-                  filesnotmatched.add(o[0]);
+                  filesnotmatched.add(new Object[] { o[0], o[1] });
                 }
               }
             }
@@ -4958,9 +4974,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               {
                 return;
               }
-              for (Object fn : filesnotmatched)
+              for (Object[] fn : filesnotmatched)
               {
-                loadJalviewDataFile(fn, null, null, null);
+                loadJalviewDataFile(fn[0], (DataSourceType) fn[1],
+                        (FileFormatI) fn[2], null);
               }
 
             }
@@ -5056,7 +5073,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           {
             format = new IdentifyFile().identify(file, sourceType);
           }
-          if (FileFormat.ScoreMatrix == format)
+          if (FileFormat.FeatureSettings == format)
+          {
+            if (featureSettings != null)
+            {
+              featureSettings.load(file, sourceType);
+            }
+            else
+            {
+              FeatureSettings.loadFeatureSettingsFile(getFeatureRenderer(),
+                      fileObject, sourceType);
+            }
+          }
+          else if (FileFormat.ScoreMatrix == format)
           {
             ScoreMatrixFile sm = new ScoreMatrixFile(
                     new FileParse(file, sourceType));
@@ -5624,9 +5653,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
   {
-    AlignmentI al = viewport.getAlignment();
-    al.justify(false);
-    viewport.firePropertyChange("alignment", null, al);
+    avc.justify_Region(true);
   }
 
   /**
@@ -5635,9 +5662,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
   {
-    AlignmentI al = viewport.getAlignment();
-    al.justify(true);
-    viewport.firePropertyChange("alignment", null, al);
+    avc.justify_Region(false);
   }
 
   @Override
@@ -5660,6 +5685,133 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     viewport.setShowUnconserved(showNonconservedMenuItem.getState());
     alignPanel.paintAlignment(false, false);
   }
+  
+  @Override
+  protected void updateShowSSRadioButtons(JMenu showSS, ButtonGroup ssButtonGroup){
+    
+    List<String> ssSources = new ArrayList<String>();
+    AlignmentAnnotation[] anns = alignPanel.getAlignment()
+            .getAlignmentAnnotation();
+    
+    ssSources = AlignmentUtils.extractSSSourceInAlignmentAnnotation(anns);
+    
+    // Get the currently selected radio button
+    String selectedButtonModelName = getSelectedRadioButtonDisplayString(ssButtonGroup);
+    boolean selectedButtonModel =  false;
+    
+    // Clear existing radio buttons
+    showSS.removeAll();
+    JRadioButtonMenuItem radioButtonAllSS = new JRadioButtonMenuItem("All");
+    radioButtonAllSS.addActionListener(new ActionListener() {
+      @Override
+      public void actionPerformed(ActionEvent e) {
+          showSS_actionPerformed("All");
+      }
+    });
+    ssButtonGroup.add(radioButtonAllSS);
+    showSS.add(radioButtonAllSS);
+    
+    JRadioButtonMenuItem radioButtonNoneSS = new JRadioButtonMenuItem("None");
+    radioButtonNoneSS.addActionListener(new ActionListener() {
+      @Override
+      public void actionPerformed(ActionEvent e) {
+          showSS_actionPerformed("None");
+      }
+    });
+    ssButtonGroup.add(radioButtonNoneSS);
+    showSS.add(radioButtonNoneSS);
+    showSS.addSeparator();
+
+       for(String ssSource : ssSources) {
+        
+        JRadioButtonMenuItem radioButton = new JRadioButtonMenuItem(ssSource);
+        radioButton.addActionListener(new ActionListener() {
+          @Override
+          public void actionPerformed(ActionEvent e) {
+              showSS_actionPerformed(ssSource);
+          }
+        });
+        ssButtonGroup.add(radioButton);
+        showSS.add(radioButton);
+        
+        // Check if this radio button's name matches the selected radio button's name
+        if (ssSource.equals(selectedButtonModelName)) {
+            radioButton.setSelected(true); // Select this radio button
+            selectedButtonModel = true;
+        }
+        
+      } 
+
+       if (selectedButtonModelName == "None") {
+         // If no radio button was previously selected, select "All"
+         ssButtonGroup.setSelected(radioButtonNoneSS.getModel(), true);
+         selectedButtonModel = true;
+       }
+       if (!selectedButtonModel) {
+           // If no radio button was previously selected, select "All"
+           ssButtonGroup.setSelected(radioButtonAllSS.getModel(), true);
+       }
+  }
+  
+  @Override
+  protected void showSS_actionPerformed(String ssSourceSelection){
+    
+
+    AlignmentAnnotation[] annotations = alignPanel.getAlignment()
+            .getAlignmentAnnotation();
+    
+    for (AlignmentAnnotation aa: annotations) {
+      
+      for (String label : Constants.SECONDARY_STRUCTURE_LABELS.keySet()) {
+        
+        if (label.equals(aa.label)) { 
+          
+          aa.visible = false;
+          
+          if(ssSourceSelection == "All") {
+            aa.visible = true;
+          }
+          
+          else {
+            String ssSource = AlignmentUtils.extractSSSourceFromAnnotationDescription(aa);
+            if(ssSource.equals(ssSourceSelection)) {
+              aa.visible = true;
+            }
+            
+            
+          }
+        }
+      }
+      
+    }
+    
+      
+      List<AlignCalcWorkerI> workers = viewport.getCalcManager()
+              .getRegisteredWorkersOfClass(SecondaryStructureConsensusThread.class);
+      if (!workers.isEmpty()) {
+          
+        viewport.getCalcManager().startWorker(workers.remove(0));
+
+      }
+      
+      PaintRefresher.Refresh(this, viewport.getSequenceSetId());
+      alignPanel.updateAnnotation();
+      alignPanel.paintAlignment(true, true);
+          
+    
+    
+  }
+  
+  protected String getSelectedRadioButtonDisplayString(ButtonGroup ssButtonGroup) {
+    Enumeration<AbstractButton> buttons = ssButtonGroup.getElements();
+    while (buttons.hasMoreElements()) {
+        AbstractButton button = buttons.nextElement();
+        if (button.isSelected()) {
+            return button.getText();
+        }
+    }
+    return null; // No radio button is selected
+}
 
   /*
    * (non-Javadoc)
@@ -5703,6 +5855,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
     alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
   }
+  
+  @Override
+  protected void showSSConsensusHistogram_actionPerformed(ActionEvent e)
+  {
+    viewport.setShowSSConsensusHistogram(showSSConsensusHistogram.getState());
+    alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
+  }
 
   /*
    * (non-Javadoc)
@@ -5842,6 +6001,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       }
     }
     alignPanel.validateAnnotationDimensions(true);
+    // TODO this triggers relayout of annotation panel - otherwise annotation
+    // label height is different to panel height
+    alignPanel.fontChanged();
     alignPanel.alignmentChanged();
   }