Mercurial > hg > Members > riono > TreeVNC_ja_comment
annotate src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncRootSelectionPanel.java @ 401:94c520535ef1
Fix selection panel
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 13 Oct 2015 18:21:46 +0900 |
parents | 845698fd6fb6 |
children | 3a7d02844cfe |
rev | line source |
---|---|
206 | 1 package jp.ac.u_ryukyu.treevnc; |
1 | 2 |
3 import javax.swing.*; | |
130 | 4 |
5 import com.glavsoft.viewer.swing.ConnectionParams; | |
6 | |
1 | 7 import java.awt.*; |
8 import java.awt.event.*; | |
398 | 9 import java.io.IOException; |
130 | 10 |
129 | 11 public class TreeVncRootSelectionPanel extends JFrame implements ActionListener, |
1 | 12 ItemListener { |
13 | |
14 /** | |
15 * | |
16 */ | |
17 private static final long serialVersionUID = 1L; | |
398 | 18 private final FindRoot findRoot; |
19 private JPanel panel = new JPanel(); | |
1 | 20 private JButton button = new JButton("Connect"); |
398 | 21 private JButton startRootButton = new JButton("Start as TreeVNC Root"); |
22 private JButton startDisplayButton = new JButton("Start Display Mode"); | |
23 private TextField t1; | |
1 | 24 private TextField t2; |
25 private double width = 750; | |
26 private double height = 500; | |
27 private JLabel label; | |
28 private boolean flag; | |
29 private int counter = 0; | |
30 // private JCheckBox[] check = new JCheckBox[20]; | |
31 private Checkbox[] check = new Checkbox[20]; | |
32 private String port; | |
33 private CheckboxGroup ch = new CheckboxGroup(); | |
32 | 34 private Container contentPane = getContentPane(); |
130 | 35 private CreateConnectionParam cp; |
1 | 36 |
398 | 37 public TreeVncRootSelectionPanel(final FindRoot findRoot) { |
38 this.findRoot = findRoot; | |
39 setTitle("TreeVNC Root Address"); | |
40 setResizable(false); | |
41 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
42 panel.add(startRootButton); | |
43 panel.add(startDisplayButton); | |
44 startRootButton.addActionListener(new ActionListener() { | |
399
28d67bbfa9f1
Implement SelectionPanel processing
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
45 @Override |
28d67bbfa9f1
Implement SelectionPanel processing
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
46 public void actionPerformed(ActionEvent e) { |
28d67bbfa9f1
Implement SelectionPanel processing
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
47 cp.setRootMode(); |
28d67bbfa9f1
Implement SelectionPanel processing
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
48 cp.restart(); |
28d67bbfa9f1
Implement SelectionPanel processing
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
49 unVisible(); |
28d67bbfa9f1
Implement SelectionPanel processing
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
50 } |
28d67bbfa9f1
Implement SelectionPanel processing
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
51 }); |
28d67bbfa9f1
Implement SelectionPanel processing
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
52 startDisplayButton.addActionListener(new ActionListener() { |
398 | 53 @Override |
400
845698fd6fb6
Remove synchronized
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
399
diff
changeset
|
54 public void actionPerformed(ActionEvent e) { |
399
28d67bbfa9f1
Implement SelectionPanel processing
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
55 cp.setDisplayMode(); |
401
94c520535ef1
Fix selection panel
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
400
diff
changeset
|
56 cp.restart(); |
94c520535ef1
Fix selection panel
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
400
diff
changeset
|
57 unVisible(); |
399
28d67bbfa9f1
Implement SelectionPanel processing
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
58 } |
398 | 59 }); |
399
28d67bbfa9f1
Implement SelectionPanel processing
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
60 contentPane.add(panel, BorderLayout.CENTER); |
28d67bbfa9f1
Implement SelectionPanel processing
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
398
diff
changeset
|
61 } |
398 | 62 |
63 public void ipRegister() { | |
1 | 64 setSize(); |
65 setText(); | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
66 setButton(); |
1 | 67 visible(); |
68 } | |
69 | |
70 private void setSize() { | |
71 Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); | |
72 width = (d.getWidth() / 2); | |
73 height = (d.getHeight() / 2); | |
74 } | |
75 | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
76 public void visible() { |
1 | 77 Point point = new Point(); |
78 point.setLocation(width - 250, height - 80); | |
79 setLocation(point.getLocation()); | |
80 pack(); | |
81 setVisible(true); | |
82 } | |
83 | |
84 public void unVisible() { | |
85 setVisible(false); | |
86 } | |
87 | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
88 private void setText() { |
1 | 89 t1 = new TextField("Address", 30); |
130 | 90 t2 = new TextField(Integer.toString(ConnectionParams.DEFAULT_VNC_ROOT), 5); |
1 | 91 panel.add(t1); |
92 panel.add(t2); | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
93 //panel.add(button); |
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
94 //button.addActionListener(this); |
1 | 95 label = new JLabel(); |
96 contentPane.add(panel, BorderLayout.CENTER); | |
97 contentPane.add(label, BorderLayout.SOUTH); | |
98 } | |
99 | |
2
dca3bd61b830
before change MyVncClient.java
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
1
diff
changeset
|
100 public void checkBox(String str) { |
1 | 101 if (counter == 0) |
102 check[counter] = new Checkbox(str, true, ch); | |
103 else | |
104 check[counter] = new Checkbox(str, false, ch); | |
105 check[counter].addItemListener(this); | |
106 panel.add(check[counter]); | |
107 panel.setLayout(new GridLayout(counter + 2, 0)); | |
108 panel.setLocation((int) width - 250, (int) height - 80); | |
109 counter++; | |
110 } | |
111 | |
112 public void setButton() { | |
113 panel.add(button); | |
114 button.addActionListener(this); | |
115 contentPane.add(panel, BorderLayout.CENTER); | |
116 } | |
117 | |
118 public String getAddressOption() { | |
119 while (!(flag)) { | |
120 try { | |
121 Thread.sleep(500); | |
122 } catch (InterruptedException e) { | |
123 e.printStackTrace(); | |
124 } | |
125 } | |
126 return t1.getText(); | |
127 } | |
128 | |
129 public String getPortOption() { | |
130 return t2.getText(); | |
131 } | |
132 | |
133 public String getPort() { | |
134 return port; | |
135 } | |
136 | |
137 public void actionPerformed(ActionEvent e) { | |
138 flag = true; | |
139 for (int t = 0; t < counter; t++) { | |
262
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
140 int ipv4AddressLength = 3; |
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
141 int ipv6AddressLength = 17; |
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
142 String port = null; |
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
143 String hostAddress = null; |
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
144 String rootAddress = null; |
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
145 if (check[t].getState()) { |
1 | 146 System.out.println(check[t].getLabel()); |
145
649794dfb9d5
add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
147 String str = check[t].getLabel(); |
649794dfb9d5
add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
148 String[] temp = str.split(":"); |
262
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
149 if (temp.length == ipv4AddressLength) { |
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
150 // IPv4 Address |
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
151 port = temp[0]; |
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
152 hostAddress = temp[1]; |
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
153 rootAddress = temp[2]; |
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
154 } else if (temp.length == ipv6AddressLength) { |
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
155 // IPv6 Address |
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
156 port = temp[0]; |
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
157 hostAddress = temp[1] + ":" + temp[2] + ":" + temp[3] + ":" + temp[4] + ":" + temp[5] + ":" + temp[6] + ":" + temp[7] + ":" + temp[8]; |
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
158 rootAddress = temp[9] + ":" + temp[10] + ":" + temp[11] + ":" + temp[12] + ":" + temp[13] + ":" + temp[14] + ":" + temp[15] + ":" + temp[16]; |
7d8f45cadd89
add parse port and hostAddress and rootAddress, when IPv6 adderss.
oc
parents:
206
diff
changeset
|
159 } |
145
649794dfb9d5
add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
160 cp.setHostName(hostAddress,Integer.parseInt(port),rootAddress); |
649794dfb9d5
add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
161 unVisible(); |
1 | 162 } |
163 } | |
164 } | |
165 | |
166 | |
167 public void itemStateChanged(ItemEvent e) { | |
168 } | |
130 | 169 |
170 public void setCp(CreateConnectionParam cp) { | |
171 this.cp = cp; | |
172 } | |
1 | 173 } |