Alphabetically order accounts.

cusax-fix
Yana Stamcheva 16 years ago
parent 413f597654
commit 79dec3e258

@ -30,8 +30,14 @@ public class AccountList
ServiceListener,
MouseListener
{
/**
* The account list model.
*/
private final AccountListModel accountListModel = new AccountListModel();
/**
* The edit button.
*/
private final JButton editButton;
/**
@ -91,11 +97,15 @@ private void accountsInit()
presence.addProviderPresenceStatusListener(this);
}
accountListModel.addElement(new Account(protocolProvider));
accountListModel.addAccount(new Account(protocolProvider));
}
}
}
/**
* Returns the selected account.
* @return the selected account
*/
public Account getSelectedAccount()
{
return (Account) this.getSelectedValue();
@ -103,6 +113,8 @@ public Account getSelectedAccount()
/**
* Refreshes the account status icon, when the status has changed.
* @param evt the <tt>ProviderPresenceStatusChangeEvent</tt> that notified
* us
*/
public void providerStatusChanged(ProviderPresenceStatusChangeEvent evt)
{
@ -154,15 +166,14 @@ public void serviceChanged(ServiceEvent event)
// Add a presence listener in order to listen for any status
// changes.
OperationSetPresence presence
= protocolProvider
.getOperationSet(OperationSetPresence.class);
= protocolProvider.getOperationSet(OperationSetPresence.class);
if (presence != null)
{
presence.addProviderPresenceStatusListener(this);
}
accountListModel.addElement(new Account(protocolProvider));
accountListModel.addAccount(new Account(protocolProvider));
}
else if (event.getType() == ServiceEvent.UNREGISTERING)
{
@ -178,6 +189,7 @@ else if (event.getType() == ServiceEvent.UNREGISTERING)
/**
* Listens for double mouse click events in order to open the edit form.
* @param e the <tt>MouseEvent</tt> that notified us
*/
public void mouseClicked(MouseEvent e)
{
@ -187,17 +199,13 @@ public void mouseClicked(MouseEvent e)
}
}
public void mouseEntered(MouseEvent e)
{}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e)
{}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e)
{}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e)
{}
public void mouseReleased(MouseEvent e) {}
/**
* Refreshes the account status icon, when the status has changed.
@ -241,5 +249,59 @@ public void contentChanged(Account account)
int index = this.indexOf(account);
this.fireContentsChanged(this, index, index);
}
/**
* Adds the given <tt>account</tt> to this model.
* @param account the <tt>Account</tt> to add
*/
public void addAccount(Account account)
{
// If this is the first account in our menu.
if (getSize() == 0)
{
addElement(account);
return;
}
boolean isAccountAdded = false;
Enumeration<Account> accounts = (Enumeration<Account>) elements();
AccountID accountID = account.getProtocolProvider().getAccountID();
// If we already have other accounts.
while (accounts.hasMoreElements())
{
Account a = accounts.nextElement();
AccountID listAccountID = a.getProtocolProvider().getAccountID();
int accountIndex = indexOf(a);
int protocolCompare
= accountID.getProtocolDisplayName().compareTo(
listAccountID.getProtocolDisplayName());
// If the new account protocol name is before the name of the
// menu we insert the new account before the given menu.
if (protocolCompare < 0)
{
insertElementAt(account, accountIndex);
isAccountAdded = true;
break;
}
else if (protocolCompare == 0)
{
// If we have the same protocol name, we check the account name.
if (accountID.getDisplayName()
.compareTo(listAccountID.getDisplayName()) < 0)
{
insertElementAt(account, accountIndex);
isAccountAdded = true;
break;
}
}
}
if (!isAccountAdded)
addElement(account);
}
}
}

@ -75,8 +75,8 @@ public NewAccountDialog()
{
super(GuiActivator.getUIService().getMainFrame());
this.setTitle(
GuiActivator.getResources().getI18NString("service.gui.NEW_ACCOUNT"));
this.setTitle(GuiActivator.getResources()
.getI18NString("service.gui.NEW_ACCOUNT"));
this.getContentPane().add(mainPanel);
@ -329,6 +329,7 @@ private void loadErrorMessage(String errorMessage)
/**
* Handles button actions.
* @param event the <tt>ActionEvent</tt> that notified us
*/
public void actionPerformed(ActionEvent event)
{
@ -433,6 +434,7 @@ public static void showNewAccountDialog()
/**
* Remove the newAccountDialog, when the window is closed.
* @param isEscaped indicates if the dialog has been escaped
*/
protected void close(boolean isEscaped)
{

@ -60,13 +60,6 @@ public class GlobalStatusSelectorBox
private final Logger logger
= Logger.getLogger(GlobalStatusSelectorBox.class);
/**
* Mapping of <tt>ProtocolProviderService</tt> and corresponding
* <tt>StatusSelectorMenu</tt>.
*/
private final Map<ProtocolProviderService, StatusSelectorMenu> accountMenus
= new Hashtable<ProtocolProviderService, StatusSelectorMenu>();
/**
* The main application window.
*/
@ -105,6 +98,11 @@ public class GlobalStatusSelectorBox
*/
private int textWidth = 0;
/**
* Indicates if this is the first account added.
*/
private boolean isFirstAccount = true;
/**
* Creates an instance of <tt>SimpleStatusSelectorBox</tt>.
*
@ -208,8 +206,53 @@ public void addAccount(ProtocolProviderService protocolProvider)
? new PresenceStatusMenu(protocolProvider)
: new SimpleStatusMenu(protocolProvider);
this.add(statusSelectorMenu);
this.accountMenus.put(protocolProvider, statusSelectorMenu);
// If this is the first account in our menu.
if (isFirstAccount)
{
add(statusSelectorMenu);
isFirstAccount = false;
return;
}
boolean isMenuAdded = false;
AccountID accountId = protocolProvider.getAccountID();
// If we already have other accounts.
for (Component c : getPopupMenu().getComponents())
{
if (!(c instanceof StatusSelectorMenu))
continue;
StatusSelectorMenu menu = (StatusSelectorMenu) c;
int menuIndex = getPopupMenu().getComponentIndex(menu);
AccountID menuAccountID = menu.getProtocolProvider().getAccountID();
int protocolCompare = accountId.getProtocolDisplayName().compareTo(
menuAccountID.getProtocolDisplayName());
// If the new account protocol name is before the name of the menu
// we insert the new account before the given menu.
if (protocolCompare < 0)
{
insert(statusSelectorMenu, menuIndex);
isMenuAdded = true;
break;
}
else if (protocolCompare == 0)
{
// If we have the same protocol name, we check the account name.
if (accountId.getDisplayName()
.compareTo(menuAccountID.getDisplayName()) < 0)
{
insert( statusSelectorMenu, menuIndex);
isMenuAdded = true;
break;
}
}
}
if (!isMenuAdded)
add(statusSelectorMenu);
}
/**
@ -220,11 +263,10 @@ public void addAccount(ProtocolProviderService protocolProvider)
*/
public void removeAccount(ProtocolProviderService protocolProvider)
{
StatusSelectorMenu statusSelectorMenu
= this.accountMenus.get(protocolProvider);
StatusSelectorMenu menu = getStatusSelectorMenu(protocolProvider);
this.remove(statusSelectorMenu);
this.accountMenus.remove(protocolProvider);
if (menu != null)
remove(menu);
}
/**
@ -236,7 +278,12 @@ public void removeAccount(ProtocolProviderService protocolProvider)
*/
public boolean containsAccount(ProtocolProviderService protocolProvider)
{
return accountMenus.containsKey(protocolProvider);
StatusSelectorMenu menu = getStatusSelectorMenu(protocolProvider);
if (menu != null)
return true;
return false;
}
/**
@ -246,7 +293,10 @@ public boolean containsAccount(ProtocolProviderService protocolProvider)
*/
public void startConnecting(ProtocolProviderService protocolProvider)
{
accountMenus.get(protocolProvider).startConnecting();
StatusSelectorMenu menu = getStatusSelectorMenu(protocolProvider);
if (menu != null)
menu.startConnecting();
}
/**
@ -256,9 +306,10 @@ public void startConnecting(ProtocolProviderService protocolProvider)
*/
public void stopConnecting(ProtocolProviderService protocolProvider)
{
StatusSelectorMenu selectorMenu = accountMenus.get(protocolProvider);
if (selectorMenu != null)
selectorMenu.stopConnecting();
StatusSelectorMenu menu = getStatusSelectorMenu(protocolProvider);
if (menu != null)
menu.stopConnecting();
}
/**
@ -269,9 +320,16 @@ public void stopConnecting(ProtocolProviderService protocolProvider)
*/
public boolean hasSelectedMenus()
{
for (StatusSelectorMenu statusSelectorMenu : accountMenus.values())
if (statusSelectorMenu.isSelected())
for (Component c : getComponents())
{
if (!(c instanceof StatusSelectorMenu))
continue;
StatusSelectorMenu menu = (StatusSelectorMenu) c;
if (menu.isSelected())
return true;
}
return false;
}
@ -497,7 +555,7 @@ else if (itemName.equals(Constants.AWAY_STATUS))
*/
public void updateStatus(ProtocolProviderService protocolProvider)
{
StatusSelectorMenu accountMenu = accountMenus.get(protocolProvider);
StatusSelectorMenu accountMenu = getStatusSelectorMenu(protocolProvider);
if (accountMenu == null)
return;
@ -543,7 +601,7 @@ public void updateStatus(ProtocolProviderService protocolProvider)
public void updateStatus(ProtocolProviderService protocolProvider,
PresenceStatus presenceStatus)
{
StatusSelectorMenu accountMenu = accountMenus.get(protocolProvider);
StatusSelectorMenu accountMenu = getStatusSelectorMenu(protocolProvider);
if (accountMenu == null)
return;
@ -867,4 +925,29 @@ private void fitSizeToText()
this.setPreferredSize(new Dimension(
textWidth + 2*IMAGE_INDENT + arrowImage.getWidth(null) + 5, 20));
}
/**
* Returns the <tt>StatusSelectorMenu</tt> corresponding to the given
* <tt>protocolProvider</tt>.
* @param protocolProvider the <tt>ProtocolProviderService</tt>, which
* corresponding menu we're looking for
* @return the <tt>StatusSelectorMenu</tt> corresponding to the given
* <tt>protocolProvider</tt>
*/
private StatusSelectorMenu getStatusSelectorMenu(
ProtocolProviderService protocolProvider)
{
for (Component c : getPopupMenu().getComponents())
{
if (!(c instanceof StatusSelectorMenu))
continue;
StatusSelectorMenu menu = (StatusSelectorMenu) c;
if (menu.getProtocolProvider() != null
&& menu.getProtocolProvider().equals(protocolProvider))
return menu;
}
return null;
}
}

@ -35,12 +35,6 @@ public class PresenceStatusMenu
{
private final Logger logger = Logger.getLogger(PresenceStatusMenu.class);
/**
* The <tt>ProtocolProviderService</tt> which has its presence status
* depicted and changed by this instance.
*/
private final ProtocolProviderService protocolProvider;
private Iterator<PresenceStatus> statusIterator;
private PresenceStatus offlineStatus;
@ -64,9 +58,8 @@ public class PresenceStatusMenu
public PresenceStatusMenu(ProtocolProviderService protocolProvider)
{
super(protocolProvider.getAccountID().getDisplayName(),
ImageLoader.getAccountStatusImage(protocolProvider));
this.protocolProvider = protocolProvider;
ImageLoader.getAccountStatusImage(protocolProvider),
protocolProvider);
this.presence
= protocolProvider.getOperationSet(OperationSetPresence.class);

@ -12,7 +12,6 @@
import javax.swing.*;
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
@ -33,8 +32,6 @@ public class SimpleStatusMenu
private static final Logger logger
= Logger.getLogger(SimpleStatusMenu.class);
private final ProtocolProviderService protocolProvider;
private final JMenuItem onlineItem;
private final JMenuItem offlineItem;
@ -57,9 +54,7 @@ private SimpleStatusMenu(ProtocolProviderService protocolProvider,
String displayName,
Image onlineImage)
{
super(displayName, new ImageIcon(onlineImage));
this.protocolProvider = protocolProvider;
super(displayName, new ImageIcon(onlineImage), protocolProvider);
this.setToolTipText("<html><b>" + displayName
+ "</b><br>Offline</html>");

@ -29,12 +29,23 @@ public abstract class StatusSelectorMenu
extends SIPCommMenu
implements ImageObserver
{
/**
* The connecting icon.
*/
private final Image connectingIcon
= GuiActivator.getResources().getImage("service.gui.icons.CONNECTING")
.getImage();
/**
* Indicates if this menu is currently connecting.
*/
private boolean isConnecting;
/**
* The <tt>ProtocolProviderService</tt> associated with this status menu.
*/
protected ProtocolProviderService protocolProvider;
/**
* Creates a <tt>StatusSelectorMenu</tt>.
*/
@ -48,10 +59,16 @@ public StatusSelectorMenu()
* show.
* @param text the text of the menu
* @param defaultIcon the icon of the menu
* @param protocolProvider the <tt>ProtocolProviderService</tt> associated
* with this status menu
*/
public StatusSelectorMenu(String text, Icon defaultIcon)
public StatusSelectorMenu( String text,
Icon defaultIcon,
ProtocolProviderService protocolProvider)
{
super(text, defaultIcon);
this.protocolProvider = protocolProvider;
}
/**
@ -187,4 +204,13 @@ public boolean imageUpdate(Image img, int infoflags,
repaint();
return true;
}
/**
* Returns the protocol provider associated with this status menu.
* @return the protocol provider associated with this status menu
*/
public ProtocolProviderService getProtocolProvider()
{
return protocolProvider;
}
}

@ -153,8 +153,7 @@ public String getUserID()
public String getDisplayName()
{
String returnValue = getUserID();
String protocolName =
getAccountPropertyString(ProtocolProviderFactory.PROTOCOL);
String protocolName = getProtocolDisplayName();
if (protocolName != null && protocolName.trim().length() > 0)
returnValue += " (" + protocolName + ")";
@ -162,6 +161,16 @@ public String getDisplayName()
return returnValue;
}
/**
* Returns the display name of the protocol.
*
* @return the display name of the protocol
*/
public String getProtocolDisplayName()
{
return getAccountPropertyString(ProtocolProviderFactory.PROTOCOL);
}
/**
* Returns a String uniquely identifying this account, guaranteed to remain
* the same across multiple installations of the same account and to always

Loading…
Cancel
Save