1 package jalview.appletgui;
\r
3 import jalview.analysis.AlignmentUtils;
\r
4 import jalview.api.AlignmentViewPanel;
\r
5 import jalview.api.ViewStyleI;
\r
6 import jalview.bin.JalviewLite;
\r
7 import jalview.datamodel.AlignmentI;
\r
8 import jalview.structure.StructureSelectionManager;
\r
9 import jalview.viewmodel.AlignmentViewport;
\r
11 import java.awt.BorderLayout;
\r
12 import java.awt.Dimension;
\r
13 import java.awt.GridLayout;
\r
15 import javax.swing.JPanel;
\r
17 public class SplitFrame extends EmbmenuFrame
\r
19 private static final long serialVersionUID = 1L;
\r
21 private AlignFrame topFrame;
\r
23 private AlignFrame bottomFrame;
\r
25 private JPanel outermost;
\r
31 public SplitFrame(AlignFrame af1, AlignFrame af2)
\r
39 * Creates a Panel containing two Panels, and adds the first and second
\r
40 * AlignFrame's components to each. At this stage we have not yet committed to
\r
41 * whether the enclosing panel will be added to this frame, for display as a
\r
42 * separate frame, or added to the applet (embedded mode).
\r
49 * Try to make and add dna/protein sequence mappings
\r
51 final AlignViewport topViewport = topFrame.viewport;
\r
52 final AlignViewport bottomViewport = bottomFrame.viewport;
\r
53 final AlignmentI topAlignment = topViewport.getAlignment();
\r
54 final AlignmentI bottomAlignment = bottomViewport.getAlignment();
\r
55 AlignmentViewport cdna = topAlignment.isNucleotide() ? topViewport
\r
56 : (bottomAlignment.isNucleotide() ? bottomViewport : null);
\r
57 AlignmentViewport protein = !topAlignment.isNucleotide() ? topViewport
\r
58 : (!bottomAlignment.isNucleotide() ? bottomViewport : null);
\r
60 boolean mapped = AlignmentUtils.mapProteinToCdna(
\r
61 protein.getAlignment(), cdna.getAlignment());
\r
64 final StructureSelectionManager ssm = StructureSelectionManager
\r
65 .getStructureSelectionManager(topViewport.applet);
\r
66 ssm.addMappings(protein.getAlignment().getCodonFrames());
\r
67 topViewport.setCodingComplement(bottomViewport);
\r
68 ssm.addCommandListener(cdna);
\r
69 ssm.addCommandListener(protein);
\r
73 * Now mappings exist, can compute cDNA consensus on protein alignment
\r
75 protein.initComplementConsensus();
\r
76 AlignmentViewPanel ap = topAlignment.isNucleotide() ? bottomFrame.alignPanel
\r
77 : topFrame.alignPanel;
\r
78 protein.updateConsensus(ap);
\r
86 protected void constructSplit()
\r
89 outermost = new JPanel(new GridLayout(2, 1));
\r
91 JPanel topPanel = new JPanel();
\r
92 JPanel bottomPanel = new JPanel();
\r
93 outermost.add(topPanel);
\r
94 outermost.add(bottomPanel);
\r
96 addAlignFrameComponents(topFrame, topPanel);
\r
97 addAlignFrameComponents(bottomFrame, bottomPanel);
\r
101 * Make any adjustments to the layout
\r
103 protected void adjustLayout()
\r
105 AlignmentViewport cdna = topFrame.getAlignViewport().getAlignment()
\r
106 .isNucleotide() ? topFrame.viewport : bottomFrame.viewport;
\r
107 AlignmentViewport protein = cdna == topFrame.viewport ? bottomFrame.viewport
\r
108 : topFrame.viewport;
\r
111 * Ensure sequence ids are the same width for good alignment.
\r
113 // TODO should do this via av.getViewStyle/setViewStyle
\r
114 // however at present av.viewStyle is not set in IdPanel.fontChanged
\r
115 int w1 = topFrame.alignPanel.idPanel.idCanvas.getWidth();
\r
116 int w2 = bottomFrame.alignPanel.idPanel.idCanvas.getWidth();
\r
117 int w3 = Math.max(w1, w2);
\r
120 Dimension d = topFrame.alignPanel.idPanel.idCanvas.getSize();
\r
121 topFrame.alignPanel.idPanel.idCanvas.setSize(new Dimension(w3,
\r
126 Dimension d = bottomFrame.alignPanel.idPanel.idCanvas.getSize();
\r
127 bottomFrame.alignPanel.idPanel.idCanvas.setSize(new Dimension(w3,
\r
132 * Scale protein to either 1 or 3 times character width of dna
\r
134 if (protein != null && cdna != null)
\r
136 ViewStyleI vs = protein.getViewStyle();
\r
137 int scale = vs.isScaleProteinAsCdna() ? 3 : 1;
\r
138 vs.setCharWidth(scale * cdna.getViewStyle().getCharWidth());
\r
139 protein.setViewStyle(vs);
\r
144 * Add the menu bar, alignment panel and status bar from the AlignFrame to the
\r
145 * panel. The menu bar is a panel 'reconstructed' from the AlignFrame's frame
\r
146 * menu bar. This allows each half of the SplitFrame to have its own menu bar.
\r
151 private void addAlignFrameComponents(AlignFrame af, JPanel panel) {
\r
152 panel.setLayout(new BorderLayout());
\r
153 JPanel menuPanel = af.makeEmbeddedPopupMenu(af.getJMenuBar(), true, false);
\r
154 panel.add(menuPanel, BorderLayout.NORTH);
\r
155 panel.add(af.statusBar, BorderLayout.SOUTH);
\r
156 panel.add(af.alignPanel, BorderLayout.CENTER);
\r
158 af.setSplitFrame(this);
\r
162 * Display the content panel either as a new frame or embedded in the applet.
\r
167 public void addToDisplay(boolean embedded, JalviewLite applet)
\r
169 createSplitFrameWindow(embedded, applet);
\r
171 topFrame.alignPanel.adjustAnnotationHeight();
\r
172 topFrame.alignPanel.paintAlignment(true);
\r
173 bottomFrame.alignPanel.adjustAnnotationHeight();
\r
174 bottomFrame.alignPanel.paintAlignment(true);
\r
178 * Either show the content panel in this frame as a new frame, or (if
\r
179 * embed=true) add it to the applet container instead.
\r
184 protected void createSplitFrameWindow(boolean embed, JalviewLite applet)
\r
188 applet.add(outermost);
\r
193 this.add(outermost);
\r
194 int width = Math.max(topFrame.frameWidth, bottomFrame.frameWidth);
\r
195 int height = topFrame.frameHeight + bottomFrame.frameHeight;
\r
196 JalviewLite.addFrame(this, this.getTitle(), width, height);
\r
201 * Returns the contained AlignFrame complementary to the one given (or null if
\r
202 * no match to top or bottom component).
\r
207 public AlignFrame getComplement(AlignFrame af)
\r
209 if (topFrame == af)
\r
211 return bottomFrame;
\r
213 else if (bottomFrame == af)
\r