view src/main/java/jp/ac/u_ryukyu/treevnc/CreateConnectionParam.java @ 130:1f6bfaa3281b

root selection panel
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 07 Jun 2014 00:03:13 +0900
parents 0cf1541f69bb
children 128cce60c43c
line wrap: on
line source

package jp.ac.u_ryukyu.treevnc;

import com.glavsoft.viewer.ViewerImpl;
import com.glavsoft.viewer.swing.ConnectionParams;

import jp.ac.u_ryukyu.treevnc.client.TreeVncProtocol;
import jp.ac.u_ryukyu.treevnc.client.GetHostClient;

public class CreateConnectionParam {
	private String hostName;
	private int portNumber = ConnectionParams.DEFAULT_VNC_ROOT;
	private MyRfbProto rfb;
	
	public CreateConnectionParam(MyRfbProto rfb) {
		this.rfb = rfb;
	}

	public void findTreeVncRoot() throws InterruptedException {
		GetHostClient getBcast = new GetHostClient(rfb.acceptPort,this);
		getBcast.getHost();
		// wait for RootSelection
        wait();
	}

	public void createConnectionParam(ViewerImpl v) {
		TreeVncProtocol echo = new TreeVncProtocol(hostName, 9999); 
		rfb.setEcho(echo);
		rfb.setProxyAddr(hostName);
		echo.getParentName();
		v.setConnectionParam(echo.getParentsAddress(), portNumber);
	}
	
	public void runAcceptThread() {
		Thread accThread = new Thread(new AcceptThread(rfb, portNumber));
		accThread.start();
	}

	public void setHostName(String _hostName, int port) {
	    hostName = _hostName;
	    portNumber = port;
	}

	public void setHostName(String hostAndPort) {
	    int i = hostAndPort.indexOf(':'); 
	    if (i>0) {
	        portNumber = Integer.parseInt(hostAndPort.substring(i+1));
	        hostName = hostAndPort.substring(0,i);
	    } else  
	        hostName = hostAndPort;
	}

}