📄 setupframe.java
字号:
else if(e.keyCode == 1 && !matcher.matches()) //过滤中文
e.doit=false;
else if(e.keyCode==8||e.keyCode==0){
e.doit = true;
}else if(e.keyCode==46||e.keyCode==16777262){
e.doit = false;
IP3.setFocus();
}else e.doit = false;
}
});
dot2 = new Label(composite1, SWT.NONE);
dot2.setText(".");
dot2.setLayoutData(gridData7);
IP3 = new Text(composite1, SWT.BORDER);
IP3.setLayoutData(gridData3);
IP3.addVerifyListener(new org.eclipse.swt.events.VerifyListener() {
public void verifyText(org.eclipse.swt.events.VerifyEvent e) {
Pattern pattern = Pattern.compile("[0-9]\\d*");
Matcher matcher = pattern.matcher(e.text);
if(matcher.matches()&&IP3.getText().length()<3){ //处理数字
e.doit=true;
}
else if(e.keyCode == 1 && !matcher.matches()) //过滤中文
e.doit=false;
else if(e.keyCode==8||e.keyCode==0){
e.doit = true;
}else if(e.keyCode==46||e.keyCode==16777262){
e.doit = false;
IP4.setFocus();
}else e.doit = false;
}
});
dot3 = new Label(composite1, SWT.NONE);
dot3.setText(".");
dot3.setLayoutData(gridData6);
IP4 = new Text(composite1, SWT.BORDER);
IP4.setLayoutData(gridData4);
IP4.addVerifyListener(new org.eclipse.swt.events.VerifyListener() {
public void verifyText(org.eclipse.swt.events.VerifyEvent e) {
Pattern pattern = Pattern.compile("[0-9]\\d*");
Matcher matcher = pattern.matcher(e.text);
if(matcher.matches()&&IP4.getText().length()<3){ //处理数字
e.doit=true;
}
else if(e.keyCode == 1 && !matcher.matches()) //过滤中文
e.doit=false;
else if(e.keyCode==8||e.keyCode==0){
e.doit = true;
}else if(e.keyCode==46||e.keyCode==16777262){
e.doit = false;
}else e.doit = false;
}
});
button = new Button(composite1, SWT.NONE);
button.setText("&Add");
button.setLayoutData(gridData2);
list = new List(composite1, SWT.BORDER);
list.setLayoutData(gridData);
list.addListener(SWT.MenuDetect,new Listener(){
public void handleEvent(Event event) {
if (list.getSelectionIndex()>=0) menu.setVisible(true);
}
});
list.addListener(SWT.DefaultSelection,new Listener(){
public void handleEvent(Event event) {
if (list.getSelectionIndex()>=0){
list.remove(list.getSelectionIndex());
writeFile(list.getItems(),"");
}
}
});
button.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
if (!IP1.getText().equals("")&&!IP2.getText().equals("")
&&!IP3.getText().equals("")&&!IP4.getText().equals("")
&&Integer.valueOf(IP1.getText()).intValue()<256
&&Integer.valueOf(IP2.getText()).intValue()<256
&&Integer.valueOf(IP3.getText()).intValue()<256
&&Integer.valueOf(IP4.getText()).intValue()<256){
add(IP1.getText()+"."+IP2.getText()+"."+IP3.getText()+"."+IP4.getText());
IP1.setText("");
IP2.setText("");
IP3.setText("");
IP4.setText("");
}
if (!IP1.getText().equals("")&&Integer.valueOf(IP1.getText()).intValue()>255) IP1.setBackground(new Color(Display.getCurrent(), 255,220,220));
else IP1.setBackground(new Color(Display.getCurrent(), 255,255,255));
if (!IP1.getText().equals("")&&Integer.valueOf(IP2.getText()).intValue()>255) IP2.setBackground(new Color(Display.getCurrent(), 255,220,220));
else IP2.setBackground(new Color(Display.getCurrent(), 255,255,255));
if (!IP1.getText().equals("")&&Integer.valueOf(IP3.getText()).intValue()>255) IP3.setBackground(new Color(Display.getCurrent(), 255,220,220));
else IP3.setBackground(new Color(Display.getCurrent(), 255,255,255));
if (!IP1.getText().equals("")&&Integer.valueOf(IP4.getText()).intValue()>255) IP4.setBackground(new Color(Display.getCurrent(), 255,220,220));
else IP4.setBackground(new Color(Display.getCurrent(), 255,255,255));
}
});
}
private void add(String str){
String[] strlist = list.getItems();
int i = 0;
while(i<strlist.length){
if (strlist[i].equals(str)) break;
i++;
}
if (i==strlist.length) {
list.add(str);
writeFile(strlist,str);
}
}
private void writeFile(String[] strlist,String str){
setupfile = new File("./","CastSetup");
try {
setuppw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(setupfile)));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int i = 0;
while (i<strlist.length){
setuppw.println(strlist[i]);
System.out.println(strlist[i]);
i++;
}
if (!str.equals("")) setuppw.println(str);
setuppw.close();
}
private void readFile(){
setupfile = new File("./","CastSetup");
try {
setupbr = new BufferedReader(new InputStreamReader(new FileInputStream(setupfile)));
while (true){
String str = setupbr.readLine();
if (str==null) break;
else{
list.add(str);
}
}
setupbr.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* This method initializes composite1
*
*/
private void createComposite() {
composite = new Composite(tabFolder, SWT.NONE);
composite.setLayout(null);
createGroup();
createGroup1();
button1 = new Button(composite, SWT.NONE);
button1.setBounds(new Rectangle(270, 240, 61, 23));
button1.setText("&Apply");
button1.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
saveSetup();
}
});
button2 = new Button(composite, SWT.NONE);
button2.setBounds(new Rectangle(203, 240, 61, 23));
button2.setText("&Ok");
button2.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
saveSetup();
SetupFrame.this.getShell().close();
}
});
createGroup2();
}
private void saveSetup(){
Configuration saveCf = new Configuration();
if (text.getText().equals("")||text==null)
try {
text.setText(new String(InetAddress.getLocalHost().getHostName().getBytes()));
} catch (UnknownHostException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (text1.getText().equals("")||text1==null) text1.setText("cmd /c start \"\"");
if (checkBox.getSelection()) saveCf.setValue("Envelop", "true");
else saveCf.setValue("Envelop", "false");
if (checkBox1.getSelection()) saveCf.setValue("Confirm", "true");
else saveCf.setValue("Confirm", "false");
if (checkBox2.getSelection()) saveCf.setValue("Reply", "true");
else saveCf.setValue("Reply", "false");
if (checkBox3.getSelection()) saveCf.setValue("Beep", "true");
else saveCf.setValue("Beep", "false");
if (checkBox4.getSelection()) saveCf.setValue("OnTop", "true");
else saveCf.setValue("OnTop", "false");
saveCf.setValue("HostName", text.getText());
saveCf.setValue("Command", text1.getText());
saveCf.saveFile(NetTransfer.SetupFile,"HostName");
new SendUDPThread("recreate");
}
/**
* This method initializes group
*
*/
private void createGroup() {
group = new Group(composite, SWT.NONE);
group.setText("Host Setup");
group.setLayout(null);
group.setBounds(new Rectangle(5, 5, 336, 72));
text = new Text(group, SWT.BORDER);
text.setBounds(new Rectangle(78, 28, 241, 19));
label = new Label(group, SWT.NONE);
label.setBounds(new Rectangle(18, 28, 58, 16));
label.setText("NiceName:");
}
/**
* This method initializes group1
*
*/
private void createGroup1() {
group1 = new Group(composite, SWT.NONE);
group1.setLayout(null);
group1.setText("Config");
group1.setBounds(new Rectangle(6, 80, 335, 60));
checkBox = new Button(group1, SWT.CHECK);
checkBox.setBounds(new Rectangle(76, 29, 62, 16));
checkBox.setText("Envelop");
checkBox1 = new Button(group1, SWT.CHECK);
checkBox1.setBounds(new Rectangle(13, 28, 75, 16));
checkBox1.setText("Confirm");
checkBox2 = new Button(group1, SWT.CHECK);
checkBox2.setBounds(new Rectangle(141, 28, 53, 16));
checkBox2.setText("Reply");
checkBox3 = new Button(group1, SWT.CHECK);
checkBox3.setBounds(new Rectangle(202, 28, 53, 16));
checkBox3.setText("Beep");
checkBox4 = new Button(group1, SWT.CHECK);
checkBox4.setBounds(new Rectangle(260, 30, 64, 16));
checkBox4.setText("On Top");
}
/**
* This method initializes group2
*
*/
private void createGroup2() {
group2 = new Group(composite, SWT.NONE);
group2.setLayout(null);
group2.setText("Receiver Setup");
group2.setBounds(new Rectangle(7, 141, 334, 75));
label1 = new Label(group2, SWT.NONE);
label1.setBounds(new Rectangle(18, 31, 76, 20));
label1.setText("Run Command:");
text1 = new Text(group2, SWT.BORDER);
text1.setBounds(new Rectangle(102, 31, 217, 19));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -