Some account configuration panel improvements including:

- ProtocolProviderService wrapped before being added to the account list in order to avoid all icon conversions in the cell renderer, should improve performance of the list.
- if an icon of size 32x32 doesn't exist in the protocol, try to get bigger supproted icons and scale them to the desired size, otherwise don't set an icon (fixes NullPointerException).
cusax-fix
Yana Stamcheva 17 years ago
parent a6f23194f1
commit ed7186953b

@ -0,0 +1,171 @@
/*
* 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.impl.gui.main.account;
import java.awt.*;
import javax.swing.*;
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
/**
* Represents an account in the account list.
*
* @author Yana Stamcheva
*/
public class Account
{
private ProtocolProviderService protocolProvider;
private String name;
private ImageIcon icon;
/**
* Creates an <tt>Account</tt> instance from the given
* <tt>protocolProvider</tt>.
* @param protocolProvider the protocol provider on which this account is
* based
*/
public Account(ProtocolProviderService protocolProvider)
{
this.protocolProvider = protocolProvider;
this.name = protocolProvider.getAccountID().getDisplayName();
this.icon = this.getProtocolIcon();
}
/**
* Returns the protocol provider, on which this account is based.
* @return the protocol provider, on which this account is based
*/
public ProtocolProviderService getProtocolProvider()
{
return protocolProvider;
}
/**
* Returns the account name.
* @return the account name
*/
public String getName()
{
return name;
}
/**
* The icon of the account.
* @return the icon of the account
*/
public ImageIcon getIcon()
{
return icon;
}
/**
* Returns the status name.
* @return the status name
*/
public String getStatusName()
{
return getAccountStatus(protocolProvider);
}
/**
* Returns the status icon of this account.
* @return the status icon of this account
*/
public ImageIcon getStatusIcon()
{
return ImageLoader.getAccountStatusImage(protocolProvider);
}
/**
* Returns the current presence status of the given protocol provider.
*
* @param protocolProvider the protocol provider which status we're looking
* for.
* @return the current presence status of the given protocol provider.
*/
private String getAccountStatus(ProtocolProviderService protocolProvider)
{
String status;
OperationSetPresence presence
= (OperationSetPresence) protocolProvider
.getOperationSet(OperationSetPresence.class);
if (presence != null)
{
status = presence.getPresenceStatus().getStatusName();
}
else
{
if (protocolProvider.isRegistered())
{
status = GuiActivator.getResources()
.getI18NString("service.gui.ONLINE");
}
else
{
status = GuiActivator.getResources()
.getI18NString("service.gui.OFFLINE");
}
}
return status;
}
/**
* Returns the protocol icon. If an icon 32x32 is available, returns it,
* otherwise tries to scale a bigger icon if available. If we didn't find
* a bigger icon to scale, we return null.
*
* @return the protocol icon
*/
private ImageIcon getProtocolIcon()
{
Image protocolImage =
ImageLoader.getBytesInImage(protocolProvider.getProtocolIcon()
.getIcon(ProtocolIcon.ICON_SIZE_32x32));
if (protocolImage != null)
{
return new ImageIcon(protocolImage);
}
else
{
protocolImage =
ImageLoader.getBytesInImage(protocolProvider.getProtocolIcon()
.getIcon(ProtocolIcon.ICON_SIZE_48x48));
if (protocolImage != null)
{
return ImageUtils.scaleIconWithinBounds(
protocolImage, 32, 32);
}
else
{
protocolImage =
ImageLoader.getBytesInImage(
protocolProvider.getProtocolIcon()
.getIcon(ProtocolIcon.ICON_SIZE_64x64));
if (protocolImage != null)
{
return ImageUtils.scaleIconWithinBounds(
protocolImage, 32, 32);
}
}
}
return null;
}
}

@ -7,6 +7,7 @@
import java.awt.event.*;
import java.beans.*;
import java.util.*;
import javax.swing.*;
@ -90,11 +91,16 @@ private void accountsInit()
presence.addProviderPresenceStatusListener(this);
}
accountListModel.addElement(protocolProvider);
accountListModel.addElement(new Account(protocolProvider));
}
}
}
public Account getSelectedAccount()
{
return (Account) this.getSelectedValue();
}
/**
* Refreshes the account status icon, when the status has changed.
*/
@ -102,7 +108,17 @@ public void providerStatusChanged(ProviderPresenceStatusChangeEvent evt)
{
ProtocolProviderService protocolProvider = evt.getProvider();
accountListModel.contentChanged(protocolProvider);
Enumeration<Account> accounts
= (Enumeration<Account>) accountListModel.elements();
while (accounts.hasMoreElements())
{
Account account = accounts.nextElement();
if (account.getProtocolProvider().equals(protocolProvider))
{
accountListModel.contentChanged(account);
}
}
}
public void providerStatusMessageChanged(PropertyChangeEvent evt) {}
@ -158,11 +174,21 @@ public void serviceChanged(ServiceEvent event)
presence.addProviderPresenceStatusListener(this);
}
accountListModel.addElement(protocolProvider);
accountListModel.addElement(new Account(protocolProvider));
}
else if (event.getType() == ServiceEvent.UNREGISTERING)
{
accountListModel.removeElement(protocolProvider);
Enumeration<Account> accounts
= (Enumeration<Account>) accountListModel.elements();
while (accounts.hasMoreElements())
{
Account account = accounts.nextElement();
if (account.getProtocolProvider().equals(protocolProvider))
{
accountListModel.removeElement(account);
}
}
}
}
@ -196,7 +222,17 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt)
{
ProtocolProviderService protocolProvider = evt.getProvider();
accountListModel.contentChanged(protocolProvider);
Enumeration<Account> accounts
= (Enumeration<Account>) accountListModel.elements();
while (accounts.hasMoreElements())
{
Account account = accounts.nextElement();
if (account.getProtocolProvider().equals(protocolProvider))
{
accountListModel.contentChanged(account);
}
}
}
/**
@ -205,9 +241,9 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt)
*/
private class AccountListModel extends DefaultListModel
{
public void contentChanged(ProtocolProviderService protocolProvider)
public void contentChanged(Account account)
{
int index = this.indexOf(protocolProvider);
int index = this.indexOf(account);
this.fireContentsChanged(this, index, index);
}
}

@ -11,7 +11,6 @@
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.swing.*;
/**
@ -53,25 +52,21 @@ public AccountListCellRenderer()
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus)
{
ProtocolProviderService protocolProvider
= (ProtocolProviderService) value;
Account account = (Account) value;
Image protocolImage =
ImageLoader.getBytesInImage(protocolProvider.getProtocolIcon()
.getIcon(ProtocolIcon.ICON_SIZE_32x32));
ImageIcon accountIcon = account.getIcon();
accountLabel.setIcon(new ImageIcon(protocolImage));
if (accountIcon != null)
accountLabel.setIcon(accountIcon);
accountLabel.setText(protocolProvider.getAccountID()
.getDisplayName());
accountLabel.setText(account.getName());
ImageIcon statusImage
= ImageLoader.getAccountStatusImage(protocolProvider);
ImageIcon statusIcon = account.getStatusIcon();
if (statusImage != null)
statusLabel.setIcon(statusImage);
if (statusIcon != null)
statusLabel.setIcon(statusIcon);
String statusName = getAccountStatus(protocolProvider);
String statusName = account.getStatusName();
if (statusName != null)
statusLabel.setText(statusName);
@ -126,40 +121,4 @@ private void internalPaintComponent(Graphics g)
g2.fillRect(0, 0, this.getWidth(), this.getHeight());
}
}
/**
* Returns the current presence status of the given protocol provider.
*
* @param protocolProvider the protocol provider which status we're looking
* for.
* @return the current presence status of the given protocol provider.
*/
private String getAccountStatus(ProtocolProviderService protocolProvider)
{
String status;
OperationSetPresence presence
= (OperationSetPresence) protocolProvider
.getOperationSet(OperationSetPresence.class);
if (presence != null)
{
status = presence.getPresenceStatus().getStatusName();
}
else
{
if (protocolProvider.isRegistered())
{
status = GuiActivator.getResources()
.getI18NString("service.gui.ONLINE");
}
else
{
status = GuiActivator.getResources()
.getI18NString("service.gui.OFFLINE");
}
}
return status;
}
}

@ -40,6 +40,9 @@ public class AccountsConfigurationPanel
new JButton(GuiActivator.getResources().getI18NString(
"service.gui.DELETE"));
/**
* Creates and initializes this account configuration panel.
*/
public AccountsConfigurationPanel()
{
super(new BorderLayout());
@ -94,8 +97,10 @@ public void actionPerformed(ActionEvent evt)
}
else if (sourceButton.equals(removeButton))
{
Account account = accountList.getSelectedAccount();
ProtocolProviderService protocolProvider
= (ProtocolProviderService) accountList.getSelectedValue();
= account.getProtocolProvider();
ProtocolProviderFactory providerFactory =
GuiActivator.getProtocolProviderFactory(protocolProvider);
@ -142,8 +147,7 @@ else if (sourceButton.equals(removeButton))
}
else if (sourceButton.equals(editButton))
{
ProtocolProviderService protocolProvider
= (ProtocolProviderService) accountList.getSelectedValue();
Account account = accountList.getSelectedAccount();
AccountRegWizardContainerImpl wizard =
(AccountRegWizardContainerImpl) GuiActivator.getUIService()
@ -152,7 +156,7 @@ else if (sourceButton.equals(editButton))
wizard.setTitle(GuiActivator.getResources().getI18NString(
"service.gui.ACCOUNT_REGISTRATION_WIZARD"));
wizard.modifyAccount(protocolProvider);
wizard.modifyAccount(account.getProtocolProvider());
wizard.showDialog(false);
}
}

@ -20,6 +20,12 @@
import org.osgi.framework.*;
/**
* The <tt>NewAccountDialog</tt> is the dialog containing the form used to
* create a new account.
*
* @author Yana Stamcheva
*/
public class NewAccountDialog
extends SIPCommDialog
implements ActionListener
@ -209,6 +215,9 @@ public int compare(AccountRegistrationWizard arg0,
}
}
/**
* A custom cell renderer for the network combobox.
*/
private static class NetworkListCellRenderer
extends JLabel
implements ListCellRenderer
@ -251,11 +260,15 @@ public Component getListCellRendererComponent(JList list, Object value,
this.setIcon(null);
}
return this;
}
}
/**
* Loads the given wizard in the user interface.
*
* @param wizard the wizard to load
*/
private void loadSelectedWizard(AccountRegistrationWizard wizard)
{
accountPanel.removeAll();
@ -271,13 +284,13 @@ private void loadSelectedWizard(AccountRegistrationWizard wizard)
simpleWizardForm.setOpaque(false);
accountPanel.add(simpleWizardForm);
//enable the add and advanced buttons if this is a real protocol
addAccountButton.setEnabled(
!(wizard instanceof EmptyAccountRegistrationWizard));
advancedButton.setEnabled(
!(wizard instanceof EmptyAccountRegistrationWizard));
accountPanel.revalidate();
accountPanel.repaint();
@ -313,6 +326,9 @@ private void loadErrorMessage(String errorMessage)
this.setSize(getWidth(), getHeight()+errorMessagePane.getHeight());
}
/**
* Handles button actions.
*/
public void actionPerformed(ActionEvent event)
{
JButton sourceButton = (JButton) event.getSource();

Loading…
Cancel
Save