JAL-3446 from applet, JAL-3584 tooltip fixes <br> and allows different
[jalview.git] / src / jalview / jbgui / GAlignFrame.java
index 075b490..c67da2b 100755 (executable)
@@ -26,7 +26,9 @@ import jalview.analysis.GeneticCodes;
 import jalview.api.SplitContainerI;
 import jalview.bin.Cache;
 import jalview.gui.JvSwingUtils;
+import jalview.gui.PaintRefresher;
 import jalview.gui.Preferences;
+import jalview.gui.TreePanel;
 import jalview.io.FileFormats;
 import jalview.schemes.ResidueColourScheme;
 import jalview.util.MessageManager;
@@ -34,6 +36,7 @@ import jalview.util.Platform;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
+import java.awt.Component;
 import java.awt.GridLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -42,7 +45,9 @@ import java.awt.event.FocusEvent;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.swing.BorderFactory;
@@ -61,15 +66,18 @@ import javax.swing.event.ChangeEvent;
 import javax.swing.event.MenuEvent;
 import javax.swing.event.MenuListener;
 
+@SuppressWarnings("serial")
 public class GAlignFrame extends JInternalFrame
 {
   protected JMenuBar alignFrameMenuBar = new JMenuBar();
 
   protected JMenuItem closeMenuItem = new JMenuItem();
 
-  protected JMenu webService = new JMenu();
+  public JMenu webService = new JMenu();// BH 2019 was protected, but not
+                                        // sufficient for AlignFrame thread run
 
-  protected JMenuItem webServiceNoServices;
+  public JMenuItem webServiceNoServices;// BH 2019 was protected, but not
+                                        // sufficient for AlignFrame thread run
 
   protected JCheckBoxMenuItem viewBoxesMenuItem = new JCheckBoxMenuItem();
 
@@ -77,7 +85,9 @@ public class GAlignFrame extends JInternalFrame
 
   protected JMenu sortByAnnotScore = new JMenu();
 
-  protected JLabel statusBar = new JLabel();
+  public JLabel statusBar = new JLabel(); // BH 2019 was protected, but not
+                                          // sufficient for
+                                          // AlignFrame.printWriter
 
   protected JMenu outputTextboxMenu = new JMenu();
 
@@ -199,6 +209,8 @@ public class GAlignFrame extends JInternalFrame
 
   protected JCheckBoxMenuItem applyAutoAnnotationSettings = new JCheckBoxMenuItem();
 
+  protected JMenuItem openFeatureSettings;
+
   private SequenceAnnotationOrder annotationSortOrder;
 
   private boolean showAutoCalculatedAbove = false;
@@ -211,6 +223,11 @@ public class GAlignFrame extends JInternalFrame
   {
     try
     {
+
+      // for Web-page embedding using id=align-frame-div
+      setName(Platform.getAppID("alignment"));
+
+
       jbInit();
       setJMenuBar(alignFrameMenuBar);
 
@@ -224,7 +241,7 @@ public class GAlignFrame extends JInternalFrame
           @Override
           public void actionPerformed(ActionEvent e)
           {
-            outputText_actionPerformed(e);
+            outputText_actionPerformed(e.getActionCommand());
           }
         });
 
@@ -235,7 +252,7 @@ public class GAlignFrame extends JInternalFrame
       System.err.println(e.toString());
     }
 
-    if (!Platform.isAMac())
+    if (Platform.allowMnemonics()) // was "not mac and not JS"
     {
       closeMenuItem.setMnemonic('C');
       outputTextboxMenu.setMnemonic('T');
@@ -259,7 +276,7 @@ public class GAlignFrame extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        saveAs_actionPerformed(e);
+        saveAs_actionPerformed();
       }
     };
 
@@ -969,7 +986,7 @@ public class GAlignFrame extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        copy_actionPerformed(e);
+        copy_actionPerformed();
       }
     };
     addMenuActionAndAccelerator(keyStroke, copy, al);
@@ -982,7 +999,7 @@ public class GAlignFrame extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        cut_actionPerformed(e);
+        cut_actionPerformed();
       }
     };
     addMenuActionAndAccelerator(keyStroke, cut, al);
@@ -994,7 +1011,7 @@ public class GAlignFrame extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        delete_actionPerformed(e);
+        delete_actionPerformed();
       }
     });
 
@@ -1161,6 +1178,24 @@ public class GAlignFrame extends JInternalFrame
       @Override
       public void menuSelected(MenuEvent e)
       {
+        enableSortMenuOptions();
+      }
+
+      @Override
+      public void menuDeselected(MenuEvent e)
+      {
+      }
+
+      @Override
+      public void menuCanceled(MenuEvent e)
+      {
+      }
+    });
+    sortByTreeMenu.addMenuListener(new MenuListener()
+    {
+      @Override
+      public void menuSelected(MenuEvent e)
+      {
         buildTreeSortMenu();
       }
 
@@ -1227,8 +1262,8 @@ public class GAlignFrame extends JInternalFrame
     /*
      * Translate as cDNA with sub-menu of translation tables
      */
-    showTranslation.setText(MessageManager
-            .getString("label.translate_cDNA"));
+    showTranslation
+            .setText(MessageManager.getString("label.translate_cDNA"));
     boolean first = true;
     for (final GeneticCodeI table : GeneticCodes.getInstance()
             .getCodeTables())
@@ -1298,7 +1333,7 @@ public class GAlignFrame extends JInternalFrame
       }
     });
 
-    JMenuItem openFeatureSettings = new JMenuItem(
+    openFeatureSettings = new JMenuItem(
             MessageManager.getString("action.feature_settings"));
     openFeatureSettings.addActionListener(new ActionListener()
     {
@@ -1308,6 +1343,10 @@ public class GAlignFrame extends JInternalFrame
         featureSettings_actionPerformed(e);
       }
     });
+
+    /*
+     * add sub-menu of database we can fetch from
+     */
     JMenuItem fetchSequence = new JMenuItem(
             MessageManager.getString("label.fetch_sequences"));
     fetchSequence.addActionListener(new ActionListener()
@@ -1315,7 +1354,7 @@ public class GAlignFrame extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        fetchSequence_actionPerformed(e);
+        fetchSequence_actionPerformed();
       }
     });
 
@@ -1329,7 +1368,8 @@ public class GAlignFrame extends JInternalFrame
         associatedData_actionPerformed(e);
       }
     });
-    loadVcf = new JMenuItem(MessageManager.getString("label.load_vcf_file"));
+    loadVcf = new JMenuItem(
+            MessageManager.getString("label.load_vcf_file"));
     loadVcf.setToolTipText(MessageManager.getString("label.load_vcf"));
     loadVcf.addActionListener(new ActionListener()
     {
@@ -1696,8 +1736,8 @@ public class GAlignFrame extends JInternalFrame
     });
     JMenuItem selectHighlighted = new JMenuItem(
             MessageManager.getString("action.select_highlighted_columns"));
-    selectHighlighted.setToolTipText(
-            MessageManager.getString("tooltip.select_highlighted_columns"));
+    selectHighlighted.setToolTipText(JvSwingUtils.wrapTooltip(true, 
+            MessageManager.getString("tooltip.select_highlighted_columns")));
     al = new ActionListener()
     {
       @Override
@@ -1720,10 +1760,13 @@ public class GAlignFrame extends JInternalFrame
     alignFrameMenuBar.add(selectMenu);
     alignFrameMenuBar.add(viewMenu);
     alignFrameMenuBar.add(annotationsMenu);
+    alignFrameMenuBar.add(calculateMenu);
     alignFrameMenuBar.add(formatMenu);
     alignFrameMenuBar.add(colourMenu);
-    alignFrameMenuBar.add(calculateMenu);
-    alignFrameMenuBar.add(webService);
+    if (!Platform.isJS())
+    {
+      alignFrameMenuBar.add(webService);
+    }
 
     fileMenu.add(fetchSequence);
     fileMenu.add(addSequenceMenu);
@@ -1741,7 +1784,10 @@ public class GAlignFrame extends JInternalFrame
     fileMenu.add(exportAnnotations);
     fileMenu.add(loadTreeMenuItem);
     fileMenu.add(associatedData);
-    fileMenu.add(loadVcf);
+    if (!Platform.isJS())
+    {
+      fileMenu.add(loadVcf);
+    }
     fileMenu.addSeparator();
     fileMenu.add(closeMenuItem);
 
@@ -1836,17 +1882,26 @@ public class GAlignFrame extends JInternalFrame
     calculateMenu.addSeparator();
     calculateMenu.add(expandAlignment);
     calculateMenu.add(extractScores);
-    calculateMenu.addSeparator();
-    calculateMenu.add(runGroovy);
+    if (!Platform.isJS())
+    {
+      calculateMenu.addSeparator();
+      calculateMenu.add(runGroovy);
+    }
 
     webServiceNoServices = new JMenuItem(
             MessageManager.getString("label.no_services"));
     webService.add(webServiceNoServices);
-    exportImageMenu.add(htmlMenuItem);
+    if (!Platform.isJS())
+    {
+      exportImageMenu.add(htmlMenuItem);
+    }
     exportImageMenu.add(epsFile);
     exportImageMenu.add(createPNG);
-    exportImageMenu.add(createBioJS);
-    exportImageMenu.add(createSVG);
+    if (!Platform.isJS())
+    {
+      exportImageMenu.add(createBioJS);
+      exportImageMenu.add(createSVG);
+    }
     addSequenceMenu.add(addFromFile);
     addSequenceMenu.add(addFromText);
     addSequenceMenu.add(addFromURL);
@@ -1887,6 +1942,10 @@ public class GAlignFrame extends JInternalFrame
     // selectMenu.add(listenToViewSelections);
   }
 
+  protected void enableSortMenuOptions()
+  {
+  }
+  
   protected void loadVcf_actionPerformed()
   {
   }
@@ -2184,7 +2243,7 @@ public class GAlignFrame extends JInternalFrame
   {
   }
 
-  protected void outputText_actionPerformed(ActionEvent e)
+  protected void outputText_actionPerformed(String formatName)
   {
   }
 
@@ -2350,15 +2409,15 @@ public class GAlignFrame extends JInternalFrame
   {
   }
 
-  protected void copy_actionPerformed(ActionEvent e)
+  protected void copy_actionPerformed()
   {
   }
 
-  protected void cut_actionPerformed(ActionEvent e)
+  protected void cut_actionPerformed()
   {
   }
 
-  protected void delete_actionPerformed(ActionEvent e)
+  protected void delete_actionPerformed()
   {
   }
 
@@ -2442,7 +2501,7 @@ public class GAlignFrame extends JInternalFrame
   {
   }
 
-  protected void saveAs_actionPerformed(ActionEvent e)
+  protected void saveAs_actionPerformed()
   {
   }
 
@@ -2470,7 +2529,7 @@ public class GAlignFrame extends JInternalFrame
 
   }
 
-  public void fetchSequence_actionPerformed(ActionEvent e)
+  public void fetchSequence_actionPerformed()
   {
 
   }
@@ -2685,4 +2744,6 @@ public class GAlignFrame extends JInternalFrame
   protected void showComplement_actionPerformed(boolean complement)
   {
   }
+  
+
 }