KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > client > beans > RichTextPanel


1 /*
2  * RichTextPanel.java
3  *
4  * Created on November 27, 2002, 3:03 AM
5  */

6
7 package com.quikj.client.beans;
8
9 import java.awt.*;
10
11 /**
12  *
13  * @author amit
14  */

15 public class RichTextPanel extends java.awt.Panel JavaDoc
16 {
17     /** Creates a new instance of RichTextPanel */
18     public RichTextPanel()
19     {
20         super();
21         
22         GridBagLayout gbl = new GridBagLayout();
23         GridBagConstraints gbc = new GridBagConstraints();
24         setLayout(gbl);
25         
26         scrollbar = new Scrollbar(Scrollbar.VERTICAL);
27         textArea = new RichTextCanvas(scrollbar);
28         
29         addToContainer(this,
30         gbl,
31         gbc,
32         textArea,
33         GridBagConstraints.REMAINDER,
34         GridBagConstraints.REMAINDER,
35         1,
36         1,
37         GridBagConstraints.BOTH,
38         GridBagConstraints.WEST,
39         100, 100);
40         
41         addToContainer(this,
42         gbl,
43         gbc,
44         scrollbar,
45         1,
46         GridBagConstraints.REMAINDER,
47         1,
48         1,
49         GridBagConstraints.VERTICAL,
50         GridBagConstraints.EAST,
51         0, 100);
52     }
53     
54     private void addToContainer(Container cont,
55     GridBagLayout gbl,
56     GridBagConstraints gbc,
57     Component comp,
58     int gridx,
59     int gridy,
60     int gridwidth,
61     int gridheight,
62     int fill,
63     int anchor,
64     int weightx,
65     int weighty,
66     Insets insets)
67     {
68         gbc.gridx = gridx;
69         gbc.gridy = gridy;
70         gbc.gridwidth = gridwidth;
71         gbc.gridheight = gridheight;
72         gbc.fill = fill;
73         gbc.anchor = anchor;
74         gbc.weightx = weightx;
75         gbc.weighty = weighty;
76         
77         if (insets != null)
78         {
79             gbc.insets = insets;
80         }
81         
82         gbl.setConstraints(comp, gbc);
83         cont.add(comp);
84     }
85     
86     private void addToContainer(Container cont,
87     GridBagLayout gbl,
88     GridBagConstraints gbc,
89     Component comp,
90     int gridx,
91     int gridy,
92     int gridwidth,
93     int gridheight,
94     int fill,
95     int anchor,
96     int weightx,
97     int weighty)
98     {
99         addToContainer(cont, gbl, gbc, comp, gridx, gridy, gridwidth, gridheight,
100         fill, anchor, weightx, weighty, null);
101     }
102     
103     /** Getter for property scrollbar.
104      * @return Value of property scrollbar.
105      *
106      */

107     public java.awt.Scrollbar JavaDoc getScrollbar()
108     {
109         return scrollbar;
110     }
111     
112     /** Setter for property scrollbar.
113      * @param scrollbar New value of property scrollbar.
114      *
115      */

116     public void setScrollbar(java.awt.Scrollbar JavaDoc scrollbar)
117     {
118         this.scrollbar = scrollbar;
119     }
120     
121     /** Getter for property textArea.
122      * @return Value of property textArea.
123      *
124      */

125     public com.quikj.client.beans.RichTextCanvas getTextArea()
126     {
127         return textArea;
128     }
129     
130     /** Setter for property textArea.
131      * @param textArea New value of property textArea.
132      *
133      */

134     public void setTextArea(com.quikj.client.beans.RichTextCanvas textArea)
135     {
136         this.textArea = textArea;
137     }
138     
139     public static void main (String JavaDoc[] args)
140     {
141         Frame frame = new Frame("Test Canvas");
142         ScrollPane sp = new ScrollPane();
143         RichTextPanel rtp = new RichTextPanel();
144         sp.add (rtp);
145         frame.add(sp);
146         frame.setSize(new Dimension(300, 200));
147         frame.show();
148         
149         RichTextCanvas canvas = rtp.getTextArea();
150         canvas.addText("Good morning: ", Color.red, Font.BOLD);
151         canvas.addText("This is a test. Send me a long1 long2 long3 long4 long5 long6 long7 message1 message2 message3 messsage4 message5 end",
152         null, -1);
153         canvas.addText(" TEST\n", null, Font.BOLD);
154         
155         canvas.addText("Hello friend: ", Color.red, Font.BOLD);
156         canvas.addText("This is a test", null, -1);
157         canvas.addText(" TEST1\n", null, Font.ITALIC);
158         
159         canvas.addText("Hello friend: ", Color.red, Font.BOLD);
160         canvas.addText("This is a test", null, -1);
161         canvas.addText(" TEST2\n", null, Font.ITALIC);
162         
163         canvas.addText("Hello friend: ", Color.red, Font.BOLD);
164         canvas.addText("This is a test", null, -1);
165         canvas.addText(" TEST3\n", null, Font.ITALIC);
166         
167         canvas.addText("Hello friend: ", Color.red, Font.BOLD);
168         canvas.addText("This is a test", null, -1);
169         canvas.addText(" TEST4\n", null, Font.ITALIC);
170     }
171     
172     private Scrollbar scrollbar;
173     private RichTextCanvas textArea;
174 }
175
Popular Tags