7 public class LogViewer extends Applet implements Runnable,CbButtonCallback
10 StringBuffer logbuffer = new StringBuffer();
13 CbButton pause, button;
14 boolean paused = false;
19 setLayout(new BorderLayout());
20 add("Center", log = new TextArea());
21 log.setEditable(false);
22 Util.setFont(new Font("TimesRoman", Font.PLAIN, 12));
23 Panel bot = new Panel();
24 bot.setBackground(Color.white);
25 bot.setForeground(Color.white);
26 bot.setLayout(new FlowLayout(FlowLayout.RIGHT));
27 if (getParameter("pause") != null) {
28 // Add button to pause display
29 bot.add(pause = new CbButton(" Pause ", this));
31 if (getParameter("buttonname") != null) {
32 // Add button for some other purpose
33 bot.add(button = new CbButton(getParameter("buttonname"),this));
40 // Start download thread
42 th = new Thread(this);
50 String killurl = getParameter("killurl");
51 if (killurl != null) {
52 // Call this CGI at stop time
54 URL u = new URL(getDocumentBase(), killurl);
55 URLConnection uc = u.openConnection();
56 String session = getParameter("session");
58 uc.setRequestProperty("Cookie", session);
59 uc.getInputStream().close();
61 catch(Exception e2) { }
63 if (is != null) is.close();
64 if (th != null) th.stop();
75 URL u = new URL(getDocumentBase(), getParameter("url"));
76 URLConnection uc = u.openConnection();
77 String session = getParameter("session");
79 uc.setRequestProperty("Cookie", session);
80 is = new LineInputStream(uc.getInputStream());
86 catch(EOFException e) {
89 catch(IOException e) {
92 append("IO error : "+e.getMessage());
96 int len = 0, oldlen = 0;
98 void append(String str) {
100 log.append((len == 0 ? "" : "\n")+str);
102 logbuffer.append((len == 0 ? "" : "\n")+str);
104 len += str.length()+1;
106 log.select(oldlen, oldlen);
110 public void click(CbButton b) {
113 // Resume display, and append missing text
114 pause.setText(" Pause ");
115 log.setText(logbuffer.toString());
116 log.select(oldlen, oldlen);
119 pause.setText("Resume");
122 } else if (b == button) {
125 URL u = new URL(getDocumentBase(),
126 getParameter("buttonlink"));
127 getAppletContext().showDocument(u);
129 catch(Exception e) { }