diff options
author | hristoterezov <hristo@jitsi.org> | 2013-11-22 12:30:20 +0200 |
---|---|---|
committer | hristoterezov <hristo@jitsi.org> | 2013-11-22 12:30:20 +0200 |
commit | a4e09b9f3c55c195a3fa078f02ccff137cebc447 (patch) | |
tree | b5d7213896edfa4137e1f7b998b6b2a3a19fc87b | |
parent | 463d4b3a843b266269f29b0dfc181f2f5761f5af (diff) | |
download | jitsi-a4e09b9f3c55c195a3fa078f02ccff137cebc447.zip jitsi-a4e09b9f3c55c195a3fa078f02ccff137cebc447.tar.gz jitsi-a4e09b9f3c55c195a3fa078f02ccff137cebc447.tar.bz2 |
Implements chat room contacts action buttons and right menu actions.
-rw-r--r-- | resources/images/images.properties | 7 | ||||
-rw-r--r-- | resources/images/impl/gui/buttons/autoJoin.png | bin | 0 -> 1200 bytes | |||
-rw-r--r-- | resources/images/impl/gui/buttons/autoJoinOver.png | bin | 0 -> 1307 bytes | |||
-rw-r--r-- | resources/images/impl/gui/buttons/autoJoinPressed.png | bin | 0 -> 1394 bytes | |||
-rw-r--r-- | resources/images/impl/gui/buttons/leaveRoom.png | bin | 0 -> 1298 bytes | |||
-rw-r--r-- | resources/images/impl/gui/buttons/leaveRoomOver.png | bin | 0 -> 1471 bytes | |||
-rw-r--r-- | resources/images/impl/gui/buttons/leaveRoomOverPressed.png | bin | 0 -> 1558 bytes | |||
-rw-r--r-- | resources/images/impl/gui/common/autoJoinRightMenu.png | bin | 0 -> 1179 bytes | |||
-rw-r--r-- | resources/languages/resources.properties | 1 | ||||
-rw-r--r-- | src/net/java/sip/communicator/impl/muc/ChatRoomQuery.java | 47 | ||||
-rw-r--r-- | src/net/java/sip/communicator/impl/muc/ChatRoomSourceContact.java | 46 | ||||
-rw-r--r-- | src/net/java/sip/communicator/impl/muc/ChatRoomWrapperImpl.java | 2 | ||||
-rw-r--r-- | src/net/java/sip/communicator/impl/muc/MUCCustomContactActionService.java | 355 |
13 files changed, 370 insertions, 88 deletions
diff --git a/resources/images/images.properties b/resources/images/images.properties index c02cec9..525cd0c 100644 --- a/resources/images/images.properties +++ b/resources/images/images.properties @@ -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 diff --git a/resources/images/impl/gui/buttons/autoJoin.png b/resources/images/impl/gui/buttons/autoJoin.png Binary files differnew file mode 100644 index 0000000..611f128 --- /dev/null +++ b/resources/images/impl/gui/buttons/autoJoin.png diff --git a/resources/images/impl/gui/buttons/autoJoinOver.png b/resources/images/impl/gui/buttons/autoJoinOver.png Binary files differnew file mode 100644 index 0000000..3da139d --- /dev/null +++ b/resources/images/impl/gui/buttons/autoJoinOver.png diff --git a/resources/images/impl/gui/buttons/autoJoinPressed.png b/resources/images/impl/gui/buttons/autoJoinPressed.png Binary files differnew file mode 100644 index 0000000..75c6a40 --- /dev/null +++ b/resources/images/impl/gui/buttons/autoJoinPressed.png diff --git a/resources/images/impl/gui/buttons/leaveRoom.png b/resources/images/impl/gui/buttons/leaveRoom.png Binary files differnew file mode 100644 index 0000000..8e1cdd5 --- /dev/null +++ b/resources/images/impl/gui/buttons/leaveRoom.png diff --git a/resources/images/impl/gui/buttons/leaveRoomOver.png b/resources/images/impl/gui/buttons/leaveRoomOver.png Binary files differnew file mode 100644 index 0000000..2ff653b --- /dev/null +++ b/resources/images/impl/gui/buttons/leaveRoomOver.png diff --git a/resources/images/impl/gui/buttons/leaveRoomOverPressed.png b/resources/images/impl/gui/buttons/leaveRoomOverPressed.png Binary files differnew file mode 100644 index 0000000..8168f75 --- /dev/null +++ b/resources/images/impl/gui/buttons/leaveRoomOverPressed.png diff --git a/resources/images/impl/gui/common/autoJoinRightMenu.png b/resources/images/impl/gui/common/autoJoinRightMenu.png Binary files differnew file mode 100644 index 0000000..935b66b --- /dev/null +++ b/resources/images/impl/gui/common/autoJoinRightMenu.png diff --git a/resources/languages/resources.properties b/resources/languages/resources.properties index b175b5e..2fdbe3c 100644 --- a/resources/languages/resources.properties +++ b/resources/languages/resources.properties @@ -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. diff --git a/src/net/java/sip/communicator/impl/muc/ChatRoomQuery.java b/src/net/java/sip/communicator/impl/muc/ChatRoomQuery.java index b794823..692a3fe 100644 --- a/src/net/java/sip/communicator/impl/muc/ChatRoomQuery.java +++ b/src/net/java/sip/communicator/impl/muc/ChatRoomQuery.java @@ -113,7 +113,7 @@ public class ChatRoomQuery ChatRoomWrapper chatRoom = provider.getChatRoom(i);
addChatRoom( provider.getProtocolProvider(),
chatRoom.getChatRoomName(), chatRoom.getChatRoomID(),
- addQueryResult);
+ addQueryResult, chatRoom.isAutojoin());
}
}
@@ -163,7 +163,10 @@ public class ChatRoomQuery }
else
{
- addChatRoom(sourceChatRoom, false);
+ ChatRoomWrapper chatRoom
+ = MUCActivator.getMUCService()
+ .findChatRoomWrapperFromChatRoom(sourceChatRoom);
+ addChatRoom(sourceChatRoom, false, chatRoom.isAutojoin());
}
}
else if ((LocalUserChatRoomPresenceChangeEvent
@@ -194,9 +197,12 @@ public class ChatRoomQuery * @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 @@ public class ChatRoomQuery )))
{
ChatRoomSourceContact contact
- = new ChatRoomSourceContact(room, this);
+ = new ChatRoomSourceContact(room, this, isAutoJoin);
synchronized (contactResults)
{
contactResults.add(contact);
@@ -229,10 +235,13 @@ public class ChatRoomQuery * @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 @@ public class ChatRoomQuery )))
{
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 class ChatRoomQuery 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 class ChatRoomQuery }
}
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;
}
diff --git a/src/net/java/sip/communicator/impl/muc/ChatRoomSourceContact.java b/src/net/java/sip/communicator/impl/muc/ChatRoomSourceContact.java index e4f8f24..f2791ee 100644 --- a/src/net/java/sip/communicator/impl/muc/ChatRoomSourceContact.java +++ b/src/net/java/sip/communicator/impl/muc/ChatRoomSourceContact.java @@ -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 class ChatRoomSourceContact 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 class ChatRoomSourceContact this.chatRoomID = chatRoom.getIdentifier();
this.provider = chatRoom.getParentProvider();
this.parentQuery = query;
+ this.isAutoJoin = isAutoJoin;
initContactProperties(
(chatRoom.isJoined()?
@@ -179,5 +191,21 @@ public class ChatRoomSourceContact 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;
+ }
}
diff --git a/src/net/java/sip/communicator/impl/muc/ChatRoomWrapperImpl.java b/src/net/java/sip/communicator/impl/muc/ChatRoomWrapperImpl.java index a6e4a5e..a22a1ed 100644 --- a/src/net/java/sip/communicator/impl/muc/ChatRoomWrapperImpl.java +++ b/src/net/java/sip/communicator/impl/muc/ChatRoomWrapperImpl.java @@ -271,6 +271,8 @@ public class ChatRoomWrapperImpl getParentProvider().getProtocolProvider(), chatRoomID, AUTOJOIN_PROPERTY_NAME, null); } + MUCActivator.getMUCService().fireChatRoomListChangedEvent(this, + ChatRoomListChangeEvent.CHAT_ROOM_CHANGED); } diff --git a/src/net/java/sip/communicator/impl/muc/MUCCustomContactActionService.java b/src/net/java/sip/communicator/impl/muc/MUCCustomContactActionService.java index 2d3884e..b0fa942 100644 --- a/src/net/java/sip/communicator/impl/muc/MUCCustomContactActionService.java +++ b/src/net/java/sip/communicator/impl/muc/MUCCustomContactActionService.java @@ -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 class MUCCustomContactActionService }
if (nickName != null)
- MUCActivator.getMUCService().joinChatRoom(chatRoomWrapper,
- nickName, null, subject);
+ MUCActivator.getMUCService().joinChatRoom(
+ chatRoomWrapper,nickName, null, subject);
else
return;
}
@@ -156,20 +256,7 @@ public class MUCCustomContactActionService 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 class MUCCustomContactActionService chatRoomWrapper.getChatRoomID());
}
},
- new MUCCustomActionRunnable()
- {
-
- @Override
- public void run()
- {
- chatRoomWrapper.setAutoJoin(!chatRoomWrapper.isAutojoin());
- }
- }
+ autoJoinRunnable,
+ autoJoinRunnable
};
/**
@@ -226,42 +306,38 @@ public class MUCCustomContactActionService 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 MUCCustomContactActionService @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 @@ public class MUCCustomContactActionService 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,30 +510,35 @@ public class MUCCustomContactActionService * 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.
*
* @param textKey the key used to retrieve the label for the menu item.
* @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 class MUCCustomContactActionService @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 class MUCCustomContactActionService @Override
public boolean isCheckBox()
{
- return isCheckBox;
+ return false;
}
@Override
@@ -487,7 +703,7 @@ public class MUCCustomContactActionService * 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 class MUCCustomContactActionService chatRoomWrapper = MUCActivator.getMUCService()
.findChatRoomWrapperFromSourceContact(contact);
}
-
}
}
|