JAL-3253 simpler coding using MouseAdapter. Using JLabel.setOpaque(true)
[jalview.git] / src / jalview / jbgui / GAlignFrame.java
index 5940172..9de31ab 100755 (executable)
 package jalview.jbgui;
 
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
+import jalview.analysis.GeneticCodeI;
+import jalview.analysis.GeneticCodes;
 import jalview.api.SplitContainerI;
 import jalview.bin.Cache;
+import jalview.bin.Jalview;
 import jalview.gui.JvSwingUtils;
 import jalview.gui.Preferences;
 import jalview.io.FileFormats;
+import jalview.schemes.ResidueColourScheme;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 
@@ -59,15 +63,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();
 
@@ -75,7 +82,9 @@ public class GAlignFrame extends JInternalFrame
 
   protected JMenu sortByAnnotScore = new JMenu();
 
-  public JLabel statusBar = new JLabel();
+  public JLabel statusBar = new JLabel(); // BH 2019 was protected, but not
+                                          // sufficient for
+                                          // AlignFrame.printWriter
 
   protected JMenu outputTextboxMenu = new JMenu();
 
@@ -123,7 +132,7 @@ public class GAlignFrame extends JInternalFrame
 
   protected JMenuItem modifyPID;
 
-  protected JMenuItem annotationColour;
+  protected JRadioButtonMenuItem annotationColour;
 
   protected JMenu sortByTreeMenu = new JMenu();
 
@@ -137,7 +146,7 @@ public class GAlignFrame extends JInternalFrame
 
   protected JCheckBoxMenuItem showDbRefsMenuitem = new JCheckBoxMenuItem();
 
-  protected JMenuItem showTranslation = new JMenuItem();
+  protected JMenu showTranslation = new JMenu();
 
   protected JMenuItem showReverse = new JMenuItem();
 
@@ -169,7 +178,7 @@ public class GAlignFrame extends JInternalFrame
 
   protected JCheckBoxMenuItem hiddenMarkers = new JCheckBoxMenuItem();
 
-  protected JTabbedPane tabbedPane = jalview.jbgui.GDesktop.createTabbedPane();
+  protected JTabbedPane tabbedPane = new JTabbedPane();
 
   protected JMenuItem reload = new JMenuItem();
 
@@ -196,14 +205,14 @@ public class GAlignFrame extends JInternalFrame
   protected JCheckBoxMenuItem normaliseSequenceLogo = new JCheckBoxMenuItem();
 
   protected JCheckBoxMenuItem applyAutoAnnotationSettings = new JCheckBoxMenuItem();
-  
+
   protected JMenuItem openFeatureSettings;
 
   private SequenceAnnotationOrder annotationSortOrder;
 
   private boolean showAutoCalculatedAbove = false;
 
-  private Map<KeyStroke, JMenuItem> accelerators = new HashMap<KeyStroke, JMenuItem>();
+  private Map<KeyStroke, JMenuItem> accelerators = new HashMap<>();
 
   private SplitContainerI splitFrame;
 
@@ -211,6 +220,10 @@ public class GAlignFrame extends JInternalFrame
   {
     try
     {
+
+      // for Web-page embedding using id=align-frame-div
+      setName(Jalview.getAppID("alignment"));
+
       jbInit();
       setJMenuBar(alignFrameMenuBar);
 
@@ -532,7 +545,11 @@ public class GAlignFrame extends JInternalFrame
 
     this.getContentPane().setLayout(new BorderLayout());
     alignFrameMenuBar.setFont(new java.awt.Font("Verdana", 0, 11));
-    statusBar.setBackground(Color.white);
+    // statusBar.setBackground(Color.white); BH 2019.08.01 -- this does nothing,
+    // as the label is not opaque
+    statusBar.setOpaque(true);// BH 2019.07.01 -- setting a label opaque avoids
+                              // frame repaint in SwingJS and has no effect in
+                              // Java
     statusBar.setFont(new java.awt.Font("Verdana", 0, 11));
     statusBar.setBorder(BorderFactory.createLineBorder(Color.black));
     statusBar.setText(MessageManager.getString("label.status_bar"));
@@ -543,7 +560,7 @@ public class GAlignFrame extends JInternalFrame
     annotationPanelMenuItem
             .setText(MessageManager.getString("label.show_annotations"));
     annotationPanelMenuItem
-            .setState(Cache.getDefault("SHOW_ANNOTATIONS", true));
+            .setState(Cache.getDefault(Preferences.SHOW_ANNOTATIONS, true));
     annotationPanelMenuItem.addActionListener(new ActionListener()
     {
       @Override
@@ -1052,7 +1069,7 @@ public class GAlignFrame extends JInternalFrame
     });
     seqLimits.setText(
             MessageManager.getString("label.show_sequence_limits"));
-    seqLimits.setState(jalview.bin.Cache.getDefault("SHOW_JVSUFFIX", true));
+    seqLimits.setState(jalview.bin.Cache.getDefault(Preferences.SHOW_JVSUFFIX, true));
     seqLimits.addActionListener(new ActionListener()
     {
       @Override
@@ -1203,7 +1220,7 @@ public class GAlignFrame extends JInternalFrame
 
     padGapsMenuitem.setText(MessageManager.getString("label.pad_gaps"));
     padGapsMenuitem
-            .setState(jalview.bin.Cache.getDefault("PAD_GAPS", false));
+            .setState(jalview.bin.Cache.getDefault(Preferences.PAD_GAPS, false));
     padGapsMenuitem.addActionListener(new ActionListener()
     {
       @Override
@@ -1223,16 +1240,32 @@ public class GAlignFrame extends JInternalFrame
         vamsasStore_actionPerformed(e);
       }
     });
+
+    /*
+     * Translate as cDNA with sub-menu of translation tables
+     */
     showTranslation
             .setText(MessageManager.getString("label.translate_cDNA"));
-    showTranslation.addActionListener(new ActionListener()
+    boolean first = true;
+    for (final GeneticCodeI table : GeneticCodes.getCodeTables())
     {
-      @Override
-      public void actionPerformed(ActionEvent e)
+      JMenuItem item = new JMenuItem(table.getId() + " " + table.getName());
+      showTranslation.add(item);
+      item.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          showTranslation_actionPerformed(table);
+        }
+      });
+      if (first)
       {
-        showTranslation_actionPerformed(e);
+        showTranslation.addSeparator();
       }
-    });
+      first = false;
+    }
+
     showReverse.setText(MessageManager.getString("label.reverse"));
     showReverse.addActionListener(new ActionListener()
     {
@@ -1316,7 +1349,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()
     {
@@ -1329,7 +1363,7 @@ public class GAlignFrame extends JInternalFrame
     autoCalculate.setText(
             MessageManager.getString("label.autocalculate_consensus"));
     autoCalculate.setState(
-            jalview.bin.Cache.getDefault("AUTO_CALC_CONSENSUS", true));
+            jalview.bin.Cache.getDefault(Preferences.AUTO_CALC_CONSENSUS, true));
     autoCalculate.addActionListener(new ActionListener()
     {
       @Override
@@ -1343,7 +1377,8 @@ public class GAlignFrame extends JInternalFrame
     sortByTree.setToolTipText("<html>" + MessageManager.getString(
             "label.enable_automatically_sort_alignment_when_open_new_tree"));
     sortByTree
-            .setState(jalview.bin.Cache.getDefault("SORT_BY_TREE", false));
+            .setState(jalview.bin.Cache.getDefault(Preferences.SORT_BY_TREE,
+                    false));
     sortByTree.addActionListener(new ActionListener()
     {
       @Override
@@ -1964,8 +1999,9 @@ public class GAlignFrame extends JInternalFrame
       }
     });
 
-    annotationColour = new JMenuItem(
+    annotationColour = new JRadioButtonMenuItem(
             MessageManager.getString("action.by_annotation"));
+    annotationColour.setName(ResidueColourScheme.ANNOTATION_COLOUR);
     annotationColour.addActionListener(new ActionListener()
     {
       @Override
@@ -2461,7 +2497,7 @@ public class GAlignFrame extends JInternalFrame
 
   }
 
-  public void showTranslation_actionPerformed(ActionEvent e)
+  public void showTranslation_actionPerformed(GeneticCodeI codeTable)
   {
 
   }