| 1 19 20 package org.lucane.client.util; 21 22 import java.awt.BorderLayout ; 23 import java.beans.PropertyChangeEvent ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 27 import javax.swing.*; 28 import javax.swing.event.InternalFrameAdapter ; 29 import javax.swing.event.InternalFrameEvent ; 30 31 import org.lucane.client.Plugin; 32 import org.lucane.client.widgets.ManagedWindow; 33 34 public class MdiWindowManager implements WindowManager 35 { 36 private HashMap windows = new HashMap (); 37 private JDesktopPane desktop = new JDesktopPane(); 38 private JFrame container = new JFrame(); 39 40 public MdiWindowManager() 41 { 42 container.getContentPane().add(desktop, BorderLayout.CENTER); 43 container.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 44 container.setSize(800, 600); 45 } 46 47 public void show(ManagedWindow window) 48 { 49 final JInternalFrame f = new JInternalFrame(window.getTitle(), true, true, true, true); 50 f.setName(window.getName()); 51 f.setContentPane(window.getContentPane()); 52 f.setJMenuBar(window.getJMenuBar()); 54 f.setSize(window.getPreferredSize()); 55 f.setResizable(window.isResizeable()); 57 if(window.getPreferredSize() == null) 58 f.pack(); 59 60 if(window.mustExitPluginOnClose()) 61 { 62 final Plugin plugin = window.getOwner(); 63 f.addInternalFrameListener(new InternalFrameAdapter () { 64 public void internalFrameClosing(InternalFrameEvent e) { 65 plugin.exit(); 66 } 67 }); 68 } 69 70 windows.put(window, f); 72 73 Iterator listeners = window.getWindowListeners(); 74 77 SwingUtilities.invokeLater(new Runnable () { 78 public void run() { 79 f.show(); 80 } 81 }); 82 83 desktop.add(f); 84 container.show(); 85 } 86 87 public void hide(ManagedWindow window) 88 { 89 final JInternalFrame f = (JInternalFrame)windows.get(window); 90 SwingUtilities.invokeLater(new Runnable () { 91 public void run() { 92 f.setVisible(false); 93 } 94 }); 95 } 96 97 public boolean isVisible(ManagedWindow window) 98 { 99 JInternalFrame f = (JInternalFrame)windows.get(window); 100 return f.isVisible(); 101 } 102 103 public void dispose(ManagedWindow window) 104 { 105 JInternalFrame f = (JInternalFrame)windows.get(window); 106 f.dispose(); 108 109 if(window.mustExitPluginOnClose()) 110 window.getOwner().exit(); 111 } 112 113 public Iterator getAllWindows() 114 { 115 return windows.keySet().iterator(); 116 } 117 118 public Iterator getWindowsFor(Plugin plugin) 119 { 120 return getAllWindows(); 122 } 123 124 public void propertyChange(PropertyChangeEvent pce) 125 { 126 } 128 } | Popular Tags |