01: package gnu.kawa.swingviews;
02:
03: import gnu.kawa.models.*;
04: import java.awt.Component;
05: import java.awt.Container;
06: import javax.swing.*;
07: import gnu.lists.*;
08:
09: public class SwingFrame extends JFrame implements
10: gnu.kawa.models.Window {
11: SwingDisplay display;
12:
13: public Display getDisplay() {
14: return display;
15: }
16:
17: public SwingFrame(String title, javax.swing.JMenuBar menubar,
18: Object contents) {
19: JFrame fr = this ;
20: if (title != null)
21: fr.setTitle(title);
22: if (menubar != null)
23: fr.setJMenuBar(menubar);
24: Container pane = getContentPane();
25: pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
26: addComponent(contents);
27: }
28:
29: public void setContent(Object content) {
30: setContentPane(new JPanel());
31: addComponent(content);
32: pack();
33: }
34:
35: public void setMenuBar(Object menubar) {
36: setJMenuBar((javax.swing.JMenuBar) menubar);
37: }
38:
39: public void addComponent(Object contents) {
40: if (contents instanceof gnu.lists.FString
41: || contents instanceof String)
42: getContentPane().add(new JLabel(contents.toString()));
43: else if (contents instanceof AbstractSequence) {
44: AbstractSequence seq = (AbstractSequence) contents;
45: for (int iter = seq.startPos(); (iter = seq.nextPos(iter)) != 0;)
46: addComponent(seq.getPosPrevious(iter));
47: } else if (contents instanceof Viewable)
48: ((Viewable) contents).makeView(getDisplay(),
49: getContentPane());
50: else if (contents instanceof Paintable)
51: getContentPane().add(
52: new SwingPaintable((Paintable) contents));
53: else if (contents != null)
54: getContentPane().add((Component) contents);
55: }
56:
57: public void open() {
58: pack();
59: setVisible(true);
60: }
61: }
|