changeset 129:a6dc674546f2

change connection param expression timing.
author oc
date Fri, 06 Jun 2014 21:12:45 +0900
parents 0cf1541f69bb
children 1f6bfaa3281b
files src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java src/main/java/jp/ac/u_ryukyu/treevnc/client/GetHostClient.java src/main/java/jp/ac/u_ryukyu/treevnc/client/TextBoxClient.java src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncRootSelectionPanel.java src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java src/main/java/jp/ac/u_ryukyu/treevnc/test/TestTextBox.java src/viewer_swing/java/com/glavsoft/viewer/Viewer.java src/viewer_swing/java/com/glavsoft/viewer/ViewerImpl.java
diffstat 8 files changed, 222 insertions(+), 194 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java	Fri Jun 06 20:28:59 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java	Fri Jun 06 21:12:45 2014 +0900
@@ -87,14 +87,23 @@
 		int command = buf.get()&0xff;
 
 		switch (command) {
+		case ProtocolContext.FIND_ROOT_REPLY :
+			handleFindRootReply(buf);
+			break;
 		case ProtocolContext.FIND_ROOT : 
-		case ProtocolContext.FIND_ROOT_REPLY :
 		case ProtocolContext.WHERE_TO_CONNECT : 
 		case ProtocolContext.LOST_PARENT :
 			System.out.println("get treeVNC command" + command);
 		}
 	}
 
+	private void handleFindRootReply(ByteBuffer buf) {
+		String hostname;
+		int port;
+		viewer.addHostToSelectionPanel(port, hostname);
+		
+	}
+
 	public void newClient(AcceptThread acceptThread, final Socket newCli,
 			final Writer os, final Reader is) throws IOException, TransportException {
 
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/GetHostClient.java	Fri Jun 06 20:28:59 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/GetHostClient.java	Fri Jun 06 21:12:45 2014 +0900
@@ -28,7 +28,7 @@
     private BufferedReader is;
     private int port;
     private boolean stopFlag;
-    private TextBoxClient text = new TextBoxClient();
+    private TreeVncRootSelectionPanel rootSelectionPanel = new TreeVncRootSelectionPanel();
     private String proxyAddr;
 
     /**
@@ -97,16 +97,16 @@
      * 
      */
     public String textAddress() {
-        return text.getAddress();
+        return rootSelectionPanel.getAddress();
     }
     
     public String  textPort() {
-        return text.getPort();
+        return rootSelectionPanel.getPort();
     }
     
     void socketClose() {
         try {
-            text.unVisible();
+            rootSelectionPanel.unVisible();
             is.close();
         } catch (IOException e) {
             e.printStackTrace();
@@ -130,17 +130,18 @@
                 // GetBroadCastProxy create this string on VNC root
                 InetAddress adr = socket.getInetAddress();
                 String proxyAddr1 = adr.getHostName();
+                String proxyAddr2 = null;
                 if (proxyAddr1 != null) {
                     int portIndex = proxyAddr.indexOf(":");
                     int restIndex = proxyAddr.indexOf(":", portIndex+1);
                     if (portIndex>0) {
-                        proxyAddr = proxyAddr.substring(0, portIndex)+":"+proxyAddr1 + ":" + proxyAddr.substring(restIndex+1);
+                        proxyAddr2 = proxyAddr.substring(0, portIndex)+":"+proxyAddr1 + ":" + proxyAddr.substring(restIndex+1);
                     }
                 }
-                if(proxyAddr!=null)
-                    text.checkBox(proxyAddr);
-                text.setButton();
-                text.visible();
+                if(proxyAddr2!=null)
+                    rootSelectionPanel.checkBox(proxyAddr2);
+                rootSelectionPanel.setButton();
+                rootSelectionPanel.visible();
             }
             System.err.println("stop");
         } catch (IOException e) {
@@ -173,7 +174,7 @@
     }
     
     public void ipRegister() {
-        text.ipRegister();
+        rootSelectionPanel.ipRegister();
     }
 
     public String getProxyAddr() {
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/TextBoxClient.java	Fri Jun 06 20:28:59 2014 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,181 +0,0 @@
-package jp.ac.u_ryukyu.treevnc.client;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.*;
-import java.util.ArrayList;
-
-public class TextBoxClient extends JFrame implements ActionListener,
-		ItemListener {
-
-	/**
-	 * 
-	 */
-	private static final long serialVersionUID = 1L;
-	private JPanel panel = new JPanel();
-	private JButton button = new JButton("Connect");
-	private TextField t1;
-	private TextField t2;
-	private double width = 750;
-	private double height = 500;
-	private JLabel label;
-	private boolean flag;
-	private ArrayList<String> temp = new ArrayList<String>();
-	private int counter = 0;
-	// private JCheckBox[] check = new JCheckBox[20];
-	private Checkbox[] check = new Checkbox[20];
-	private boolean firstFlag = true;
-	private String hostAddress;
-	private String port;
-	private CheckboxGroup ch = new CheckboxGroup();
-	private Container contentPane = getContentPane();
-
-	public TextBoxClient() {
-		setTitle("TreeVNC Root Address");
-		setResizable(false);
-		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-	}
-
-	public void ipRegister() {
-		setSize();
-		setText();
-		setButton();
-		visible();
-	}
-
-	private void setSize() {
-		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
-		width = (d.getWidth() / 2);
-		height = (d.getHeight() / 2);
-	}
-
-	public void visible() {
-		Point point = new Point();
-		point.setLocation(width - 250, height - 80);
-		setLocation(point.getLocation());
-		pack();
-		setVisible(true);
-	}
-
-	public void unVisible() {
-		setVisible(false);
-	}
-
-	private  void setText() {
-		t1 = new TextField("Address", 30);
-		t2 = new TextField("5999", 5);
-		panel.add(t1);
-		panel.add(t2);
-		//panel.add(button);
-		//button.addActionListener(this);
-		label = new JLabel();
-		contentPane.add(panel, BorderLayout.CENTER);
-		contentPane.add(label, BorderLayout.SOUTH);
-	}
-
-	public void checkBox(String str) {
-		if (counter == 0)
-			check[counter] = new Checkbox(str, true, ch);
-		else
-			check[counter] = new Checkbox(str, false, ch);
-		check[counter].addItemListener(this);
-		panel.add(check[counter]);
-		panel.setLayout(new GridLayout(counter + 2, 0));
-		panel.setLocation((int) width - 250, (int) height - 80);
-		counter++;
-	}
-
-	public void setButton() {
-		panel.add(button);
-		button.addActionListener(this);
-		contentPane.add(panel, BorderLayout.CENTER);
-	}
-
-	public String getAddressOption() {
-		while (!(flag)) {
-			try {
-				Thread.sleep(500);
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-			}
-		}
-		return t1.getText();
-	}
-
-	public String getAddress() {
-		int i = 0;
-		while (!(flag)) {
-			if (i >= 50) {
-				return "notFound";
-			}
-			try {
-				Thread.sleep(500);
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-			}
-			i++;
-		}
-		return hostAddress;
-	}
-
-	public String getPortOption() {
-		return t2.getText();
-	}
-
-	public String getPort() {
-		return port;
-	}
-
-	public void actionPerformed(ActionEvent e) {
-		flag = true;
-		for (int t = 0; t < counter; t++) {
-			if (check[t].getState()) {
-				System.out.println(check[t].getLabel());
-				setStatus(check[t].getLabel());
-				unVisible();
-			}
-		}
-	}
-
-	private void setStatus(String str) {
-		String[] temp = str.split(":");
-		if (temp.length == 2) {
-			hostAddress = temp[0];
-			port = temp[1];
-		} else {
-			port = temp[0];
-			System.out.println("root=" + str);
-			hostAddress = temp[1];
-		}
-	}
-
-	String splitString(String str) {
-		String[] split = str.split("\\*");
-		String comper;
-		if (split.length > 4) {
-			split[4] = null;
-		}
-		comper = split[1] + split[3];
-		if (firstFlag) {
-			temp.add(comper);
-			firstFlag = false;
-			return "port:" + split[0] + ":host:" + split[1] + ":proxy:"
-					+ split[3];
-		}
-		for (int t = 0; t < temp.size(); t++) {
-			if (!(comper.equals(temp.get(t)))) {
-				if (t == temp.size() - 1) {
-					temp.add(comper);
-					return "port:" + split[0] + ":host:" + split[1] + ":proxy:"
-							+ split[3];
-				}
-			} else {
-				break;
-			}
-		}
-		return null;
-	}
-
-	public void itemStateChanged(ItemEvent e) {
-	}
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncRootSelectionPanel.java	Fri Jun 06 21:12:45 2014 +0900
@@ -0,0 +1,181 @@
+package jp.ac.u_ryukyu.treevnc.client;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.util.ArrayList;
+
+public class TreeVncRootSelectionPanel extends JFrame implements ActionListener,
+		ItemListener {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+	private JPanel panel = new JPanel();
+	private JButton button = new JButton("Connect");
+	private TextField t1;
+	private TextField t2;
+	private double width = 750;
+	private double height = 500;
+	private JLabel label;
+	private boolean flag;
+	private ArrayList<String> temp = new ArrayList<String>();
+	private int counter = 0;
+	// private JCheckBox[] check = new JCheckBox[20];
+	private Checkbox[] check = new Checkbox[20];
+	private boolean firstFlag = true;
+	private String hostAddress;
+	private String port;
+	private CheckboxGroup ch = new CheckboxGroup();
+	private Container contentPane = getContentPane();
+
+	public TreeVncRootSelectionPanel() {
+		setTitle("TreeVNC Root Address");
+		setResizable(false);
+		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+	}
+
+	public void ipRegister() {
+		setSize();
+		setText();
+		setButton();
+		visible();
+	}
+
+	private void setSize() {
+		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
+		width = (d.getWidth() / 2);
+		height = (d.getHeight() / 2);
+	}
+
+	public void visible() {
+		Point point = new Point();
+		point.setLocation(width - 250, height - 80);
+		setLocation(point.getLocation());
+		pack();
+		setVisible(true);
+	}
+
+	public void unVisible() {
+		setVisible(false);
+	}
+
+	private  void setText() {
+		t1 = new TextField("Address", 30);
+		t2 = new TextField("5999", 5);
+		panel.add(t1);
+		panel.add(t2);
+		//panel.add(button);
+		//button.addActionListener(this);
+		label = new JLabel();
+		contentPane.add(panel, BorderLayout.CENTER);
+		contentPane.add(label, BorderLayout.SOUTH);
+	}
+
+	public void checkBox(String str) {
+		if (counter == 0)
+			check[counter] = new Checkbox(str, true, ch);
+		else
+			check[counter] = new Checkbox(str, false, ch);
+		check[counter].addItemListener(this);
+		panel.add(check[counter]);
+		panel.setLayout(new GridLayout(counter + 2, 0));
+		panel.setLocation((int) width - 250, (int) height - 80);
+		counter++;
+	}
+
+	public void setButton() {
+		panel.add(button);
+		button.addActionListener(this);
+		contentPane.add(panel, BorderLayout.CENTER);
+	}
+
+	public String getAddressOption() {
+		while (!(flag)) {
+			try {
+				Thread.sleep(500);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+		return t1.getText();
+	}
+
+	public String getAddress() {
+		int i = 0;
+		while (!(flag)) {
+			if (i >= 50) {
+				return "notFound";
+			}
+			try {
+				Thread.sleep(500);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+			i++;
+		}
+		return hostAddress;
+	}
+
+	public String getPortOption() {
+		return t2.getText();
+	}
+
+	public String getPort() {
+		return port;
+	}
+
+	public void actionPerformed(ActionEvent e) {
+		flag = true;
+		for (int t = 0; t < counter; t++) {
+			if (check[t].getState()) {
+				System.out.println(check[t].getLabel());
+				setStatus(check[t].getLabel());
+				unVisible();
+			}
+		}
+	}
+
+	private void setStatus(String str) {
+		String[] temp = str.split(":");
+		if (temp.length == 2) {
+			hostAddress = temp[0];
+			port = temp[1];
+		} else {
+			port = temp[0];
+			System.out.println("root=" + str);
+			hostAddress = temp[1];
+		}
+	}
+
+	String splitString(String str) {
+		String[] split = str.split("\\*");
+		String comper;
+		if (split.length > 4) {
+			split[4] = null;
+		}
+		comper = split[1] + split[3];
+		if (firstFlag) {
+			temp.add(comper);
+			firstFlag = false;
+			return "port:" + split[0] + ":host:" + split[1] + ":proxy:"
+					+ split[3];
+		}
+		for (int t = 0; t < temp.size(); t++) {
+			if (!(comper.equals(temp.get(t)))) {
+				if (t == temp.size() - 1) {
+					temp.add(comper);
+					return "port:" + split[0] + ":host:" + split[1] + ":proxy:"
+							+ split[3];
+				}
+			} else {
+				break;
+			}
+		}
+		return null;
+	}
+
+	public void itemStateChanged(ItemEvent e) {
+	}
+}
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java	Fri Jun 06 20:28:59 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java	Fri Jun 06 21:12:45 2014 +0900
@@ -7,6 +7,7 @@
 import java.util.logging.Logger;
 
 import jp.ac.u_ryukyu.treevnc.AcceptThread;
+import jp.ac.u_ryukyu.treevnc.client.TreeVncRootSelectionPanel;
 
 import com.glavsoft.core.SettingsChangedEvent;
 import com.glavsoft.rfb.IChangeSettingsListener;
@@ -206,4 +207,16 @@
 	public  LinkedList<String> clientList() {
 		return clients.getList();
 	}
+
+	public void addHostToSelectionPanel(int port, String hostname) {
+		if (rootSelectionPanel != null) {
+			rootSelectionPanel.checkBox(Integer.toString(port) + ":" + hostname);
+			rootSelectionPanel.setButton();
+			rootSelectionPanel.visible();			
+		}
+	}
+	
+	public void createRootSelectionPanel() {
+		rootSelectionPanel = new TreeVncRootSelectionPanel();
+	}
 }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/test/TestTextBox.java	Fri Jun 06 20:28:59 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/test/TestTextBox.java	Fri Jun 06 21:12:45 2014 +0900
@@ -1,9 +1,9 @@
 package jp.ac.u_ryukyu.treevnc.test;
 
-import jp.ac.u_ryukyu.treevnc.client.TextBoxClient;
+import jp.ac.u_ryukyu.treevnc.client.TreeVncRootSelectionPanel;
 
 public class TestTextBox {
-	TextBoxClient text = new TextBoxClient();
+	TreeVncRootSelectionPanel text = new TreeVncRootSelectionPanel();
 	public static void main(String[] args) {
 			TestTextBox t = new TestTextBox();
 			t.testText();
--- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java	Fri Jun 06 20:28:59 2014 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java	Fri Jun 06 21:12:45 2014 +0900
@@ -34,6 +34,7 @@
 import com.glavsoft.viewer.swing.gui.ConnectionView;
 
 import javax.swing.*;
+
 import java.awt.*;
 import java.awt.event.WindowEvent;
 import java.awt.event.WindowListener;
@@ -47,6 +48,7 @@
 import jp.ac.u_ryukyu.treevnc.CreateConnectionParam;
 import jp.ac.u_ryukyu.treevnc.MyRfbProto;
 import jp.ac.u_ryukyu.treevnc.client.MyRfbProtoClient;
+import jp.ac.u_ryukyu.treevnc.client.TreeVncRootSelectionPanel;
 
 @SuppressWarnings("serial")
 public class Viewer extends JApplet implements Runnable, WindowListener , ViewerImpl{
@@ -66,6 +68,7 @@
     boolean isTreeVNC = false;
     protected MyRfbProto myRfb;
 	private boolean noConnection;
+	public TreeVncRootSelectionPanel rootSelectionPanel = null;
 
     public static void main(String[] args) {
 		Parser parser = new Parser();
--- a/src/viewer_swing/java/com/glavsoft/viewer/ViewerImpl.java	Fri Jun 06 20:28:59 2014 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/ViewerImpl.java	Fri Jun 06 21:12:45 2014 +0900
@@ -27,4 +27,6 @@
     public void startViewer(String hostName, boolean b);
 
     public void startViewer();
+
+	public void createRootSelectionPanel();
 }