src/main/java/de/unixwork/im/Main.java

changeset 0
f3095cda599e
equal deleted inserted replaced
-1:000000000000 0:f3095cda599e
1 package de.unixwork.im;
2
3 import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.util.logging.Level;
8 import java.util.logging.Logger;
9 import org.jivesoftware.smack.ConnectionConfiguration;
10 import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
11 import org.jxmpp.stringprep.XmppStringprepException;
12
13
14 public class Main {
15
16 public static void main(String[] args) {
17 // Create the dialog
18 JDialog loginDialog = new JDialog((Frame) null, "Login", true);
19 loginDialog.setSize(300, 200);
20 loginDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
21 loginDialog.setLayout(new BorderLayout(5, 5));
22
23 // Create components
24 JPanel inputPanel = new JPanel(new GridBagLayout());
25 GridBagConstraints gbc = new GridBagConstraints();
26 gbc.fill = GridBagConstraints.HORIZONTAL;
27 gbc.insets = new Insets(5, 5, 5, 5);
28
29 JLabel usernameLabel = new JLabel("Username:");
30 JTextField usernameField = new JTextField(15);
31 JLabel domainLabel = new JLabel("Domain:");
32 JTextField domainField = new JTextField(15);
33 JLabel passwordLabel = new JLabel("Password:");
34 JPasswordField passwordField = new JPasswordField(15);
35
36 gbc.gridx = 0;
37 gbc.gridy = 0;
38 gbc.weightx = 0;
39 inputPanel.add(usernameLabel, gbc);
40
41 gbc.gridx = 1;
42 gbc.gridy = 0;
43 gbc.weightx = 1;
44 inputPanel.add(usernameField, gbc);
45
46 gbc.gridx = 0;
47 gbc.gridy = 1;
48 gbc.weightx = 0;
49 inputPanel.add(domainLabel, gbc);
50
51 gbc.gridx = 1;
52 gbc.gridy = 1;
53 gbc.weightx = 1;
54 inputPanel.add(domainField, gbc);
55
56 gbc.gridx = 0;
57 gbc.gridy = 2;
58 gbc.weightx = 0;
59 inputPanel.add(passwordLabel, gbc);
60
61 gbc.gridx = 1;
62 gbc.gridy = 2;
63 gbc.weightx = 1;
64 inputPanel.add(passwordField, gbc);
65
66 JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
67 JButton loginButton = new JButton("Login");
68 JButton cancelButton = new JButton("Cancel");
69 buttonPanel.add(loginButton);
70 buttonPanel.add(cancelButton);
71
72 // Add panels to the dialog
73 loginDialog.add(inputPanel, BorderLayout.CENTER);
74 loginDialog.add(buttonPanel, BorderLayout.SOUTH);
75
76 // Action listeners
77 loginButton.addActionListener(new ActionListener() {
78 @Override
79 public void actionPerformed(ActionEvent e) {
80 String username = usernameField.getText();
81 String domain = domainField.getText();
82 String password = new String(passwordField.getPassword());
83
84 loginDialog.dispose();
85
86 try {
87 XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
88 .setUsernameAndPassword(username, password)
89 .setXmppDomain(domain)
90 .setResource("IM5")
91 .setHost(domain)
92 .setPort(5222)
93 //.addEnabledSaslMechanism("PLAIN")
94 //.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
95 .build();
96
97 Xmpp xmpp = new Xmpp(config);
98
99 App app = new App(xmpp);
100
101 xmpp.start();
102 } catch (XmppStringprepException ex) {
103 ex.printStackTrace();
104 System.exit(-1);
105 } catch (Exception ex) {
106 ex.printStackTrace();
107 System.exit(-1);
108 }
109 }
110 });
111
112 cancelButton.addActionListener(new ActionListener() {
113 @Override
114 public void actionPerformed(ActionEvent e) {
115 loginDialog.dispose();
116 }
117 });
118
119 // Center the dialog and make it visible
120 loginDialog.setLocationRelativeTo(null);
121 loginDialog.setVisible(true);
122 }
123 }

mercurial