View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.plugin.news;
21  
22  import java.util.Date;
23  
24  import javax.swing.Action;
25  
26  /***
27   * Implements the basic requirements for a news item. News items can be
28   * displayed in the news pane and can be provided by any plugin.  */
29  public class DefaultNewsItem implements NewsItem {
30  
31      //--- Constant(s) ---
32  
33      //--- Method(s) ---
34  
35  	private String title;
36  	private String description;
37  	private String link;
38  	private String author;
39  	private Date date;
40  	private Action[] actions;
41  
42  	/***
43  	 * Sets the title of this news item. */
44  	public void setTitle(String title)
45  	{
46  		this.title = title;
47  	}
48  
49  	/***
50  	 * Returns the title of this news item. */
51  	public String getTitle()
52  	{
53  		return title;
54  	}
55  
56  	/***
57  	 * Sets the description of this news item. */
58  	public void setDescription(String description)
59  	{
60  		this.description = description;
61  	}
62  
63  	/***
64  	 * Returns the description of this news item. */
65  	public String getDescription() 
66  	{
67  		return description;
68  	}
69  
70  	/***
71  	 * Sets the link of this news item. */
72  	public void setLink(String link)
73  	{
74  		this.link = link;
75  	}
76  
77  	/***
78  	 * Returns the link of this news item. */
79  	public String getLink()
80  	{
81  		return link;
82  	}
83  
84  	/***
85  	 * Sets the author of this news item. */
86  	public void setAuthor(String author)
87  	{
88  		this.author = author;
89  	}
90  
91  	/*
92  	 * Return the author of this new item. */
93  	public String getAuthor()
94  	{
95  		return author;
96  	}
97  
98  	/***
99  	 * Sets the publishing date of this news item. */
100 	public void setDate(Date date)
101 	{
102 		this.date = date;
103 	}
104 
105 	/***
106 	 * Returns the publishing date of this news item. */
107 	public Date getDate()
108 	{
109 		return date;
110 	}
111 
112 	/***
113 	 * Sets the actions. */
114 	public void setActions(Action[] actions)
115 	{
116 		this.actions = actions;
117 	}
118 
119     /***
120      * Returns the actions that can performed by the news item. */
121     public Action[] getActions()
122 	{
123 		return actions;
124 	}
125 
126 	public String toString() {
127 		return title;
128 	}
129 	
130 	/***
131 	 * @see java.lang.Object#equals(java.lang.Object)
132 	 */
133 	public boolean equals(Object obj) {
134 		if (obj instanceof NewsItem) {
135 			String one = title + description + author + link + date;
136 			NewsItem ni = (NewsItem)obj;
137 			String two = ni.getTitle() + ni.getDescription() + ni.getAuthor()
138 				+ ni.getLink() + ni.getDate();
139 			return one.equals(two);
140 		}
141 		return false;
142 	}
143 
144 	/***
145 	 * @see java.lang.Object#hashCode()
146 	 */
147 	public int hashCode() {
148 		String one = title + description + author + link + date.toString();
149 		return one.hashCode();
150 	}
151 
152 }