KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > agent > client > standalone > StandaloneGUI


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.standalone;
21
22 import java.io.IOException JavaDoc;
23
24 import org.eclipse.swt.graphics.Image;
25
26 import com.maverick.http.AuthenticationCancelledException;
27 import com.maverick.http.HttpAuthenticator;
28 import com.maverick.http.HttpException;
29 import com.maverick.http.UnsupportedAuthenticationException;
30 import com.sslexplorer.agent.client.AgentAction;
31 import com.sslexplorer.agent.client.gui.swt.SWTAuthenticationDialog;
32 import com.sslexplorer.agent.client.gui.swt.SWTRunner;
33 import com.sslexplorer.agent.client.gui.swt.SWTSystemTrayGUI;
34
35 public class StandaloneGUI extends SWTSystemTrayGUI {
36
37     // #ifdef DEBUG
38
static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(StandaloneGUI.class);
39     // #endif
40

41     private Image authImage;
42     
43     /* (non-Javadoc)
44      * @see com.sslexplorer.agent.client.gui.swt.SWTSystemTrayGUI#doInit()
45      */

46     protected void doInit() {
47         super.doInit();
48         authImage = loadImage(SWTSystemTrayGUI.class, "/images/authentication-dialog.png"); //$NON-NLS-1$
49

50         addMenu("Connection");
51         addMenuItem("Connection", new AgentAction() {
52
53             public void actionPerformed() {
54                 try {
55                     getAgent().connect("localhost", 443, null, null, false);
56                 } catch (IOException JavaDoc e) {
57                     // TODO Auto-generated catch block
58
e.printStackTrace();
59                 } catch (HttpException e) {
60                     // TODO Auto-generated catch block
61
e.printStackTrace();
62                 } catch (UnsupportedAuthenticationException e) {
63                     // TODO Auto-generated catch block
64
e.printStackTrace();
65                 } catch (AuthenticationCancelledException e) {
66                     // TODO Auto-generated catch block
67
e.printStackTrace();
68                 }
69             }
70
71             public String JavaDoc getAction() {
72                 return "Connect";
73             }
74             
75         });
76         addMenuItem("Connection", new AgentAction() {
77
78             public void actionPerformed() {
79                 getAgent().disconnect();
80             }
81
82             public String JavaDoc getAction() {
83                 return "Disconnect";
84             }
85         });
86         addMenuSeperator(null);
87     }
88
89     /* (non-Javadoc)
90      * @see com.sslexplorer.agent.client.gui.swt.SWTSystemTrayGUI#exit()
91      */

92     protected void exit() {
93         super.exit();
94         getAgent().startShutdownProcedure();
95         // #ifdef DEBUG
96
log.info("Exiting JVM."); //$NON-NLS-1$
97
// #endif
98
System.exit(0);
99     }
100
101     /* (non-Javadoc)
102      * @see com.sslexplorer.agent.client.gui.swt.SWTSystemTrayGUI#promptForCredentials(boolean, com.maverick.http.HttpAuthenticator)
103      */

104     public boolean promptForCredentials(final boolean proxy, final HttpAuthenticator authenticator) {
105         return ((Boolean JavaDoc)SWTRunner.syncExec(getDisplay(), new SWTRunner() {
106             public Object JavaDoc doRun() {
107                 return new Boolean JavaDoc(SWTAuthenticationDialog.promptForCredentials(proxy, getShell(), authenticator, proxy ? null : authImage));
108             }
109             
110         })).booleanValue();
111     }
112
113 }
114
Popular Tags