1 19 20 package org.lucane.applications.quicklaunch; 21 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 27 import javax.swing.JMenu ; 28 import javax.swing.JMenuItem ; 29 import javax.swing.event.MenuEvent ; 30 import javax.swing.event.MenuListener ; 31 32 import org.lucane.client.Client; 33 import org.lucane.client.Plugin; 34 import org.lucane.client.PluginManager; 35 import org.lucane.client.widgets.ManagedWindow; 36 37 public class WindowMenu extends JMenu 38 implements MenuListener , ActionListener 39 { 40 private Plugin plugin; 41 private HashMap toggleButtons; 42 43 public WindowMenu(Plugin plugin) 44 { 45 super(plugin.tr("mnu.windows")); 46 this.plugin = plugin; 47 48 this.toggleButtons = new HashMap (); 49 this.addMenuListener(this); 50 } 51 52 public void menuCanceled(MenuEvent e) {} 53 public void menuDeselected(MenuEvent e) {} 54 public void menuSelected(MenuEvent e) 55 { 56 toggleButtons.clear(); 58 this.removeAll(); 59 Iterator plugins = PluginManager.getInstance().getRunningPlugins(); 60 while(plugins.hasNext()) 61 { 62 Plugin plugin = (Plugin)plugins.next(); 63 64 if(plugin.getName().equals(Client.getInstance().getStartupPlugin())) 66 continue; 67 68 Iterator windows = Client.getInstance().getWindowManager().getWindowsFor(plugin); 69 70 if(!windows.hasNext()) 72 continue; 73 74 JMenu menu = new JMenu (plugin.getTitle()); 75 76 JMenuItem toggle = new JMenuItem (tr("mnu.hide")); 78 toggleButtons.put(toggle, plugin); 79 if(isHidden(plugin)) 80 toggle.setText(tr("mnu.show")); 81 toggle.addActionListener(this); 82 menu.add(toggle); 83 menu.addSeparator(); 84 85 while(windows.hasNext()) 86 { 87 ManagedWindow window = (ManagedWindow)windows.next(); 88 JMenuItem item = new JMenuItem (window.getTitle()); 89 item.setEnabled(false); 90 menu.add(item); 91 } 92 93 this.add(menu); 94 } 95 96 if(this.getItemCount() == 0) 98 { 99 JMenuItem dumb = new JMenuItem (tr("mnu.none")); 100 dumb.setEnabled(false); 101 this.add(dumb); 102 } 103 } 104 105 public void actionPerformed(ActionEvent ae) 106 { 107 JMenuItem toggle = (JMenuItem )ae.getSource(); 108 if(toggle.getText().equals(tr("mnu.hide"))) 109 { 110 Plugin plugin = (Plugin)toggleButtons.get(toggle); 111 hideWindowsFor(plugin); 112 } 113 else 114 { 115 Plugin plugin = (Plugin)toggleButtons.get(toggle); 116 showWindowsFor(plugin); 117 } 118 } 119 120 private boolean isHidden(Plugin plugin) 121 { 122 Iterator windows = Client.getInstance().getWindowManager().getWindowsFor(plugin); 123 while(windows.hasNext()) 124 { 125 ManagedWindow window = (ManagedWindow)windows.next(); 126 if(window.isVisible()) 127 return false; 128 } 129 130 return true; 131 } 132 133 private void hideWindowsFor(Plugin plugin) 134 { 135 Iterator windows = Client.getInstance().getWindowManager().getWindowsFor(plugin); 136 while(windows.hasNext()) 137 { 138 ManagedWindow window = (ManagedWindow)windows.next(); 139 window.hide(); 140 } 141 } 142 143 private void showWindowsFor(Plugin plugin) 144 { 145 Iterator windows = Client.getInstance().getWindowManager().getWindowsFor(plugin); 146 while(windows.hasNext()) 147 { 148 ManagedWindow window = (ManagedWindow)windows.next(); 149 window.show(); 150 } 151 } 152 153 private String tr(String s) 154 { 155 return plugin.tr(s); 156 } 157 } | Popular Tags |