use of org.jivesoftware.spark.component.tabbedPane.SparkTab in project Spark by igniterealtime.
the class CallManager method getSparkTab.
/**
* Returns the <code>SparkTab</code> that acts as a container to this PhonePanel.
*
* @param phonePanel the <code>PhonePanel</code>
* @return the SparkTab.
*/
public SparkTab getSparkTab(PhonePanel phonePanel) {
final ChatContainer chatContainer = SparkManager.getChatManager().getChatContainer();
int tabCount = chatContainer.getTabCount();
for (int i = 0; i < tabCount; i++) {
SparkTab sparkTab = chatContainer.getTabAt(i);
Component containerComponent = chatContainer.getComponentInTab(sparkTab);
if (containerComponent.equals(phonePanel)) {
return sparkTab;
}
if (containerComponent instanceof ChatRoom) {
ChatRoom chatRoom = (ChatRoom) containerComponent;
Component rightComponent = chatRoom.getSplitPane().getRightComponent();
if (phonePanel.equals(rightComponent)) {
return sparkTab;
}
}
}
return null;
}
use of org.jivesoftware.spark.component.tabbedPane.SparkTab in project Spark by igniterealtime.
the class ChatContainer method setChatRoomTitle.
public void setChatRoomTitle(ChatRoom room, String title) {
int index = indexOfComponent(room);
if (index != -1) {
SparkTab tab = getTabAt(index);
fireChatRoomStateUpdated(room);
tab.setTabTitle(room.getTabTitle());
}
}
use of org.jivesoftware.spark.component.tabbedPane.SparkTab in project Spark by igniterealtime.
the class ChatContainer method addChatRoom.
/**
* Adds a new ChatRoom to Spark.
*
* @param room the ChatRoom to add.
*/
public synchronized void addChatRoom(final ChatRoom room) {
createFrameIfNeeded();
room.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY));
AndFilter presenceFilter = new AndFilter(new StanzaTypeFilter(Presence.class), FromMatchesFilter.createBare(room.getRoomname()));
// Next, create a packet listener. We use an anonymous inner class for brevity.
StanzaListener myListener = stanza -> SwingUtilities.invokeLater(() -> handleRoomPresence((Presence) stanza));
room.registeredToFrame(chatFrame);
SparkManager.getConnection().addAsyncStanzaListener(myListener, presenceFilter);
// Add to PresenceMap
presenceMap.put(room.getRoomname(), myListener);
String tooltip;
if (room instanceof ChatRoomImpl) {
tooltip = ((ChatRoomImpl) room).getParticipantJID();
String nickname = SparkManager.getUserManager().getUserNicknameFromJID(((ChatRoomImpl) room).getParticipantJID());
tooltip = "<html><body><b>Contact: </b>" + nickname + "<br><b>JID: </b>" + tooltip;
} else {
tooltip = room.getRoomname();
}
// Create ChatRoom UI and dock
SparkTab tab = addTab(room.getTabTitle(), room.getTabIcon(), room, tooltip);
tab.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
checkTabPopup(e);
}
public void mousePressed(MouseEvent e) {
checkTabPopup(e);
}
});
room.addMessageListener(this);
// Remove brand panel
final String title = getTabAt(0).getActualText();
if (title.equals(WELCOME_TITLE)) {
chatFrame.setTitle(room.getRoomTitle());
}
final TimerTask visibleTask = new SwingTimerTask() {
public void doRun() {
checkVisibility(room);
}
};
TaskEngine.getInstance().schedule(visibleTask, 100);
// Add to ChatRoomList
chatRoomList.add(room);
// Notify users that the chat room has been opened.
fireChatRoomOpened(room);
// Focus Chat
focusChat();
// Add Room listeners to override issue with input maps and keybinding on the mac.
if (Spark.isMac()) {
room.getChatInputEditor().addKeyListener(this);
}
}
use of org.jivesoftware.spark.component.tabbedPane.SparkTab in project Spark by igniterealtime.
the class ChatManager method notifySparkTabHandlers.
/**
* Notifies all <code>ContainerDecorator</code>
*
* @param component the component within the tab.
*/
public void notifySparkTabHandlers(Component component) {
final SparkTab tab = chatContainer.getTabContainingComponent(component);
if (tab == null) {
return;
}
boolean isChatFrameInFocus = getChatContainer().getChatFrame().isInFocus();
boolean isSelectedTab = getChatContainer().getSelectedComponent() == component;
for (SparkTabHandler decorator : sparkTabHandlers) {
try {
boolean isHandled = decorator.isTabHandled(tab, component, isSelectedTab, isChatFrameInFocus);
if (isHandled) {
tab.validateTab();
return;
}
} catch (Exception e) {
Log.error("A SparkTabHandler ('" + decorator + "') threw an exception.", e);
}
}
}
use of org.jivesoftware.spark.component.tabbedPane.SparkTab in project Spark by igniterealtime.
the class ChatContainer method checkTabPopup.
private void checkTabPopup(MouseEvent e) {
final SparkTab tab = (SparkTab) e.getSource();
if (!e.isPopupTrigger()) {
return;
}
final JPopupMenu popup = new JPopupMenu();
// Handle closing this room.
Action closeThisAction = new AbstractAction() {
private static final long serialVersionUID = 5002889397735856123L;
public void actionPerformed(ActionEvent e) {
ChatRoom chatRoom = (ChatRoom) getComponentInTab(tab);
if (chatRoom != null) {
closeTab(chatRoom);
}
}
};
closeThisAction.putValue(Action.NAME, Res.getString("message.close.this.chat"));
popup.add(closeThisAction);
if (getChatRooms().size() > 1) {
// Handle closing other rooms.
Action closeOthersAction = new AbstractAction() {
private static final long serialVersionUID = 1869236917427431585L;
public void actionPerformed(ActionEvent e) {
ChatRoom chatRoom = (ChatRoom) getComponentInTab(tab);
if (chatRoom != null) {
for (ChatRoom cRoom : getChatRooms()) {
if (chatRoom != cRoom) {
closeTab(cRoom);
}
}
}
}
};
closeOthersAction.putValue(Action.NAME, Res.getString("message.close.other.chats"));
popup.add(closeOthersAction);
Action closeOldAction = new AbstractAction() {
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent e) {
for (ChatRoom rooms : getStaleChatRooms()) {
closeTab(rooms);
}
}
};
closeOldAction.putValue(Action.NAME, Res.getString("message.close.stale.chats"));
popup.add(closeOldAction);
}
popup.show(tab, e.getX(), e.getY());
}
Aggregations