view src/main/java/jp/ac/u_ryukyu/treevnc/CreateConnectionParam.java @ 153:e68dfd1972ac

fix bad names.
author oc
date Fri, 13 Jun 2014 18:04:42 +0900
parents 1291cf1122ca
children 7cea8789387b
line wrap: on
line source

package jp.ac.u_ryukyu.treevnc;

import java.io.IOException;

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

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

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

	public synchronized void findTreeVncRoot() throws InterruptedException {
		rfb.createRootSelectionPanel(this);
		FindRoot getBcast = new FindRoot(rfb.acceptPort,this);
		getBcast.findRoot();
		// wait for RootSelection
		wait();
	}

	/**
	 * To find parent, send WHERE_TO_CONNECT command to the TreeVNC root
	 * Incoming CONNECT_TO message is handled in MyRFBProto
	 * @param v
	 */
	public void createConnectionParam(ViewerInterface v) {
		TreeVncProtocol echo = new TreeVncProtocol(hostName,portNumber);
		rfb.setEcho(echo);
		try {
            echo.whereToConnect(myHostName,rfb.getAcceptPort());
        } catch (IOException e) {
            // cannot send where to connect
        }
	}
	
	public void runTreeVncCommandListener() {
		rfb.selectPort(ConnectionParams.DEFAULT_VNC_ROOT);
		TreeVncCommandCannelListener acceptThread = new TreeVncCommandCannelListener(rfb, rfb.getAcceptPort());
		accThread = new Thread(acceptThread, "tree-vnc-command-listener");
		accThread.start();
	}

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

	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;
	}

	public String getMyHostName() {
	    return myHostName;
	}

    public  Thread getAcceptThread() {
        return accThread;
    }
}