KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > jemacs > swing > SwingFrame


1 // Copyright (c) 2002 Per M.A. Bothner.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.jemacs.swing;
5 import gnu.jemacs.buffer.*;
6 import gnu.lists.FString;
7 import gnu.lists.FVector;
8 import gnu.lists.LList;
9
10 import javax.swing.*;
11
12 /** An Emacs frame (EFrame) implemented using the Swing toolkits. */
13
14 public class SwingFrame extends EFrame
15 {
16   javax.swing.JFrame JavaDoc jframe;
17   JMenuBar menuBar;
18   JPanel contents;
19
20   public SwingFrame ()
21   {
22     super();
23   }
24
25   public SwingFrame (Buffer buffer)
26   {
27     this(new SwingWindow(buffer, true));
28   }
29
30   public SwingFrame (SwingWindow window)
31   {
32     super(window);
33     contents = window.wrap();
34     jframe = new JFrame(defaultName());
35     jframe.getContentPane().add(contents);
36     jframe.setSize(600, 400);
37     jframe.setVisible(true);
38     jframe.setTitle("JEmacs");
39     menuBar = new JMenuBar();
40     jframe.setJMenuBar(menuBar);
41   }
42
43   public boolean isLive()
44   {
45     return contents != null;
46   }
47
48   public void validate ()
49   {
50     jframe.validate();
51   }
52
53   public void delete()
54   {
55     super.delete();
56     contents = null;
57     jframe.dispose();
58   }
59
60   public String JavaDoc ask(String JavaDoc prompt)
61   {
62     String JavaDoc result = JOptionPane.showInputDialog(jframe, prompt);
63     if (result == null)
64       throw new CancelledException();
65     return result;
66   }
67
68   public void setMenuBar (EMenu menu)
69   {
70     SwingMenu swingMenu = (SwingMenu) menu;
71     menuBar.removeAll();
72     // a menubar contain a list of menus, stored inside a single menu
73
while (swingMenu.getMenuComponentCount() > 0)
74       menuBar.add(swingMenu.getMenuComponent(0));
75     menuBar.updateUI();
76   }
77
78   public void setMenu(LList menu)
79   {
80     SwingMenu sMenu = new SwingMenu(menu);
81     setMenuBar(sMenu);
82   }
83
84   
85   public String JavaDoc toString()
86   {
87     StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc(100);
88     sbuf.append("#<frame #");
89     sbuf.append(id);
90     if (jframe != null)
91       {
92     sbuf.append(" size: ");
93     sbuf.append(jframe.getSize());
94     sbuf.append(" preferred: ");
95     sbuf.append(jframe.getPreferredSize());
96       }
97     sbuf.append('>');
98     return sbuf.toString();
99   }
100 }
101
102
Popular Tags