aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/gui/main/chatroomslist/joinforms/JoinChatRoomWizardPage2.java
blob: ff8980085c3e52a8008cc53cd9bc5408ff8131a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package net.java.sip.communicator.impl.gui.main.chatroomslist.joinforms;

import javax.swing.event.*;

import net.java.sip.communicator.impl.gui.main.contactlist.addcontact.*;
import net.java.sip.communicator.service.gui.*;

/**
 * The <tt>JoinChatRoomWizardPage2</tt> is the second page of the
 * "Join chat room" wizard. Contains the <tt>SearchChatRoomPanel</tt>,
 * where the user should specify the chat room to join.
 * 
 * @author Yana Stamcheva
 */
public class JoinChatRoomWizardPage2
        implements WizardPage
{
    public static final String IDENTIFIER = "SEARCH_CHAT_ROOM_PANEL";
    
    private SearchChatRoomPanel searchChatRoomPanel;
    
    private WizardContainer wizard;
    
    private NewChatRoom joinChatRoom;

    /**
     * Creates an instance of <tt>JoinChatRoomWizardPage2</tt>.
     * 
     * @param wizard the parent wizard container
     * @param joinChatRoom the object that collects all information for the
     * chat room, collected throughout the wizard
     */
    public JoinChatRoomWizardPage2( WizardContainer wizard,
                                    NewChatRoom joinChatRoom)
    {
        this.wizard = wizard;

        this.joinChatRoom = joinChatRoom;

        searchChatRoomPanel = new SearchChatRoomPanel(wizard);

        searchChatRoomPanel.addChatRoomNameListener(
            new ChatRoomDocumentListener());
    }

    /**
     * Implements the <tt>WizardPanelDescriptor</tt> method to return the
     * identifier of the next wizard page.
     * 
     * @return the identifier of the next wizard page
     */
    public Object getNextPageIdentifier()
    {
        return WizardPage.FINISH_PAGE_IDENTIFIER;
    }
    
    /**
     * Implements the <tt>WizardPanelDescriptor</tt> method to return the
     * identifier of the previous wizard page.
     * 
     * @return the identifier of the previous wizard page
     */
    public Object getBackPageIdentifier()
    {
        return AddContactWizardPage1.IDENTIFIER;
    }
    
    /**
     * Before finishing the wizard sets the identifier entered by the user
     * to the <tt>NewChatRoom</tt> object.
     */
    public void pageHiding()
    {
        joinChatRoom.setChatRoomName(searchChatRoomPanel.getChatRoomName());
    }

    /**
     * Implements the <tt>WizardPanelDescriptor</tt> method to return the
     * identifier of this page.
     * 
     * @return the identifier of this page
     */
    public Object getIdentifier()
    {
        return IDENTIFIER;
    }

    /**
     * Returns the form contained in this wizard page. In this case it's the
     * <tt>ChatRoomNamePanel</tt>.
     * 
     * @return the form contained in this wizard page
     */
    public Object getWizardForm()
    {
        return searchChatRoomPanel;
    }

    /**
     * Pre-configures some properties when showing the page.
     */
    public void pageShown()
    {
        // Disable the finish button before there's anything in the chat room
        // field.
        wizard.setNextFinishButtonEnabled(false);

        searchChatRoomPanel.requestFocusInField();
        searchChatRoomPanel.setProtocolProvider(
            joinChatRoom.getProtocolProvider());
    }

    public void pageShowing()
    {
    }

    public void pageNext()
    {
    }

    public void pageBack()
    {
    }

    /**
     * Creates a <tt>DocumentListener</tt>, which would listen for events
     * coming from the <tt>SearchChatRoomPanel</tt>, when the user enters the
     * name of the chat room to join.
     */
    private class ChatRoomDocumentListener implements DocumentListener
    {
        /**
         * Called when the user enters new content in the chat room name field.
         */
        public void insertUpdate(DocumentEvent e)
        {
            if (e.getDocument().getLength() > 0)
                wizard.setNextFinishButtonEnabled(true);
            else
                wizard.setNextFinishButtonEnabled(false);
        }

        /**
         * Called when the user removes content from the chat room name field.
         */
        public void removeUpdate(DocumentEvent e)
        {
            if (e.getDocument().getLength() > 0)
                wizard.setNextFinishButtonEnabled(true);
            else
                wizard.setNextFinishButtonEnabled(false);
        }

        public void changedUpdate(DocumentEvent e)
        {}
    }
}