JAL-3253-applet adds NOMENUBAR, NOSTATUS, NOCALCULATION, SHOWOVERVIEW
[jalview.git] / src / jalview / gui / AlignFrame.java
index 2d7c11b..d87f0f0 100644 (file)
@@ -28,16 +28,17 @@ import jalview.analysis.GeneticCodeI;
 import jalview.analysis.ParseProperties;
 import jalview.analysis.SequenceIdMatcher;
 import jalview.api.AlignExportSettingsI;
+import jalview.api.AlignFrameI;
 import jalview.api.AlignViewControllerGuiI;
 import jalview.api.AlignViewControllerI;
 import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
+//from JalviewLite imports import jalview.api.FeatureRenderer;
 import jalview.api.FeatureSettingsControllerI;
 import jalview.api.SplitContainerI;
 import jalview.api.ViewStyleI;
 import jalview.api.analysis.SimilarityParamsI;
 import jalview.bin.Cache;
-import jalview.bin.Instance;
 import jalview.bin.Jalview;
 import jalview.commands.CommandI;
 import jalview.commands.EditCommand;
@@ -163,7 +164,8 @@ import ext.vamsas.ServiceHandle;
  * @version $Revision$
  */
 @SuppressWarnings("serial")
-public class AlignFrame extends GAlignFrame implements DropTargetListener,
+public class AlignFrame extends GAlignFrame
+        implements AlignFrameI, DropTargetListener,
         IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
 {
 
@@ -351,6 +353,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     if (!Jalview.isHeadlessMode())
     {
       progressBar = new ProgressBar(this.statusPanel, this.statusBar);
+      statusPanel.setVisible(Jalview.getInstance().getShowStatus());
+      alignFrameMenuBar.setVisible(Jalview.getInstance().getAllowMenuBar());
     }
 
     avc = new jalview.controller.AlignViewController(this, viewport,
@@ -365,7 +369,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       // modifyPID.setEnabled(false);
     }
 
-    String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
+    String sortby = jalview.bin.Cache.getDefault(Preferences.SORT_ALIGNMENT,
             "No sort");
 
     if (sortby.equals("Id"))
@@ -408,7 +412,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       wrapMenuItem_actionPerformed(null);
     }
 
-    if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
+    if (jalview.bin.Cache.getDefault(Preferences.SHOW_OVERVIEW, false))
     {
       this.overviewMenuItem_actionPerformed(null);
     }
@@ -791,9 +795,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       {
         ap.av.getAlignment().padGaps();
       }
-      ap.av.updateConservation(ap);
-      ap.av.updateConsensus(ap);
-      ap.av.updateStrucConsensus(ap);
+      if (Jalview.getInstance().getStartCalculations())
+      {
+        ap.av.updateConservation(ap);
+        ap.av.updateConsensus(ap);
+        ap.av.updateStrucConsensus(ap);
+      }
     }
   }
 
@@ -816,7 +823,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   private void addServiceListeners()
   {
     final java.beans.PropertyChangeListener thisListener;
-    Instance.getDesktop().addJalviewPropertyChangeListener("services",
+    Desktop.getInstance().addJalviewPropertyChangeListener("services",
             thisListener = new java.beans.PropertyChangeListener()
             {
               @Override
@@ -847,7 +854,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               javax.swing.event.InternalFrameEvent evt)
       {
         // System.out.println("deregistering discoverer listener");
-        Instance.getDesktop().removeJalviewPropertyChangeListener("services",
+        Desktop.getInstance().removeJalviewPropertyChangeListener("services",
                 thisListener);
         closeMenuItem_actionPerformed(true);
       }
@@ -924,10 +931,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     /*
      * Show/hide annotations only enabled if annotation panel is shown
      */
-    showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
-    hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
-    showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
-    hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
+    syncAnnotationMenuItems();
+
     viewBoxesMenuItem.setSelected(av.getShowBoxes());
     viewTextMenuItem.setSelected(av.getShowText());
     showNonconservedMenuItem.setSelected(av.getShowUnconserved());
@@ -945,7 +950,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     applyToAllGroups.setState(av.getColourAppliesToAllGroups());
     showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
     showDbRefsMenuitem.setSelected(av.isShowDBRefs());
-    autoCalculate.setSelected(av.autoCalculateConsensus);
+    autoCalculate.setSelected(av.getAutoCalculateConsensusAndConservation());
     sortByTree.setSelected(av.sortByTree);
     listenToViewSelections.setSelected(av.followSelection);
 
@@ -1028,7 +1033,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void addFromFile_actionPerformed(ActionEvent e)
   {
-    Instance.getDesktop().inputLocalFileMenuItem_actionPerformed(viewport);
+    Desktop.getInstance().inputLocalFileMenuItem_actionPerformed(viewport);
   }
 
   @Override
@@ -1052,20 +1057,20 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             try
             {
               frames[i].setSelected(true);
-              Instance.getDesktop().closeAssociatedWindows();
+              Desktop.getInstance().closeAssociatedWindows();
             } catch (java.beans.PropertyVetoException ex)
             {
             }
           }
 
         }
-        Instance.getDesktop().closeAssociatedWindows();
+        Desktop.getInstance().closeAssociatedWindows();
 
         FileLoader loader = new FileLoader();
         DataSourceType protocol = fileName.startsWith("http:")
                 ? DataSourceType.URL
                 : DataSourceType.FILE;
-        loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
+        loader.loadFile(viewport, fileName, protocol, currentFileFormat);
       }
       else
       {
@@ -1081,12 +1086,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           DataSourceType protocol = (fileName.startsWith("http:")
                   ? DataSourceType.URL
                   : DataSourceType.FILE);
-          newframe = loader.LoadFileWaitTillLoaded(fileName, protocol,
+          newframe = loader.loadFileWaitTillLoaded(fileName, protocol,
                   currentFileFormat);
         }
         else
         {
-          newframe = loader.LoadFileWaitTillLoaded(fileObject,
+          newframe = loader.loadFileWaitTillLoaded(fileObject,
                   DataSourceType.FILE, currentFileFormat);
         }
 
@@ -1117,14 +1122,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void addFromText_actionPerformed(ActionEvent e)
   {
-    Instance.getDesktop()
+    Desktop.getInstance()
             .inputTextboxMenuItem_actionPerformed(viewport.getAlignPanel());
   }
 
   @Override
   public void addFromURL_actionPerformed(ActionEvent e)
   {
-    Instance.getDesktop().inputURLMenuItem_actionPerformed(viewport);
+    Desktop.getInstance().inputURLMenuItem_actionPerformed(viewport);
   }
 
   @Override
@@ -1931,7 +1936,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     StringSelection ss = new StringSelection(output);
 
-    Desktop d = Instance.getDesktop();
+    Desktop d = Desktop.getInstance();
     try
     {
       d.internalCopy = true;
@@ -1941,7 +1946,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               .setContents(new StringSelection(""), null);
 
       Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
-              Instance.getDesktop());
+              Desktop.getInstance());
     } catch (OutOfMemoryError er)
     {
       new OOMWarning("copying region", er);
@@ -2033,7 +2038,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       boolean annotationAdded = false;
       AlignmentI alignment = null;
 
-      Desktop d = Instance.getDesktop();
+      Desktop d = Desktop.getInstance();
 
       if (d.jalviewClipboard != null)
       {
@@ -2342,7 +2347,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               DEFAULT_HEIGHT);
       String newtitle = new String("Flanking alignment");
 
-      Desktop d = Instance.getDesktop();
+      Desktop d = Desktop.getInstance();
 
       if (d.jalviewClipboard != null && d.jalviewClipboard[2] != null)
       {
@@ -2917,7 +2922,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void gatherViews_actionPerformed(ActionEvent e)
   {
-    Instance.getDesktop().gatherViews(this);
+    Desktop.getInstance().gatherViews(this);
   }
 
   /**
@@ -3295,13 +3300,20 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     final boolean setVisible = annotationPanelMenuItem.isSelected();
     viewport.setShowAnnotation(setVisible);
-    this.showAllSeqAnnotations.setEnabled(setVisible);
-    this.hideAllSeqAnnotations.setEnabled(setVisible);
-    this.showAllAlAnnotations.setEnabled(setVisible);
-    this.hideAllAlAnnotations.setEnabled(setVisible);
+    syncAnnotationMenuItems();
     alignPanel.updateLayout();
   }
 
+  private void syncAnnotationMenuItems()
+  {
+    final boolean setVisible = annotationPanelMenuItem.isSelected();
+    showAllSeqAnnotations.setEnabled(setVisible);
+    hideAllSeqAnnotations.setEnabled(setVisible);
+    showAllAlAnnotations.setEnabled(setVisible);
+    hideAllAlAnnotations.setEnabled(setVisible);
+  }
+
+
   @Override
   public void alignmentProperties()
   {
@@ -3367,7 +3379,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     Desktop.addInternalFrame(frame, MessageManager
             .formatMessage("label.overview_params", new Object[]
             { this.getTitle() }), true, frame.getWidth(), frame.getHeight(),
-            true, true);
+            true, true, "overview");
     frame.pack();
     frame.setLayer(JLayeredPane.PALETTE_LAYER);
     frame.addInternalFrameListener(
@@ -3647,8 +3659,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void autoCalculate_actionPerformed(ActionEvent e)
   {
-    viewport.autoCalculateConsensus = autoCalculate.isSelected();
-    if (viewport.autoCalculateConsensus)
+    viewport.setAutoCalculateConsensusAndConservation(autoCalculate.isSelected());
+    if (viewport.getAutoCalculateConsensusAndConservation())
     {
       viewport.firePropertyChange("alignment", null,
               viewport.getAlignment().getSequences());
@@ -4218,7 +4230,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                 // boolean new_sspred = false;
                 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
                 {
-                  Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
+                  Jws2Discoverer jws2servs = Jws2Discoverer.getInstance();
                   if (jws2servs != null)
                   {
                     if (jws2servs.hasServices())
@@ -4429,7 +4441,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
       {
         final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
-        viewport.openSplitFrame(af, new Alignment(seqs));
+        AlignViewport.openSplitFrame(this, af, new Alignment(seqs));
       }
       else
       {
@@ -4462,7 +4474,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     // BH 2018
     return avc.parseFeaturesFile(file, sourceType,
-            Cache.getDefault("RELAXEDSEQIDMATCHING", false));
+            Cache.getDefault(Preferences.RELAXEDSEQIDMATCHING, false));
 
   }
 
@@ -4605,7 +4617,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             if (filesmatched.size() > 0)
             {
               boolean autoAssociate = Cache
-                      .getDefault("AUTOASSOCIATE_PDBANDSEQS", false);
+                      .getDefault(Preferences.AUTOASSOCIATE_PDBANDSEQS, false);
               if (!autoAssociate)
               {
                 String msg = MessageManager.formatMessage(
@@ -4628,10 +4640,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                   // associating PDB files which have no IDs.
                   for (SequenceI toassoc : (SequenceI[]) fm[2])
                   {
-                    PDBEntry pe = new AssociatePdbFileWithSeq()
+                    PDBEntry pe = AssociatePdbFileWithSeq
                             .associatePdbWithSeq(fm[0].toString(),
-                                    (DataSourceType) fm[1], toassoc, false,
-                                    Instance.getDesktop());
+                                    (DataSourceType) fm[1], toassoc, false);
                     if (pe != null)
                     {
                       System.err.println("Associated file : "
@@ -4801,17 +4812,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           }
           else
           {
-            new FileLoader().LoadFile(viewport, file, sourceType, format);
+            new FileLoader().loadFile(viewport, file, sourceType, format);
           }
         }
       }
       if (isAnnotation)
       {
-
-        alignPanel.adjustAnnotationHeight();
-        viewport.updateSequenceIdColours();
-        buildSortByAnnotationScoresMenu();
-        alignPanel.paintAlignment(true, true);
+        updateForAnnotations();
       }
     } catch (Exception ex)
     {
@@ -4840,6 +4847,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   /**
+   * Do all updates necessary after an annotation file such as jnet. Also called
+   * from Jalview.loadAppletParams for "annotations", "jnetFile"
+   */
+  public void updateForAnnotations()
+  {
+    alignPanel.adjustAnnotationHeight();
+    viewport.updateSequenceIdColours();
+    buildSortByAnnotationScoresMenu();
+    alignPanel.paintAlignment(true, true);
+  }
+
+  /**
    * Method invoked by the ChangeListener on the tabbed pane, in other words
    * when a different tabbed pane is selected by the user or programmatically.
    */
@@ -4922,6 +4941,32 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   /**
+   * Change the display state for the given feature groups -- Added by BH from
+   * JalviewLite
+   * 
+   * @param groups
+   *          list of group strings
+   * @param state
+   *          visible or invisible
+   */
+  public void setFeatureGroupState(String[] groups, boolean state)
+  {
+    jalview.api.FeatureRenderer fr = null;
+    viewport.setShowSequenceFeatures(true);
+    if (alignPanel != null
+            && (fr = alignPanel.getFeatureRenderer()) != null)
+    {
+
+      fr.setGroupVisibility(Arrays.asList(groups), state);
+      alignPanel.getSeqPanel().seqCanvas.repaint();
+      if (alignPanel.overviewPanel != null)
+      {
+        alignPanel.overviewPanel.updateOverviewImage();
+      }
+    }
+  }
+
+  /**
    * Open the dialog for regex description parsing.
    */
   @Override
@@ -5065,14 +5110,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       @Override
       public void run()
       {
-        final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
-                .getSequenceFetcherSingleton();
         javax.swing.SwingUtilities.invokeLater(new Runnable()
         {
           @Override
           public void run()
           {
-            String[] dbclasses = sf.getNonAlignmentSources();
+            String[] dbclasses = jalview.ws.SequenceFetcher.getInstance()
+                    .getNonAlignmentSources();
             List<DbSourceProxy> otherdb;
             JMenu dfetch = new JMenu();
             JMenu ifetch = new JMenu();
@@ -5082,7 +5126,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             int dbi = 0;
             for (String dbclass : dbclasses)
             {
-              otherdb = sf.getSourceProxy(dbclass);
+              otherdb = jalview.ws.SequenceFetcher.getInstance()
+                      .getSourceProxy(dbclass);
               // add a single entry for this class, or submenu allowing 'fetch
               // all' or pick one
               if (otherdb == null || otherdb.size() < 1)
@@ -5755,6 +5800,67 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
   }
 
+  /**
+   * BH 2019 from JalviewLite
+   * 
+   * get sequence feature groups that are hidden or shown
+   * 
+   * @param visible
+   *          true is visible
+   * @return list
+   */
+  public String[] getFeatureGroupsOfState(boolean visible)
+  {
+    jalview.api.FeatureRenderer fr = null;
+    if (alignPanel != null
+            && (fr = alignPanel
+                    .getFeatureRenderer()) != null)
+    {
+      List<String> gps = fr.getGroups(visible);
+      String[] _gps = gps.toArray(new String[gps.size()]);
+      return _gps;
+    }
+    return null;
+  }
+
+  public void scrollTo(int row, int column)
+  {
+    alignPanel.getSeqPanel().scrollTo(row, column);
+  }
+
+  public void scrollToRow(int row)
+  {
+    alignPanel.getSeqPanel().scrollToRow(row);
+  }
+
+  public void scrollToColumn(int column)
+  {
+    alignPanel.getSeqPanel().scrollToColumn(column);
+  }
+
+  /**
+   * 
+   * @return list of feature groups on the view
+   */
+  public String[] getFeatureGroups()
+  {
+    jalview.api.FeatureRenderer fr = null;
+    if (alignPanel != null
+            && (fr = alignPanel.getFeatureRenderer()) != null)
+    {
+      List<String> gps = fr.getFeatureGroups();
+      String[] _gps = gps.toArray(new String[gps.size()]);
+      return _gps;
+    }
+    return null;
+  }
+
+  public void select(SequenceGroup sel, ColumnSelection csel,
+          HiddenColumns hidden)
+  {
+    alignPanel.getSeqPanel().selection(sel, csel, hidden, null);
+  }
+
 }
 
 class PrintThread extends Thread
@@ -5793,4 +5899,5 @@ class PrintThread extends Thread
       }
     }
   }
+
 }