1 19 20 package com.sslexplorer.agent.client.gui.awt; 21 22 import java.awt.BorderLayout ; 23 import java.awt.Color ; 24 import java.awt.Component ; 25 import java.awt.Dimension ; 26 import java.awt.Frame ; 27 import java.awt.Image ; 28 import java.awt.Menu ; 29 import java.awt.MenuBar ; 30 import java.awt.MenuItem ; 31 import java.awt.Panel ; 32 import java.awt.event.ActionEvent ; 33 import java.awt.event.ActionListener ; 34 import java.awt.event.WindowAdapter ; 35 import java.awt.event.WindowEvent ; 36 import java.util.Hashtable ; 37 38 import com.sshtools.ui.awt.ImageCanvas; 39 import com.sshtools.ui.awt.UIUtil; 40 import com.sshtools.ui.awt.tooltips.ToolTipManager; 41 import com.sslexplorer.agent.client.Agent; 42 import com.sslexplorer.agent.client.AgentAction; 43 44 52 public class BasicFrameGUI extends AbstractAWTGUI { 53 54 56 private Image idle; 57 private Image tx; 58 private Image rx; 59 private Image txrx; 60 private Image disconnected; 61 private Image banner; 62 private ImageCanvas activityPanel; 63 private Frame frame; 64 private Menu file; 65 private MenuBar menu; 66 private Hashtable menuLookup; 67 68 71 public void init(Agent agent) { 72 super.init(agent); 73 74 MenuItem open = new MenuItem (Messages.getString("GUI.menu.openBrowser")); open.addActionListener(new ActionListener () { 76 public void actionPerformed(ActionEvent evt) { 77 openBrowser(null); 78 } 79 }); 80 81 MenuItem console = new MenuItem (Messages.getString("GUI.menu.debugConsole")); console.addActionListener(new ActionListener () { 84 public void actionPerformed(ActionEvent evt) { 85 getConsole().show(); 86 } 87 }); 88 90 MenuItem ports = new MenuItem (Messages.getString("GUI.menu.tunnelMonitor")); ports.addActionListener(new ActionListener () { 92 public void actionPerformed(ActionEvent evt) { 93 getPortMonitor().setVisible(!getPortMonitor().isVisible()); 94 } 95 }); 96 97 MenuItem exit = new MenuItem (Messages.getString("GUI.menu.exit")); exit.addActionListener(new ActionListener () { 99 public void actionPerformed(ActionEvent evt) { 100 getAgent().disconnect(); 101 } 102 }); 103 104 Panel main = new Panel (new BorderLayout ()); 105 main.setBackground(Color.black); 106 107 108 banner = UIUtil.loadImage(getClass(), "/images/banner-small.gif"); idle = UIUtil.loadImage(getClass(), "/images/tray-idle.gif"); tx = UIUtil.loadImage(getClass(), "/images/tray-tx.gif"); rx = UIUtil.loadImage(getClass(), "/images/tray-rx.gif"); txrx = UIUtil.loadImage(getClass(), "/images/tray-txrx.gif"); disconnected = UIUtil.loadImage(getClass(), "/images/tray-disconnecting.gif"); 115 UIUtil.waitFor(banner, main); 116 UIUtil.waitFor(idle, main); 117 UIUtil.waitFor(tx, main); 118 UIUtil.waitFor(rx, main); 119 UIUtil.waitFor(txrx, main); 120 UIUtil.waitFor(disconnected, main); 121 122 ImageCanvas bannerCanvas = new ImageCanvas(banner); 123 bannerCanvas.setHalign(ImageCanvas.LEFT_ALIGNMENT); 124 bannerCanvas.setBackground(Color.black); 125 main.add(bannerCanvas, BorderLayout.CENTER); 126 127 activityPanel = new ImageCanvas(idle); 128 activityPanel.setSize(new Dimension (32, 32)); 129 activityPanel.setBorder(4); 130 131 main.add(activityPanel, BorderLayout.EAST); 132 133 menu = new MenuBar (); 134 menuLookup = new Hashtable (); 135 136 file = new Menu (Messages.getString("GUI.menu.file")); file.add(console); 139 file.add(open); 141 file.add(ports); 142 file.addSeparator(); 143 file.add(exit); 144 menu.add(file); 145 146 frame = new Frame (Messages.getString("GUI.title")); frame.add(main); 148 frame.setSize(440, 96); 149 frame.setMenuBar(menu); 150 frame.setIconImage(UIUtil.loadImage(getClass(), "/images/frame-agent.gif")); frame.setVisible(true); 152 153 frame.addWindowListener(new WindowAdapter () { 154 public void windowClosing(WindowEvent e) { 155 getAgent().disconnect(); 156 } 157 }); 158 } 159 160 163 public void addMenu(final String name) { 164 Menu foo = new Menu (name); 165 menuLookup.put(name, foo); 166 menu.add(foo); 167 } 168 169 172 public void removeMenu(String name) { 173 Menu menu = (Menu )menuLookup.get(name); 174 if(menu != null) { 175 menuLookup.remove(name); 176 this.menu.remove(menu); 177 } 178 } 179 180 183 public void clearMenu(String name) { 184 Menu menu = (Menu )menuLookup.get(name); 185 if(menu != null) { 186 while(menu.getItemCount() > 0) { 187 menu.remove(0); 188 } 189 } 190 } 191 192 195 public boolean isMenuExists(String name) { 196 return menuLookup.containsKey(name); 197 } 198 199 202 public void addMenuItem(final String parentName, final AgentAction action) { 203 204 Menu menu = parentName == null ? file : (Menu ) menuLookup.get(parentName); 205 if(menu==null) 206 return; 207 MenuItem item = new MenuItem (action.getAction()); 208 item.addActionListener(new ActionListener () { 209 public void actionPerformed(ActionEvent evt) { 210 action.actionPerformed(); 211 } 212 }); 213 menu.add(item); 214 } 215 216 219 public void showIdle() { 220 activityPanel.setImage(idle); 221 } 222 223 226 public void showDisconnected() { 227 activityPanel.setImage(disconnected); 228 } 229 230 233 public void showTx() { 234 activityPanel.setImage(tx); 235 } 236 237 240 public void showRx() { 241 activityPanel.setImage(rx); 242 } 243 244 247 public void dispose() { 248 frame.dispose(); 249 super.dispose(); 250 } 251 252 255 public void addMenuSeperator(String parentName) { 256 257 Menu m = parentName == null ? file : (Menu )menuLookup.get(parentName); 258 if(m==null) 259 return; 260 261 m.addSeparator(); 262 263 } 264 265 268 public void showTxRx() { 269 activityPanel.setImage(txrx); 270 } 271 272 275 public void setInfo(String info) { 276 ToolTipManager.getInstance().requestToolTip(activityPanel, info); 277 } 278 279 282 public Component getGUIComponent() { 283 return frame; 284 } 285 286 } 287 | Popular Tags |