d77f3313b944fbcfb7112d21772afb690867e160
[jalview.git] / src / jalview / appletgui / SplitFrame.java
1 package jalview.appletgui;
2
3 import jalview.bin.JalviewLite;
4
5 import java.awt.BorderLayout;
6 import java.awt.GridLayout;
7 import java.awt.Panel;
8
9 public class SplitFrame extends EmbmenuFrame
10 {
11   private static final long serialVersionUID = 1L;
12
13   private AlignFrame topFrame;
14
15   private AlignFrame bottomFrame;
16
17   private Panel outermost;
18
19   /**
20    * Constructor
21    */
22   public SplitFrame(AlignFrame af1, AlignFrame af2)
23   {
24     topFrame = af1;
25     bottomFrame = af2;
26     init();
27   }
28
29   /**
30    * Creates a Panel containing two Panels, and adds the first and second
31    * AlignFrame's components to each. At this stage we have not yet committed to
32    * whether the enclosing panel will be added to this frame, for display as a
33    * separate frame, or added to the applet (embedded mode).
34    */
35   public void init()
36   {
37     setMenuBar(null);
38     outermost = new Panel();
39     outermost.setLayout(new GridLayout(2, 1));
40
41     Panel topPanel = new Panel();
42     Panel bottomPanel = new Panel();
43     outermost.add(topPanel);
44     outermost.add(bottomPanel);
45
46     addAlignFrameComponents(topFrame, topPanel);
47     addAlignFrameComponents(bottomFrame, bottomPanel);
48   }
49
50   /**
51    * Add the menu bar, alignment panel and status bar from the AlignFrame to the
52    * panel. The menu bar is a panel 'reconstructed' from the AlignFrame's frame
53    * menu bar. This allows each half of the SplitFrame to have its own menu bar.
54    * 
55    * @param af
56    * @param panel
57    */
58   private void addAlignFrameComponents(AlignFrame af, Panel panel)
59   {
60     panel.setLayout(new BorderLayout());
61     Panel menuPanel = makeEmbeddedPopupMenu(af.getMenuBar(), FONT_ARIAL_PLAIN_11, true, false);
62     panel.add(menuPanel, BorderLayout.NORTH);
63     panel.add(af.statusBar, BorderLayout.SOUTH);
64     panel.add(af.alignPanel, BorderLayout.CENTER);
65   }
66
67   /**
68    * Display the content panel either as a new frame or embedded in the applet.
69    * 
70    * @param embedded
71    * @param applet
72    */
73   public void addToDisplay(boolean embedded, JalviewLite applet)
74   {
75     createAlignFrameWindow(embedded, applet);
76     validate();
77     topFrame.alignPanel.adjustAnnotationHeight();
78     topFrame.alignPanel.paintAlignment(true);
79     bottomFrame.alignPanel.adjustAnnotationHeight();
80     bottomFrame.alignPanel.paintAlignment(true);
81   }
82
83   /**
84    * Either show the content panel in this frame as a new frame, or (if
85    * embed=true) add it to the applet container instead.
86    * 
87    * @param embed
88    * @param applet
89    */
90   public void createAlignFrameWindow(boolean embed, JalviewLite applet)
91   {
92     if (embed)
93     {
94       applet.add(outermost);
95       applet.validate();
96     }
97     else
98     {
99       this.add(outermost);
100       int width = Math.max(topFrame.DEFAULT_WIDTH,
101               bottomFrame.DEFAULT_WIDTH);
102       int height = topFrame.DEFAULT_HEIGHT + bottomFrame.DEFAULT_HEIGHT;
103       jalview.bin.JalviewLite
104               .addFrame(this, this.getTitle(), width, height);
105     }
106   }
107 }