1 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 13 14 public class SwingFrame extends EFrame 15 { 16 javax.swing.JFrame 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 ask(String prompt) 61 { 62 String 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 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 toString() 86 { 87 StringBuffer sbuf = new StringBuffer (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 |