Search in sources :

Example 1 with SparkTab

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;
}
Also used : ChatContainer(org.jivesoftware.spark.ui.ChatContainer) SparkTab(org.jivesoftware.spark.component.tabbedPane.SparkTab) ChatRoom(org.jivesoftware.spark.ui.ChatRoom)

Example 2 with SparkTab

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());
    }
}
Also used : SparkTab(org.jivesoftware.spark.component.tabbedPane.SparkTab)

Example 3 with SparkTab

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:&nbsp;</b>" + nickname + "<br><b>JID:&nbsp;</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);
    }
}
Also used : java.util(java.util) SparkTabbedPaneListener(org.jivesoftware.spark.component.tabbedPane.SparkTabbedPaneListener) SettingsManager(org.jivesoftware.sparkimpl.settings.local.SettingsManager) Res(org.jivesoftware.resource.Res) Log(org.jivesoftware.spark.util.log.Log) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl) MainWindow(org.jivesoftware.MainWindow) SparkToaster(org.jivesoftware.sparkimpl.plugin.alerts.SparkToaster) ChangeListener(javax.swing.event.ChangeListener) GroupChatRoomListener(org.jivesoftware.spark.ui.conferences.GroupChatRoomListener) AndFilter(org.jivesoftware.smack.filter.AndFilter) TaskEngine(org.jivesoftware.spark.util.TaskEngine) ChangeEvent(javax.swing.event.ChangeEvent) FromMatchesFilter(org.jivesoftware.smack.filter.FromMatchesFilter) Presence(org.jivesoftware.smack.packet.Presence) ChatManager(org.jivesoftware.spark.ChatManager) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) SparkRes(org.jivesoftware.resource.SparkRes) SwingWorker(org.jivesoftware.spark.util.SwingWorker) SparkTabbedPane(org.jivesoftware.spark.component.tabbedPane.SparkTabbedPane) SparkTab(org.jivesoftware.spark.component.tabbedPane.SparkTab) GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) XmppStringUtils(org.jxmpp.util.XmppStringUtils) Spark(org.jivesoftware.Spark) java.awt(java.awt) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) List(java.util.List) SparkManager(org.jivesoftware.spark.SparkManager) java.awt.event(java.awt.event) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) Message(org.jivesoftware.smack.packet.Message) Pattern(java.util.regex.Pattern) StanzaListener(org.jivesoftware.smack.StanzaListener) javax.swing(javax.swing) AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) SparkTab(org.jivesoftware.spark.component.tabbedPane.SparkTab) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) Presence(org.jivesoftware.smack.packet.Presence) StanzaListener(org.jivesoftware.smack.StanzaListener) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 4 with SparkTab

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);
        }
    }
}
Also used : SparkTab(org.jivesoftware.spark.component.tabbedPane.SparkTab) SmackException(org.jivesoftware.smack.SmackException) URISyntaxException(java.net.URISyntaxException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 5 with SparkTab

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());
}
Also used : SparkTab(org.jivesoftware.spark.component.tabbedPane.SparkTab) GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom)

Aggregations

SparkTab (org.jivesoftware.spark.component.tabbedPane.SparkTab)5 GroupChatRoom (org.jivesoftware.spark.ui.rooms.GroupChatRoom)2 java.awt (java.awt)1 java.awt.event (java.awt.event)1 URISyntaxException (java.net.URISyntaxException)1 java.util (java.util)1 List (java.util.List)1 Pattern (java.util.regex.Pattern)1 javax.swing (javax.swing)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1 MainWindow (org.jivesoftware.MainWindow)1 Spark (org.jivesoftware.Spark)1 Res (org.jivesoftware.resource.Res)1 SparkRes (org.jivesoftware.resource.SparkRes)1 SmackException (org.jivesoftware.smack.SmackException)1 StanzaListener (org.jivesoftware.smack.StanzaListener)1 XMPPException (org.jivesoftware.smack.XMPPException)1 AndFilter (org.jivesoftware.smack.filter.AndFilter)1 FromMatchesFilter (org.jivesoftware.smack.filter.FromMatchesFilter)1