JAL-3288 override JInternalFrame.setSelected() to avoid cancelling menus
[jalview.git] / src / jalview / gui / SplitFrame.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.gui;
22
23 import jalview.api.SplitContainerI;
24 import jalview.datamodel.AlignmentI;
25 import jalview.jbgui.GAlignFrame;
26 import jalview.jbgui.GSplitFrame;
27 import jalview.structure.StructureSelectionManager;
28 import jalview.util.Platform;
29 import jalview.viewmodel.AlignmentViewport;
30
31 import java.awt.Component;
32 import java.awt.event.ActionEvent;
33 import java.awt.event.ActionListener;
34 import java.awt.event.KeyAdapter;
35 import java.awt.event.KeyEvent;
36 import java.awt.event.KeyListener;
37 import java.beans.PropertyVetoException;
38 import java.util.Arrays;
39 import java.util.List;
40 import java.util.Map.Entry;
41
42 import javax.swing.AbstractAction;
43 import javax.swing.InputMap;
44 import javax.swing.JComponent;
45 import javax.swing.JMenuItem;
46 import javax.swing.KeyStroke;
47 import javax.swing.event.InternalFrameAdapter;
48 import javax.swing.event.InternalFrameEvent;
49
50 /**
51  * An internal frame on the desktop that hosts a horizontally split view of
52  * linked DNA and Protein alignments. Additional views can be created in linked
53  * pairs, expanded to separate split frames, or regathered into a single frame.
54  * <p>
55  * (Some) operations on each alignment are automatically mirrored on the other.
56  * These include mouseover (highlighting), sequence and column selection,
57  * sequence ordering and sorting, and grouping, colouring and sorting by tree.
58  * 
59  * @author gmcarstairs
60  *
61  */
62 public class SplitFrame extends GSplitFrame implements SplitContainerI
63 {
64   private static final int WINDOWS_INSETS_WIDTH = 28; // tbc
65
66   private static final int MAC_INSETS_WIDTH = 28;
67
68   private static final int WINDOWS_INSETS_HEIGHT = 50; // tbc
69
70   private static final int MAC_INSETS_HEIGHT = 50;
71
72   private static final int DESKTOP_DECORATORS_HEIGHT = 65;
73
74   private static final long serialVersionUID = 1L;
75
76   public SplitFrame(GAlignFrame top, GAlignFrame bottom)
77   {
78     super(top, bottom);
79     init();
80   }
81
82   /**
83    * Initialise this frame.
84    */
85   protected void init()
86   {
87     getTopFrame().setSplitFrame(this);
88     getBottomFrame().setSplitFrame(this);
89     getTopFrame().setVisible(true);
90     getBottomFrame().setVisible(true);
91
92     ((AlignFrame) getTopFrame()).getViewport().setCodingComplement(
93             ((AlignFrame) getBottomFrame()).getViewport());
94
95     /*
96      * estimate width and height of SplitFrame; this.getInsets() doesn't seem to
97      * give the full additional size (a few pixels short)
98      */
99     int widthFudge = Platform.isAMac() ? MAC_INSETS_WIDTH
100             : WINDOWS_INSETS_WIDTH;
101     int heightFudge = Platform.isAMac() ? MAC_INSETS_HEIGHT
102             : WINDOWS_INSETS_HEIGHT;
103     int width = ((AlignFrame) getTopFrame()).getWidth() + widthFudge;
104     int height = ((AlignFrame) getTopFrame()).getHeight()
105             + ((AlignFrame) getBottomFrame()).getHeight() + DIVIDER_SIZE
106             + heightFudge;
107     height = fitHeightToDesktop(height);
108     setSize(width, height);
109
110     adjustLayout();
111
112     addCloseFrameListener();
113
114     addKeyListener();
115
116     addKeyBindings();
117
118     addCommandListeners();
119   }
120
121   /**
122    * Reduce the height if too large to fit in the Desktop. Also adjust the
123    * divider location in proportion.
124    * 
125    * @param height
126    *          in pixels
127    * @return original or reduced height
128    */
129   public int fitHeightToDesktop(int height)
130   {
131     // allow about 65 pixels for Desktop decorators on Windows
132
133     int newHeight = Math.min(height,
134             Desktop.instance.getHeight() - DESKTOP_DECORATORS_HEIGHT);
135     if (newHeight != height)
136     {
137       int oldDividerLocation = getDividerLocation();
138       setDividerLocation(oldDividerLocation * newHeight / height);
139     }
140     return newHeight;
141   }
142
143   /**
144    * Set the top and bottom frames to listen to each others Commands (e.g. Edit,
145    * Order).
146    */
147   protected void addCommandListeners()
148   {
149     // TODO if CommandListener is only ever 1:1 for complementary views,
150     // may change broadcast pattern to direct messaging (more efficient)
151     final StructureSelectionManager ssm = StructureSelectionManager
152             .getStructureSelectionManager(Desktop.instance);
153     ssm.addCommandListener(((AlignFrame) getTopFrame()).getViewport());
154     ssm.addCommandListener(((AlignFrame) getBottomFrame()).getViewport());
155   }
156
157   /**
158    * Do any tweaking and twerking of the layout wanted.
159    */
160   public void adjustLayout()
161   {
162     /*
163      * Ensure sequence ids are the same width so sequences line up
164      */
165     int w1 = ((AlignFrame) getTopFrame()).getViewport().getIdWidth();
166     int w2 = ((AlignFrame) getBottomFrame()).getViewport().getIdWidth();
167     int w3 = Math.max(w1, w2);
168     if (w1 != w3)
169     {
170       ((AlignFrame) getTopFrame()).getViewport().setIdWidth(w3);
171     }
172     if (w2 != w3)
173     {
174       ((AlignFrame) getBottomFrame()).getViewport().setIdWidth(w3);
175     }
176
177     /*
178      * Scale protein to either 1 or 3 times character width of dna
179      */
180     final AlignViewport topViewport = ((AlignFrame) getTopFrame()).viewport;
181     final AlignViewport bottomViewport = ((AlignFrame) getBottomFrame()).viewport;
182     final AlignmentI topAlignment = topViewport.getAlignment();
183     final AlignmentI bottomAlignment = bottomViewport.getAlignment();
184     AlignmentViewport cdna = topAlignment.isNucleotide() ? topViewport
185             : (bottomAlignment.isNucleotide() ? bottomViewport : null);
186     AlignmentViewport protein = !topAlignment.isNucleotide() ? topViewport
187             : (!bottomAlignment.isNucleotide() ? bottomViewport : null);
188     if (protein != null && cdna != null)
189     {
190       int scale = protein.isScaleProteinAsCdna() ? 3 : 1;
191       protein.setCharWidth(scale * cdna.getViewStyle().getCharWidth());
192     }
193   }
194
195   /**
196    * Adjusts the divider for a sensible split of the real estate (for example,
197    * when many transcripts are shown with a single protein). This should only be
198    * called after the split pane has been laid out (made visible) so it has a
199    * height. The aim is to avoid unnecessary vertical scroll bars, while
200    * ensuring that at least 2 sequences are visible in each panel.
201    * <p>
202    * Once laid out, the user may choose to customise as they wish, so this
203    * method is not called again after the initial layout.
204    */
205   protected void adjustInitialLayout()
206   {
207     AlignFrame topFrame = (AlignFrame) getTopFrame();
208     AlignFrame bottomFrame = (AlignFrame) getBottomFrame();
209
210     /*
211      * recompute layout of top and bottom panels to reflect their
212      * actual (rather than requested) height
213      */
214     topFrame.alignPanel.adjustAnnotationHeight();
215     bottomFrame.alignPanel.adjustAnnotationHeight();
216
217     final AlignViewport topViewport = topFrame.viewport;
218     final AlignViewport bottomViewport = bottomFrame.viewport;
219     final AlignmentI topAlignment = topViewport.getAlignment();
220     final AlignmentI bottomAlignment = bottomViewport.getAlignment();
221     boolean topAnnotations = topViewport.isShowAnnotation();
222     boolean bottomAnnotations = bottomViewport.isShowAnnotation();
223     // TODO need number of visible sequences here, not #sequences - how?
224     int topCount = topAlignment.getHeight();
225     int bottomCount = bottomAlignment.getHeight();
226     int topCharHeight = topViewport.getViewStyle().getCharHeight();
227     int bottomCharHeight = bottomViewport.getViewStyle().getCharHeight();
228
229     /*
230      * calculate the minimum ratio that leaves at least the height 
231      * of two sequences (after rounding) visible in the top panel
232      */
233     int topPanelHeight = topFrame.getHeight();
234     int bottomPanelHeight = bottomFrame.getHeight();
235     int topSequencesHeight = topFrame.alignPanel.getSeqPanel().seqCanvas
236             .getHeight();
237     int topPanelMinHeight = topPanelHeight
238             - Math.max(0, topSequencesHeight - 3 * topCharHeight);
239     double totalHeight = (double) topPanelHeight + bottomPanelHeight;
240     double minRatio = topPanelMinHeight / totalHeight;
241
242     /*
243      * calculate the maximum ratio that leaves at least the height 
244      * of two sequences (after rounding) visible in the bottom panel
245      */
246     int bottomSequencesHeight = bottomFrame.alignPanel.getSeqPanel().seqCanvas
247             .getHeight();
248     int bottomPanelMinHeight = bottomPanelHeight
249             - Math.max(0, bottomSequencesHeight - 3 * bottomCharHeight);
250     double maxRatio = (totalHeight - bottomPanelMinHeight) / totalHeight;
251
252     /*
253      * estimate ratio of (topFrameContent / bottomFrameContent)
254      */
255     int insets = Platform.isAMac() ? MAC_INSETS_HEIGHT
256             : WINDOWS_INSETS_HEIGHT;
257     // allow 3 'rows' for scale, scrollbar, status bar
258     int topHeight = insets + (3 + topCount) * topCharHeight
259             + (topAnnotations ? topViewport.calcPanelHeight() : 0);
260     int bottomHeight = insets + (3 + bottomCount) * bottomCharHeight
261             + (bottomAnnotations ? bottomViewport.calcPanelHeight() : 0);
262     double ratio = ((double) topHeight)
263             / (double) (topHeight + bottomHeight);
264
265     /*
266      * limit ratio to avoid concealing all sequences
267      */
268     ratio = Math.min(ratio, maxRatio);
269     ratio = Math.max(ratio, minRatio);
270     setRelativeDividerLocation(ratio);
271   }
272
273   /**
274    * Add a listener to tidy up when the frame is closed.
275    */
276   protected void addCloseFrameListener()
277   {
278     addInternalFrameListener(new InternalFrameAdapter()
279     {
280       @Override
281       public void internalFrameClosed(InternalFrameEvent evt)
282       {
283         close();
284       };
285     });
286   }
287
288   /**
289    * Add a key listener that delegates to whichever split component the mouse is
290    * in (or does nothing if neither).
291    */
292   protected void addKeyListener()
293   {
294     addKeyListener(new KeyAdapter()
295     {
296
297       @Override
298       public void keyPressed(KeyEvent e)
299       {
300         AlignFrame af = (AlignFrame) getFrameAtMouse();
301
302         /*
303          * Intercept and override any keys here if wanted.
304          */
305         if (!overrideKey(e, af))
306         {
307           if (af != null)
308           {
309             for (KeyListener kl : af.getKeyListeners())
310             {
311               kl.keyPressed(e);
312             }
313           }
314         }
315       }
316
317       @Override
318       public void keyReleased(KeyEvent e)
319       {
320         Component c = getFrameAtMouse();
321         if (c != null)
322         {
323           for (KeyListener kl : c.getKeyListeners())
324           {
325             kl.keyReleased(e);
326           }
327         }
328       }
329
330     });
331   }
332
333   /**
334    * Returns true if the key event is overriden and actioned (or ignored) here,
335    * else returns false, indicating it should be delegated to the AlignFrame's
336    * usual handler.
337    * <p>
338    * We can't handle Cmd-Key combinations here, instead this is done by
339    * overriding key bindings.
340    * 
341    * @see addKeyOverrides
342    * @param e
343    * @param af
344    * @return
345    */
346   protected boolean overrideKey(KeyEvent e, AlignFrame af)
347   {
348     boolean actioned = false;
349     int keyCode = e.getKeyCode();
350     switch (keyCode)
351     {
352     case KeyEvent.VK_DOWN:
353       if (e.isAltDown() || !af.viewport.cursorMode)
354       {
355         /*
356          * Key down (or Alt-key-down in cursor mode) - move selected sequences
357          */
358         ((AlignFrame) getTopFrame()).moveSelectedSequences(false);
359         ((AlignFrame) getBottomFrame()).moveSelectedSequences(false);
360         actioned = true;
361         e.consume();
362       }
363       break;
364     case KeyEvent.VK_UP:
365       if (e.isAltDown() || !af.viewport.cursorMode)
366       {
367         /*
368          * Key up (or Alt-key-up in cursor mode) - move selected sequences
369          */
370         ((AlignFrame) getTopFrame()).moveSelectedSequences(true);
371         ((AlignFrame) getBottomFrame()).moveSelectedSequences(true);
372         actioned = true;
373         e.consume();
374       }
375       break;
376     default:
377     }
378     return actioned;
379   }
380
381   /**
382    * Set key bindings (recommended for Swing over key accelerators).
383    */
384   private void addKeyBindings()
385   {
386     overrideDelegatedKeyBindings();
387
388     overrideImplementedKeyBindings();
389   }
390
391   /**
392    * Override key bindings with alternative action methods implemented in this
393    * class.
394    */
395   protected void overrideImplementedKeyBindings()
396   {
397     overrideFind();
398     overrideNewView();
399     overrideCloseView();
400     overrideExpandViews();
401     overrideGatherViews();
402   }
403
404   /**
405    * Replace Cmd-W close view action with our version.
406    */
407   protected void overrideCloseView()
408   {
409     AbstractAction action;
410     /*
411      * Ctrl-W / Cmd-W - close view or window
412      */
413     KeyStroke key_cmdW = KeyStroke.getKeyStroke(KeyEvent.VK_W,
414             jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
415     action = new AbstractAction()
416     {
417       @Override
418       public void actionPerformed(ActionEvent e)
419       {
420         closeView_actionPerformed();
421       }
422     };
423     overrideKeyBinding(key_cmdW, action);
424   }
425
426   /**
427    * Replace Cmd-T new view action with our version.
428    */
429   protected void overrideNewView()
430   {
431     /*
432      * Ctrl-T / Cmd-T open new view
433      */
434     KeyStroke key_cmdT = KeyStroke.getKeyStroke(KeyEvent.VK_T,
435             jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
436     AbstractAction action = new AbstractAction()
437     {
438       @Override
439       public void actionPerformed(ActionEvent e)
440       {
441         newView_actionPerformed();
442       }
443     };
444     overrideKeyBinding(key_cmdT, action);
445   }
446
447   /**
448    * For now, delegates key events to the corresponding key accelerator for the
449    * AlignFrame that the mouse is in. Hopefully can be simplified in future if
450    * AlignFrame is changed to use key bindings rather than accelerators.
451    */
452   protected void overrideDelegatedKeyBindings()
453   {
454     if (getTopFrame() instanceof AlignFrame)
455     {
456       /*
457        * Get all accelerator keys in the top frame (the bottom should be
458        * identical) and override each one.
459        */
460       for (Entry<KeyStroke, JMenuItem> acc : ((AlignFrame) getTopFrame())
461               .getAccelerators().entrySet())
462       {
463         overrideKeyBinding(acc);
464       }
465     }
466   }
467
468   /**
469    * Overrides an AlignFrame key accelerator with our version which delegates to
470    * the action listener in whichever frame has the mouse (and does nothing if
471    * neither has).
472    * 
473    * @param acc
474    */
475   private void overrideKeyBinding(Entry<KeyStroke, JMenuItem> acc)
476   {
477     final KeyStroke ks = acc.getKey();
478     InputMap inputMap = this.getInputMap(JComponent.WHEN_FOCUSED);
479     inputMap.put(ks, ks);
480     this.getActionMap().put(ks, new AbstractAction()
481     {
482       @Override
483       public void actionPerformed(ActionEvent e)
484       {
485         Component c = getFrameAtMouse();
486         if (c != null && c instanceof AlignFrame)
487         {
488           for (ActionListener a : ((AlignFrame) c).getAccelerators().get(ks)
489                   .getActionListeners())
490           {
491             a.actionPerformed(null);
492           }
493         }
494       }
495     });
496   }
497
498   /**
499    * Replace an accelerator key's action with the specified action.
500    * 
501    * @param ks
502    */
503   protected void overrideKeyBinding(KeyStroke ks, AbstractAction action)
504   {
505     this.getActionMap().put(ks, action);
506     overrideMenuItem(ks, action);
507   }
508
509   /**
510    * Create and link new views (with matching names) in both panes.
511    * <p>
512    * Note this is _not_ multiple tabs, each hosting a split pane view, rather it
513    * is a single split pane with each split holding multiple tabs which are
514    * linked in pairs.
515    * <p>
516    * TODO implement instead with a tabbed holder in the SplitView, each tab
517    * holding a single JSplitPane. Would avoid a duplicated tab, at the cost of
518    * some additional coding.
519    */
520   protected void newView_actionPerformed()
521   {
522     AlignFrame topFrame = (AlignFrame) getTopFrame();
523     AlignFrame bottomFrame = (AlignFrame) getBottomFrame();
524     final boolean scaleProteinAsCdna = topFrame.viewport
525             .isScaleProteinAsCdna();
526
527     AlignmentPanel newTopPanel = topFrame.newView(null, true);
528     AlignmentPanel newBottomPanel = bottomFrame.newView(null, true);
529
530     /*
531      * This currently (for the first new view only) leaves the top pane on tab 0
532      * but the bottom on tab 1. This results from 'setInitialTabVisible' echoing
533      * from the bottom back to the first frame. Next line is a fudge to work
534      * around this. TODO find a better way.
535      */
536     if (topFrame.getTabIndex() != bottomFrame.getTabIndex())
537     {
538       topFrame.setDisplayedView(newTopPanel);
539     }
540
541     newBottomPanel.av.setViewName(newTopPanel.av.getViewName());
542     newTopPanel.av.setCodingComplement(newBottomPanel.av);
543
544     /*
545      * These lines can be removed once scaleProteinAsCdna is added to element
546      * Viewport in jalview.xsd, as Jalview2XML.copyAlignPanel will then take
547      * care of it
548      */
549     newTopPanel.av.setScaleProteinAsCdna(scaleProteinAsCdna);
550     newBottomPanel.av.setScaleProteinAsCdna(scaleProteinAsCdna);
551
552     /*
553      * Line up id labels etc
554      */
555     adjustLayout();
556
557     final StructureSelectionManager ssm = StructureSelectionManager
558             .getStructureSelectionManager(Desktop.instance);
559     ssm.addCommandListener(newTopPanel.av);
560     ssm.addCommandListener(newBottomPanel.av);
561   }
562
563   /**
564    * Close the currently selected view in both panes. If there is only one view,
565    * close this split frame.
566    */
567   protected void closeView_actionPerformed()
568   {
569     int viewCount = ((AlignFrame) getTopFrame()).getAlignPanels().size();
570     if (viewCount < 2)
571     {
572       close();
573       return;
574     }
575
576     AlignmentPanel topPanel = ((AlignFrame) getTopFrame()).alignPanel;
577     AlignmentPanel bottomPanel = ((AlignFrame) getBottomFrame()).alignPanel;
578
579     ((AlignFrame) getTopFrame()).closeView(topPanel);
580     ((AlignFrame) getBottomFrame()).closeView(bottomPanel);
581
582   }
583
584   /**
585    * Close child frames and this split frame.
586    */
587   public void close()
588   {
589     ((AlignFrame) getTopFrame()).closeMenuItem_actionPerformed(true);
590     ((AlignFrame) getBottomFrame()).closeMenuItem_actionPerformed(true);
591     try
592     {
593       this.setClosed(true);
594     } catch (PropertyVetoException e)
595     {
596       // ignore
597     }
598   }
599
600   /**
601    * Replace AlignFrame 'expand views' action with SplitFrame version.
602    */
603   protected void overrideExpandViews()
604   {
605     KeyStroke key_X = KeyStroke.getKeyStroke(KeyEvent.VK_X, 0, false);
606     AbstractAction action = new AbstractAction()
607     {
608       @Override
609       public void actionPerformed(ActionEvent e)
610       {
611         expandViews_actionPerformed();
612       }
613     };
614     overrideMenuItem(key_X, action);
615   }
616
617   /**
618    * Replace AlignFrame 'gather views' action with SplitFrame version.
619    */
620   protected void overrideGatherViews()
621   {
622     KeyStroke key_G = KeyStroke.getKeyStroke(KeyEvent.VK_G, 0, false);
623     AbstractAction action = new AbstractAction()
624     {
625       @Override
626       public void actionPerformed(ActionEvent e)
627       {
628         gatherViews_actionPerformed();
629       }
630     };
631     overrideMenuItem(key_G, action);
632   }
633
634   /**
635    * Override the menu action associated with the keystroke in the child frames,
636    * replacing it with the given action.
637    * 
638    * @param ks
639    * @param action
640    */
641   private void overrideMenuItem(KeyStroke ks, AbstractAction action)
642   {
643     overrideMenuItem(ks, action, getTopFrame());
644     overrideMenuItem(ks, action, getBottomFrame());
645   }
646
647   /**
648    * Override the menu action associated with the keystroke in one child frame,
649    * replacing it with the given action. Mwahahahaha.
650    * 
651    * @param key
652    * @param action
653    * @param comp
654    */
655   private void overrideMenuItem(KeyStroke key, final AbstractAction action,
656           JComponent comp)
657   {
658     if (comp instanceof AlignFrame)
659     {
660       JMenuItem mi = ((AlignFrame) comp).getAccelerators().get(key);
661       if (mi != null)
662       {
663         for (ActionListener al : mi.getActionListeners())
664         {
665           mi.removeActionListener(al);
666         }
667         mi.addActionListener(new ActionListener()
668         {
669           @Override
670           public void actionPerformed(ActionEvent e)
671           {
672             action.actionPerformed(e);
673           }
674         });
675       }
676     }
677   }
678
679   /**
680    * Expand any multiple views (which are always in pairs) into separate split
681    * frames.
682    */
683   protected void expandViews_actionPerformed()
684   {
685     Desktop.instance.explodeViews(this);
686   }
687
688   /**
689    * Gather any other SplitFrame views of this alignment back in as multiple
690    * (pairs of) views in this SplitFrame.
691    */
692   protected void gatherViews_actionPerformed()
693   {
694     Desktop.instance.gatherViews(this);
695   }
696
697   /**
698    * Returns the alignment in the complementary frame to the one given.
699    */
700   @Override
701   public AlignmentI getComplement(Object alignFrame)
702   {
703     if (alignFrame == this.getTopFrame())
704     {
705       return ((AlignFrame) getBottomFrame()).viewport.getAlignment();
706     }
707     else if (alignFrame == this.getBottomFrame())
708     {
709       return ((AlignFrame) getTopFrame()).viewport.getAlignment();
710     }
711     return null;
712   }
713
714   /**
715    * Returns the title of the complementary frame to the one given.
716    */
717   @Override
718   public String getComplementTitle(Object alignFrame)
719   {
720     if (alignFrame == this.getTopFrame())
721     {
722       return ((AlignFrame) getBottomFrame()).getTitle();
723     }
724     else if (alignFrame == this.getBottomFrame())
725     {
726       return ((AlignFrame) getTopFrame()).getTitle();
727     }
728     return null;
729   }
730
731   /**
732    * Set the 'other half' to hidden / revealed.
733    */
734   @Override
735   public void setComplementVisible(Object alignFrame, boolean show)
736   {
737     /*
738      * Hiding the AlignPanel suppresses unnecessary repaints
739      */
740     if (alignFrame == getTopFrame())
741     {
742       ((AlignFrame) getBottomFrame()).alignPanel.setVisible(show);
743     }
744     else if (alignFrame == getBottomFrame())
745     {
746       ((AlignFrame) getTopFrame()).alignPanel.setVisible(show);
747     }
748     super.setComplementVisible(alignFrame, show);
749   }
750
751   /**
752    * return the AlignFrames held by this container
753    * 
754    * @return { Top alignFrame (Usually CDS), Bottom AlignFrame (Usually
755    *         Protein)}
756    */
757   public List<AlignFrame> getAlignFrames()
758   {
759     return Arrays
760             .asList(new AlignFrame[]
761             { (AlignFrame) getTopFrame(), (AlignFrame) getBottomFrame() });
762   }
763
764   /**
765    * Replace Cmd-F Find action with our version. This is necessary because the
766    * 'default' Finder searches in the first AlignFrame it finds. We need it to
767    * search in the half of the SplitFrame that has the mouse.
768    */
769   protected void overrideFind()
770   {
771     /*
772      * Ctrl-F / Cmd-F open Finder dialog, 'focused' on the right alignment
773      */
774     KeyStroke key_cmdF = KeyStroke.getKeyStroke(KeyEvent.VK_F,
775             jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(), false);
776     AbstractAction action = new AbstractAction()
777     {
778       @Override
779       public void actionPerformed(ActionEvent e)
780       {
781         Component c = getFrameAtMouse();
782         if (c != null && c instanceof AlignFrame)
783         {
784           AlignFrame af = (AlignFrame) c;
785           new Finder(af.viewport, af.alignPanel);
786         }
787       }
788     };
789     overrideKeyBinding(key_cmdF, action);
790   }
791
792   /**
793    * Override to do nothing - let the embedded AlignFrame's be the selected frame
794    */
795   @Override
796   public void setSelected(boolean selected) throws PropertyVetoException
797   {
798     // no-op here fixes JAL-3288 (menus close immediately)
799   }
800 }