Move the simple account registration form to a separate plugin.

cusax-fix
Yana Stamcheva 18 years ago
parent c86f5769eb
commit f52d604e05

@ -619,8 +619,8 @@
bundle-ssh,bundle-plugin-sshaccregwizz,
bundle-contacteventhandler,bundle-plugin-contactinfo,
bundle-plugin-accountinfo,bundle-plugin-chatalerter,
bundle-plugin-statusupdate,
bundle-updatecheckplugin"/>
bundle-plugin-statusupdate,
bundle-updatecheckplugin, bundle-plugin-simpleaccreg"/>
<!--BUNDLE-HISTORY-->
<target name="bundle-history">
@ -1109,8 +1109,6 @@ javax.swing.event, javax.swing.border"/>
prefix="resources/colors"/>
<zipfileset dir="${resources}" includes="application.properties"
prefix="resources"/>
<zipfileset dir="${resources}" includes="login.properties"
prefix="resources"/>
<zipfileset dir="${resources}" includes="lookandfeel.properties"
prefix="resources"/>
<zipfileset dir="${resources}/size" includes="size.properties"
@ -1646,5 +1644,19 @@ javax.swing.event, javax.swing.border"/>
prefix="resources/languages/plugin/statusupdate"/>
</jar>
</target>
<!--BUNDLE-StatusUpdatePlugin-->
<target name="bundle-plugin-simpleaccreg">
<jar compress="false" destfile="${bundles.dest}/simpleaccreg.jar"
manifest="${src}/net/java/sip/communicator/plugin/simpleaccreg/simpleaccreg.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/plugin/simpleaccreg"
prefix="net/java/sip/communicator/plugin/simpleaccreg" />
<zipfileset dir="${resources}/languages/plugin/simpleaccreg"
prefix="resources/languages/plugin/simpleaccreg"/>
<zipfileset dir="${resources}" includes="login.properties"
prefix="resources"/>
<zipfileset dir="${resources}/colors"
prefix="resources/colors"/>
</jar>
</target>
</project>

@ -111,6 +111,7 @@ felix.auto.start.60= \
reference:file:sc-bundles/rssaccregwizz.jar \
reference:file:sc-bundles/zeroconfaccregwizz.jar \
reference:file:sc-bundles/ircaccregwizz.jar \
reference:file:sc-bundles/simpleaccreg.jar \
reference:file:sc-bundles/contacteventhandler.jar \
reference:file:sc-bundles/contactinfo.jar \
reference:file:sc-bundles/accountinfo.jar \

@ -224,7 +224,6 @@ newMessage=New message...
newName=New name:
newStatusMessage=New status message
no=No
initialAccountRegistration=Configure all your favorite protocols in one click.
noAvailableRooms=The list of rooms for this server is currently not available.
noMessage=No message
noMultiChatAccountAvailable=No accounts, supporting multi user chat found. Check sip-communicator.org for more information on which protocols support multi user chat.

@ -143,25 +143,6 @@ public void runLogin(MainFrame parent)
}
}
}
if (!hasRegisteredAccounts)
{
this.showAccountRegistrationWizard();
}
}
/**
* Shows the wizard, which allows to register a new account.
*/
private void showAccountRegistrationWizard()
{
// If no preferred wizard is specified we launch the default wizard.
InitialAccountRegistrationFrame accountRegFrame
= new InitialAccountRegistrationFrame();
accountRegFrame.pack();
accountRegFrame.setLocation(0, 0);
accountRegFrame.setVisible(true);
}
/**

@ -0,0 +1,390 @@
/*
* 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.simpleaccreg;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.imageio.*;
import javax.swing.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
* The <tt>NoAccountFoundPage</tt> is the page shown in the account
* registration wizard shown in the beginning of the program, when no registered
* accounts are found.
*
* @author Yana Stamcheva
*/
public class InitialAccountRegistrationFrame
extends JFrame
implements ServiceListener
{
private Logger logger
= Logger.getLogger(InitialAccountRegistrationFrame.class);
private JTextArea messageArea =
new JTextArea(Resources.getString("initialAccountRegistration"));
private MainPanel mainPanel = new MainPanel(new BorderLayout(10, 10));
private JPanel mainAccountsPanel = new JPanel(new BorderLayout(10, 10));
private JPanel accountsPanel = new JPanel(new GridLayout(0, 2, 10, 10));
private JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
private JButton signinButton
= new JButton(Resources.getString("signin"));
private Vector registrationForms = new Vector();
/**
* Creates an instance of <tt>NoAccountFoundPage</tt>.
*/
public InitialAccountRegistrationFrame()
{
this.setTitle(Resources.getString("signin"));
this.mainPanel.setBorder(
BorderFactory.createEmptyBorder(20, 20, 20, 20));
this.getContentPane().add(mainPanel);
this.mainPanel.add(messageArea, BorderLayout.NORTH);
this.mainPanel.add(mainAccountsPanel, BorderLayout.CENTER);
this.mainPanel.add(buttonPanel, BorderLayout.SOUTH);
this.mainAccountsPanel.add(accountsPanel, BorderLayout.CENTER);
this.mainAccountsPanel.setOpaque(false);
this.accountsPanel.setOpaque(false);
this.buttonPanel.setOpaque(false);
this.signinButton.addActionListener(new SigninActionListener());
this.buttonPanel.add(signinButton);
this.messageArea.setLineWrap(true);
this.messageArea.setWrapStyleWord(true);
this.messageArea.setEditable(false);
this.messageArea.setOpaque(false);
this.initAccountWizards();
}
private void initAccountWizards()
{
SimpleAccountRegistrationActivator.bundleContext.addServiceListener(this);
ServiceReference[] serviceRefs = null;
try
{
serviceRefs = SimpleAccountRegistrationActivator.bundleContext
.getServiceReferences(
AccountRegistrationWizard.class.getName(), null);
if (serviceRefs == null || serviceRefs.length <= 0)
return;
AccountRegistrationWizard wizard;
for (int i = 0; i < serviceRefs.length; i++)
{
wizard = (AccountRegistrationWizard)
SimpleAccountRegistrationActivator
.bundleContext.getService(serviceRefs[i]);
this.addAccountRegistrationForm(wizard);
}
}
catch (InvalidSyntaxException ex)
{
logger.error("GuiActivator : ", ex);
}
}
/**
*
*/
private class AccountRegistrationPanel extends JPanel
{
private JLabel protocolLabel = new JLabel();
private JLabel usernameLabel = new JLabel("Login");
private JLabel passwordLabel = new JLabel("Password");
private JTextField usernameField = new JTextField();
private JLabel usernameExampleLabel = new JLabel();
private JPasswordField passwordField = new JPasswordField();
private JPanel labelsPanel = new JPanel(new GridLayout(0, 1, 5, 0));
private JPanel fieldsPanel = new JPanel(new GridLayout(0, 1, 5, 0));
private JPanel emptyPanel = new JPanel();
private JPanel inputPanel = new JPanel(new BorderLayout(5, 5));
private JPanel iconDescriptionPanel = new JPanel(new BorderLayout());
private JPanel inputRegisterPanel = new JPanel(new BorderLayout());
private JTextArea descriptionArea = new JTextArea();
private AccountRegistrationWizard wizard;
public AccountRegistrationPanel(
AccountRegistrationWizard wizard,
boolean isPreferredWizard)
{
super(new BorderLayout(5, 5));
this.wizard = wizard;
this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
this.setPreferredSize(new Dimension(230, 140));
this.setOpaque(false);
this.inputPanel.setOpaque(false);
this.labelsPanel.setOpaque(false);
this.fieldsPanel.setOpaque(false);
this.emptyPanel.setOpaque(false);
this.add(inputRegisterPanel, BorderLayout.CENTER);
this.inputRegisterPanel.add(inputPanel, BorderLayout.NORTH);
this.inputPanel.add(labelsPanel, BorderLayout.WEST);
this.inputPanel.add(fieldsPanel, BorderLayout.CENTER);
this.iconDescriptionPanel.add(
protocolLabel, BorderLayout.NORTH);
this.protocolLabel.setFont(
protocolLabel.getFont().deriveFont(Font.BOLD, 14f));
this.usernameExampleLabel.setForeground(Color.DARK_GRAY);
this.usernameExampleLabel.setFont(
usernameExampleLabel.getFont().deriveFont(8f));
this.labelsPanel.add(usernameLabel);
this.labelsPanel.add(emptyPanel);
this.labelsPanel.add(passwordLabel);
this.fieldsPanel.add(usernameField);
this.fieldsPanel.add(usernameExampleLabel);
this.fieldsPanel.add(passwordField);
this.usernameExampleLabel.setText(wizard.getUserNameExample());
this.protocolLabel.setText(wizard.getProtocolName());
Image image = null;
try
{
image = ImageIO.read(
new ByteArrayInputStream(wizard.getPageImage()));
}
catch (IOException e)
{
logger.error("Unable to load image.", e);
}
if (image != null)
{
image = image.getScaledInstance(32, 32, Image.SCALE_SMOOTH);
protocolLabel.setIcon(new ImageIcon(image));
}
if (isPreferredWizard)
{
descriptionArea.setBorder(BorderFactory
.createEmptyBorder(10, 0, 0, 0));
descriptionArea.setFont(
descriptionArea.getFont().deriveFont(10f));
descriptionArea.setPreferredSize(new Dimension(200, 50));
descriptionArea.setLineWrap(true);
descriptionArea.setWrapStyleWord(true);
descriptionArea.setText(wizard.getProtocolDescription());
// descriptionArea.setBorder(SIPCommBorders.getRoundBorder());
this.iconDescriptionPanel.add(
descriptionArea, BorderLayout.CENTER);
this.add(iconDescriptionPanel, BorderLayout.WEST);
}
else
{
this.add(iconDescriptionPanel, BorderLayout.NORTH);
}
}
public void paintComponent(Graphics g)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// do the superclass behavior first
super.paintComponent(g2d);
g2d.setColor(new Color(
Resources.getColor("desktopBackgroundColor")));
// paint the background with the chosen color
g2d.fillRoundRect(0, 0, getWidth(), getHeight(), 15, 15);
}
public boolean isFilled()
{
if(usernameField.getText() != null
&& usernameField.getText().length() > 0)
return true;
return false;
}
public void signin()
{
wizard.signin( usernameField.getText(),
new String(passwordField.getPassword()));
}
}
/**
*
*/
protected void close(boolean isEscaped)
{
}
/**
* Handles registration of a new account wizard.
*/
public void serviceChanged(ServiceEvent event)
{
Object sService = SimpleAccountRegistrationActivator.bundleContext.
getService(event.getServiceReference());
// we don't care if the source service is not a plugin component
if (! (sService instanceof AccountRegistrationWizard))
return;
AccountRegistrationWizard wizard
= (AccountRegistrationWizard) sService;
if (event.getType() == ServiceEvent.REGISTERED)
{
this.addAccountRegistrationForm(wizard);
}
}
/**
* Adds a simple account registration form corresponding to the given
* <tt>AccountRegistrationWizard</tt>.
*
* @param wizard the <tt>AccountRegistrationWizard</tt>, which gives us
* information to fill our simple form.
*/
private void addAccountRegistrationForm(AccountRegistrationWizard wizard)
{
// We don't need to add wizards that are not interested in a
// simple sign in form.
if (!wizard.isSimpleFormEnabled())
return;
String preferredWizardName
= Resources.getLoginProperty("preferredAccountWizard");
AccountRegistrationPanel accountPanel;
if (preferredWizardName != null
&& preferredWizardName.equals(wizard.getClass().getName()))
{
accountPanel = new AccountRegistrationPanel(wizard, true);
mainAccountsPanel.add(
accountPanel,
BorderLayout.NORTH);
}
else
{
accountPanel = new AccountRegistrationPanel(wizard, false);
this.accountsPanel.add(accountPanel);
}
this.registrationForms.add(accountPanel);
this.pack();
}
/**
* Handles the event triggered by the "Signin" button.
*/
private class SigninActionListener implements ActionListener
{
public void actionPerformed(ActionEvent arg0)
{
Iterator regIterator = registrationForms.iterator();
if (regIterator.hasNext())
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
while(regIterator.hasNext())
{
AccountRegistrationPanel regForm
= (AccountRegistrationPanel) regIterator.next();
if (regForm.isFilled())
regForm.signin();
}
InitialAccountRegistrationFrame.this.dispose();
}
}
private class MainPanel extends JPanel
{
public MainPanel(LayoutManager layoutManager)
{
super(layoutManager);
}
public void paintComponent(Graphics g)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// do the superclass behavior first
super.paintComponent(g2d);
g2d.setColor(new Color(
Resources.getColor("accountRegistrationBackground")));
// paint the background with the chosen color
g2d.fillRoundRect(10, 10, getWidth() - 20, getHeight() - 20, 15, 15);
}
}
}

@ -0,0 +1,124 @@
/*
* 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.simpleaccreg;
import java.io.*;
import java.util.*;
import net.java.sip.communicator.util.*;
/**
* The <tt>Resources</tt> class manages the access to the internationalization
* properties files and the image resources used in this plugin.
*
* @author Yana Stamcheva
*/
public class Resources
{
private static Logger log = Logger.getLogger(Resources.class);
/**
* The name of the resource, where internationalization strings for this
* plugin are stored.
*/
private static final String STRING_RESOURCE_NAME
= "resources.languages.plugin.simpleaccreg.resources";
/**
* The string resource bundle.
*/
private static final ResourceBundle STRING_RESOURCE_BUNDLE
= ResourceBundle.getBundle(STRING_RESOURCE_NAME);
/**
* Name of the bundle where we will search for color resources.
*/
private static final String COLOR_BUNDLE_NAME
= "resources.colors.colorResources";
/**
* Bundle which handle access to localized resources.
*/
private static final ResourceBundle COLOR_RESOURCE_BUNDLE = ResourceBundle
.getBundle( COLOR_BUNDLE_NAME,
Locale.getDefault(),
Resources.class.getClassLoader());
/**
* Name of the bundle where we will search for color resources.
*/
private static final String LOGIN_BUNDLE_NAME
= "resources.login";
/**
* Bundle which handle access to localized resources.
*/
private static final ResourceBundle LOGIN_PROPERTIES_BUNDLE = ResourceBundle
.getBundle(LOGIN_BUNDLE_NAME);
/**
* Returns an internationalized string corresponding to the given key.
*
* @param key The key of the string.
* @return An internationalized string corresponding to the given key.
*/
public static String getString(String key)
{
try
{
return STRING_RESOURCE_BUNDLE.getString(key);
}
catch (MissingResourceException exc)
{
return '!' + key + '!';
}
}
/**
* Returns an int RGB color corresponding to the given key.
*
* @param key The key of the string.
*
* @return An internationalized string corresponding to the given key.
*/
public static int getColor(String key)
{
try
{
return Integer.parseInt(COLOR_RESOURCE_BUNDLE.getString(key), 16);
}
catch (MissingResourceException e)
{
log.error("Missing color resource.", e);
return 0xFFFFFF;
}
}
/**
* Returns the application property corresponding to the given key.
*
* @param key The key of the string.
*
* @return the application property corresponding to the given key
*/
public static String getLoginProperty(String key)
{
try
{
return LOGIN_PROPERTIES_BUNDLE.getString(key);
}
catch (MissingResourceException e)
{
log.error("Missing property.", e);
return "";
}
}
}

@ -0,0 +1,106 @@
/*
* 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.simpleaccreg;
import java.awt.*;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
public class SimpleAccountRegistrationActivator
implements BundleActivator
{
private static Logger logger
= Logger.getLogger(SimpleAccountRegistrationActivator.class);
public static BundleContext bundleContext;
public void start(BundleContext bc) throws Exception
{
bundleContext = bc;
if (!hasRegisteredAccounts())
{
// If no preferred wizard is specified we launch the default wizard.
InitialAccountRegistrationFrame accountRegFrame
= new InitialAccountRegistrationFrame();
accountRegFrame.pack();
accountRegFrame.setLocation(
Toolkit.getDefaultToolkit().getScreenSize().width/2
- accountRegFrame.getWidth()/2,
Toolkit.getDefaultToolkit().getScreenSize().height/2
- accountRegFrame.getHeight()/2
);
accountRegFrame.setVisible(true);
}
}
public void stop(BundleContext bc) throws Exception
{
}
/**
* Returns all <tt>ProtocolProviderFactory</tt>s obtained from the bundle
* context.
* @return all <tt>ProtocolProviderFactory</tt>s obtained from the bundle
* context
*/
private static boolean hasRegisteredAccounts()
{
boolean hasRegisteredAccounts = false;
ServiceReference[] serRefs = null;
try
{
//get all registered provider factories
serRefs = bundleContext.getServiceReferences(
ProtocolProviderFactory.class.getName(), null);
}
catch (InvalidSyntaxException e)
{
logger.error("Unable to obtain service references. " + e);
}
for (int i = 0; i < serRefs.length; i++)
{
ProtocolProviderFactory providerFactory
= (ProtocolProviderFactory) bundleContext
.getService(serRefs[i]);
ArrayList accountsList = providerFactory.getRegisteredAccounts();
AccountID accountID;
ServiceReference serRef;
ProtocolProviderService protocolProvider;
for (int j = 0; j < accountsList.size(); j++)
{
accountID = (AccountID) accountsList.get(i);
boolean isHidden =
accountID.getAccountProperties()
.get("HIDDEN_PROTOCOL") != null;
if(!isHidden)
{
hasRegisteredAccounts = true;
break;
}
}
if (hasRegisteredAccounts)
break;
}
return hasRegisteredAccounts;
}
}

@ -0,0 +1,30 @@
Bundle-Activator: net.java.sip.communicator.plugin.simpleaccreg.SimpleAccountRegistrationActivator
Bundle-Name: Simple account registration form
Bundle-Description: Simple account registration form.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 0.0.1
Import-Package: org.osgi.framework,
net.java.sip.communicator.util,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.configuration.event,
net.java.sip.communicator.service.protocol,
net.java.sip.communicator.service.protocol.event,
net.java.sip.communicator.service.contactlist,
net.java.sip.communicator.service.contactlist.event,
net.java.sip.communicator.service.gui,
net.java.sip.communicator.service.gui.event,
net.java.sip.communicator.service.browserlauncher,
javax.swing,
javax.swing.event,
javax.swing.table,
javax.swing.text,
javax.swing.text.html,
javax.accessibility,
javax.swing.plaf,
javax.swing.plaf.metal,
javax.swing.plaf.basic,
javax.imageio,
javax.swing.filechooser,
javax.swing.tree,
javax.swing.undo,
javax.swing.border
Loading…
Cancel
Save