1 package jalview.appletgui;
3 import java.awt.BorderLayout;
4 import java.awt.Dimension;
5 import java.awt.GridLayout;
8 import jalview.analysis.AlignmentUtils;
9 import jalview.api.AlignmentViewPanel;
10 import jalview.api.ViewStyleI;
11 import jalview.bin.JalviewLite;
12 import jalview.datamodel.AlignmentI;
13 import jalview.structure.StructureSelectionManager;
14 import jalview.viewmodel.AlignmentViewport;
16 public class SplitFrame extends EmbmenuFrame
18 private static final long serialVersionUID = 1L;
20 private AlignFrame topFrame;
22 private AlignFrame bottomFrame;
24 private Panel outermost;
29 public SplitFrame(AlignFrame af1, AlignFrame af2)
37 * Creates a Panel containing two Panels, and adds the first and second
38 * AlignFrame's components to each. At this stage we have not yet committed to
39 * whether the enclosing panel will be added to this frame, for display as a
40 * separate frame, or added to the applet (embedded mode).
47 * Try to make and add dna/protein sequence mappings
49 final AlignViewport topViewport = topFrame.viewport;
50 final AlignViewport bottomViewport = bottomFrame.viewport;
51 final AlignmentI topAlignment = topViewport.getAlignment();
52 final AlignmentI bottomAlignment = bottomViewport.getAlignment();
53 AlignmentViewport cdna = topAlignment.isNucleotide() ? topViewport
54 : (bottomAlignment.isNucleotide() ? bottomViewport : null);
55 AlignmentViewport protein = !topAlignment.isNucleotide() ? topViewport
56 : (!bottomAlignment.isNucleotide() ? bottomViewport : null);
58 boolean mapped = AlignmentUtils.mapProteinToCdna(
59 protein.getAlignment(), cdna.getAlignment());
62 final StructureSelectionManager ssm = StructureSelectionManager
63 .getStructureSelectionManager(topViewport.applet);
64 ssm.addMappings(protein.getAlignment().getCodonFrames());
65 topViewport.setCodingComplement(bottomViewport);
66 ssm.addCommandListener(cdna);
67 ssm.addCommandListener(protein);
71 * Now mappings exist, can compute cDNA consensus on protein alignment
73 protein.initComplementConsensus();
74 AlignmentViewPanel ap = topAlignment.isNucleotide() ? bottomFrame.alignPanel
75 : topFrame.alignPanel;
76 protein.updateConsensus(ap);
84 protected void constructSplit()
87 outermost = new Panel(new GridLayout(2, 1));
89 Panel topPanel = new Panel();
90 Panel bottomPanel = new Panel();
91 outermost.add(topPanel);
92 outermost.add(bottomPanel);
94 addAlignFrameComponents(topFrame, topPanel);
95 addAlignFrameComponents(bottomFrame, bottomPanel);
99 * Make any adjustments to the layout
101 protected void adjustLayout()
103 AlignmentViewport cdna = topFrame.getAlignViewport().getAlignment()
104 .isNucleotide() ? topFrame.viewport : bottomFrame.viewport;
105 AlignmentViewport protein = cdna == topFrame.viewport ? bottomFrame.viewport
109 * Ensure sequence ids are the same width for good alignment.
111 // TODO should do this via av.getViewStyle/setViewStyle
112 // however at present av.viewStyle is not set in IdPanel.fontChanged
113 int w1 = topFrame.alignPanel.idPanel.idCanvas.getWidth();
114 int w2 = bottomFrame.alignPanel.idPanel.idCanvas.getWidth();
115 int w3 = Math.max(w1, w2);
118 Dimension d = topFrame.alignPanel.idPanel.idCanvas.getSize();
119 topFrame.alignPanel.idPanel.idCanvas.setSize(new Dimension(w3,
124 Dimension d = bottomFrame.alignPanel.idPanel.idCanvas.getSize();
125 bottomFrame.alignPanel.idPanel.idCanvas.setSize(new Dimension(w3,
130 * Scale protein to either 1 or 3 times character width of dna
132 if (protein != null && cdna != null)
134 ViewStyleI vs = protein.getViewStyle();
135 int scale = vs.isScaleProteinAsCdna() ? 3 : 1;
136 vs.setCharWidth(scale * cdna.getViewStyle().getCharWidth());
137 protein.setViewStyle(vs);
142 * Add the menu bar, alignment panel and status bar from the AlignFrame to the
143 * panel. The menu bar is a panel 'reconstructed' from the AlignFrame's frame
144 * menu bar. This allows each half of the SplitFrame to have its own menu bar.
149 private void addAlignFrameComponents(AlignFrame af, Panel panel)
151 panel.setLayout(new BorderLayout());
153 .makeEmbeddedPopupMenu(af.getMenuBar(), true, false);
154 panel.add(menuPanel, BorderLayout.NORTH);
155 panel.add(af.statusBar, BorderLayout.SOUTH);
156 panel.add(af.alignPanel, BorderLayout.CENTER);
158 af.setSplitFrame(this);
162 * Display the content panel either as a new frame or embedded in the applet.
167 public void addToDisplay(boolean embedded, JalviewLite applet)
169 createSplitFrameWindow(embedded, applet);
171 topFrame.alignPanel.adjustAnnotationHeight();
172 topFrame.alignPanel.paintAlignment(true);
173 bottomFrame.alignPanel.adjustAnnotationHeight();
174 bottomFrame.alignPanel.paintAlignment(true);
178 * Either show the content panel in this frame as a new frame, or (if
179 * embed=true) add it to the applet container instead.
184 protected void createSplitFrameWindow(boolean embed, JalviewLite applet)
188 applet.add(outermost);
194 int width = Math.max(topFrame.frameWidth, bottomFrame.frameWidth);
195 int height = topFrame.frameHeight + bottomFrame.frameHeight;
196 jalview.bin.JalviewLite
197 .addFrame(this, this.getTitle(), width, height);
202 * Returns the contained AlignFrame complementary to the one given (or null if
203 * no match to top or bottom component).
208 public AlignFrame getComplement(AlignFrame af)
214 else if (bottomFrame == af)