1 16 package net.sf.jftp.tools; 17 18 import net.sf.jftp.config.Settings; 19 import net.sf.jftp.gui.*; 20 import net.sf.jftp.gui.base.StatusCanvas; 21 import net.sf.jftp.gui.framework.*; 22 import net.sf.jftp.system.LocalIO; 23 import net.sf.jftp.system.logging.Log; 24 import net.sf.jftp.util.*; 25 26 import java.awt.*; 27 import java.awt.event.*; 28 29 import java.net.*; 30 31 import java.util.*; 32 33 import javax.swing.*; 34 35 36 public class RSSFeeder extends JPanel implements Runnable , ActionListener 37 { 38 public static String urlstring = Settings.getRSSFeed(); 39 Thread runner; 40 URL url; 41 RSSParser parser; 42 StatusCanvas can = new StatusCanvas(); 43 HImageButton next = new HImageButton(Settings.nextRSSImage, "nextRSS", 44 "Display next RSS news item", this); 45 boolean header = false; 46 boolean breakHeader = false; 47 int HEADER_IVAL = 4000; 48 int LOAD_IVAL = 31 * 60000; 49 50 public RSSFeeder() 52 { 53 setLayout(new BorderLayout(0, 0)); 54 next.setPreferredSize(new Dimension(22, 22)); 55 next.setMaximumSize(new Dimension(22, 22)); 56 57 add("West", next); 59 add("Center", can); 60 setPreferredSize(new Dimension(500, 25)); 61 runner = new Thread (this); 62 runner.start(); 63 } 64 65 public void switchTo(String u) 66 { 67 if(u == null) 68 { 69 return; 70 } 71 72 urlstring = u; 73 74 runner.stop(); 75 runner = new Thread (this); 76 runner.start(); 77 } 78 79 public void run() 80 { 81 long time; 82 83 LocalIO.pause(3000); 84 85 Log.out("Starting RSS Feed"); 86 87 try 88 { 89 can.setInterval(10); 90 url = new URL(urlstring); 91 parser = new RSSParser(url); 92 time = System.currentTimeMillis(); 93 } 94 catch(Exception ex) 95 { 96 Log.debug("Error: Can't load RSS feed (" + ex + ")"); 97 ex.printStackTrace(); 98 99 return; 100 } 101 102 while(true) 103 { 104 try 105 { 106 Enumeration e = parser.titles.elements(); 107 Enumeration e2 = parser.descs.elements(); 108 109 while(e.hasMoreElements()) 110 { 111 can.setText((String ) e.nextElement()); 112 next.setEnabled(true); 113 header = true; 114 115 int i = 0; 116 117 while(!breakHeader && (i < 100)) 118 { 119 LocalIO.pause(HEADER_IVAL / 100); 120 i++; 121 } 122 123 next.setEnabled(false); 124 breakHeader = false; 125 header = false; 126 127 if(e2.hasMoreElements()) 128 { 129 next.setEnabled(true); 130 can.scrollText((String ) e2.nextElement()); 131 next.setEnabled(false); 132 } 133 } 134 } 135 catch(Exception ex) 136 { 137 ex.printStackTrace(); 138 } 139 140 if(System.currentTimeMillis() > (LOAD_IVAL + time)) 141 { 142 parser = new RSSParser(url); 143 time = System.currentTimeMillis(); 144 } 145 } 146 } 147 148 public void actionPerformed(ActionEvent e) 149 { 150 if(e.getSource() == next) 151 { 152 if(header) 153 { 154 breakHeader = true; 155 } 156 else 157 { 158 can.forward(); 159 } 160 } 161 } 162 } 163 | Popular Tags |