-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadTest.java
More file actions
146 lines (120 loc) · 4.63 KB
/
ReadTest.java
File metadata and controls
146 lines (120 loc) · 4.63 KB
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
import java.awt.Desktop;
import java.awt.FontMetrics;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URISyntaxException;
import java.util.StringTokenizer;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JApplet;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
class changeDisplay {
private int len;
private Timer timer;
private String feedMsgs[];
private static int counter=0;
private JEditorPane editorPane;
public changeDisplay (int seconds, String feedMsgs[], JEditorPane editorPane, int len) {
timer = new Timer();
timer.schedule(new RemindTask(),
0, //initial delay
seconds*1000); //subsequent rate
this.len = len;
this.feedMsgs = feedMsgs;
this.editorPane = editorPane;
}
String formatContents(String input) {
String title="", description="", link="", author="";
String rawString = input.substring(13,input.length()-1);
StringTokenizer st = new StringTokenizer(rawString, "#;");
while(st.hasMoreTokens()) {
String key = st.nextToken().trim();
String val = st.nextToken().trim();
if ( key.equals("title"))
title = val;
else if ( key.equals("description"))
description = val;
else if ( key.equals("link"))
link = val;
else if ( key.equals("author"))
author = val;
}
StringWriter sout = new StringWriter();
PrintWriter out = new PrintWriter(sout);
ReadTest.class.getClassLoader();
String imgsrc = ClassLoader.getSystemResource("rss.png").toString();
out.println("<br /> <img src=\'"+imgsrc+"\' width=12 height=12 align=\"left\" /> <strong><a href=\""+link+"\" target=\"_blank\">"+title+"</a></strong> ");
out.println("<font size=\"2.25\" color=\"gray\">by "+author+"<br /></font>");
out.println(" <font size=\"3\" color=\"black\">"+description+"</font>");
out.close();
return sout.toString();
}
class RemindTask extends TimerTask {
public void run() {
String output = formatContents(feedMsgs[counter++]);
editorPane.setText(output);
counter = counter % len;
}
}
}
public class ReadTest extends JApplet
{
private Thread runner;
private String tickerline, displaystring;
private JEditorPane editorPane;
private RSSFeedParser parser = new RSSFeedParser("http://www.ece.illinois.edu/mediacenter/news_rss.asp");
private Feed feed = parser.readFeed();
private int cnt, i=0, delay = 200;
private boolean isRunning = false;
private FontMetrics fm;
private String feedMsgsArray[] = new String[100];;
public void init()
{
try
{
for (FeedMessage message : feed.getMessages()) {
//System.out.println("Received message : "+message.toString());
feedMsgsArray[i++] = message.toString();
}
createGUI();
new changeDisplay(5, feedMsgsArray, editorPane,i);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//creates bkground creates screen(editor pane) to put stuff on.
private void createGUI() throws IOException {
editorPane = new JEditorPane();
editorPane.setEditable(false); //setting stuff on editor pane
editorPane.setContentType("text/html");
//editorPane.setEditorKit(JEditorPane.createEditorKitForContentType("text/html"));
//editorPane.addHyperlinkListener(new ActivatedHyperlinkListener(editorPane));
// Set up the JEditorPane to handle clicks on hyperlinks
editorPane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
// Do something with e.getURL() here
if(Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(e.getURL().toURI());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (URISyntaxException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
});
JScrollPane scrollPane = new JScrollPane(editorPane);
getContentPane().add(editorPane);
}
}