KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > rssreader > RssReader


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.rssreader;
20
21 import java.awt.Dimension JavaDoc;
22 import java.awt.event.WindowEvent JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.util.ArrayList JavaDoc;
26
27 import org.lucane.applications.rssreader.gui.*;
28 import org.lucane.applications.rssreader.rss.ChannelInfo;
29 import org.lucane.client.*;
30 import org.lucane.client.widgets.DialogBox;
31 import org.lucane.common.ConnectInfo;
32 import org.lucane.common.net.ObjectConnection;
33
34 public class RssReader extends StandalonePlugin
35 {
36     private MainFrame frame;
37     private ConnectInfo service;
38     
39     public RssReader()
40     {
41     }
42
43     public Plugin newInstance(ConnectInfo[] friends)
44     {
45         return new RssReader();
46     }
47
48     public void start()
49     {
50         this.service = Communicator.getInstance().getConnectInfo(getName());
51
52         setProxyFromLocalConfig();
53         
54         frame = new MainFrame(this);
55         frame.refreshChannelList();
56         frame.setPreferredSize(new Dimension JavaDoc(600, 600));
57         frame.restoreState();
58         frame.show();
59     }
60     
61     public void setProxyFromLocalConfig()
62     {
63         System.setProperty("proxySet", getLocalConfig().get("proxySet", "false"));
64         System.setProperty("proxyHost", getLocalConfig().get("proxyHost", ""));
65         System.setProperty("proxyPort", getLocalConfig().get("proxyPort", ""));
66     }
67
68     public void openUrl(URL JavaDoc url)
69     {
70         try {
71             BrowserLauncher.openURL(url.toString());
72         } catch (IOException JavaDoc e) {
73             e.printStackTrace();
74         }
75     }
76     
77     public void addChannel(ChannelInfo channel)
78     {
79         RssAction action = new RssAction(RssAction.ADD_CHANNEL, channel);
80         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
81                 service, service.getName(), action);
82         
83         String JavaDoc ack = tr("err.connection");
84         try {
85              ack = oc.readString();
86         } catch(Exception JavaDoc e) {}
87         
88         if(! ack.equals("OK"))
89             DialogBox.error(tr("err.addChannel") + ack);
90         else
91             frame.refreshChannelList();
92
93         oc.close();
94     }
95     
96     public void removeChannel(ChannelInfo channel)
97     {
98         RssAction action = new RssAction(RssAction.REMOVE_CHANNEL, channel);
99         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
100                 service, service.getName(), action);
101         
102         String JavaDoc ack = tr("err.connection");
103         try {
104             ack = oc.readString();
105         } catch(Exception JavaDoc e) {}
106         
107         if(! ack.equals("OK"))
108             DialogBox.error(tr("err.removeChannel") + ack);
109         else
110             frame.refreshChannelList();
111
112         oc.close();
113     }
114     
115     public ArrayList JavaDoc getChannels()
116     {
117         ArrayList JavaDoc channels;
118         
119         RssAction action = new RssAction(RssAction.GET_CHANNELS);
120         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
121                 service, service.getName(), action);
122         
123         String JavaDoc ack = tr("err.connection");
124         try {
125             ack = oc.readString();
126             channels = (ArrayList JavaDoc)oc.read();
127         } catch(Exception JavaDoc e) {
128             channels = new ArrayList JavaDoc();
129             e.printStackTrace();
130         }
131         
132         if(! ack.equals("OK"))
133             DialogBox.error(tr("err.listChannels") + ack);
134         
135         oc.close();
136         
137         return channels;
138     }
139     
140     public void windowClosing(WindowEvent JavaDoc e)
141     {
142         frame.saveState();
143         this.exit();
144     }
145 }
146
Popular Tags