1 19 package org.lucane.applications.quicklaunch; 20 21 import org.lucane.client.*; 22 import org.lucane.client.widgets.*; 23 import org.lucane.common.*; 24 25 import java.awt.*; 26 import java.awt.event.*; 27 import java.util.*; 28 29 import javax.swing.*; 30 31 32 public class QuickLaunch 33 extends StandalonePlugin 34 implements ActionListener, MouseListener 35 { 36 private static final String MAIN_INTERFACE = "org.lucane.applications.maininterface"; 37 38 private TrayIcon trayIcon; 39 40 43 public QuickLaunch() 44 { 45 } 46 47 53 public Plugin newInstance(ConnectInfo[] friends) 54 { 55 QuickLaunch self = new QuickLaunch(); 56 57 try { 58 self.trayIcon = new TrayIcon(this.getImageIcon(getIcon16()), 59 Client.getInstance().getMyInfos().getName() + " - Lucane Groupware"); 60 } catch (Throwable t) { 61 self.trayIcon = null; 62 } 63 64 return self; 65 } 66 67 68 71 public void start() 72 { 73 if(this.trayIcon == null) 74 { 75 if(System.getProperty("os.name").startsWith("Win")) 77 DialogBox.error(tr("err.noTray")); 78 else 79 Logging.getLogger().info("Not on windows, running MainInterface instead of QuickLaunch"); 80 81 PluginManager.getInstance().run(MAIN_INTERFACE, new ConnectInfo[0]); 82 Client.getInstance().setStartupPlugin(MAIN_INTERFACE); 83 return; 84 } 85 86 addMenuToTray(); 87 88 this.trayIcon.addMouseListener(this); 89 this.trayIcon.setVisible(true); 90 91 if(getLocalConfig().getInt("show-popup", 1) != 0) 93 { 94 this.trayIcon.showInfo(tr("lucane.is.ready"), "Lucane Groupware"); 95 getLocalConfig().set("show-popup", 0); 96 } 97 } 98 99 public void actionPerformed(ActionEvent ae) 100 { 101 if(ae.getSource() instanceof JMenuItem) 102 { 103 JMenuItem src = (JMenuItem)ae.getSource(); 104 105 if(src.getName().equals("exit")) 106 { 107 cleanExit(); 108 return; 109 } 110 111 if(src.getName().equals(MAIN_INTERFACE)) 112 showMainInterface(); 113 else 114 runPlugin(src.getName()); 115 } 116 else 117 showMainInterface(); 118 } 119 120 public void mouseClicked(MouseEvent e) {} 121 public void mouseEntered(MouseEvent e) {} 122 public void mouseExited(MouseEvent e) {} 123 public void mouseReleased(MouseEvent e) {} 124 public void mousePressed(MouseEvent e) 125 { 126 if(e.getClickCount() == 2) 127 showMainInterface(); 128 } 129 130 131 private void addMenuToTray() 132 { 133 HashMap categories = new HashMap(); 134 135 Iterator plugins = PluginManager.getInstance().getAvailablePlugins(); 137 plugins = PluginComparator.sortPlugins(plugins); 138 139 while(plugins.hasNext()) 140 { 141 Plugin p = (Plugin)plugins.next(); 142 143 JMenu category = (JMenu)categories.get(p.getCategory()); 144 if(category == null) 145 { 146 category = new JMenu(p.getCategory()); 147 categories.put(p.getCategory(), category); 148 149 if(!p.getCategory().equals("Invisible")) 151 this.trayIcon.add(category); 152 } 153 154 ImageIcon icon = new ImageIcon(); 155 try { 156 icon = p.getImageIcon(p.getIcon()); 157 icon = new ImageIcon(icon.getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH)); 158 } catch(Exception e) { 159 } 161 162 JMenuItem menu = new JMenuItem(p.getTitle(), icon); 163 menu.setName(p.getName()); 164 menu.setToolTipText(p.getToolTip()); 165 menu.addActionListener(this); 166 category.add(menu); 167 } 168 169 this.trayIcon.addSeparator(); 170 171 this.trayIcon.add(new WindowMenu(this)); 173 174 JMenuItem menu = new JMenuItem(tr("open")); 176 menu.setName("org.lucane.applications.maininterface"); 177 menu.addActionListener(this); 178 this.trayIcon.add(menu); 179 180 menu = new JMenuItem(tr("exit")); 182 menu.setName("exit"); 183 menu.addActionListener(this); 184 this.trayIcon.add(menu); 185 } 186 187 private void runPlugin(String pluginName) 188 { 189 ConnectInfo[] friends = null; 190 Plugin plugin = PluginManager.getInstance().getPlugin(pluginName); 191 192 if(plugin.isStandalone()) 194 friends = new ConnectInfo[0]; 195 else 196 { 197 ListBox userList = new ListBox(null, plugin.getTitle(), tr("msg.selectUsers"), Client.getInstance().getUserList()); 198 Object [] users = userList.selectItems(); 199 if(users != null) 200 { 201 friends = new ConnectInfo[users.length]; 202 for(int i=0;i<friends.length;i++) 203 friends[i] = Communicator.getInstance().getConnectInfo((String )users[i]); 204 } 205 } 206 207 if(friends != null) 209 PluginManager.getInstance().run(pluginName, friends); 210 } 211 212 private boolean activatePlugin(String pluginName) 213 { 214 boolean activated = false; 215 216 Iterator plugins = PluginManager.getInstance().getRunningPlugins(); 217 while(plugins.hasNext()) 218 { 219 Plugin plugin = (Plugin)plugins.next(); 220 if(!plugin.getName().equals(pluginName)) 221 continue; 222 223 Iterator windows = Client.getInstance().getWindowManager().getWindowsFor(plugin); 224 if(!windows.hasNext()) 225 continue; 226 227 while(windows.hasNext()) 228 { 229 ManagedWindow window = (ManagedWindow)windows.next(); 230 window.show(); 231 } 232 activated = true; 233 } 234 235 return activated; 236 } 237 238 private void showMainInterface() 239 { 240 if(!activatePlugin(MAIN_INTERFACE)) 241 runPlugin(MAIN_INTERFACE); 242 } 243 244 private void cleanExit() 245 { 246 Logging.getLogger().finer("QuickLaunch::cleanExit()"); 247 this.trayIcon.setVisible(false); 248 exit(); 249 } 250 } 251 | Popular Tags |