1 19 20 package com.sslexplorer.agent.client.applications; 21 22 import java.io.IOException ; 23 import java.text.MessageFormat ; 24 25 import com.sslexplorer.agent.client.Agent; 26 import com.sslexplorer.agent.client.Messages; 27 import com.sslexplorer.agent.client.TaskProgress; 28 import com.sslexplorer.agent.client.util.ApplicationLauncherEvents; 29 import com.sslexplorer.agent.client.util.TunnelConfiguration; 30 31 38 public class ApplicationEventListener implements ApplicationLauncherEvents { 39 40 static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(ApplicationEventListener.class); 42 44 private static final String LABEL_TITLE = Messages.getString("VPNClient.error"); private Agent client; 47 private TaskProgress progress; 48 private String application; 49 private long totalNumBytes; 50 51 56 public ApplicationEventListener(Agent client) { 57 this.client = client; 58 } 59 60 65 public void startingLaunch(String application) { 66 this.application = application; 67 progress = this.client.getGUI().createTaskProgress( 68 MessageFormat.format(Messages.getString("ApplicationEventListener.application"), new Object [] { application }), Messages.getString("ApplicationEventListener.title"), 100, false); progress.updateValue(7); 71 72 } 73 74 79 public void processingDescriptor() { 80 progress.setMessage(MessageFormat.format( 81 Messages.getString("ApplicationEventListener.processing"), new Object [] { application })); progress.updateValue(14); 83 84 } 85 86 91 public void startDownload(long totalNumBytes) { 92 this.totalNumBytes = totalNumBytes; 93 progress.setMessage(Messages.getString("ApplicationEventListener.downloading")); progress.updateValue(20); 95 } 96 97 102 public void progressedDownload(long bytesSoFar) { 103 int percent = (int) (((float) bytesSoFar / (float) totalNumBytes) * 70f) + 20; 105 progress.updateValue(percent); 106 } 107 108 113 public void completedDownload() { 114 progress.setMessage(Messages.getString("ApplicationEventListener.downloadComplete")); progress.updateValue(90); 116 } 117 118 124 public void executingApplication(String name, String cmdline) { 125 progress.setMessage(MessageFormat.format(Messages.getString("ApplicationEventListener.launching"), new Object [] { name })); progress.updateValue(95); 127 } 128 129 134 public void finishedLaunch() { 135 136 Thread t = new Thread () { 137 public void run() { 138 progress.updateValue(100); 139 try { 140 Thread.sleep(2000); 141 } catch (InterruptedException ex) { 142 } 143 progress.dispose(); 144 } 145 }; 146 147 t.start(); 148 149 } 150 151 157 public TunnelConfiguration createTunnel(String name, String hostToConnect, int portToConnect, boolean usePreferredPort, 158 boolean singleConnection, String sourceInterface)throws IOException { 159 try { 160 return client.getTunnelManager().startTemporaryLocalTunnel(name, hostToConnect, sourceInterface, portToConnect, usePreferredPort, singleConnection, null).getTunnel(); 161 } catch (IOException e) { 162 log.error("Failed to start application tunnel " + name, e); throw e; 166 } 167 } 168 169 174 public void debug(String msg) { 175 log.info(msg); 177 } 179 180 public void error(String msg) { 181 log.error(msg); 183 client.getGUI().popup(null, msg, LABEL_TITLE, "popup-error", -1); 185 } 186 } | Popular Tags |