source: trunk/gli/src/org/greenstone/gatherer/feedback/MyTextArea.java@ 9078

Last change on this file since 9078 was 7315, checked in by kjdon, 20 years ago

Veronika's feedback code - still needs some work, but its disabled by default

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1package org.greenstone.gatherer.feedback;
2
3import javax.swing.*;
4import javax.swing.text.*;
5import java.util.Date;
6import java.awt.Color;
7
8/**
9 * This class will allow us to changed what should be inputted to the
10 * text area as the user inputted the text to the text area.
11 * @author Veronica Liesaputra
12 */
13public class MyTextArea extends JTextArea
14{
15 /**
16 * Creating an empty JTextArea.
17 */
18 public MyTextArea ()
19 {
20 super();
21 }
22
23 /**
24 * Creating a JTextArea already appended with cols.
25 * (Precondition: (cols != null))
26 * @param cols the text to be appended.
27 */
28 public MyTextArea(String cols)
29 {
30 super(cols);
31 }
32
33 /**
34 * It will give the default model this text area should use.
35 * @return the default model this text area used.
36 */
37 protected Document createDefaultModel()
38 {
39 return new UpperCaseDocument();
40 }
41
42 /**
43 * This class will be used as the default model of MyTextArea.
44 * Here we can control and modified the string that is going to be inserted to
45 * the document.
46 */
47 static class UpperCaseDocument extends PlainDocument
48 {
49 /**
50 * This method will caused the document to be appended with the date followed by newline
51 * everytime user trying to insert a new line to the document.
52 * (Precondition : (offs >= 0) && (str != null))
53 * @param offs is the offset placted to insert the string.
54 * @param str is the string to be inserted.
55 * @param a is the attribute set to be used.
56 */
57 public void insertString(int offs, String str, AttributeSet a)
58 throws BadLocationException
59 {
60 if (str == null)
61 {
62 return;
63 }
64
65 char[] upper;
66 upper = str.toCharArray();
67
68 if (str.endsWith("\n") == true)
69 {
70 String str2;
71 str2 = str + ((new Date()).toString()) + "\n\n>";
72 upper = str2.toCharArray();
73 }
74
75 super.insertString(offs, new String(upper), a);
76 }
77 }
78}
79
80
81
82
83
Note: See TracBrowser for help on using the repository browser.