Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.gui

File SplitFrame.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
56% of files have more coverage

Code metrics

64
201
40
1
792
474
80
0.4
5.03
40
2

Classes

Class Line # Actions
SplitFrame 63 201 80 305
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

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