KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > thinlet > drafts > EventLogger


1 package thinlet.drafts;
2
3 import thinlet.*;
4
5 /**
6  *
7  */

8 public class EventLogger {
9     
10     public void buttonAction(String JavaDoc text) { log("button action " + text); }
11     public void selectAction(String JavaDoc name, String JavaDoc text) { log(name + " select " + text); }
12     public void doubleClick(String JavaDoc name, String JavaDoc text) { log(name + " double click " + text); }
13     public void expand(String JavaDoc text) { log("expand " + text); }
14     public void collapse(String JavaDoc text) { log("collapse " + text); }
15     public void insert(String JavaDoc text, int start, int end) { log("insert " + text + " " + start + " " + end); }
16     public void remove(String JavaDoc text, int start, int end) { log("remove " + text + " " + start + " " + end); }
17     public void caret(String JavaDoc text, int start, int end) { log("caret " + text + " " + start + " " + end); }
18     public void perform(String JavaDoc text) { log("perform " + text); }
19     public void tabChanged(int selected) { log("tab changed " + selected); }
20     public void menuAction(String JavaDoc text) { log("menuitem selected " + text); }
21     
22     private Thinlet thinlet;
23     private Object JavaDoc logarea;
24     
25     /**
26      * Cache thinlet and the log textarea
27      */

28     public void setLogArea(Thinlet thinlet, Object JavaDoc logarea) {
29         this.thinlet = thinlet;
30         this.logarea = logarea;
31     }
32     
33     /**
34      * Append the given text to the log textarea
35      */

36     private void log(String JavaDoc text) {
37         StringBuffer JavaDoc update = new StringBuffer JavaDoc(thinlet.getString(logarea, "text"));
38         if (update.length() > 0) { update.append('\n'); }
39         update.append(text);
40         thinlet.setString(logarea, "text", update.toString());
41         int length = update.length(); // to scroll down
42
thinlet.setInteger(logarea, "start", length);
43         thinlet.setInteger(logarea, "end", length);
44     }
45     
46     public void showLink(Thinlet thinlet) {
47         log("link pressed");
48     }
49 }
Popular Tags