?? joinworkspacedialog.java
字號:
package connex.app.wsUI;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import connex.core.WS.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyAdapter;
public class JoinWorkspaceDialog extends JDialog {
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JTextField logname = new JTextField();
JLabel jLabel1 = new JLabel();
JPasswordField pass = new JPasswordField();
JLabel jLabel2 = new JLabel();
JPanel jPanel2 = new JPanel();
JButton Join = new JButton();
JButton cancel = new JButton();
Workspace toJoin;
boolean canceled = false;
JLabel status = new JLabel();
public JoinWorkspaceDialog(Frame frame, Workspace ws) {
super(frame, true);
this.setTitle(ws.getName());
this.toJoin = ws;
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public JoinWorkspaceDialog() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setSize(334, 189);
getContentPane().setLayout(borderLayout1);
jPanel1.setLayout(null);
logname.setBounds(new Rectangle(129, 20, 176, 24));
if (toJoin.getName().equals("NetPeerGroup")) {
logname.setText(toJoin.getPeerAdv().getName());
}
jLabel1.setText("* Login name");
jLabel1.setBounds(new Rectangle(18, 20, 113, 22));
pass.setBounds(new Rectangle(129, 57, 176, 24));
pass.addKeyListener(new JoinWorkspaceDialog_pass_keyAdapter(this));
jLabel2.setText("* Password");
jLabel2.setBounds(new Rectangle(18, 54, 113, 22));
Join.setText("Join");
Join.addActionListener(new JoinWorkspaceDialog_actionAdapter(this));
cancel.setText("Cancel");
cancel.addActionListener(new JoinWorkspaceDialog_actionAdapter(this));
jPanel2.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setBorder(BorderFactory.createEtchedBorder());
this.addWindowListener(new JoinWorkspaceDialog_this_windowAdapter(this));
status.setPreferredSize(new Dimension(0, 20));
status.setText("");
jPanel1.add(logname);
jPanel1.add(jLabel1);
jPanel1.add(pass);
jPanel1.add(jLabel2);
jPanel2.add(Join);
jPanel2.add(cancel);
this.getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
this.getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
this.getContentPane().add(status, java.awt.BorderLayout.NORTH);
centerFrame();
this.setAlwaysOnTop(true);
}
private void centerFrame() {
// Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
this.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
setVisible(true);
}
public boolean isCanceled() {
return this.canceled;
}
public String getLoginName() {
return logname.getText();
}
public String getPass() {
return new String(pass.getPassword());
}
public void Join_actionPerformed(ActionEvent e) {
if ((getLoginName().trim().equals("")) || (getPass().trim().equals(""))) {
status.setText("please enter Workspace login and password !!");
return;
}
boolean b = true;
if (!WorkspaceUtil.isAuthenticated(toJoin)) {
System.err.println("joining :" + toJoin.getName());
if (!toJoin.getName().equals("NetPeerGroup")) {
b = WorkspaceUtil.joinWorkspace(toJoin,
getLoginName(),
getPass());
} else {
b = Boot.login(getLoginName(), getPass());
}
}
if (WorkspaceUtil.isAuthenticated(toJoin)) {
System.out.println(toJoin.getName() + ": has been joined ");
WorkspaceManager.getInstance().setCurrentWorkspace(toJoin);
}
if (!b) {
status.setText("wrong ID or password !! please try again");
return;
}
this.dispose();
}
public void cancel_actionPerformed(ActionEvent e) {
this.canceled = true;
this.dispose();
}
public void this_windowClosing(WindowEvent e) {
this.canceled = true;
this.dispose();
}
public void pass_keyTyped(KeyEvent e) {
if (e.getKeyChar() == '\n') {
Join_actionPerformed(null);
}
}
}
class JoinWorkspaceDialog_pass_keyAdapter extends KeyAdapter {
private JoinWorkspaceDialog adaptee;
JoinWorkspaceDialog_pass_keyAdapter(JoinWorkspaceDialog adaptee) {
this.adaptee = adaptee; }
public void keyTyped(KeyEvent e) {
adaptee.pass_keyTyped(e); }}
class JoinWorkspaceDialog_this_windowAdapter extends WindowAdapter {
private JoinWorkspaceDialog adaptee;
JoinWorkspaceDialog_this_windowAdapter(JoinWorkspaceDialog adaptee) {
this.adaptee = adaptee;
}
public void windowClosing(WindowEvent e) {
adaptee.this_windowClosing(e);
}
}
class JoinWorkspaceDialog_actionAdapter implements ActionListener {
private JoinWorkspaceDialog adaptee;
JoinWorkspaceDialog_actionAdapter(JoinWorkspaceDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Cancel")) {
adaptee.cancel_actionPerformed(e);
}
if (e.getActionCommand().equals("Join")) {
adaptee.Join_actionPerformed(e);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -