]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/richtext/test/ITestTextPanel.java
go
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / richtext / test / ITestTextPanel.java
1 /*\r
2  * (C) Copyright IBM Corp. 1998-2007.  All Rights Reserved.\r
3  *\r
4  * The program is provided "as is" without any warranty express or\r
5  * implied, including the warranty of non-infringement and the implied\r
6  * warranties of merchantibility and fitness for a particular purpose.\r
7  * IBM will not be liable for any damages suffered by you as a result\r
8  * of using the Program. In no event will IBM be liable for any\r
9  * special, indirect or consequential damages or lost profits even if\r
10  * IBM has been advised of the possibility of their occurrence. IBM\r
11  * will not be liable for any third party claims against you.\r
12  */\r
13 package com.ibm.richtext.test;\r
14 \r
15 import java.awt.Button;\r
16 import java.awt.Frame;\r
17 import java.awt.GridLayout;\r
18 import java.awt.datatransfer.Clipboard;\r
19 import java.awt.event.ActionEvent;\r
20 import java.awt.event.ActionListener;\r
21 import java.awt.event.WindowEvent;\r
22 import java.awt.event.WindowAdapter;\r
23 \r
24 import java.util.Date;\r
25 import java.text.DateFormat;\r
26 \r
27 import com.ibm.richtext.textpanel.MTextPanel;\r
28 import com.ibm.richtext.awtui.TextFrame;\r
29 \r
30 public class ITestTextPanel extends Frame implements ActionListener {\r
31 \r
32     /**\r
33      * For serialization\r
34      */\r
35     private static final long serialVersionUID = 4776220202735727574L;\r
36 \r
37     //static final String COPYRIGHT =\r
38     //            "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";\r
39     private static long fgOpCount = 0;\r
40 \r
41     private TestTextPanel fTest;\r
42     \r
43     private MTextPanel fTextPanel;\r
44     private Frame fTextFrame;\r
45     private Clipboard fClipboard;\r
46     private Button fExersize, fStressTest;\r
47 \r
48     public static void main(String[] args) {\r
49 \r
50         Date startDate = new Date();\r
51 \r
52         try {\r
53             Clipboard clipboard = new Clipboard("ITextTestPanel");\r
54             TextFrame frame = new TextFrame(null, "Interactive Test", clipboard);\r
55             MTextPanel panel = frame.getTextPanel();\r
56 \r
57             new ITestTextPanel(panel, frame, clipboard).show();\r
58         }\r
59         finally {\r
60             DateFormat df = DateFormat.getDateTimeInstance();\r
61             System.out.println("Start time: " + df.format(startDate));\r
62             System.out.println("End Time: " + df.format(new Date()));\r
63             System.out.println("Op count: " + fgOpCount);\r
64         }\r
65     }\r
66 \r
67     public ITestTextPanel(MTextPanel panel,\r
68                           Frame frame,\r
69                           Clipboard clipboard) {\r
70 \r
71         fTextPanel = panel;\r
72         fTest = new TestTextPanel(fTextPanel);\r
73         fClipboard = clipboard;\r
74 \r
75         setLayout(new GridLayout(0, 1));\r
76 \r
77         fTextFrame = frame;\r
78         fTextFrame.setSize(350, 500);\r
79         fTextFrame.show();\r
80 \r
81         // initialize UI:\r
82         fExersize = new Button("Exercise");\r
83         fExersize.addActionListener(this);\r
84         add(fExersize);\r
85 \r
86         fStressTest = new Button("Stress Test");\r
87         fStressTest.addActionListener(this);\r
88         add(fStressTest);\r
89 \r
90         pack();\r
91 \r
92         addWindowListener(new WindowAdapter() {\r
93             public void windowActivated(WindowEvent e) {\r
94                 //activateTextFrame();\r
95             }\r
96             public void windowClosing(WindowEvent e) {\r
97                 System.exit(0);\r
98             }\r
99         });\r
100 \r
101         setSize(280, 150);\r
102     }\r
103 \r
104     private void activateTextFrame() {\r
105 \r
106         fTextFrame.toFront();\r
107     }\r
108 \r
109     public void actionPerformed(ActionEvent event) {\r
110 \r
111         Object source = event.getSource();\r
112         activateTextFrame();\r
113         Date startDate = new Date();\r
114         boolean exitedNormally = false;\r
115 \r
116         try {\r
117             if (source == fExersize) {\r
118                 fTest.incRandSeed();\r
119                 for (int i=0; i < 100; i++) {\r
120                     selectOperation(fTextFrame, fClipboard);\r
121                 }\r
122             }\r
123             else if (source == fStressTest) {\r
124                 fTest.incRandSeed();\r
125                 while (true) {\r
126                     selectOperation(fTextFrame, fClipboard);\r
127                 }\r
128             }\r
129             exitedNormally = true;\r
130         }\r
131         finally {\r
132             if (!exitedNormally) {\r
133                 DateFormat df = DateFormat.getDateTimeInstance();\r
134                 System.out.println("Start time: " + df.format(startDate));\r
135                 System.out.println("End Time: " + df.format(new Date()));\r
136                 System.out.println("Rand seed: " + fTest.getRandSeed());\r
137                 System.out.println("Op count: " + fgOpCount);\r
138             }\r
139         }\r
140     }\r
141 \r
142     /**\r
143      * Perform a random operation on the MTextPanel.  Frame can\r
144      * be null.\r
145      */\r
146     private static final int OP_COUNT = 15;\r
147 \r
148     public void selectOperation(Frame frame,\r
149                                 Clipboard clipboard) {\r
150 \r
151         int op = fTest.randInt(OP_COUNT);\r
152 \r
153         switch (op) {\r
154 \r
155             case 0:\r
156                 fTest._testSetSelection();\r
157                 break;\r
158 \r
159             case 1:\r
160                 fTest._testModifications(TestTextPanel.MOD_TEXT,\r
161                                         true);\r
162                 break;\r
163 \r
164             case 2:\r
165                 fTest._testEditMenuOperations(clipboard);\r
166                 break;\r
167 \r
168             case 3:\r
169                 fTest._testModFlag(fTextPanel.getCommandLogSize());\r
170                 break;\r
171 \r
172             case 4:\r
173                 fTest.applyCharacterStyle();\r
174                 break;\r
175 \r
176             case 5:\r
177                 fTest.applyParagraphStyle();\r
178                 break;\r
179 \r
180             case 6:\r
181             case 7:\r
182             case 8:\r
183             case 9:\r
184                 fTest.typeKeys();\r
185                 break;\r
186 \r
187             case 10:\r
188                 fTest.selectText();\r
189                 break;\r
190 \r
191             case 11:\r
192                 fTest.undoRedo();\r
193                 break;\r
194 \r
195             case 12:\r
196                 //if (frame != null) {\r
197                 //    fTest.resizeFrame(frame);\r
198                 //    break;\r
199                 //}\r
200 \r
201             case 13:\r
202                 fTest.applyKeyRemap();\r
203                 break;\r
204 \r
205             case 14:\r
206                 fTest._testCommandLogControl();\r
207                 break;\r
208 \r
209             default:\r
210                 throw new Error("OP_COUNT is incorrect");\r
211         }\r
212         fgOpCount++;\r
213     }\r
214 \r
215 \r
216 }\r