Implements chat room contacts action buttons and right menu actions.

cusax-fix 4918
hristoterezov 13 years ago
parent 463d4b3a84
commit a4e09b9f3c

@ -15,6 +15,7 @@ service.gui.DEFAULT_USER_PHOTO_SMALL=resources/images/impl/gui/common/personPhot
# service gui icons
service.gui.icons.ACCOUNT_ICON=resources/images/impl/gui/buttons/addAccount.png
service.gui.icons.ADD_ACCOUNT_MENU_ICON=resources/images/impl/gui/buttons/addAccountMenu.png
service.gui.icons.AUTOJOIN=resources/images/impl/gui/common/autoJoinRightMenu.png
service.gui.icons.CONFIGURE_ICON=resources/images/impl/gui/common/configureIcon.png
service.gui.icons.SHOW_HIDE_OFFLINE_ICON=resources/images/impl/gui/common/showHideOffline.png
service.gui.icons.NO_SOUND_ICON=resources/images/impl/gui/common/noSound.png
@ -260,6 +261,12 @@ service.gui.buttons.CONTACT_LIST_DIAL_BUTTON=resources/images/impl/gui/buttons/c
service.gui.buttons.DIAL_PAD_CALL_BUTTON_BG=resources/images/impl/gui/buttons/dialPadCallButtonBg.png
service.gui.buttons.CALL_INFO=resources/images/impl/gui/buttons/callInfo.png
service.gui.buttons.ZRTP_ID_BUTTON=resources/images/impl/gui/buttons/zrtpEditId.png
service.gui.icons.LEAVE_ICON_BUTTON=resources/images/impl/gui/buttons/leaveRoom.png
service.gui.icons.LEAVE_ICON_ROLLOVER_BUTTON=resources/images/impl/gui/buttons/leaveRoomOver.png
service.gui.icons.LEAVE_ICON_PRESSED_BUTTON=resources/images/impl/gui/buttons/leaveRoomOverPressed.png
service.gui.icons.AUTOJOIN_ICON_BUTTON=resources/images/impl/gui/buttons/autoJoin.png
service.gui.icons.AUTOJOIN_ICON_ROLLOVER_BUTTON=resources/images/impl/gui/buttons/autoJoinOver.png
service.gui.icons.AUTOJOIN_ICON_PRESSED_BUTTON=resources/images/impl/gui/buttons/autoJoinPressed.png
# Sound level icons
service.gui.soundlevel.SOUND_LEVEL_ACTIVE_LEFT=resources/images/impl/gui/common/soundlevel/soundActiveLeft.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

@ -308,6 +308,7 @@ service.gui.JOIN_CHAT_ROOM_TITLE=Join chat room
service.gui.JOIN_CHAT_ROOM_NAME=Please enter the name of the chat room you would like to join.
service.gui.JOIN_CHAT_ROOM_WIZARD=Join chat room wizard
service.gui.JOIN_AUTOMATICALLY=Join automatically
service.gui.DONT_JOIN_AUTOMATICALLY=Don't join automatically
service.gui.KICK=&Kick
service.gui.KICK_FAILED=Kick failed
service.gui.KICK_FAILED_GENERAL_ERROR=Failed to kick {0}. A general server error occurred.

@ -113,7 +113,7 @@ private void providerAdded(ChatRoomProviderWrapper provider,
ChatRoomWrapper chatRoom = provider.getChatRoom(i);
addChatRoom( provider.getProtocolProvider(),
chatRoom.getChatRoomName(), chatRoom.getChatRoomID(),
addQueryResult);
addQueryResult, chatRoom.isAutojoin());
}
}
@ -163,7 +163,10 @@ public void localUserPresenceChanged(
}
else
{
addChatRoom(sourceChatRoom, false);
ChatRoomWrapper chatRoom
= MUCActivator.getMUCService()
.findChatRoomWrapperFromChatRoom(sourceChatRoom);
addChatRoom(sourceChatRoom, false, chatRoom.isAutojoin());
}
}
else if ((LocalUserChatRoomPresenceChangeEvent
@ -194,9 +197,12 @@ else if ((LocalUserChatRoomPresenceChangeEvent
* @param pps the protocol provider associated with the found chat room.
* @param chatRoomName the name of the chat room.
* @param chatRoomID the id of the chat room.
* @param addQueryResult
* @param addQueryResult indicates whether we should add the chat room to
* the query results or fire an event without adding it to the results.
* @param isAutoJoin the auto join state of the contact.
*/
private void addChatRoom(ChatRoom room, boolean addQueryResult)
private void addChatRoom(ChatRoom room, boolean addQueryResult,
boolean isAutoJoin)
{
if(queryString == null
|| ((room.getName().startsWith(
@ -205,7 +211,7 @@ private void addChatRoom(ChatRoom room, boolean addQueryResult)
)))
{
ChatRoomSourceContact contact
= new ChatRoomSourceContact(room, this);
= new ChatRoomSourceContact(room, this, isAutoJoin);
synchronized (contactResults)
{
contactResults.add(contact);
@ -229,10 +235,13 @@ private void addChatRoom(ChatRoom room, boolean addQueryResult)
* @param pps the protocol provider associated with the found chat room.
* @param chatRoomName the name of the chat room.
* @param chatRoomID the id of the chat room.
* @param addQueryResult
* @param addQueryResult indicates whether we should add the chat room to
* the query results or fire an event without adding it to the results.
* @param isAutoJoin the auto join state of the contact.
*/
private void addChatRoom(ProtocolProviderService pps,
String chatRoomName, String chatRoomID, boolean addQueryResult)
String chatRoomName, String chatRoomID, boolean addQueryResult,
boolean isAutoJoin)
{
if(queryString == null
|| ((chatRoomName.startsWith(
@ -241,7 +250,8 @@ private void addChatRoom(ProtocolProviderService pps,
)))
{
ChatRoomSourceContact contact
= new ChatRoomSourceContact(chatRoomName, chatRoomID, this, pps);
= new ChatRoomSourceContact(chatRoomName, chatRoomID, this, pps,
isAutoJoin);
synchronized (contactResults)
{
contactResults.add(contact);
@ -269,7 +279,8 @@ public void contentChanged(ChatRoomListChangeEvent evt)
switch(evt.getEventID())
{
case ChatRoomListChangeEvent.CHAT_ROOM_ADDED:
addChatRoom(chatRoom.getChatRoom(), false);
addChatRoom(chatRoom.getChatRoom(), false,
chatRoom.isAutojoin());
break;
case ChatRoomListChangeEvent.CHAT_ROOM_REMOVED:
LinkedList<ChatRoomSourceContact> tmpContactResults;
@ -291,6 +302,24 @@ public void contentChanged(ChatRoomListChangeEvent evt)
}
}
break;
case ChatRoomListChangeEvent.CHAT_ROOM_CHANGED:
synchronized (contactResults)
{
for(ChatRoomSourceContact contact : contactResults)
{
if(contact.getContactAddress().equals(
chatRoom.getChatRoomName()))
{
if(chatRoom.isAutojoin() != contact.isAutoJoin())
{
contact.setAutoJoin(chatRoom.isAutojoin());
fireContactChanged(contact);
}
break;
}
}
}
break;
default:
break;
}

@ -39,14 +39,21 @@ public class ChatRoomSourceContact
private ProtocolProviderService provider;
/**
*
* @param chatRoomName
* @param chatRoomID
* @param query
* @param pps
* The protocol provider of the chat room associated with the contact.
*/
private boolean isAutoJoin;
/**
* Contsructs new chat room source contact.
* @param chatRoomName the name of the chat room associated with the room.
* @param chatRoomID the id of the chat room associated with the room.
* @param query the query associated with the contact.
* @param pps the protocol provider of the contact.
* @param isAutoJoin the auto join state.
*/
public ChatRoomSourceContact(String chatRoomName,
String chatRoomID, ChatRoomQuery query, ProtocolProviderService pps)
String chatRoomID, ChatRoomQuery query, ProtocolProviderService pps,
boolean isAutoJoin)
{
super(query, query.getContactSource(), chatRoomName,
generateDefaultContactDetails(chatRoomName));
@ -55,17 +62,21 @@ public ChatRoomSourceContact(String chatRoomName,
this.chatRoomID = chatRoomID;
this.provider = pps;
this.parentQuery = query;
this.isAutoJoin = isAutoJoin;
initContactProperties(getChatRoomStateByName());
}
/**
* Constructs new chat room source contact.
*
* @param chatRoom
* @param query
* @param chatRoom the chat room associated with the contact.
* @param query the query associated with the contact.
* @param isAutoJoin the auto join state
*/
public ChatRoomSourceContact(ChatRoom chatRoom, ChatRoomQuery query)
public ChatRoomSourceContact(ChatRoom chatRoom, ChatRoomQuery query,
boolean isAutoJoin)
{
super(query, query.getContactSource(), chatRoom.getName(),
generateDefaultContactDetails(chatRoom.getName()));
@ -74,6 +85,7 @@ public ChatRoomSourceContact(ChatRoom chatRoom, ChatRoomQuery query)
this.chatRoomID = chatRoom.getIdentifier();
this.provider = chatRoom.getParentProvider();
this.parentQuery = query;
this.isAutoJoin = isAutoJoin;
initContactProperties(
(chatRoom.isJoined()?
@ -179,5 +191,21 @@ public int getIndex()
return parentQuery.indexOf(this);
}
/**
* Returns the auto join state of the contact.
* @return the auto join state of the contact.
*/
public boolean isAutoJoin()
{
return isAutoJoin;
}
/**
* Sets the auto join state of the contact.
* @param isAutoJoin the auto join state to be set.
*/
public void setAutoJoin(boolean isAutoJoin)
{
this.isAutoJoin = isAutoJoin;
}
}

@ -271,6 +271,8 @@ public void setAutoJoin(boolean value)
getParentProvider().getProtocolProvider(),
chatRoomID, AUTOJOIN_PROPERTY_NAME, null);
}
MUCActivator.getMUCService().fireChatRoomListChangedEvent(this,
ChatRoomListChangeEvent.CHAT_ROOM_CHANGED);
}

@ -32,31 +32,131 @@ public class MUCCustomContactActionService
= new LinkedList<ContactActionMenuItem<SourceContact>>();
/**
* Array of labels for the custom menu items.
* List of custom actions.
*/
private final List<ContactAction<SourceContact>> MUCActions
= new LinkedList<ContactAction<SourceContact>>();
/**
* Array of names for the custom actions.
*/
private String[] actionsNames = {
"leave", "autojoin", "autojoin_pressed"
};
/**
* Array of labels for the custom actions.
*/
private String[] actionsLabels = {
"service.gui.LEAVE",
"service.gui.JOIN_AUTOMATICALLY",
"service.gui.JOIN_AUTOMATICALLY"
};
/**
* Array of icons for the custom actions.
*/
private String[] actionsIcons = {
"service.gui.icons.LEAVE_ICON_BUTTON",
"service.gui.icons.AUTOJOIN_ICON_BUTTON",
"service.gui.icons.AUTOJOIN_ICON_PRESSED_BUTTON"
};
/**
* Array of rollover icons for the custom actions.
*/
private String[] actionsIconsRollover = {
"service.gui.icons.LEAVE_ICON_ROLLOVER_BUTTON",
"service.gui.icons.AUTOJOIN_ICON_ROLLOVER_BUTTON",
"service.gui.icons.AUTOJOIN_ICON_ROLLOVER_BUTTON"
};
/**
* Array of pressed icons for the custom actions.
*/
private String[] actionsIconsPressed = {
"service.gui.icons.LEAVE_ICON_PRESSED_BUTTON",
"service.gui.icons.AUTOJOIN_ICON_PRESSED_BUTTON",
"service.gui.icons.AUTOJOIN_ICON_BUTTON",
};
/**
* Array of names for the custom menu items.
*/
private String[] menuActionsNames = {
"open", "join", "join_as", "leave", "remove", "change_nick", "autojoin",
"autojoin_pressed"
};
/**
* Array of labels for the custom menu items.
*/
private String[] menuActionsLabels = {
"service.gui.OPEN", "service.gui.JOIN",
"service.gui.JOIN_AS", "service.gui.LEAVE",
"service.gui.REMOVE", "service.gui.CHANGE_NICK",
"service.gui.JOIN_AUTOMATICALLY"
"service.gui.JOIN_AUTOMATICALLY",
"service.gui.DONT_JOIN_AUTOMATICALLY"
};
/**
* Array of icons for the custom menu items.
*/
private String[] actionsIcons = {
private String[] menuActionsIcons = {
"service.gui.icons.CHAT_ROOM_16x16_ICON", "service.gui.icons.JOIN_ICON",
"service.gui.icons.JOIN_AS_ICON", "service.gui.icons.LEAVE_ICON",
"service.gui.icons.REMOVE_CHAT_ICON",
"service.gui.icons.RENAME_16x16_ICON",
null
"service.gui.icons.AUTOJOIN", "service.gui.icons.AUTOJOIN"
};
/**
* A runnable that leaves the chat room.
*/
private MUCCustomActionRunnable leaveRunnable
= new MUCCustomActionRunnable()
{
@Override
public void run()
{
ChatRoomWrapper leavedRoomWrapped
= MUCActivator.getMUCService().leaveChatRoom(
chatRoomWrapper);
if(leavedRoomWrapped != null)
MUCActivator.getUIService().closeChatRoomWindow(
leavedRoomWrapped);
}
};
/**
* A runnable that sets / unsets auto join setting of the chat room.
*/
private MUCCustomActionRunnable autoJoinRunnable
= new MUCCustomActionRunnable()
{
@Override
public void run()
{
chatRoomWrapper.setAutoJoin(!chatRoomWrapper.isAutojoin());
}
};
/**
* Array of <tt>MUCCustomActionRunnable</tt> objects for the custom menu
* items. They will be executed when the item is pressed.
*/
private MUCCustomActionRunnable[] actionsRunnable = {
leaveRunnable, autoJoinRunnable, autoJoinRunnable
};
/**
* Array of <tt>MUCCustomActionRunnable</tt> objects for the custom menu
* items. They will be executed when the item is pressed.
*/
private MUCCustomActionRunnable[] menuActionsRunnable = {
new MUCCustomActionRunnable()
{
@Override
@ -100,8 +200,8 @@ public void run()
}
if (nickName != null)
MUCActivator.getMUCService().joinChatRoom(chatRoomWrapper,
nickName, null, subject);
MUCActivator.getMUCService().joinChatRoom(
chatRoomWrapper,nickName, null, subject);
else
return;
}
@ -156,20 +256,7 @@ public void run()
joinOptions[1]);
}
},
new MUCCustomActionRunnable()
{
@Override
public void run()
{
ChatRoomWrapper leavedRoomWrapped
= MUCActivator.getMUCService().leaveChatRoom(
chatRoomWrapper);
if(leavedRoomWrapped != null)
MUCActivator.getUIService().closeChatRoomWindow(
leavedRoomWrapped);
}
},
leaveRunnable,
new MUCCustomActionRunnable()
{
@ -204,15 +291,8 @@ public void run()
chatRoomWrapper.getChatRoomID());
}
},
new MUCCustomActionRunnable()
{
@Override
public void run()
{
chatRoomWrapper.setAutoJoin(!chatRoomWrapper.isAutojoin());
}
}
autoJoinRunnable,
autoJoinRunnable
};
/**
@ -226,42 +306,38 @@ public void run()
new LeaveEnableChecker(),
null,
null,
null,
null
};
/**
* Array for the custom menu items that describes the type of the menu item.
* If <tt>true</tt> - the item is check box.
*/
private boolean[] actionsIsCheckBox = {
false,
false,
false,
false,
false,
false,
true
};
/**
* The resource management service instance.
*/
ResourceManagementService resources = MUCActivator.getResources();
/**
* Constructs the custom actions.
*/
public MUCCustomContactActionService()
{
for(int i = 0; i < actionsLabels.length; i++)
for(int i = 0; i < menuActionsLabels.length; i++)
{
MUCActionMenuItems item = new MUCActionMenuItems(actionsLabels[i],
actionsIcons[i], actionsRunnable[i], actionsIsCheckBox[i]);
MUCActionMenuItems item
= new MUCActionMenuItems(menuActionsNames[i], menuActionsLabels[i],
menuActionsIcons[i], menuActionsRunnable[i]);
MUCActionMenuItems.add(item);
if(actionsEnabledCheckers[i] != null)
item.setEnabled(actionsEnabledCheckers[i]);
}
for(int i = 0; i < actionsLabels.length; i++)
{
MUCAction item = new MUCAction(actionsNames[i], actionsLabels[i],
actionsIcons[i], actionsIconsRollover[i], actionsIconsPressed[i],
actionsRunnable[i]);
MUCActions.add(item);
}
}
/**
@ -285,7 +361,128 @@ public Class<SourceContact> getContactSourceClass()
@Override
public Iterator<ContactAction<SourceContact>> getCustomContactActions()
{
return null;
return MUCActions.iterator();
}
/**
* Implements the MUC custom action.
*/
private class MUCAction
implements ContactAction<SourceContact>
{
/**
* The text of the action.
*/
private String text;
/**
* The icon of the action
*/
private byte[] icon;
/**
* The icon that is shown when the action is pressed.
*/
private byte[] iconPressed;
/**
* The runnable that is executed when the action is pressed.
*/
private MUCCustomActionRunnable actionPerformed;
/**
* The icon that is shown when the mouse is over the action.
*/
private byte[] iconRollover;
/**
* The name of the action.
*/
private String name;
/**
* Constructs <tt>MUCAction</tt> instance.
*
* @param textKey the key used to retrieve the label for the action.
* @param iconKey the key used to retrieve the icon for the action.
* @param actionPerformed the action executed when the action is
* pressed.
* @param iconRolloverKey the key used to retrieve the rollover icon for
* the action.
* @param iconPressedKey the key used to retrieve the pressed icon for
* the action.
*/
public MUCAction(String name, String textKey, String iconKey,
String iconRolloverKey, String iconPressedKey,
MUCCustomActionRunnable actionPerformed)
{
this.name = name;
this.text = resources.getI18NString(textKey);
this.icon = resources.getImageInBytes(iconKey);
this.iconRollover = resources.getImageInBytes(iconRolloverKey);
this.iconPressed = resources.getImageInBytes(iconPressedKey);
this.actionPerformed = actionPerformed;
}
@Override
public void actionPerformed(SourceContact actionSource, int x, int y)
throws OperationFailedException
{
if(!(actionSource instanceof ChatRoomSourceContact))
return;
actionPerformed.setContact(actionSource);
new Thread(actionPerformed).start();
}
@Override
public byte[] getIcon()
{
return icon;
}
@Override
public byte[] getRolloverIcon()
{
return iconRollover;
}
@Override
public byte[] getPressedIcon()
{
return iconPressed;
}
@Override
public String getToolTipText()
{
return text;
}
@Override
public boolean isVisible(SourceContact actionSource)
{
if(actionSource instanceof ChatRoomSourceContact)
{
if(name.equals("leave"))
{
return true;
}
else
{
ChatRoomSourceContact contact
= (ChatRoomSourceContact) actionSource;
ChatRoomWrapper room = MUCActivator.getMUCService()
.findChatRoomWrapperFromSourceContact(contact);
if(name.equals("autojoin"))
return !room.isAutojoin();
if(name.equals("autojoin_pressed"))
return room.isAutojoin();
}
}
return false;
}
}
/**
@ -295,14 +492,14 @@ private class MUCActionMenuItems
implements ContactActionMenuItem<SourceContact>
{
/**
* The key used to retrieve the label for the menu item.
* The label for the menu item.
*/
private String textKey;
private String text;
/**
* The key used to retrieve the icon for the menu item.
* The the icon for the menu item.
*/
private String imageKey;
private byte[] image;
/**
* The action executed when the menu item is pressed.
@ -313,13 +510,17 @@ private class MUCActionMenuItems
* Object that is used to check if the item is enabled or disabled.
*/
private EnableChecker enabled;
/**
* if <tt>true</tt> the item should be check box and if <tt>false</tt>
* it is standard menu item.
* The name of the custom action menu item.
*/
private boolean isCheckBox;
private String name;
/**
* The mnemonic for the action.
*/
private char mnemonics;
/**
* Constructs <tt>MUCActionMenuItems</tt> instance.
*
@ -327,16 +528,17 @@ private class MUCActionMenuItems
* @param imageKey the key used to retrieve the icon for the menu item.
* @param actionPerformed the action executed when the menu item is
* pressed.
* @param isCheckBox if <tt>true</tt> the item should be check box.
*/
public MUCActionMenuItems(String textKey, String imageKey,
MUCCustomActionRunnable actionPerformed, boolean isCheckBox)
public MUCActionMenuItems(String name, String textKey, String imageKey,
MUCCustomActionRunnable actionPerformed)
{
this.textKey = textKey;
this.imageKey = imageKey;
this.text = resources.getI18NString(textKey);
this.image = (imageKey == null)? null :
resources.getImageInBytes(imageKey);
this.actionPerformed = actionPerformed;
this.enabled = new EnableChecker();
this.isCheckBox = isCheckBox;
this.name = name;
this.mnemonics = resources.getI18nMnemonic(text);
}
@Override
@ -352,27 +554,41 @@ public void actionPerformed(SourceContact actionSource)
@Override
public byte[] getIcon()
{
return (imageKey == null)? null :
resources.getImageInBytes(imageKey);
return image;
}
@Override
public String getText()
{
return resources.getI18NString(textKey);
return text;
}
@Override
public boolean isVisible(SourceContact actionSource)
{
return (actionSource instanceof ChatRoomSourceContact);
if(!(actionSource instanceof ChatRoomSourceContact))
return false;
if(name.equals("autojoin") || name.equals("autojoin_pressed"))
{
ChatRoomSourceContact contact
= (ChatRoomSourceContact) actionSource;
ChatRoomWrapper room = MUCActivator.getMUCService()
.findChatRoomWrapperFromSourceContact(contact);
if(name.equals("autojoin"))
return !room.isAutojoin();
if(name.equals("autojoin_pressed"))
return room.isAutojoin();
}
return true;
}
@Override
public char getMnemonics()
{
return resources.getI18nMnemonic(textKey);
return mnemonics;
}
@Override
@ -395,7 +611,7 @@ public void setEnabled(EnableChecker enabled)
@Override
public boolean isCheckBox()
{
return isCheckBox;
return false;
}
@Override
@ -487,7 +703,7 @@ private abstract class MUCCustomActionRunnable implements Runnable
* The contact associated with the menu item.
*/
protected ChatRoomWrapper chatRoomWrapper;
/**
* Sets the source contact.
* @param contact the contact to set
@ -498,6 +714,5 @@ public void setContact(SourceContact contact)
chatRoomWrapper = MUCActivator.getMUCService()
.findChatRoomWrapperFromSourceContact(contact);
}
}
}

Loading…
Cancel
Save