01: // Copyright (c) 2002 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.jemacs.swing;
05:
06: import gnu.jemacs.buffer.*;
07: import gnu.lists.FString;
08: import gnu.lists.FVector;
09: import gnu.lists.LList;
10:
11: import javax.swing.*;
12:
13: /** An Emacs frame (EFrame) implemented using the Swing toolkits. */
14:
15: public class SwingFrame extends EFrame {
16: javax.swing.JFrame jframe;
17: JMenuBar menuBar;
18: JPanel contents;
19:
20: public SwingFrame() {
21: super ();
22: }
23:
24: public SwingFrame(Buffer buffer) {
25: this (new SwingWindow(buffer, true));
26: }
27:
28: public SwingFrame(SwingWindow window) {
29: super (window);
30: contents = window.wrap();
31: jframe = new JFrame(defaultName());
32: jframe.getContentPane().add(contents);
33: jframe.setSize(600, 400);
34: jframe.setVisible(true);
35: jframe.setTitle("JEmacs");
36: menuBar = new JMenuBar();
37: jframe.setJMenuBar(menuBar);
38: }
39:
40: public boolean isLive() {
41: return contents != null;
42: }
43:
44: public void validate() {
45: jframe.validate();
46: }
47:
48: public void delete() {
49: super .delete();
50: contents = null;
51: jframe.dispose();
52: }
53:
54: public String ask(String prompt) {
55: String result = JOptionPane.showInputDialog(jframe, prompt);
56: if (result == null)
57: throw new CancelledException();
58: return result;
59: }
60:
61: public void setMenuBar(EMenu menu) {
62: SwingMenu swingMenu = (SwingMenu) menu;
63: menuBar.removeAll();
64: // a menubar contain a list of menus, stored inside a single menu
65: while (swingMenu.getMenuComponentCount() > 0)
66: menuBar.add(swingMenu.getMenuComponent(0));
67: menuBar.updateUI();
68: }
69:
70: public void setMenu(LList menu) {
71: SwingMenu sMenu = new SwingMenu(menu);
72: setMenuBar(sMenu);
73: }
74:
75: public String toString() {
76: StringBuffer sbuf = new StringBuffer(100);
77: sbuf.append("#<frame #");
78: sbuf.append(id);
79: if (jframe != null) {
80: sbuf.append(" size: ");
81: sbuf.append(jframe.getSize());
82: sbuf.append(" preferred: ");
83: sbuf.append(jframe.getPreferredSize());
84: }
85: sbuf.append('>');
86: return sbuf.toString();
87: }
88: }
|