use of org.jivesoftware.spark.ui.rooms.GroupChatRoom in project Spark by igniterealtime.
the class BannedUsers method setChatRoom.
/**
* Binds a ChatRoom to listen to.
*
* @param cRoom the group chat room.
*/
public void setChatRoom(ChatRoom cRoom) {
GroupChatRoom chatRoom = (GroupChatRoom) cRoom;
chat = chatRoom.getMultiUserChat();
}
use of org.jivesoftware.spark.ui.rooms.GroupChatRoom in project Spark by igniterealtime.
the class ChatRoom method handleNickNameCompletion.
/**
* Handles the Nickname Completion dialog, when Pressing CTRL + SPACE<br>
* it searches for matches in the current GroupchatList and also in the
* Roster
*
* @throws ChatRoomNotFoundException
* when for some reason the GroupChatRoom cannot be found, this
* should <u>not</u> happen, since we retrieve it from the
* ActiveWindowTab and thus <u>can be ignored</u>
*/
private void handleNickNameCompletion() throws ChatRoomNotFoundException {
// Search for a name that starts with the same word as the last word in the chat input editor.
final String text = getChatInputEditor().getText();
if (text == null || text.isEmpty()) {
return;
}
// -1 when space does not occur.
final int lastSpaceCharacterIndex = text.lastIndexOf(' ');
final String needle = text.substring(lastSpaceCharacterIndex + 1);
final Set<String> matches = new TreeSet<>(String::compareToIgnoreCase);
if (SparkManager.getChatManager().getChatContainer().getActiveChatRoom() instanceof GroupChatRoom) {
final GroupChatRoom activeChatRoom = (GroupChatRoom) SparkManager.getChatManager().getChatContainer().getActiveChatRoom();
for (String participant : activeChatRoom.getParticipants()) {
final String nickname = participant.substring(participant.lastIndexOf("/") + 1);
if (nickname.toLowerCase().startsWith(needle.toLowerCase())) {
matches.add(nickname);
}
}
} else {
for (RosterEntry re : Roster.getInstanceFor(SparkManager.getConnection()).getEntries()) {
// Use the name if available, otherwise the localpart of the JID.
final String username;
if (re.getName() != null) {
username = re.getName();
} else {
username = re.getUser().substring(0, re.getUser().indexOf('@'));
}
if (username.toLowerCase().startsWith(needle.toLowerCase())) {
matches.add(username);
}
}
}
if (matches.size() == 1) {
// If we only have 1 match, that match can be used immediately.
getChatInputEditor().appendText(matches.iterator().next().substring(needle.length()));
} else {
// More than one match: create Popupmenu and let the user select one.
final JPopupMenu popup = new JPopupMenu();
for (final String match : matches) {
final JMenuItem menuItem = new JMenuItem(match);
popup.add(menuItem);
menuItem.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
getChatInputEditor().appendText(match.substring(needle.length()));
popup.setVisible(false);
}
});
}
popup.show(SparkManager.getChatManager().getChatContainer(), getChatInputEditor().getCaret().getMagicCaretPosition().x, SparkManager.getChatManager().getChatContainer().getHeight() - 20);
}
}
use of org.jivesoftware.spark.ui.rooms.GroupChatRoom in project Spark by igniterealtime.
the class ConferenceRoomBrowser method createRoom.
/**
* Create a new room based on room table selection.
*/
private void createRoom() {
RoomCreationDialog mucRoomDialog = new RoomCreationDialog();
final MultiUserChat groupChat = mucRoomDialog.createGroupChat(SparkManager.getMainWindow(), serviceName);
LocalPreferences pref = SettingsManager.getLocalPreferences();
if (null != groupChat) {
// Join Room
try {
GroupChatRoom room = UIComponentRegistry.createGroupChatRoom(groupChat);
groupChat.create(pref.getNickname());
chatManager.getChatContainer().addChatRoom(room);
chatManager.getChatContainer().activateChatRoom(room);
// Send Form
Form form = groupChat.getConfigurationForm().createAnswerForm();
if (mucRoomDialog.isPasswordProtected()) {
String password = mucRoomDialog.getPassword();
room.setPassword(password);
form.setAnswer("muc#roomconfig_passwordprotectedroom", true);
form.setAnswer("muc#roomconfig_roomsecret", password);
}
form.setAnswer("muc#roomconfig_roomname", mucRoomDialog.getRoomName());
form.setAnswer("muc#roomconfig_roomdesc", mucRoomDialog.getRoomTopic());
if (mucRoomDialog.isPermanent()) {
form.setAnswer("muc#roomconfig_persistentroom", true);
}
List<String> owners = new ArrayList<>();
owners.add(SparkManager.getSessionManager().getBareAddress());
form.setAnswer("muc#roomconfig_roomowners", owners);
// new DataFormDialog(groupChat, form);
groupChat.sendConfigurationForm(form);
addRoomToTable(groupChat.getRoom(), XmppStringUtils.parseLocalpart(groupChat.getRoom()), 1);
} catch (XMPPException | SmackException e1) {
Log.error("Error creating new room.", e1);
UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
JOptionPane.showMessageDialog(this, Res.getString("message.room.creation.error"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
}
}
}
use of org.jivesoftware.spark.ui.rooms.GroupChatRoom in project Spark by igniterealtime.
the class ConferenceUtils method isChatRoomClosable.
public static boolean isChatRoomClosable(Component c) {
if (c instanceof GroupChatRoom) {
GroupChatRoom groupChatRoom = (GroupChatRoom) c;
String roomName = groupChatRoom.getChatRoom().getRoomname();
if (unclosableChatRooms.contains(roomName)) {
return false;
}
}
return true;
}
use of org.jivesoftware.spark.ui.rooms.GroupChatRoom in project Spark by igniterealtime.
the class UserInvitationPane method startFastpathChat.
private void startFastpathChat(String fullRoomJID, String roomName) {
// Add to Chat window
ChatManager chatManager = SparkManager.getChatManager();
GroupChatRoom chatRoom;
try {
chatRoom = chatManager.getGroupChat(fullRoomJID);
if (!chatRoom.isActive()) {
// Remove old room, add new room.
chatManager.removeChat(chatRoom);
MultiUserChat chat = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(fullRoomJID);
chatRoom = new GroupChatRoom(chat);
} else {
// Already in the room, do not process invitation
try {
offer.reject();
} catch (SmackException.NotConnectedException e) {
Log.warning("Unable to reject offer " + offer, e);
}
return;
}
} catch (ChatNotFoundException e) {
MultiUserChat chat = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(fullRoomJID);
chatRoom = new GroupChatRoom(chat);
}
chatRoom.getSplitPane().setDividerSize(5);
chatRoom.getSplitPane().getRightComponent().setVisible(true);
chatRoom.getBottomPanel().setVisible(true);
chatRoom.getScrollPaneForTranscriptWindow().setVisible(true);
chatRoom.getEditorBar().setVisible(true);
chatRoom.getChatInputEditor().setEnabled(true);
chatRoom.getToolBar().setVisible(true);
chatRoom.getVerticalSlipPane().setDividerLocation(0.8);
chatRoom.getSplitPane().setDividerLocation(0.6);
try {
chatRoom.setTabTitle(roomName);
chatRoom.getConferenceRoomInfo().setNicknameChangeAllowed(false);
chatRoom.getToolBar().setVisible(true);
chatRoom.getEditorBar().setVisible(true);
chatRoom.getChatInputEditor().setEnabled(true);
ChatContainer chatContainer = SparkManager.getChatManager().getChatContainer();
chatContainer.addChatRoom(chatRoom);
FastpathPlugin.getLitWorkspace().addFastpathChatRoom(chatRoom, Workpane.RoomState.activeRoom);
chatContainer.setChatRoomTitle(chatRoom, roomName);
if (chatContainer.getActiveChatRoom() == chatRoom) {
chatContainer.getChatFrame().setTitle(roomName);
}
} catch (Exception e) {
Log.error(e);
}
ConferenceUtils.enterRoomOnSameThread(roomName, fullRoomJID, null);
removeOwner(chatRoom.getMultiUserChat());
FastpathPlugin.getLitWorkspace().checkForDecoration(chatRoom, offer.getSessionID());
if (listener != null) {
listener.yesOption();
listener = null;
}
}
Aggregations