KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > agent > client > gui > awt > BasicFrameGUI


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.agent.client.gui.awt;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Color JavaDoc;
24 import java.awt.Component JavaDoc;
25 import java.awt.Dimension JavaDoc;
26 import java.awt.Frame JavaDoc;
27 import java.awt.Image JavaDoc;
28 import java.awt.Menu JavaDoc;
29 import java.awt.MenuBar JavaDoc;
30 import java.awt.MenuItem JavaDoc;
31 import java.awt.Panel JavaDoc;
32 import java.awt.event.ActionEvent JavaDoc;
33 import java.awt.event.ActionListener JavaDoc;
34 import java.awt.event.WindowAdapter JavaDoc;
35 import java.awt.event.WindowEvent JavaDoc;
36 import java.util.Hashtable JavaDoc;
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 /**
45  * Implementation of an {@link AbstractAWTGUI} that uses a simple frame to provide
46  * a GUI for the Agent. This is most likely to be used on platforms that do not
47  * support system tray functionality.
48  *
49  * @author Lee David Painter <a HREF="mailto: lee@3sp.com">&lt;lee@3sp.com&gt;</a>
50  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
51  */

52 public class BasicFrameGUI extends AbstractAWTGUI {
53
54     // Private instance variables
55

56     private Image JavaDoc idle;
57     private Image JavaDoc tx;
58     private Image JavaDoc rx;
59     private Image JavaDoc txrx;
60     private Image JavaDoc disconnected;
61     private Image JavaDoc banner;
62     private ImageCanvas activityPanel;
63     private Frame JavaDoc frame;
64     private Menu JavaDoc file;
65     private MenuBar JavaDoc menu;
66     private Hashtable JavaDoc menuLookup;
67
68     /* (non-Javadoc)
69      * @see com.sslexplorer.agent.client.AgentClientGUI#init(com.sslexplorer.agent.client.Agent)
70      */

71     public void init(Agent agent) {
72         super.init(agent);
73
74         MenuItem JavaDoc open = new MenuItem JavaDoc(Messages.getString("GUI.menu.openBrowser")); //$NON-NLS-1$
75
open.addActionListener(new ActionListener JavaDoc() {
76             public void actionPerformed(ActionEvent JavaDoc evt) {
77                 openBrowser(null);
78             }
79         });
80
81         // #ifdef DEBUG
82
MenuItem JavaDoc console = new MenuItem JavaDoc(Messages.getString("GUI.menu.debugConsole")); //$NON-NLS-1$
83
console.addActionListener(new ActionListener JavaDoc() {
84             public void actionPerformed(ActionEvent JavaDoc evt) {
85                 getConsole().show();
86             }
87         });
88         // #endif
89

90         MenuItem JavaDoc ports = new MenuItem JavaDoc(Messages.getString("GUI.menu.tunnelMonitor")); //$NON-NLS-1$
91
ports.addActionListener(new ActionListener JavaDoc() {
92             public void actionPerformed(ActionEvent JavaDoc evt) {
93                 getPortMonitor().setVisible(!getPortMonitor().isVisible());
94             }
95         });
96
97         MenuItem JavaDoc exit = new MenuItem JavaDoc(Messages.getString("GUI.menu.exit")); //$NON-NLS-1$
98
exit.addActionListener(new ActionListener JavaDoc() {
99             public void actionPerformed(ActionEvent JavaDoc evt) {
100                 getAgent().disconnect();
101             }
102         });
103
104         Panel JavaDoc main = new Panel JavaDoc(new BorderLayout JavaDoc());
105         main.setBackground(Color.black);
106         
107
108         banner = UIUtil.loadImage(getClass(), "/images/banner-small.gif"); //$NON-NLS-1$
109
idle = UIUtil.loadImage(getClass(), "/images/tray-idle.gif"); //$NON-NLS-1$
110
tx = UIUtil.loadImage(getClass(), "/images/tray-tx.gif"); //$NON-NLS-1$
111
rx = UIUtil.loadImage(getClass(), "/images/tray-rx.gif"); //$NON-NLS-1$
112
txrx = UIUtil.loadImage(getClass(), "/images/tray-txrx.gif"); //$NON-NLS-1$
113
disconnected = UIUtil.loadImage(getClass(), "/images/tray-disconnecting.gif"); //$NON-NLS-1$
114

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 JavaDoc(32, 32));
129         activityPanel.setBorder(4);
130         
131         main.add(activityPanel, BorderLayout.EAST);
132
133         menu = new MenuBar JavaDoc();
134         menuLookup = new Hashtable JavaDoc();
135
136         file = new Menu JavaDoc(Messages.getString("GUI.menu.file")); //$NON-NLS-1$
137
// #ifdef DEBUG
138
file.add(console);
139         // #endif
140
file.add(open);
141         file.add(ports);
142         file.addSeparator();
143         file.add(exit);
144         menu.add(file);
145
146         frame = new Frame JavaDoc(Messages.getString("GUI.title")); //$NON-NLS-1$
147
frame.add(main);
148         frame.setSize(440, 96);
149         frame.setMenuBar(menu);
150         frame.setIconImage(UIUtil.loadImage(getClass(), "/images/frame-agent.gif")); //$NON-NLS-1$
151
frame.setVisible(true);
152
153         frame.addWindowListener(new WindowAdapter JavaDoc() {
154             public void windowClosing(WindowEvent JavaDoc e) {
155                 getAgent().disconnect();
156             }
157         });
158     }
159     
160     /* (non-Javadoc)
161      * @see com.sslexplorer.agent.client.AgentClientGUI#addMenu(java.lang.String)
162      */

163     public void addMenu(final String JavaDoc name) {
164         Menu JavaDoc foo = new Menu JavaDoc(name);
165         menuLookup.put(name, foo);
166         menu.add(foo);
167     }
168
169     /* (non-Javadoc)
170      * @see com.sslexplorer.agent.client.AgentClientGUI#removeMenu(java.lang.String)
171      */

172     public void removeMenu(String JavaDoc name) {
173         Menu JavaDoc menu = (Menu JavaDoc)menuLookup.get(name);
174         if(menu != null) {
175             menuLookup.remove(name);
176             this.menu.remove(menu);
177         }
178     }
179     
180     /* (non-Javadoc)
181      * @see com.sslexplorer.agent.client.AgentClientGUI#clearMenu(java.lang.String)
182      */

183     public void clearMenu(String JavaDoc name) {
184         Menu JavaDoc menu = (Menu JavaDoc)menuLookup.get(name);
185         if(menu != null) {
186             while(menu.getItemCount() > 0) {
187                 menu.remove(0);
188             }
189         }
190     }
191     
192     /* (non-Javadoc)
193      * @see com.sslexplorer.agent.client.AgentClientGUI#isMenuExists(java.lang.String)
194      */

195     public boolean isMenuExists(String JavaDoc name) {
196         return menuLookup.containsKey(name);
197     }
198     
199     /* (non-Javadoc)
200      * @see com.sslexplorer.agent.client.AgentClientGUI#addMenuItem(java.lang.String, com.sslexplorer.agent.client.AgentAction)
201      */

202     public void addMenuItem(final String JavaDoc parentName, final AgentAction action) {
203         
204         Menu JavaDoc menu = parentName == null ? file : (Menu JavaDoc) menuLookup.get(parentName);
205         if(menu==null)
206             return;
207         MenuItem JavaDoc item = new MenuItem JavaDoc(action.getAction());
208         item.addActionListener(new ActionListener JavaDoc() {
209             public void actionPerformed(ActionEvent JavaDoc evt) {
210                 action.actionPerformed();
211             }
212         });
213         menu.add(item);
214     }
215
216     /* (non-Javadoc)
217      * @see com.sslexplorer.vpn.client.VPNClientGUI#showIdle()
218      */

219     public void showIdle() {
220         activityPanel.setImage(idle);
221     }
222
223     /* (non-Javadoc)
224      * @see com.sslexplorer.vpn.client.VPNClientGUI#showDisconnected()
225      */

226     public void showDisconnected() {
227         activityPanel.setImage(disconnected);
228     }
229
230     /* (non-Javadoc)
231      * @see com.sslexplorer.vpn.client.VPNClientGUI#showTx()
232      */

233     public void showTx() {
234         activityPanel.setImage(tx);
235     }
236
237     /* (non-Javadoc)
238      * @see com.sslexplorer.vpn.client.VPNClientGUI#showRx()
239      */

240     public void showRx() {
241         activityPanel.setImage(rx);
242     }
243
244     /* (non-Javadoc)
245      * @see com.sslexplorer.agent.client.gui.awt.AbstractAWTGUI#dispose()
246      */

247     public void dispose() {
248         frame.dispose();
249         super.dispose();
250     }
251
252     /* (non-Javadoc)
253      * @see com.sslexplorer.agent.client.AgentClientGUI#addMenuSeperator(java.lang.String)
254      */

255     public void addMenuSeperator(String JavaDoc parentName) {
256     
257         Menu JavaDoc m = parentName == null ? file : (Menu JavaDoc)menuLookup.get(parentName);
258         if(m==null)
259             return;
260         
261         m.addSeparator();
262         
263     }
264
265     /* (non-Javadoc)
266      * @see com.sslexplorer.vpn.client.VPNClientGUI#showTxRx()
267      */

268     public void showTxRx() {
269         activityPanel.setImage(txrx);
270     }
271
272     /* (non-Javadoc)
273      * @see com.sslexplorer.vpn.client.VPNClientGUI#setInfo(java.lang.String)
274      */

275     public void setInfo(String JavaDoc info) {
276         ToolTipManager.getInstance().requestToolTip(activityPanel, info);
277     }
278
279     /* (non-Javadoc)
280      * @see com.sslexplorer.vpn.client.AbstractGUI#getGUIComponent()
281      */

282     public Component JavaDoc getGUIComponent() {
283         return frame;
284     }
285
286 }
287
Popular Tags