Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/relayirc/swingui/ChatChannelPanel.java


1   
2   /* 
3    * FILE: ChatChannelPanel.java 
4    * 
5    * The contents of this file are subject to the Mozilla Public License
6    * Version 1.0 (the "License"); you may not use this file except in
7    * compliance with the License. You may obtain a copy of the License at
8    * http://www.mozilla.org/MPL/
9    * 
10   * Software distributed under the License is distributed on an "AS IS"
11   * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
12   * License for the specific language governing rights and limitations
13   * under the License.
14   * 
15   * The Original Code is Relay IRC chat client.
16   * 
17   * The Initial Developer of the Original Code is David M. Johnson.
18   * Portions created by David M. Johnson are Copyright (C) 1998. 
19   * All Rights Reserved.
20   *
21   * Contributor(s): No contributors to this file.
22   */
23  package org.relayirc.swingui;
24  import org.relayirc.chatengine.*;
25  import org.relayirc.swingutil.*;
26  import org.relayirc.util.*;
27  
28  import java.awt.*;
29  import java.awt.event.*;
30  import java.util.*;
31  import javax.swing.*;
32  import javax.swing.event.*;
33  
34  ///////////////////////////////////////////////////////////////////////
35  
36  /**
37   * A chat panel for one specific chat channel. Implements the
38   * <strong>IChatView</strong> interface and uses the <strong>
39   * UserList</strong> class to provide a list of the users that are
40   * present in the chat channel.
41   */
42  public class ChatChannelPanel extends ChatPanel implements ChannelListener, MDIClientPanel {
43     private UserList _userList;
44     private int      _initialized=3; // kludge to force a resize
45     private String   _dockState = MDIPanel.DOCK_NONE;
46  
47     //------------------------------------------------------------------
48     public ChatChannelPanel(Channel chan, Container container) {
49  
50        super(chan,container);
51  
52        // Add list of users in east part of layout
53        _userList = new UserList(chan);
54        _userList.setBackground(Color.white);
55        JScrollPane scrollPane = new JScrollPane(_userList,
56           ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
57           ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER );
58        add(scrollPane,"East");
59  
60        validate();
61       
62        // Listen to the channel
63        chan.addChannelListener(this);
64     }
65  
66     //------------------------------------------------------------------
67     public void onActivation(ChannelEvent event) {
68        if (_container instanceof JInternalFrame) {
69           ((JInternalFrame)_container).toFront();
70        }
71     }
72     
73     //------------------------------------------------------------------
74     public void onAction(ChannelEvent event) {
75        println("* "+event.getOriginNick()+" "+event.getValue(),
76           _options.getDisplayColor("Actions"));
77     }
78     
79     //------------------------------------------------------------------
80     public void onBan(ChannelEvent event) {
81        println(event.getSubjectNick()+" was banned by "+event.getOriginNick(),
82           _options.getDisplayColor("Bans"));
83        _userList.remove(event.getSubjectNick());
84     }
85     
86     //------------------------------------------------------------------
87     public void onConnect(ChannelEvent event) {
88     }
89     //------------------------------------------------------------------
90     public void onDisconnect(ChannelEvent event) {
91        ChatApp.getChatApp().removeChatPanel(this);
92     }
93     //------------------------------------------------------------------
94     public void onJoin(ChannelEvent event) {
95        forceLayout();
96        println(event.getOriginNick()+" has joined "+_channel.getName(),
97           _options.getDisplayColor("Joins"));
98        _userList.addItem(event.getOriginNick());
99     }
100    
101    //------------------------------------------------------------------
102    public void onJoins(ChannelEvent event) {
103       RCTest.println("ChatChannelView: users joined - "+(String)event.getValue()+"\n");
104       forceLayout();
105       StringTokenizer toker = new StringTokenizer((String)event.getValue());
106       try {
107          String user;
108          while ( (user=toker.nextToken()) != null ) {
109             _userList.addItem(user);
110          }
111       }
112       catch ( NoSuchElementException e ) {
113       }
114       catch ( Exception e ) {
115          e.printStackTrace();
116       }
117    }
118    
119    //------------------------------------------------------------------
120    public void onKick(ChannelEvent event) {
121       println(event.getSubjectNick()+" was kicked by "+event.getOriginNick(),
122          _options.getDisplayColor("Kicks"));
123 
124       _userList.remove(event.getSubjectNick());
125 
126    }
127    
128    //------------------------------------------------------------------
129    public void onMessage(ChannelEvent event) {
130       print(event.getOriginNick()+"> ","Bold-"+_options.getDisplayColor("Messages"));
131       println((String)event.getValue(),_options.getDisplayColor("Messages"));
132    }
133    
134    //------------------------------------------------------------------
135    public void onNick(ChannelEvent event) {
136       if (_userList.contains(event.getOriginNick())) {
137          println(event.getOriginNick()+" is now known as "+(String)event.getValue(),
138             _options.getDisplayColor("Nicks"));
139          _userList.remove(event.getOriginNick());
140          _userList.addItem((String)event.getValue());
141       }
142    }
143    
144    //------------------------------------------------------------------
145    public void onOp(ChannelEvent event) {
146       if ( ((DefaultListModel)_userList.getModel()).contains(event.getSubjectNick()) ) {
147          println(event.getOriginNick()+" give operator rights to "+event.getSubjectNick(),
148             _options.getDisplayColor("Ops"));
149          _userList.remove(event.getSubjectNick());
150          _userList.addItem("@"+event.getSubjectNick());
151       }
152    }
153    
154    //------------------------------------------------------------------
155    public void onPart(ChannelEvent event) {
156       println(event.getOriginNick()+" has left "+_channel,
157          _options.getDisplayColor("Parts"));
158       _userList.remove(event.getOriginNick());
159    }
160 
161    //------------------------------------------------------------------
162    public void onQuit(ChannelEvent event) {
163       if ( ((DefaultListModel)_userList.getModel()).contains(event.getOriginNick()) ) {
164          println(event.getOriginNick()+" has quit IRC ("+(String)event.getValue()+")",
165             _options.getDisplayColor("Parts"));
166          _userList.remove(event.getOriginNick());
167       }
168    }
169    
170    //------------------------------------------------------------------
171    public void onTopicChange(ChannelEvent event) {
172       RCTest.println("Need to set title to "+_channel+" - "+(String)event.getValue());
173       //setTitle(_channel+" - "+topic);
174    }
175    
176    //------------------------------------------------------------------
177    /**
178     * Kludge to force a layout. Added this because UserList is 
179     * initially sized too wide and corrects itself upon layout.
180     */
181    public void forceLayout() {
182       if (_initialized-- > 0) { 
183          setSize(getSize().width+1,getSize().height+1);
184          setSize(getSize().width+1,getSize().height+1);
185          setVisible(true);
186       }
187    }
188    //------------------------------------------------------------------
189    public void part() {
190       _channel.sendPart();
191    }
192    //------------------------------------------------------------------
193    public String getDockState() {
194       return _dockState;
195    }   
196    //------------------------------------------------------------------
197    public void setDockState(String dockState) {
198       _dockState = dockState;
199    }
200    //------------------------------------------------------------------
201    public JPanel getPanel() {
202       return this;
203    }
204 }
205