mirror of https://github.com/sipwise/jitsi.git
parent
b741c059fb
commit
1ccc8a5f28
@ -0,0 +1,242 @@
|
||||
package net.java.sip.communicator.plugin.jabberaccregwizz;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
|
||||
import net.java.sip.communicator.util.*;
|
||||
import net.java.sip.communicator.util.swing.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class AccountPanel
|
||||
extends TransparentPanel
|
||||
implements DocumentListener
|
||||
{
|
||||
private static final Logger logger = Logger.getLogger(AccountPanel.class);
|
||||
|
||||
public static final String USER_NAME_EXAMPLE = "Ex: johnsmith@jabber.org";
|
||||
|
||||
private final JPanel userIDPassPanel
|
||||
= new TransparentPanel(new BorderLayout(10, 10));
|
||||
|
||||
private final JPanel labelsPanel = new TransparentPanel();
|
||||
|
||||
private final JPanel valuesPanel = new TransparentPanel();
|
||||
|
||||
private final JLabel userIDLabel
|
||||
= new JLabel(Resources.getString("plugin.jabberaccregwizz.USERNAME"));
|
||||
|
||||
private final JLabel passLabel
|
||||
= new JLabel(Resources.getString("service.gui.PASSWORD"));
|
||||
|
||||
private final JPanel emptyPanel = new TransparentPanel();
|
||||
|
||||
private final JLabel userIDExampleLabel = new JLabel(USER_NAME_EXAMPLE);
|
||||
|
||||
private final JTextField userIDField = new JTextField();
|
||||
|
||||
private final JPasswordField passField = new JPasswordField();
|
||||
|
||||
private final JCheckBox rememberPassBox = new SIPCommCheckBox(Resources
|
||||
.getString("service.gui.REMEMBER_PASSWORD"));
|
||||
|
||||
private final JPanel registerPanel
|
||||
= new TransparentPanel(new GridLayout(0, 1));
|
||||
|
||||
private final JPanel buttonPanel
|
||||
= new TransparentPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
|
||||
private final JTextArea registerArea = new JTextArea(Resources
|
||||
.getString("plugin.jabberaccregwizz.REGISTER_NEW_ACCOUNT_TEXT"));
|
||||
|
||||
private final JButton registerButton = new JButton(Resources
|
||||
.getString("plugin.jabberaccregwizz.NEW_ACCOUNT_TITLE"));
|
||||
|
||||
private JabberNewAccountDialog jabberNewAccountDialog;
|
||||
|
||||
private final FirstWizardPage parentPage;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>AccountPanel</tt> by specifying the parent
|
||||
* wizard page, where it's contained.
|
||||
* @param parentPage the parent page where this panel is contained
|
||||
*/
|
||||
public AccountPanel(final FirstWizardPage parentPage)
|
||||
{
|
||||
super(new BorderLayout());
|
||||
|
||||
this.parentPage = parentPage;
|
||||
|
||||
labelsPanel.setLayout(new BoxLayout(labelsPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
valuesPanel.setLayout(new BoxLayout(valuesPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
userIDField.getDocument().addDocumentListener(this);
|
||||
rememberPassBox.setSelected(true);
|
||||
|
||||
userIDExampleLabel.setForeground(Color.GRAY);
|
||||
userIDExampleLabel.setFont(userIDExampleLabel.getFont().deriveFont(8));
|
||||
emptyPanel.setMaximumSize(new Dimension(40, 35));
|
||||
userIDExampleLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 0));
|
||||
|
||||
labelsPanel.add(userIDLabel);
|
||||
labelsPanel.add(emptyPanel);
|
||||
labelsPanel.add(passLabel);
|
||||
|
||||
valuesPanel.add(userIDField);
|
||||
valuesPanel.add(userIDExampleLabel);
|
||||
valuesPanel.add(passField);
|
||||
|
||||
userIDPassPanel.add(labelsPanel, BorderLayout.WEST);
|
||||
userIDPassPanel.add(valuesPanel, BorderLayout.CENTER);
|
||||
userIDPassPanel.add(rememberPassBox, BorderLayout.SOUTH);
|
||||
|
||||
registerButton.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent evt)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Reg OK");
|
||||
|
||||
// Open the new account dialog.
|
||||
jabberNewAccountDialog = new JabberNewAccountDialog();
|
||||
|
||||
if (jabberNewAccountDialog.isOK == true)
|
||||
{
|
||||
ConnectionPanel connectionPanel
|
||||
= parentPage.getConnectionPanel();
|
||||
|
||||
if (connectionPanel != null)
|
||||
{
|
||||
connectionPanel
|
||||
.setServerAddress(jabberNewAccountDialog.server);
|
||||
connectionPanel
|
||||
.setServerPort(jabberNewAccountDialog.port);
|
||||
}
|
||||
|
||||
// This userIDField contains the username "@" the server.
|
||||
userIDField.setText(jabberNewAccountDialog.userID + "@"
|
||||
+ jabberNewAccountDialog.server);
|
||||
|
||||
passField.setText(jabberNewAccountDialog.password);
|
||||
}
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Reg End");
|
||||
}
|
||||
});
|
||||
|
||||
buttonPanel.add(registerButton);
|
||||
|
||||
registerArea.setEditable(false);
|
||||
registerArea.setOpaque(false);
|
||||
registerArea.setLineWrap(true);
|
||||
registerArea.setWrapStyleWord(true);
|
||||
|
||||
registerPanel.add(registerArea);
|
||||
registerPanel.add(buttonPanel);
|
||||
|
||||
registerPanel.setBorder(BorderFactory.createTitledBorder(Resources
|
||||
.getString("plugin.jabberaccregwizz.NEW_ACCOUNT_TITLE")));
|
||||
|
||||
JPanel mainPanel = new TransparentPanel();
|
||||
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
|
||||
mainPanel.add(userIDPassPanel);
|
||||
mainPanel.add(Box.createVerticalStrut(10));
|
||||
mainPanel.add(registerPanel);
|
||||
|
||||
add(mainPanel, BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles the <tt>DocumentEvent</tt> triggered when user types in the
|
||||
* UserID field. Enables or disables the "Next" wizard button according to
|
||||
* whether the UserID field is empty.
|
||||
*
|
||||
* @param evt the document event that has triggered this method call.
|
||||
*/
|
||||
public void insertUpdate(DocumentEvent evt)
|
||||
{
|
||||
parentPage.setNextButtonAccordingToUserIDAndResource();
|
||||
|
||||
parentPage.setServerFieldAccordingToUsername(userIDField.getText());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the <tt>DocumentEvent</tt> triggered when user deletes letters
|
||||
* from the User ID field. Enables or disables the "Next" wizard button
|
||||
* according to whether the User ID field is empty.
|
||||
*
|
||||
* @param evt the document event that has triggered this method call.
|
||||
*/
|
||||
public void removeUpdate(DocumentEvent evt)
|
||||
{
|
||||
parentPage.setNextButtonAccordingToUserIDAndResource();
|
||||
|
||||
parentPage.setServerFieldAccordingToUsername(userIDField.getText());
|
||||
}
|
||||
|
||||
public void changedUpdate(DocumentEvent evt) {}
|
||||
|
||||
/**
|
||||
* Returns the username entered in this panel.
|
||||
* @return the username entered in this panel
|
||||
*/
|
||||
String getUsername()
|
||||
{
|
||||
return userIDField.getText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the username to display in the username field.
|
||||
* @param username the username to set
|
||||
*/
|
||||
void setUsername(String username)
|
||||
{
|
||||
userIDField.setText(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the password entered in this panel.
|
||||
* @return the password entered in this panel
|
||||
*/
|
||||
char[] getPassword()
|
||||
{
|
||||
return passField.getPassword();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the password to display in the password field of this panel.
|
||||
* @param password the password to set
|
||||
*/
|
||||
void setPassword(String password)
|
||||
{
|
||||
passField.setText(password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the remember password box is selected.
|
||||
* @return <tt>true</tt> if the remember password check box is selected,
|
||||
* otherwise returns <tt>false</tt>
|
||||
*/
|
||||
boolean isRememberPassword()
|
||||
{
|
||||
return rememberPassBox.isSelected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects/deselects the remember password check box depending on the given
|
||||
* <tt>isRemember</tt> parameter.
|
||||
* @param isRemember indicates if the remember password checkbox should be
|
||||
* selected or not
|
||||
*/
|
||||
void setRememberPassword(boolean isRemember)
|
||||
{
|
||||
rememberPassBox.setSelected(isRemember);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,269 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.plugin.jabberaccregwizz;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
|
||||
import net.java.sip.communicator.util.swing.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class ConnectionPanel
|
||||
extends TransparentPanel
|
||||
{
|
||||
private final TransparentPanel mainPanel = new TransparentPanel();
|
||||
|
||||
private final JPanel advancedOpPanel
|
||||
= new TransparentPanel(new BorderLayout(10, 10));
|
||||
|
||||
private final JPanel labelsAdvOpPanel
|
||||
= new TransparentPanel(new GridLayout(0, 1, 10, 10));
|
||||
|
||||
private final JPanel valuesAdvOpPanel
|
||||
= new TransparentPanel(new GridLayout(0, 1, 10, 10));
|
||||
|
||||
private final JCheckBox sendKeepAliveBox = new SIPCommCheckBox(
|
||||
Resources.getString("plugin.jabberaccregwizz.ENABLE_KEEP_ALIVE"));
|
||||
|
||||
private final JCheckBox gmailNotificationsBox = new SIPCommCheckBox(
|
||||
Resources.getString(
|
||||
"plugin.jabberaccregwizz.ENABLE_GMAIL_NOTIFICATIONS"));
|
||||
|
||||
private final JLabel resourceLabel
|
||||
= new JLabel(Resources.getString("plugin.jabberaccregwizz.RESOURCE"));
|
||||
|
||||
private final JTextField resourceField
|
||||
= new JTextField(JabberAccountRegistration.DEFAULT_RESOURCE);
|
||||
|
||||
private final JLabel priorityLabel = new JLabel(
|
||||
Resources.getString("plugin.jabberaccregwizz.PRIORITY"));
|
||||
|
||||
private final JTextField priorityField
|
||||
= new JTextField(JabberAccountRegistration.DEFAULT_PRIORITY);
|
||||
|
||||
private final JLabel serverLabel
|
||||
= new JLabel(Resources.getString("plugin.jabberaccregwizz.SERVER"));
|
||||
|
||||
private final JTextField serverField = new JTextField();
|
||||
|
||||
private final JLabel portLabel
|
||||
= new JLabel(Resources.getString("plugin.jabberaccregwizz.PORT"));
|
||||
|
||||
private final JTextField portField
|
||||
= new JTextField(JabberAccountRegistration.DEFAULT_PORT);
|
||||
|
||||
private final JabberAccountRegistrationWizard wizard;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>ConnectionPanel</tt> by specifying the parent
|
||||
* wizard, where it's contained.
|
||||
* @param wizard the parent wizard
|
||||
*/
|
||||
public ConnectionPanel(JabberAccountRegistrationWizard wizard)
|
||||
{
|
||||
super(new BorderLayout());
|
||||
|
||||
this.wizard = wizard;
|
||||
|
||||
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
portField.getDocument().addDocumentListener(new DocumentListener()
|
||||
{
|
||||
public void changedUpdate(DocumentEvent evt)
|
||||
{
|
||||
}
|
||||
|
||||
public void insertUpdate(DocumentEvent evt)
|
||||
{
|
||||
setNextButtonAccordingToPortAndPriority();
|
||||
}
|
||||
|
||||
public void removeUpdate(DocumentEvent evt)
|
||||
{
|
||||
setNextButtonAccordingToPortAndPriority();
|
||||
}
|
||||
});
|
||||
|
||||
priorityField.getDocument().addDocumentListener(new DocumentListener()
|
||||
{
|
||||
public void changedUpdate(DocumentEvent evt)
|
||||
{
|
||||
}
|
||||
|
||||
public void insertUpdate(DocumentEvent evt)
|
||||
{
|
||||
setNextButtonAccordingToPortAndPriority();
|
||||
}
|
||||
|
||||
public void removeUpdate(DocumentEvent evt)
|
||||
{
|
||||
setNextButtonAccordingToPortAndPriority();
|
||||
}
|
||||
});
|
||||
|
||||
labelsAdvOpPanel.add(serverLabel);
|
||||
labelsAdvOpPanel.add(portLabel);
|
||||
labelsAdvOpPanel.add(resourceLabel);
|
||||
labelsAdvOpPanel.add(priorityLabel);
|
||||
|
||||
valuesAdvOpPanel.add(serverField);
|
||||
valuesAdvOpPanel.add(portField);
|
||||
valuesAdvOpPanel.add(resourceField);
|
||||
valuesAdvOpPanel.add(priorityField);
|
||||
|
||||
JPanel checkBoxesPanel
|
||||
= new TransparentPanel(new GridLayout(0, 1, 10, 10));
|
||||
checkBoxesPanel.add(sendKeepAliveBox);
|
||||
checkBoxesPanel.add(gmailNotificationsBox);
|
||||
|
||||
advancedOpPanel.add(checkBoxesPanel, BorderLayout.NORTH);
|
||||
advancedOpPanel.add(labelsAdvOpPanel, BorderLayout.WEST);
|
||||
advancedOpPanel.add(valuesAdvOpPanel, BorderLayout.CENTER);
|
||||
|
||||
mainPanel.add(advancedOpPanel);
|
||||
|
||||
add(mainPanel, BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the server address.
|
||||
* @return the server address
|
||||
*/
|
||||
String getServerAddress()
|
||||
{
|
||||
return serverField.getText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the server address.
|
||||
* @param serverAddress the server address
|
||||
*/
|
||||
void setServerAddress(String serverAddress)
|
||||
{
|
||||
serverField.setText(serverAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the server port.
|
||||
* @return the server port
|
||||
*/
|
||||
String getServerPort()
|
||||
{
|
||||
return portField.getText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the server port.
|
||||
* @param serverPort the server port
|
||||
*/
|
||||
void setServerPort(String serverPort)
|
||||
{
|
||||
portField.setText(serverPort);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the resource.
|
||||
* @return the resource
|
||||
*/
|
||||
String getResource()
|
||||
{
|
||||
return resourceField.getText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the resource field value.
|
||||
* @param resource the resource to set
|
||||
*/
|
||||
void setResource(String resource)
|
||||
{
|
||||
resourceField.setText(resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the priority field value.
|
||||
* @return the priority field value
|
||||
*/
|
||||
String getPriority()
|
||||
{
|
||||
return priorityField.getText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the priority field value.
|
||||
* @param priority the priority field value
|
||||
*/
|
||||
void setPriority(String priority)
|
||||
{
|
||||
priorityField.setText(priority);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <tt>true</tt> if the "send keep alive" check box is selected,
|
||||
* otherwise returns <tt>false</tt>.
|
||||
* @return <tt>true</tt> if the "send keep alive" check box is selected,
|
||||
* otherwise returns <tt>false</tt>
|
||||
*/
|
||||
boolean isSendKeepAlive()
|
||||
{
|
||||
return sendKeepAliveBox.isSelected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects/unselects the "send keep alive" check box according to the given
|
||||
* <tt>isSendKeepAlive</tt> property.
|
||||
* @param isSendKeepAlive indicates if the "send keep alive" check box
|
||||
* should be selected or not
|
||||
*/
|
||||
void setSendKeepAlive(boolean isSendKeepAlive)
|
||||
{
|
||||
sendKeepAliveBox.setSelected(isSendKeepAlive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <tt>true</tt> if the "gmail notifications" check box is selected,
|
||||
* otherwise returns <tt>false</tt>.
|
||||
* @return <tt>true</tt> if the "gmail notifications" check box is selected,
|
||||
* otherwise returns <tt>false</tt>
|
||||
*/
|
||||
boolean isGmailNotificationsEnabled()
|
||||
{
|
||||
return gmailNotificationsBox.isSelected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects/unselects the "gmail notifications" check box according to the
|
||||
* given <tt>isEnabled</tt> property.
|
||||
* @param isEnabled indicates if the "gmail notifications"
|
||||
* check box should be selected or not
|
||||
*/
|
||||
void setGmailNotificationsEnabled(boolean isEnabled)
|
||||
{
|
||||
gmailNotificationsBox.setSelected(isEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables Next Button if Port field value is incorrect
|
||||
*/
|
||||
private void setNextButtonAccordingToPortAndPriority()
|
||||
{
|
||||
try
|
||||
{
|
||||
Integer.parseInt(getServerPort());
|
||||
Integer.parseInt(getPriority());
|
||||
wizard.getWizardContainer().setNextFinishButtonEnabled(true);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
wizard.getWizardContainer().setNextFinishButtonEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,526 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.plugin.jabberaccregwizz;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.*;
|
||||
|
||||
import net.java.sip.communicator.util.swing.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class IceConfigPanel
|
||||
extends TransparentPanel
|
||||
{
|
||||
/**
|
||||
* The check box allowing the user to choose to use ICE.
|
||||
*/
|
||||
private final JCheckBox iceBox = new SIPCommCheckBox(
|
||||
Resources.getString("plugin.jabberaccregwizz.USE_ICE"));
|
||||
|
||||
/**
|
||||
* The check box allowing the user to choose to automatically discover
|
||||
* STUN servers.
|
||||
*/
|
||||
private final JCheckBox autoDiscoverBox = new SIPCommCheckBox(
|
||||
Resources.getString("plugin.jabberaccregwizz.AUTO_DISCOVER_STUN"));
|
||||
|
||||
/**
|
||||
* The table model for our additional stun servers table.
|
||||
*/
|
||||
private final DefaultTableModel tableModel = new StunServerTableModel();
|
||||
|
||||
/**
|
||||
* The stun server table.
|
||||
*/
|
||||
private final JTable table = new JTable(tableModel);
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>IceConfigPanel</tt>.
|
||||
*/
|
||||
public IceConfigPanel()
|
||||
{
|
||||
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||
|
||||
iceBox.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
autoDiscoverBox.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
|
||||
JPanel checkBoxPanel = new TransparentPanel(new GridLayout(0, 1));
|
||||
checkBoxPanel.add(iceBox);
|
||||
checkBoxPanel.add(autoDiscoverBox);
|
||||
|
||||
add(checkBoxPanel);
|
||||
add(Box.createVerticalStrut(10));
|
||||
add(createAdditionalServersComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the list of additional STUN/TURN servers that are added by the
|
||||
* user.
|
||||
* @return the created component
|
||||
*/
|
||||
private Component createAdditionalServersComponent()
|
||||
{
|
||||
table.setPreferredScrollableViewportSize(new Dimension(450, 60));
|
||||
|
||||
tableModel.addColumn(
|
||||
Resources.getString("plugin.jabberaccregwizz.IP_ADDRESS")
|
||||
+ "/" + Resources.getString("plugin.jabberaccregwizz.PORT"));
|
||||
tableModel.addColumn(
|
||||
Resources.getString("plugin.jabberaccregwizz.SUPPORT_TURN"));
|
||||
|
||||
table.setDefaultRenderer( StunServer.class,
|
||||
new StunServerCellRenderer());
|
||||
|
||||
//Create the scroll pane and add the table to it.
|
||||
JScrollPane scrollPane = new JScrollPane(table);
|
||||
|
||||
JButton addButton
|
||||
= new JButton(Resources.getString("service.gui.ADD"));
|
||||
addButton.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
StunConfigDialog stunDialog = new StunConfigDialog();
|
||||
|
||||
stunDialog.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
JButton editButton
|
||||
= new JButton(Resources.getString("service.gui.EDIT"));
|
||||
editButton.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
StunServer stunServer
|
||||
= (StunServer) tableModel.getValueAt(
|
||||
table.getSelectedRow(), 0);
|
||||
|
||||
if (stunServer != null)
|
||||
{
|
||||
StunConfigDialog dialog
|
||||
= new StunConfigDialog( stunServer.getIpAddress(),
|
||||
stunServer.getPort(),
|
||||
stunServer.isSupportTurn(),
|
||||
stunServer.getUsername(),
|
||||
stunServer.getPassword());
|
||||
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
JButton deleteButton
|
||||
= new JButton(Resources.getString("service.gui.DELETE"));
|
||||
deleteButton.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
tableModel.removeRow(table.getSelectedRow());
|
||||
}
|
||||
});
|
||||
|
||||
TransparentPanel buttonsPanel
|
||||
= new TransparentPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
|
||||
buttonsPanel.add(addButton);
|
||||
buttonsPanel.add(editButton);
|
||||
buttonsPanel.add(deleteButton);
|
||||
|
||||
TransparentPanel mainPanel = new TransparentPanel(new BorderLayout());
|
||||
mainPanel.setBorder(BorderFactory.createTitledBorder(
|
||||
Resources.getString(
|
||||
"plugin.jabberaccregwizz.ADDITIONAL_STUN_SERVERS")));
|
||||
mainPanel.add(scrollPane);
|
||||
mainPanel.add(buttonsPanel, BorderLayout.SOUTH);
|
||||
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* The STUN configuration window.
|
||||
*/
|
||||
private class StunConfigDialog extends SIPCommDialog
|
||||
{
|
||||
private final JPanel mainPanel = new TransparentPanel(new BorderLayout());
|
||||
private final JTextField addressField = new JTextField();
|
||||
private final JTextField portField = new JTextField();
|
||||
private final JCheckBox supportTurnCheckBox = new JCheckBox(
|
||||
Resources.getString("plugin.jabberaccregwizz.SUPPORT_TURN"));
|
||||
private final JTextField usernameField = new JTextField();
|
||||
private final JPasswordField passwordField = new JPasswordField();
|
||||
private JEditorPane errorMessagePane;
|
||||
|
||||
public StunConfigDialog(String address,
|
||||
String port,
|
||||
boolean isSupportTurn,
|
||||
String username,
|
||||
char[] password)
|
||||
{
|
||||
this();
|
||||
|
||||
addressField.setText(address);
|
||||
portField.setText(port);
|
||||
supportTurnCheckBox.setSelected(isSupportTurn);
|
||||
usernameField.setText(username);
|
||||
passwordField.setText(password.toString());
|
||||
}
|
||||
|
||||
public StunConfigDialog()
|
||||
{
|
||||
super(false);
|
||||
|
||||
setTitle(Resources.getString(
|
||||
"plugin.jabberaccregwizz.ADD_STUN_SERVER"));
|
||||
|
||||
JLabel addressLabel = new JLabel(
|
||||
Resources.getString("plugin.jabberaccregwizz.IP_ADDRESS"));
|
||||
JLabel portLabel = new JLabel(
|
||||
Resources.getString("plugin.jabberaccregwizz.PORT"));
|
||||
JLabel usernameLabel = new JLabel(
|
||||
Resources.getString("plugin.jabberaccregwizz.USERNAME"));
|
||||
JLabel passwordLabel = new JLabel(
|
||||
Resources.getString("service.gui.PASSWORD"));
|
||||
|
||||
TransparentPanel labelsPanel
|
||||
= new TransparentPanel(new GridLayout(0, 1));
|
||||
|
||||
labelsPanel.add(new JLabel());
|
||||
labelsPanel.add(addressLabel);
|
||||
labelsPanel.add(portLabel);
|
||||
labelsPanel.add(usernameLabel);
|
||||
labelsPanel.add(passwordLabel);
|
||||
|
||||
TransparentPanel valuesPanel
|
||||
= new TransparentPanel(new GridLayout(0, 1));
|
||||
|
||||
valuesPanel.add(supportTurnCheckBox);
|
||||
valuesPanel.add(addressField);
|
||||
valuesPanel.add(portField);
|
||||
valuesPanel.add(usernameField);
|
||||
valuesPanel.add(passwordField);
|
||||
|
||||
JButton addButton
|
||||
= new JButton(Resources.getString("service.gui.ADD"));
|
||||
JButton cancelButton
|
||||
= new JButton(Resources.getString("service.gui.CANCEL"));
|
||||
|
||||
addButton.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
String address = addressField.getText();
|
||||
String port = portField.getText();
|
||||
String username = usernameField.getText();
|
||||
char[] password = passwordField.getPassword();
|
||||
|
||||
String errorMessage = null;
|
||||
if (address == null || address.length() <= 0)
|
||||
errorMessage = Resources.getString(
|
||||
"plugin.jabberaccregwizz.NO_STUN_ADDRESS");
|
||||
|
||||
if (username == null || username.length() <= 0)
|
||||
errorMessage = Resources.getString(
|
||||
"plugin.jabberaccregwizz.NO_STUN_USERNAME");
|
||||
|
||||
if (port == null || port.length() <= 0)
|
||||
port = JabberAccountRegistration.DEFAULT_STUN_PORT;
|
||||
|
||||
if (containsStunServer(address, port))
|
||||
errorMessage = Resources.getString(
|
||||
"plugin.jabberaccregwizz.STUN_ALREADY_EXIST");
|
||||
|
||||
if (errorMessage != null)
|
||||
{
|
||||
loadErrorMessage(errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
StunServer stunServer = new StunServer(
|
||||
address,
|
||||
port,
|
||||
supportTurnCheckBox.isSelected(),
|
||||
username,
|
||||
password,
|
||||
table.getRowCount());
|
||||
|
||||
addStunServer(stunServer);
|
||||
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
|
||||
cancelButton.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
|
||||
TransparentPanel buttonsPanel
|
||||
= new TransparentPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
buttonsPanel.add(addButton);
|
||||
buttonsPanel.add(cancelButton);
|
||||
|
||||
mainPanel.add(labelsPanel, BorderLayout.WEST);
|
||||
mainPanel.add(valuesPanel, BorderLayout.CENTER);
|
||||
mainPanel.add(buttonsPanel, BorderLayout.SOUTH);
|
||||
|
||||
mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
getContentPane().add(mainPanel, BorderLayout.NORTH);
|
||||
pack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the given error message in the current dialog, by re-validating
|
||||
* the content.
|
||||
*
|
||||
* @param errorMessage The error message to load.
|
||||
*/
|
||||
private void loadErrorMessage(String errorMessage)
|
||||
{
|
||||
if (errorMessagePane == null)
|
||||
{
|
||||
errorMessagePane = new JEditorPane();
|
||||
|
||||
errorMessagePane.setOpaque(false);
|
||||
errorMessagePane.setForeground(Color.RED);
|
||||
|
||||
mainPanel.add(errorMessagePane, BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
errorMessagePane.setText(errorMessage);
|
||||
mainPanel.revalidate();
|
||||
mainPanel.repaint();
|
||||
|
||||
this.pack();
|
||||
|
||||
//WORKAROUND: there's something wrong happening in this pack and
|
||||
//components get cluttered, partially hiding the password text field.
|
||||
//I am under the impression that this has something to do with the
|
||||
//message pane preferred size being ignored (or being 0) which is why
|
||||
//I am adding it's height to the dialog. It's quite ugly so please fix
|
||||
//if you have something better in mind.
|
||||
this.setSize(getWidth(), getHeight()+errorMessagePane.getHeight());
|
||||
}
|
||||
@Override
|
||||
protected void close(boolean escaped) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* A custom cell renderer used in the cell containing the
|
||||
* <tt>StunServer</tt> instance.
|
||||
*/
|
||||
private static class StunServerCellRenderer
|
||||
extends DefaultTableCellRenderer
|
||||
{
|
||||
// We need a place to store the color the JLabel should be returned
|
||||
// to after its foreground and background colors have been set
|
||||
// to the selection background color.
|
||||
// These ivars will be made protected when their names are finalized.
|
||||
private Color unselectedForeground;
|
||||
private Color unselectedBackground;
|
||||
|
||||
/**
|
||||
* Overrides <code>JComponent.setForeground</code> to assign
|
||||
* the unselected-foreground color to the specified color.
|
||||
*
|
||||
* @param c set the foreground color to this value
|
||||
*/
|
||||
public void setForeground(Color c)
|
||||
{
|
||||
super.setForeground(c);
|
||||
unselectedForeground = c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides <code>JComponent.setBackground</code> to assign
|
||||
* the unselected-background color to the specified color.
|
||||
*
|
||||
* @param c set the background color to this value
|
||||
*/
|
||||
public void setBackground(Color c)
|
||||
{
|
||||
super.setBackground(c);
|
||||
unselectedBackground = c;
|
||||
}
|
||||
|
||||
public Component getTableCellRendererComponent( JTable table,
|
||||
Object value,
|
||||
boolean isSelected,
|
||||
boolean hasFocus,
|
||||
int row,
|
||||
int column)
|
||||
{
|
||||
|
||||
if (value instanceof StunServer)
|
||||
{
|
||||
StunServer stunServer = (StunServer) value;
|
||||
|
||||
this.setText( stunServer.getIpAddress()
|
||||
+ "/" + stunServer.getPort());
|
||||
|
||||
if (isSelected)
|
||||
{
|
||||
super.setForeground(table.getSelectionForeground());
|
||||
super.setBackground(table.getSelectionBackground());
|
||||
}
|
||||
else
|
||||
{
|
||||
super.setForeground((unselectedForeground != null)
|
||||
? unselectedForeground
|
||||
: table.getForeground());
|
||||
super.setBackground((unselectedBackground != null)
|
||||
? unselectedBackground
|
||||
: table.getBackground());
|
||||
}
|
||||
}
|
||||
else
|
||||
return super.getTableCellRendererComponent(table, value,
|
||||
isSelected, hasFocus, row, column);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A custom table model, with a non editable cells and a custom class column
|
||||
* objects.
|
||||
*
|
||||
*/
|
||||
private class StunServerTableModel
|
||||
extends DefaultTableModel
|
||||
{
|
||||
/**
|
||||
* Returns the class of the objects contained in the column given by
|
||||
* the index. The class is used to distinguish which renderer should be
|
||||
* used.
|
||||
*
|
||||
* @param columnIndex the column being queried
|
||||
* @return the class of objects contained in the column
|
||||
*/
|
||||
public Class getColumnClass(int columnIndex)
|
||||
{
|
||||
return getValueAt(0, columnIndex).getClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <tt>false</tt> to indicate that none of the columns is
|
||||
* editable.
|
||||
*
|
||||
* @param row the row whose value is to be queried
|
||||
* @param column the column whose value is to be queried
|
||||
* @return false
|
||||
*/
|
||||
public boolean isCellEditable(int row, int column)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if ice should be used for this account.
|
||||
* @return <tt>true</tt> if ICE should be used for this account, otherwise
|
||||
* returns <tt>false</tt>
|
||||
*/
|
||||
boolean isUseIce()
|
||||
{
|
||||
return iceBox.isSelected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the <tt>useIce</tt> property.
|
||||
* @param isUseIce <tt>true</tt> to indicate that ICE should be used for
|
||||
* this account, <tt>false</tt> - otherwise.
|
||||
*/
|
||||
void setUseIce(boolean isUseIce)
|
||||
{
|
||||
iceBox.setSelected(isUseIce);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the stun server should be automatically discovered.
|
||||
* @return <tt>true</tt> if the stun server should be automatically
|
||||
* discovered, otherwise returns <tt>false</tt>.
|
||||
*/
|
||||
boolean isAutoDiscoverStun()
|
||||
{
|
||||
return autoDiscoverBox.isSelected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the <tt>autoDiscoverStun</tt> property.
|
||||
* @param isAutoDiscover <tt>true</tt> to indicate that stun server should
|
||||
* be auto-discovered, <tt>false</tt> - otherwise.
|
||||
*/
|
||||
void setAutoDiscoverStun(boolean isAutoDiscover)
|
||||
{
|
||||
autoDiscoverBox.setSelected(isAutoDiscover);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of additional stun servers entered by the user.
|
||||
* @return the list of additional stun servers entered by the user
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
List<StunServer> getAdditionalStunServers()
|
||||
{
|
||||
LinkedList<StunServer> serversList = new LinkedList<StunServer>();
|
||||
Iterator i = tableModel.getDataVector().iterator();
|
||||
|
||||
while(i.hasNext())
|
||||
{
|
||||
Vector row = (Vector) i.next();
|
||||
|
||||
serversList.add((StunServer) row.elementAt(0));
|
||||
}
|
||||
|
||||
return serversList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given <tt>stunServer</tt> to the list of additional stun
|
||||
* servers.
|
||||
* @param stunServer the stun server to add
|
||||
*/
|
||||
void addStunServer(StunServer stunServer)
|
||||
{
|
||||
tableModel.addRow(new Object[]{stunServer,
|
||||
stunServer.isSupportTurn()});
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if a stun server with the given <tt>address</tt> and
|
||||
* <tt>port</tt> already exists in the additional stun servers table.
|
||||
* @param address the STUN server address to check
|
||||
* @param port the STUN server port to check
|
||||
* @return <tt>true</tt> if a STUN server with the given <tt>address</tt>
|
||||
* and <tt>port</tt> already exists in the table, otherwise returns
|
||||
* <tt>false</tt>
|
||||
*/
|
||||
boolean containsStunServer(String address, String port)
|
||||
{
|
||||
for (int i = 0; i < tableModel.getRowCount(); i++)
|
||||
{
|
||||
StunServer stunServer = (StunServer) tableModel.getValueAt(i, 0);
|
||||
|
||||
if (stunServer.getIpAddress().equalsIgnoreCase(address)
|
||||
&& stunServer.getPort().equalsIgnoreCase(port))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,173 @@
|
||||
package net.java.sip.communicator.plugin.jabberaccregwizz;
|
||||
|
||||
/**
|
||||
* The <tt>StunServer</tt> keeps all information related to the stun server.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class StunServer
|
||||
{
|
||||
/**
|
||||
* The IP address of the server.
|
||||
*/
|
||||
private String ipAddress;
|
||||
|
||||
/**
|
||||
* The port of the server.
|
||||
*/
|
||||
private String port;
|
||||
|
||||
/**
|
||||
* Indicates if Turn is supported by this server.
|
||||
*/
|
||||
private boolean supportTurn;
|
||||
|
||||
/**
|
||||
* The username.
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* The password.
|
||||
*/
|
||||
private char[] password;
|
||||
|
||||
/**
|
||||
* The index of this server in the additional servers table.
|
||||
*/
|
||||
private int index;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>StunServer</tt> by specifying all parameters.
|
||||
* @param ipAddress the IP address of the STUN server
|
||||
* @param port the port of the server
|
||||
* @param supportTurn indicates if this STUN server supports TURN
|
||||
* @param username the user name for authenticating
|
||||
* @param password the password
|
||||
* @param index the index of this server in the additional servers table
|
||||
*/
|
||||
public StunServer( String ipAddress,
|
||||
String port,
|
||||
boolean supportTurn,
|
||||
String username,
|
||||
char[] password,
|
||||
int index)
|
||||
{
|
||||
this.ipAddress = ipAddress;
|
||||
this.port = port;
|
||||
this.supportTurn = supportTurn;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the IP address of this server.
|
||||
* @return the IP address of this server
|
||||
*/
|
||||
String getIpAddress()
|
||||
{
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the IP address of this server.
|
||||
* @param ipAddress the IP address to set
|
||||
*/
|
||||
void setIpAddress(String ipAddress)
|
||||
{
|
||||
this.ipAddress = ipAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the port of this server.
|
||||
* @return the port of this server
|
||||
*/
|
||||
String getPort()
|
||||
{
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the port corresponding to this server.
|
||||
* @param port the port to set
|
||||
*/
|
||||
void setPort(String port)
|
||||
{
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if Turn is supported by this server.
|
||||
* @return <tt>true</tt> if Turn is supported by this server, otherwise -
|
||||
* returns <tt>false</tt>
|
||||
*/
|
||||
boolean isSupportTurn()
|
||||
{
|
||||
return supportTurn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the support turn property to indicate if this server supports Turn.
|
||||
* @param supportTurn <tt>true</tt> to indicate that Turn is supported,
|
||||
* <tt>false</tt> - otherwise
|
||||
*/
|
||||
void setSupportTurn(boolean supportTurn)
|
||||
{
|
||||
this.supportTurn = supportTurn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the username associated to this server.
|
||||
* @return the username associated to this server
|
||||
*/
|
||||
String getUsername()
|
||||
{
|
||||
return username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the username associated to this server.
|
||||
* @param username the username to set
|
||||
*/
|
||||
void setUsername(String username)
|
||||
{
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the password associated to this server username.
|
||||
* @return the password associated to this server username
|
||||
*/
|
||||
char[] getPassword()
|
||||
{
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the password associated to this server username.
|
||||
* @param password the password to set
|
||||
*/
|
||||
void setPassword(char[] password)
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
* The index of this server int the additional stun servers table.
|
||||
* @return the index of this server int the additional stun servers table
|
||||
*/
|
||||
int getIndex()
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the index of this server int the additional stun servers table.
|
||||
* @param index the index to set
|
||||
*/
|
||||
void setIndex(int index)
|
||||
{
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue