1 package jalview.appletgui;
3 import jalview.analysis.AlignmentUtils;
4 import jalview.analysis.AlignmentUtils.MappingResult;
5 import jalview.api.ViewStyleI;
6 import jalview.bin.JalviewLite;
7 import jalview.datamodel.AlignmentI;
8 import jalview.structure.StructureSelectionManager;
10 import java.awt.BorderLayout;
11 import java.awt.GridLayout;
12 import java.awt.Panel;
14 public class SplitFrame extends EmbmenuFrame
16 private static final long serialVersionUID = 1L;
18 private AlignFrame topFrame;
20 private AlignFrame bottomFrame;
22 private Panel outermost;
27 public SplitFrame(AlignFrame af1, AlignFrame af2)
35 * Creates a Panel containing two Panels, and adds the first and second
36 * AlignFrame's components to each. At this stage we have not yet committed to
37 * whether the enclosing panel will be added to this frame, for display as a
38 * separate frame, or added to the applet (embedded mode).
43 outermost = new Panel(new GridLayout(2, 1));
45 Panel topPanel = new Panel();
46 Panel bottomPanel = new Panel();
47 outermost.add(topPanel);
48 outermost.add(bottomPanel);
50 addAlignFrameComponents(topFrame, topPanel);
51 addAlignFrameComponents(bottomFrame, bottomPanel);
54 * Try to make and add dna/protein sequence mappings
56 final AlignViewport topViewport = topFrame.viewport;
57 final AlignViewport bottomViewport = bottomFrame.viewport;
58 final AlignmentI topAlignment = topViewport.getAlignment();
59 final AlignmentI bottomAlignment = bottomViewport.getAlignment();
60 AlignViewport cdna = topAlignment.isNucleotide() ? topViewport
61 : (bottomAlignment.isNucleotide() ? bottomViewport : null);
62 AlignViewport protein = !topAlignment.isNucleotide() ? topViewport
63 : (!bottomAlignment.isNucleotide() ? bottomViewport : null);
65 MappingResult mapped = AlignmentUtils.mapProteinToCdna(
66 protein.getAlignment(), cdna.getAlignment());
67 if (mapped != MappingResult.NotMapped)
69 final StructureSelectionManager ssm = StructureSelectionManager
70 .getStructureSelectionManager(topViewport.applet);
71 ssm.addMappings(protein.getAlignment().getCodonFrames());
72 topViewport.setCodingComplement(bottomViewport);
73 ssm.addCommandListener(cdna);
74 ssm.addCommandListener(protein);
78 * Expand protein to 3 times character width of dna
80 if (protein != null && cdna != null)
82 ViewStyleI vs = protein.getViewStyle();
83 vs.setCharWidth(3 * vs.getCharWidth());
84 protein.setViewStyle(vs);
90 * Add the menu bar, alignment panel and status bar from the AlignFrame to the
91 * panel. The menu bar is a panel 'reconstructed' from the AlignFrame's frame
92 * menu bar. This allows each half of the SplitFrame to have its own menu bar.
97 private void addAlignFrameComponents(AlignFrame af, Panel panel)
99 panel.setLayout(new BorderLayout());
101 .makeEmbeddedPopupMenu(af.getMenuBar(), true, false);
102 panel.add(menuPanel, BorderLayout.NORTH);
103 panel.add(af.statusBar, BorderLayout.SOUTH);
104 panel.add(af.alignPanel, BorderLayout.CENTER);
108 * Display the content panel either as a new frame or embedded in the applet.
113 public void addToDisplay(boolean embedded, JalviewLite applet)
115 createAlignFrameWindow(embedded, applet);
117 topFrame.alignPanel.adjustAnnotationHeight();
118 topFrame.alignPanel.paintAlignment(true);
119 bottomFrame.alignPanel.adjustAnnotationHeight();
120 bottomFrame.alignPanel.paintAlignment(true);
124 * Either show the content panel in this frame as a new frame, or (if
125 * embed=true) add it to the applet container instead.
130 public void createAlignFrameWindow(boolean embed, JalviewLite applet)
134 applet.add(outermost);
140 int width = Math.max(topFrame.DEFAULT_WIDTH,
141 bottomFrame.DEFAULT_WIDTH);
142 int height = topFrame.DEFAULT_HEIGHT + bottomFrame.DEFAULT_HEIGHT;
143 jalview.bin.JalviewLite
144 .addFrame(this, this.getTitle(), width, height);