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

Quick Search    Search Deep

Source code: org/relayirc/chatengine/Server.java


1   
2   /* 
3    * FILE: Server.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.chatengine;
24  import org.relayirc.util.*;
25  
26  import java.io.*;
27  import java.util.Vector;
28  import java.beans.*;
29  
30  /**
31   * Currently, a server object just holds information about an IRC server.
32   * It might make sense to have an openConnection() method which returns
33   * an IRC connection object.
34   * @author David M. Johnson.
35   */
36  public class Server implements Serializable {
37     static final long serialVersionUID = -6620548660161628041L;
38  
39     private String  _name =  "";       // Server host name
40     private int     _ports[] = null;   // Currently, only the 1st one is used
41     private String  _title =  "";      // Optional
42     private String  _network = "";     // Optional
43     private String  _group = "";       // Optional
44     private boolean _favorite = false;   
45  
46     private transient PropertyChangeSupport _propChangeSupport = null;
47  
48     //---------------------------------------------------------------
49     public Server(String name, int port) {
50        this(name,port,"");
51     }  
52     //---------------------------------------------------------------
53     public Server(String name, int port, String group) {
54        this(name,port,"","",group);
55     }
56     //---------------------------------------------------------------
57     public Server(String name, int port, String title, String network, String group) {
58        _propChangeSupport = new PropertyChangeSupport(this);
59        _title = title;
60        _network = network;
61        _name = name;
62        _group = group;
63        setPort(port);
64     }
65     //-------------------------------------------------------------------
66     private void readObject(java.io.ObjectInputStream in)
67        throws IOException, ClassNotFoundException {
68        
69        try {in.defaultReadObject();} catch (NotActiveException e) {e.printStackTrace();}
70        _propChangeSupport = new PropertyChangeSupport(this);
71     }
72     //------------------------------------------------------------------
73     public void addPropertyChangeListener(PropertyChangeListener listener) {
74        _propChangeSupport.addPropertyChangeListener(listener);
75     }
76     //------------------------------------------------------------------
77     public void removePropertyChangeListener(PropertyChangeListener listener) {
78        _propChangeSupport.removePropertyChangeListener(listener);
79     }
80     //---------------------------------------------------------------
81     public boolean isFavorite() {
82        return _favorite;
83     }
84     public void setFavorite(boolean fave) {
85        boolean old = _favorite;
86        _favorite=fave;
87        _propChangeSupport.firePropertyChange("Favorite",new Boolean(old),new Boolean(_favorite));
88     }
89     //---------------------------------------------------------------
90     public String getGroup() {
91        return _group;
92     }
93     public void setGroup(String group) {
94        String old = _group;
95        _group = group;
96        _propChangeSupport.firePropertyChange("Group",old,_group);
97     }
98     //---------------------------------------------------------------
99     public String getName() {
100       return _name;
101    }
102    public void setName(String name) {
103       _name = name;
104    }
105    //---------------------------------------------------------------
106    public String getNetwork() {
107       return _network;
108    }
109    public void setNetwork(String network) {
110       String old = _network;
111       _network = network;
112       _propChangeSupport.firePropertyChange("Network",old,_network);
113    }
114    //---------------------------------------------------------------
115    public int getPort() {
116       if (_ports==null) {
117          _ports = new int[1];
118          _ports[0] = 0;
119       }
120       return _ports[0];
121    }
122    public void setPort(int port) {
123       int old = 0;
124       if (_ports==null) {
125          _ports = new int[1];
126       }
127       else {
128          old = _ports[0];
129       }
130       _ports[0] = port;
131       _propChangeSupport.firePropertyChange("Port",new Integer(old),new Integer(_ports[0]));
132    }
133    //---------------------------------------------------------------
134    // FIX: add property change support
135    public int[] getPorts() { 
136       return _ports;
137    }
138    // FIX: add property change support
139    public void setPorts(int ports[]) {
140       _ports = ports;
141    }
142    //---------------------------------------------------------------
143    public String getTitle() {
144       return _title;
145    }
146    public void setTitle(String title) {
147       String old = _title;
148       _title = title;
149       _propChangeSupport.firePropertyChange("Title",old,_title);
150    }
151    //---------------------------------------------------------------
152    public String toString() {
153       if (_network!=null && _network.length()>0)
154          return _name+" ("+_network+")";
155       else
156          return _name;
157    }
158 }
159