Source Code Cross Referenced for TypingPerfTest.java in  » Internationalization-Localization » icu4j » com » ibm » richtext » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Internationalization Localization » icu4j » com.ibm.richtext.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * (C) Copyright IBM Corp. 1998-2004.  All Rights Reserved.
003:         *
004:         * The program is provided "as is" without any warranty express or
005:         * implied, including the warranty of non-infringement and the implied
006:         * warranties of merchantibility and fitness for a particular purpose.
007:         * IBM will not be liable for any damages suffered by you as a result
008:         * of using the Program. In no event will IBM be liable for any
009:         * special, indirect or consequential damages or lost profits even if
010:         * IBM has been advised of the possibility of their occurrence. IBM
011:         * will not be liable for any third party claims against you.
012:         */
013:        package com.ibm.richtext.test;
014:
015:        import java.awt.Button;
016:        import java.awt.GridLayout;
017:        import java.awt.Frame;
018:
019:        import java.awt.event.ActionEvent;
020:        import java.awt.event.ActionListener;
021:        import java.awt.event.KeyEvent;
022:        import java.awt.event.WindowAdapter;
023:        import java.awt.event.WindowEvent;
024:
025:        import java.io.File;
026:        import java.io.PrintWriter;
027:        import java.io.IOException;
028:
029:        import java.text.DateFormat;
030:        import java.util.Date;
031:
032:        import com.ibm.richtext.textpanel.KeyEventForwarder;
033:        import com.ibm.richtext.textpanel.TextPanel;
034:        import com.ibm.richtext.awtui.TextFrame;
035:        import com.ibm.richtext.styledtext.MConstText;
036:
037:        import com.ibm.richtext.demo.EditDemo;
038:        import com.ibm.richtext.demo.TextDocument;
039:
040:        public class TypingPerfTest implements  ActionListener {
041:
042:            static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
043:            private TextFrame fTextFrame;
044:            private KeyEventForwarder fKeyEventForwarder;
045:            private PrintWriter fOut;
046:
047:            private static final String fgAtStartCommand = "Insert at start";
048:            private static final String fgAtEndCommand = "Insert at end";
049:            private static final String fgFwdDelete = "Forward delete";
050:            private static final String fgBackspace = "Backspace";
051:            private static final String fgAtCurrentPosCommand = "Insert at current position";
052:            private static final String fgLotsOfTextCommand = "Insert a lot of text";
053:
054:            private static final String USAGE = "Usage: java com.ibm.richtext.test.TypingPerfTest [file] [-insertionText text]";
055:            private char[] fInsText;
056:
057:            public static void main(String[] args) throws IOException {
058:
059:                // not used OutputStream outStream = null;
060:                PrintWriter writer = new PrintWriter(System.out);
061:
062:                MConstText text = Declaration.fgDeclaration;
063:                char[] insText = "The quick brown fox jumps over the lazy dog. The end. "
064:                        .toCharArray();
065:
066:                int index = 0;
067:                while (index < args.length) {
068:                    if (args[index].equals("-insertionText")) {
069:                        if (args.length == ++index) {
070:                            throw new Error(USAGE);
071:                        }
072:                        insText = args[index++].toCharArray();
073:                    } else {
074:                        // This will try MConstText first, then plain text.
075:                        TextDocument doc = EditDemo
076:                                .getDocumentFromFile(new File(args[index++]));
077:                        if (doc == null) {
078:                            throw new Error("Couldn't open file "
079:                                    + args[index - 1]);
080:                        }
081:                        text = doc.getText();
082:                    }
083:                }
084:
085:                if (index != args.length) {
086:                    throw new Error(USAGE);
087:                }
088:
089:                new TypingPerfTest(writer, text, insText);
090:            }
091:
092:            public TypingPerfTest(PrintWriter out, MConstText text,
093:                    char[] insText) throws IOException {
094:
095:                fInsText = insText;
096:                fTextFrame = new TextFrame(text, "", null);
097:                TextPanel textPanel = (TextPanel) fTextFrame.getTextPanel();
098:                fKeyEventForwarder = new KeyEventForwarder(textPanel);
099:                fOut = out;
100:
101:                DateFormat df = DateFormat.getDateTimeInstance();
102:                out.println("Test date: " + df.format(new Date()));
103:
104:                fTextFrame.setSize(500, 700);
105:                fTextFrame.show();
106:
107:                Frame f = new Frame("Typing Perf Test");
108:                f.setLayout(new GridLayout(0, 1));
109:                Button b;
110:                /*
111:                 b = new Button(fgAtStartCmd);
112:                 b.addActionListener(this);
113:                 f.add(b);
114:
115:                 b = new Button(fgAtEndCmd);
116:                 b.addActionListener(this);
117:                 f.add(b);
118:                 */
119:                b = new Button(fgAtCurrentPosCommand);
120:                b.addActionListener(this );
121:                f.add(b);
122:
123:                b = new Button(fgLotsOfTextCommand);
124:                b.addActionListener(this );
125:                f.add(b);
126:
127:                b = new Button(fgFwdDelete);
128:                b.addActionListener(this );
129:                f.add(b);
130:
131:                b = new Button(fgBackspace);
132:                b.addActionListener(this );
133:                f.add(b);
134:
135:                f.doLayout();
136:                WindowAdapter closer = new WindowAdapter() {
137:                    public void windowClosing(WindowEvent e) {
138:                        fOut.close();
139:                        System.exit(0);
140:                    }
141:                };
142:
143:                f.addWindowListener(closer);
144:                fTextFrame.addWindowListener(closer);
145:
146:                f.setSize(200, 80);
147:                f.show();
148:            }
149:
150:            public void actionPerformed(ActionEvent evt) {
151:
152:                try {
153:                    if (evt.getActionCommand().equals(fgAtCurrentPosCommand)) {
154:
155:                        insertAtCurrentPos(1);
156:                    } else if (evt.getActionCommand().equals(
157:                            fgLotsOfTextCommand)) {
158:
159:                        insertAtCurrentPos(8);
160:                    } else if (evt.getActionCommand().equals(fgFwdDelete)) {
161:
162:                        forwardDelete(1);
163:                    } else if (evt.getActionCommand().equals(fgBackspace)) {
164:
165:                        backspace(1);
166:                    }
167:                } catch (IOException e) {
168:                    System.out.println("Caught exception: " + e);
169:                }
170:            }
171:
172:            private void insertAtCurrentPos(final int times) throws IOException {
173:
174:                fTextFrame.toFront();
175:
176:                System.gc();
177:
178:                long startTime = System.currentTimeMillis();
179:
180:                for (int t = 0; t < times; t++) {
181:                    for (int i = 0; i < fInsText.length; i++) {
182:
183:                        KeyEvent event = new KeyEvent(fTextFrame,
184:                                KeyEvent.KEY_TYPED, 0, 0, 0, fInsText[i]);
185:                        fKeyEventForwarder.handleKeyEvent(event);
186:                    }
187:                }
188:
189:                long time = System.currentTimeMillis() - startTime;
190:
191:                fOut.println("Total time: " + time);
192:                fOut.println("Millis per character: "
193:                        + (time / (fInsText.length * times)));
194:                fOut.flush();
195:            }
196:
197:            private void forwardDelete(final int times) throws IOException {
198:
199:                System.gc();
200:
201:                long startTime = System.currentTimeMillis();
202:
203:                for (int t = 0; t < times; t++) {
204:                    for (int i = 0; i < fInsText.length; i++) {
205:
206:                        KeyEvent event = new KeyEvent(fTextFrame, 0, 0, 0,
207:                                KeyEvent.VK_DELETE, '\u00FF');
208:                        fKeyEventForwarder.handleKeyEvent(event);
209:                    }
210:                }
211:
212:                long time = System.currentTimeMillis() - startTime;
213:
214:                fOut.println("Total time: " + time);
215:                fOut.println("Millis per character: "
216:                        + (time / (fInsText.length * times)));
217:                fOut.flush();
218:            }
219:
220:            private void backspace(final int times) throws IOException {
221:
222:                System.gc();
223:
224:                long startTime = System.currentTimeMillis();
225:
226:                for (int t = 0; t < times; t++) {
227:                    for (int i = 0; i < fInsText.length; i++) {
228:
229:                        KeyEvent event = new KeyEvent(fTextFrame, 0, 0, 0,
230:                                KeyEvent.VK_BACK_SPACE, '\u0010');
231:                        fKeyEventForwarder.handleKeyEvent(event);
232:                    }
233:                }
234:
235:                long time = System.currentTimeMillis() - startTime;
236:
237:                fOut.println("Total time: " + time);
238:                fOut.println("Millis per character: "
239:                        + (time / (fInsText.length * times)));
240:                fOut.flush();
241:            }
242:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.