Source Code Cross Referenced for DefaultEditorKit_Actions_MultithreadedTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » text » 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 » Apache Harmony Java SE » javax package » javax.swing.text 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
0003:         *  contributor license agreements.  See the NOTICE file distributed with
0004:         *  this work for additional information regarding copyright ownership.
0005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
0006:         *  (the "License"); you may not use this file except in compliance with
0007:         *  the License.  You may obtain a copy of the License at
0008:         *
0009:         *     http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         *  Unless required by applicable law or agreed to in writing, software
0012:         *  distributed under the License is distributed on an "AS IS" BASIS,
0013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         *  See the License for the specific language governing permissions and
0015:         *  limitations under the License.
0016:         */
0017:        /**
0018:         * @author Alexander T. Simbirtsev
0019:         * @version $Revision$
0020:         * Created on 05.03.2005
0021:
0022:         */package javax.swing.text;
0023:
0024:        import java.awt.Dimension;
0025:        import java.awt.Font;
0026:        import java.awt.FontMetrics;
0027:        import java.awt.HeadlessException;
0028:        import java.awt.Point;
0029:        import java.awt.Toolkit;
0030:        import java.awt.datatransfer.Clipboard;
0031:        import java.awt.datatransfer.DataFlavor;
0032:        import java.awt.datatransfer.StringSelection;
0033:        import java.awt.datatransfer.UnsupportedFlavorException;
0034:        import java.awt.event.ActionEvent;
0035:        import java.io.ByteArrayOutputStream;
0036:        import java.io.IOException;
0037:        import java.io.PrintStream;
0038:        import java.lang.reflect.InvocationTargetException;
0039:        import java.util.HashSet;
0040:        import javax.swing.Action;
0041:        import javax.swing.BasicSwingTestCase;
0042:        import javax.swing.JComponent;
0043:        import javax.swing.JFrame;
0044:        import javax.swing.JPanel;
0045:        import javax.swing.JScrollPane;
0046:        import javax.swing.JTextArea;
0047:        import javax.swing.JViewport;
0048:        import javax.swing.ScrollPaneConstants;
0049:        import javax.swing.SwingUtilities;
0050:
0051:        public class DefaultEditorKit_Actions_MultithreadedTest extends
0052:                BasicSwingTestCase {
0053:            protected DefaultEditorKit kit = null;
0054:
0055:            protected JFrame frame;
0056:
0057:            @Override
0058:            protected void setUp() throws Exception {
0059:                super .setUp();
0060:                kit = new DefaultEditorKit();
0061:            }
0062:
0063:            @Override
0064:            protected void tearDown() throws Exception {
0065:                kit = null;
0066:                if (frame != null) {
0067:                    frame.dispose();
0068:                    frame = null;
0069:                }
0070:                super .tearDown();
0071:            }
0072:
0073:            protected Action getAction(final String actionName) {
0074:                Action[] actions = kit.getActions();
0075:                for (int i = 0; i < actions.length; i++) {
0076:                    if (actionName.equals(actions[i].getValue(Action.NAME))) {
0077:                        return actions[i];
0078:                    }
0079:                }
0080:                return null;
0081:            }
0082:
0083:            protected void performAction(final Object source,
0084:                    final Action action, final String command)
0085:                    throws InterruptedException, InvocationTargetException {
0086:                final ActionEvent actionEvent = new ActionEvent(source,
0087:                        ActionEvent.ACTION_PERFORMED, command);
0088:                SwingUtilities.invokeAndWait(new Runnable() {
0089:                    public void run() {
0090:                        action.actionPerformed(actionEvent);
0091:                    }
0092:                });
0093:            }
0094:
0095:            protected void putStringToClipboard(final String str)
0096:                    throws InterruptedException, InvocationTargetException {
0097:                SwingUtilities.invokeAndWait(new Runnable() {
0098:                    public void run() {
0099:                        final Clipboard systemClipboard = Toolkit
0100:                                .getDefaultToolkit().getSystemClipboard();
0101:                        if (systemClipboard == null) {
0102:                            fail("unable to get systemClipboard");
0103:                        }
0104:                        systemClipboard.setContents(new StringSelection(str),
0105:                                null);
0106:                    }
0107:                });
0108:            }
0109:
0110:            protected String getStringFromClipboard()
0111:                    throws InterruptedException, InvocationTargetException {
0112:                class ResultableThread implements  Runnable {
0113:                    public String result;
0114:
0115:                    public void run() {
0116:                        try {
0117:                            final Clipboard systemClipboard = Toolkit
0118:                                    .getDefaultToolkit().getSystemClipboard();
0119:                            if (systemClipboard == null) {
0120:                                fail("unable to get systemClipboard");
0121:                            }
0122:                            result = (String) systemClipboard.getContents(null)
0123:                                    .getTransferData(DataFlavor.stringFlavor);
0124:                        } catch (HeadlessException e) {
0125:                            fail(e.getMessage());
0126:                        } catch (UnsupportedFlavorException e) {
0127:                            fail(e.getMessage());
0128:                        } catch (IOException e) {
0129:                            fail(e.getMessage());
0130:                        }
0131:                    }
0132:                }
0133:                ;
0134:                ResultableThread thread = new ResultableThread();
0135:                SwingUtilities.invokeAndWait(thread);
0136:                return thread.result;
0137:            }
0138:
0139:            protected void performAction(final Object source,
0140:                    final Action action) throws InterruptedException,
0141:                    InvocationTargetException {
0142:                performAction(source, action, "command");
0143:            }
0144:
0145:            private JTextArea initComponent(final JTextArea c,
0146:                    final int startPos, final int endPos, final String text)
0147:                    throws Exception {
0148:                if (frame != null) {
0149:                    frame.dispose();
0150:                }
0151:                c.setText(text);
0152:                frame = new JFrame();
0153:                JScrollPane scroll = new JScrollPane(c);
0154:                ((JViewport) c.getParent())
0155:                        .setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
0156:                int strHeight = c.getFontMetrics(c.getFont()).getHeight();
0157:                scroll.setPreferredSize(new Dimension(300, strHeight * 5));
0158:                scroll
0159:                        .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
0160:                frame.getContentPane().add(scroll);
0161:                frame.pack();
0162:                if (!isHarmony()) {
0163:                    frame.setVisible(true);
0164:                    waitForIdle();
0165:                }
0166:                java.awt.EventQueue.invokeAndWait(new Runnable() {
0167:                    public void run() {
0168:                        c.setCaretPosition(startPos);
0169:                        if (endPos >= 0) {
0170:                            c.moveCaretPosition(endPos);
0171:                        }
0172:                    }
0173:                });
0174:                return c;
0175:            }
0176:
0177:            protected JTextArea getInitedComponent(final int startPos,
0178:                    final int endPos, final String text) throws Exception {
0179:                JTextArea c = createTextArea();
0180:                return initComponent(c, startPos, endPos, text);
0181:            }
0182:
0183:            protected JTextArea getInitedComponent(final int caretPos,
0184:                    final String text) throws Exception {
0185:                JTextArea c = createTextArea();
0186:                return initComponent(c, caretPos, -1, text);
0187:            }
0188:
0189:            private JTextArea createTextArea() {
0190:                return new JTextArea() {
0191:                    private static final long serialVersionUID = 1L;
0192:
0193:                    @Override
0194:                    public FontMetrics getFontMetrics(final Font f) {
0195:                        return DefaultEditorKit_Actions_MultithreadedTest.this 
0196:                                .getFontMetrics(f, 6);
0197:                    };
0198:                };
0199:            }
0200:
0201:            public void testUnselectActionPerformed() throws Exception {
0202:                String text = "012345  6789\nasfd\nasd  asd";
0203:                Action action = getAction(DefaultEditorKit.unselectAction);
0204:                JTextArea c = getInitedComponent(10, 15, text);
0205:                assertEquals("selected text ", "89\nas", c.getSelectedText());
0206:                performAction(c, action);
0207:                assertNull("selected text ", c.getSelectedText());
0208:            }
0209:
0210:            public void testToggleComponentOrientationPerformed()
0211:                    throws Exception {
0212:                String text = "012345  6789\nasfd\nasd  asd";
0213:                Action action = getAction(DefaultEditorKit.toggleComponentOrientationAction);
0214:                JTextArea c = getInitedComponent(10, 15, text);
0215:                assertTrue("component is horizontal", c
0216:                        .getComponentOrientation().isHorizontal());
0217:                assertTrue("component is LR", c.getComponentOrientation()
0218:                        .isLeftToRight());
0219:                performAction(c, action);
0220:                assertTrue("component is horizontal", c
0221:                        .getComponentOrientation().isHorizontal());
0222:                assertFalse("component is RL", c.getComponentOrientation()
0223:                        .isLeftToRight());
0224:            }
0225:
0226:            public void testDumpModelActionPerformed() throws Exception {
0227:                ByteArrayOutputStream out = new ByteArrayOutputStream();
0228:                PrintStream oldErr = System.err;
0229:                System.setErr(new PrintStream(out));
0230:                try {
0231:                    String text = "012345  6789\nasfd\nasd  asd";
0232:                    Action action = getAction("dump-model");
0233:                    JTextArea c = getInitedComponent(10, 15, text);
0234:                    performAction(c, action);
0235:                    assertEquals("<paragraph>\n" + "  <content>\n"
0236:                            + "    [0,13][012345  6789\n" + "]\n"
0237:                            + "  <content>\n" + "    [13,18][asfd\n" + "]\n"
0238:                            + "  <content>\n" + "    [18,27][asd  asd\n"
0239:                            + "]\n" + "<bidi root>\n" + "  <bidi level\n"
0240:                            + "    bidiLevel=0\n" + "  >\n"
0241:                            + "    [0,27][012345  6789\n" + "asfd\n"
0242:                            + "asd  asd\n" + "]\n", AbstractDocumentTest
0243:                            .filterNewLines(out.toString()));
0244:                } finally {
0245:                    System.setErr(oldErr);
0246:                }
0247:            }
0248:
0249:            public void testPageActionPerformed() throws Exception {
0250:                String text = "01\n23\n45\n677777777777777777777777777777777777777777777777777\n89\n0-\nqwe\nrty\nasd\n\n\n\n\nzxc\nvbn";
0251:                Action action = getAction("selection-page-right");
0252:                JTextArea c = getInitedComponent(3, 7, text);
0253:                performAction(c, action);
0254:                assertEquals(
0255:                        "selected string",
0256:                        "23\n45\n677777777777777777777777777777777777777777777777777\n89",
0257:                        c.getSelectedText());
0258:                assertEquals("caret position", 63, c.getCaretPosition());
0259:                performAction(c, action);
0260:                assertEquals(
0261:                        "selected string",
0262:                        "23\n45\n677777777777777777777777777777777777777777777777777\n89",
0263:                        c.getSelectedText());
0264:                assertEquals("caret position", 63, c.getCaretPosition());
0265:                action = getAction("selection-page-left");
0266:                c = getInitedComponent(60, text);
0267:                performAction(c, action);
0268:                assertEquals(
0269:                        "selected string",
0270:                        "01\n23\n45\n677777777777777777777777777777777777777777777777777",
0271:                        c.getSelectedText());
0272:                assertEquals("caret position", 0, c.getCaretPosition());
0273:                c = getInitedComponent(10, text);
0274:                performAction(c, action);
0275:                assertEquals("selected string", "01\n23\n45\n6", c
0276:                        .getSelectedText());
0277:                assertEquals("caret position", 0, c.getCaretPosition());
0278:                performAction(c, action);
0279:                assertEquals("selected string", "01\n23\n45\n6", c
0280:                        .getSelectedText());
0281:                assertEquals("caret position", 0, c.getCaretPosition());
0282:            }
0283:
0284:            public void testVerticalPageActionPerformed() throws Exception {
0285:                String text = "111111111111111\n2\n3\n44444444\n55555555555\n6\n7\n8\n9\n0\n1\n2\n3\n4\n5555555555555555555";
0286:                Action action = getAction(DefaultEditorKit.pageDownAction);
0287:                JTextArea c = getInitedComponent(4, 6, text);
0288:                performAction(c, action, null);
0289:                assertNull("selected string", c.getSelectedText());
0290:                assertEquals("caret position", 35, c.getCaretPosition());
0291:                performAction(c, action, null);
0292:                assertNull("selected string", c.getSelectedText());
0293:                assertEquals("caret position", 48, c.getCaretPosition());
0294:                performAction(c, action, null);
0295:                assertNull("selected string", c.getSelectedText());
0296:                assertEquals("caret position", 56, c.getCaretPosition());
0297:                performAction(c, action, null);
0298:                assertNull("selected string", c.getSelectedText());
0299:                assertEquals("caret position", 78, c.getCaretPosition());
0300:                action = getAction(DefaultEditorKit.pageUpAction);
0301:                performAction(c, action, null);
0302:                assertNull("selected string", c.getSelectedText());
0303:                assertEquals("caret position", 50, c.getCaretPosition());
0304:                performAction(c, action, null);
0305:                assertNull("selected string", c.getSelectedText());
0306:                assertEquals("caret position", 35, c.getCaretPosition());
0307:                action = getAction(DefaultEditorKit.pageUpAction);
0308:                performAction(c, action, null);
0309:                assertNull("selected string", c.getSelectedText());
0310:                assertEquals("caret position", 6, c.getCaretPosition());
0311:                action = getAction(DefaultEditorKit.pageUpAction);
0312:                performAction(c, action, null);
0313:                assertNull("selected string", c.getSelectedText());
0314:                assertEquals("caret position", 6, c.getCaretPosition());
0315:                action = getAction(DefaultEditorKit.pageDownAction);
0316:                performAction(c, action, null);
0317:                assertNull("selected string", c.getSelectedText());
0318:                assertEquals("caret position", 35, c.getCaretPosition());
0319:                action = getAction(DefaultEditorKit.pageUpAction);
0320:                c = getInitedComponent(0, text);
0321:                performAction(c, action, null);
0322:                assertNull("selected string", c.getSelectedText());
0323:                assertEquals("caret position", 0, c.getCaretPosition());
0324:                action = getAction(DefaultEditorKit.selectionPageDownAction);
0325:                c = getInitedComponent(3, 7, text);
0326:                performAction(c, action);
0327:                assertEquals("selected string",
0328:                        "111111111111\n2\n3\n44444444\n5555555", c
0329:                                .getSelectedText());
0330:                assertEquals("caret position", 36, c.getCaretPosition());
0331:                performAction(c, action);
0332:                assertEquals(
0333:                        "selected string",
0334:                        "111111111111\n2\n3\n44444444\n55555555555\n6\n7\n8\n9",
0335:                        c.getSelectedText());
0336:                assertEquals("caret position", 48, c.getCaretPosition());
0337:                action = getAction(DefaultEditorKit.selectionPageUpAction);
0338:                c = getInitedComponent(19, text);
0339:                performAction(c, action);
0340:                assertEquals("selected string", "11111111111111\n2\n3", c
0341:                        .getSelectedText());
0342:                assertEquals("caret position", 1, c.getCaretPosition());
0343:                c = getInitedComponent(10, text);
0344:                performAction(c, action);
0345:                assertNull("selected string", c.getSelectedText());
0346:                assertEquals("caret position", 10, c.getCaretPosition());
0347:            }
0348:
0349:            public void testWritableActionPerformed() throws Exception {
0350:                String text = "012345  6789\nasfd\nasd  asd";
0351:                Action action = getAction(DefaultEditorKit.writableAction);
0352:                JTextArea c = getInitedComponent(13, 15, text);
0353:                c.setEditable(false);
0354:                assertFalse("component is now read-only ", c.isEditable());
0355:                performAction(c, action);
0356:                assertTrue("component is now writable ", c.isEditable());
0357:            }
0358:
0359:            public void testReadOnlyActionPerformed() throws Exception {
0360:                String text = "012345  6789\nasfd\nasd  asd";
0361:                Action action = getAction(DefaultEditorKit.readOnlyAction);
0362:                JTextArea c = getInitedComponent(13, 15, text);
0363:                assertTrue("component is now writable ", c.isEditable());
0364:                performAction(c, action);
0365:                assertFalse("component is now read-only ", c.isEditable());
0366:            }
0367:
0368:            public void testEndParagraphActionPerformed() throws Exception {
0369:                String text = "\t012345  6789\nasfd\n\n\tasd  asd";
0370:                Action action = getAction(DefaultEditorKit.endParagraphAction);
0371:                JTextArea c = getInitedComponent(6, text);
0372:                performAction(c, action);
0373:                assertNull("selected string", c.getSelectedText());
0374:                assertEquals("caret position", 14, c.getCaretPosition());
0375:                c = getInitedComponent(16, text);
0376:                performAction(c, action);
0377:                assertNull("resulted string", c.getSelectedText());
0378:                assertEquals("caret position", 19, c.getCaretPosition());
0379:                action = getAction(DefaultEditorKit.selectionEndParagraphAction);
0380:                c = getInitedComponent(6, text);
0381:                performAction(c, action);
0382:                assertEquals("selected string", "5  6789\n", c
0383:                        .getSelectedText());
0384:                assertEquals("caret position", 14, c.getCaretPosition());
0385:                c = getInitedComponent(16, text);
0386:                performAction(c, action);
0387:                assertEquals("resulted string", "fd\n", c.getSelectedText());
0388:                assertEquals("caret position", 19, c.getCaretPosition());
0389:                c = getInitedComponent(0, null);
0390:                performAction(c, action);
0391:                assertNull("resulted string", c.getSelectedText());
0392:            }
0393:
0394:            public void testBeginParagraphActionPerformed() throws Exception {
0395:                String text = "\t012345  6789\nasfd\n\n\tasd  asd";
0396:                Action action = getAction(DefaultEditorKit.beginParagraphAction);
0397:                JTextArea c = getInitedComponent(6, text);
0398:                performAction(c, action);
0399:                assertNull("selected string", c.getSelectedText());
0400:                assertEquals("caret position", 0, c.getCaretPosition());
0401:                c = getInitedComponent(16, text);
0402:                performAction(c, action);
0403:                assertNull("resulted string", c.getSelectedText());
0404:                assertEquals("caret position", 14, c.getCaretPosition());
0405:                action = getAction(DefaultEditorKit.selectionBeginParagraphAction);
0406:                c = getInitedComponent(6, text);
0407:                performAction(c, action);
0408:                assertEquals("selected string", "\t01234", c.getSelectedText());
0409:                assertEquals("caret position", 0, c.getCaretPosition());
0410:                c = getInitedComponent(16, text);
0411:                performAction(c, action);
0412:                assertEquals("resulted string", "as", c.getSelectedText());
0413:                assertEquals("caret position", 14, c.getCaretPosition());
0414:                c = getInitedComponent(0, null);
0415:                performAction(c, action);
0416:                assertNull("resulted string", c.getSelectedText());
0417:            }
0418:
0419:            public void testBeginWordActionPerformed() throws Exception {
0420:                String text = "012345  6789\nasfd\nasd  asd";
0421:                Action action = getAction(DefaultEditorKit.beginWordAction);
0422:                JTextArea c = getInitedComponent(13, 15, text);
0423:                performAction(c, action);
0424:                assertNull("selected string", c.getSelectedText());
0425:                assertEquals("caret position", 13, c.getCaretPosition());
0426:                c = getInitedComponent(1, text);
0427:                performAction(c, action);
0428:                assertNull("selected string", c.getSelectedText());
0429:                assertEquals("caret position", 0, c.getCaretPosition());
0430:                c = getInitedComponent(0, text);
0431:                performAction(c, action);
0432:                assertNull("selected string", c.getSelectedText());
0433:                assertEquals("caret position", 0, c.getCaretPosition());
0434:                action = getAction(DefaultEditorKit.selectionBeginWordAction);
0435:                c = getInitedComponent(13, 17, text);
0436:                performAction(c, action);
0437:                assertEquals("selected string", "asfd", c.getSelectedText());
0438:                assertEquals("caret position", 17, c.getCaretPosition());
0439:                c = getInitedComponent(15, 17, text);
0440:                performAction(c, action);
0441:                assertEquals("selected string", "fd", c.getSelectedText());
0442:                assertEquals("caret position", 17, c.getCaretPosition());
0443:                c = getInitedComponent(2, 1, text);
0444:                performAction(c, action);
0445:                assertEquals("selected string", "01", c.getSelectedText());
0446:                assertEquals("caret position", 0, c.getCaretPosition());
0447:                c = getInitedComponent(0, text);
0448:                performAction(c, action);
0449:                assertNull("selected string", c.getSelectedText());
0450:                assertEquals("caret position", 0, c.getCaretPosition());
0451:            }
0452:
0453:            public void testEndWordActionPerformed() throws Exception {
0454:                String text = "012345  6789\nasfd\nasd  asd";
0455:                Action action = getAction(DefaultEditorKit.endWordAction);
0456:                JTextArea c = getInitedComponent(13, 15, text);
0457:                performAction(c, action);
0458:                assertNull("selected string", c.getSelectedText());
0459:                assertEquals("caret position", 17, c.getCaretPosition());
0460:                c = getInitedComponent(25, text);
0461:                performAction(c, action);
0462:                assertNull("selected string", c.getSelectedText());
0463:                assertEquals("caret position", 26, c.getCaretPosition());
0464:                c = getInitedComponent(26, text);
0465:                performAction(c, action);
0466:                assertNull("selected string", c.getSelectedText());
0467:                assertEquals("caret position", 26, c.getCaretPosition());
0468:                action = getAction(DefaultEditorKit.selectionEndWordAction);
0469:                c = getInitedComponent(14, 16, text);
0470:                performAction(c, action);
0471:                assertEquals("selected string", "sfd", c.getSelectedText());
0472:                assertEquals("caret position", 17, c.getCaretPosition());
0473:                c = getInitedComponent(24, 25, text);
0474:                performAction(c, action);
0475:                assertEquals("selected string", "sd", c.getSelectedText());
0476:                assertEquals("caret position", 26, c.getCaretPosition());
0477:                c = getInitedComponent(26, text);
0478:                performAction(c, action);
0479:                assertNull("selected string", c.getSelectedText());
0480:                assertEquals("caret position", 26, c.getCaretPosition());
0481:            }
0482:
0483:            public void testPreviousWordActionPerformed() throws Exception {
0484:                String text = "012345  6789\nasfd\nasd  asd";
0485:                Action action = getAction(DefaultEditorKit.previousWordAction);
0486:                JTextArea c = getInitedComponent(13, 15, text);
0487:                performAction(c, action);
0488:                assertNull("selected string", c.getSelectedText());
0489:                assertEquals("caret position", 13, c.getCaretPosition());
0490:                c = getInitedComponent(1, text);
0491:                performAction(c, action);
0492:                assertNull("selected string", c.getSelectedText());
0493:                assertEquals("caret position", 0, c.getCaretPosition());
0494:                c = getInitedComponent(0, text);
0495:                performAction(c, action);
0496:                assertNull("selected string", c.getSelectedText());
0497:                assertEquals("caret position", 0, c.getCaretPosition());
0498:                action = getAction(DefaultEditorKit.selectionPreviousWordAction);
0499:                c = getInitedComponent(13, 17, text);
0500:                performAction(c, action);
0501:                assertNull("selected string", c.getSelectedText());
0502:                assertEquals("caret position", 13, c.getCaretPosition());
0503:                c = getInitedComponent(15, 17, text);
0504:                performAction(c, action);
0505:                assertEquals("selected string", "as", c.getSelectedText());
0506:                assertEquals("caret position", 13, c.getCaretPosition());
0507:                c = getInitedComponent(2, 1, text);
0508:                performAction(c, action);
0509:                assertEquals("selected string", "01", c.getSelectedText());
0510:                assertEquals("caret position", 0, c.getCaretPosition());
0511:                c = getInitedComponent(0, text);
0512:                performAction(c, action);
0513:                assertNull("selected string", c.getSelectedText());
0514:                assertEquals("caret position", 0, c.getCaretPosition());
0515:            }
0516:
0517:            public void testNextWordActionPerformed() throws Exception {
0518:                String text = "012345  6789\nasfd\nasd  asd";
0519:                Action action = getAction(DefaultEditorKit.nextWordAction);
0520:                JTextArea c = getInitedComponent(13, 15, text);
0521:                performAction(c, action);
0522:                assertNull("selected string", c.getSelectedText());
0523:                assertEquals("caret position", 18, c.getCaretPosition());
0524:                c = getInitedComponent(25, text);
0525:                performAction(c, action);
0526:                assertNull("selected string", c.getSelectedText());
0527:                assertEquals("caret position", 26, c.getCaretPosition());
0528:                c = getInitedComponent(26, text);
0529:                performAction(c, action);
0530:                assertNull("selected string", c.getSelectedText());
0531:                assertEquals("caret position", 26, c.getCaretPosition());
0532:                action = getAction(DefaultEditorKit.selectionNextWordAction);
0533:                c = getInitedComponent(14, 16, text);
0534:                performAction(c, action);
0535:                assertEquals("selected string", "sfd\n", c.getSelectedText());
0536:                assertEquals("caret position", 18, c.getCaretPosition());
0537:                c = getInitedComponent(24, 25, text);
0538:                performAction(c, action);
0539:                assertEquals("selected string", "sd", c.getSelectedText());
0540:                assertEquals("caret position", 26, c.getCaretPosition());
0541:                c = getInitedComponent(26, text);
0542:                performAction(c, action);
0543:                assertNull("selected string", c.getSelectedText());
0544:                assertEquals("caret position", 26, c.getCaretPosition());
0545:            }
0546:
0547:            public void testBeginLineActionPerformed() throws Exception {
0548:                Action action = getAction(DefaultEditorKit.beginLineAction);
0549:                String text = "0123456789\n12341234\n12341234";
0550:                JTextArea c = getInitedComponent(14, text);
0551:                performAction(c, action);
0552:                assertNull("selected string", c.getSelectedText());
0553:                assertEquals("caret position", 11, c.getCaretPosition());
0554:                c = getInitedComponent(8, text);
0555:                performAction(c, action);
0556:                assertNull("selected string", c.getSelectedText());
0557:                assertEquals("caret position", 0, c.getCaretPosition());
0558:                action = getAction(DefaultEditorKit.selectionBeginLineAction);
0559:                c = getInitedComponent(8, 3, text);
0560:                performAction(c, action);
0561:                assertEquals("selected string", "01234567", c.getSelectedText());
0562:                assertEquals("caret position", 0, c.getCaretPosition());
0563:                c = getInitedComponent(0, null);
0564:                performAction(c, action);
0565:                assertNull("selected string", c.getSelectedText());
0566:                assertEquals("caret position", 0, c.getCaretPosition());
0567:            }
0568:
0569:            public void testEndLineActionPerformed() throws Exception {
0570:                Action action = getAction(DefaultEditorKit.endLineAction);
0571:                String text = "0123456789\n12341234\n12341234";
0572:                JTextArea c = getInitedComponent(14, text);
0573:                performAction(c, action);
0574:                assertNull("selected string", c.getSelectedText());
0575:                assertEquals("caret position", 19, c.getCaretPosition());
0576:                c = getInitedComponent(10, text);
0577:                performAction(c, action);
0578:                assertNull("selected string", c.getSelectedText());
0579:                assertEquals("caret position", 10, c.getCaretPosition());
0580:                action = getAction(DefaultEditorKit.selectionEndLineAction);
0581:                c = getInitedComponent(3, 8, text);
0582:                performAction(c, action);
0583:                assertEquals("selected string", "3456789", c.getSelectedText());
0584:                assertEquals("caret position", 10, c.getCaretPosition());
0585:                c = getInitedComponent(0, null);
0586:                performAction(c, action);
0587:                assertNull("selected string", c.getSelectedText());
0588:                assertEquals("caret position", 0, c.getCaretPosition());
0589:            }
0590:
0591:            public void testEndActionPerformed() throws Exception {
0592:                Action action = getAction(DefaultEditorKit.endAction);
0593:                String text = "0123456789\n12341234\n12341234";
0594:                JTextArea c = getInitedComponent(8, 14, text);
0595:                performAction(c, action);
0596:                assertNull("selected string", c.getSelectedText());
0597:                assertEquals("caret position", 28, c.getCaretPosition());
0598:                c = getInitedComponent(0, null);
0599:                performAction(c, action);
0600:                assertNull("selected string", c.getSelectedText());
0601:                assertEquals("caret position", 0, c.getCaretPosition());
0602:                action = getAction(DefaultEditorKit.selectionEndAction);
0603:                c = getInitedComponent(12, 14, text);
0604:                performAction(c, action);
0605:                assertEquals("selected string", "2341234\n12341234", c
0606:                        .getSelectedText());
0607:                assertEquals("caret position", 28, c.getCaretPosition());
0608:                c = getInitedComponent(0, null);
0609:                performAction(c, action);
0610:                assertNull("selected string", c.getSelectedText());
0611:                assertEquals("caret position", 0, c.getCaretPosition());
0612:            }
0613:
0614:            public void testBeginActionPerformed() throws Exception {
0615:                Action action = getAction(DefaultEditorKit.beginAction);
0616:                String text = "0123456789\n12341234\n12341234";
0617:                JTextArea c = getInitedComponent(8, 14, text);
0618:                performAction(c, action);
0619:                assertNull("selected string", c.getSelectedText());
0620:                assertEquals("caret position", 0, c.getCaretPosition());
0621:                c = getInitedComponent(0, null);
0622:                performAction(c, action);
0623:                assertNull("selected string", c.getSelectedText());
0624:                assertEquals("caret position", 0, c.getCaretPosition());
0625:                action = getAction(DefaultEditorKit.selectionBeginAction);
0626:                c = getInitedComponent(16, 14, text);
0627:                performAction(c, action);
0628:                assertEquals("selected string", "0123456789\n12341", c
0629:                        .getSelectedText());
0630:                assertEquals("caret position", 0, c.getCaretPosition());
0631:                c = getInitedComponent(0, null);
0632:                performAction(c, action);
0633:                assertNull("selected string", c.getSelectedText());
0634:                assertEquals("caret position", 0, c.getCaretPosition());
0635:            }
0636:
0637:            public void testSelectWordActionPerformed() throws Exception {
0638:                String text = "012345  6789\nasfd\nasd  asd";
0639:                Action action = getAction(DefaultEditorKit.selectWordAction);
0640:                JTextArea c = getInitedComponent(15, text);
0641:                performAction(c, action);
0642:                assertEquals("resulted string", "asfd", c.getSelectedText());
0643:                c = getInitedComponent(9, text);
0644:                performAction(c, action);
0645:                assertEquals("resulted string", "6789", c.getSelectedText());
0646:                c = getInitedComponent(7, text);
0647:                performAction(c, action);
0648:                assertEquals("resulted string", "  ", c.getSelectedText());
0649:                c = getInitedComponent(0, null);
0650:                performAction(c, action);
0651:                assertNull("resulted string", c.getSelectedText());
0652:            }
0653:
0654:            public void testSelectLineActionPerformed() throws Exception {
0655:                String text = "0123  456789\nasdf";
0656:                Action action = getAction(DefaultEditorKit.selectLineAction);
0657:                JTextArea c = getInitedComponent(5, text);
0658:                performAction(c, action);
0659:                assertEquals("resulted string", "0123  456789", c
0660:                        .getSelectedText());
0661:                c = getInitedComponent(14, text);
0662:                performAction(c, action);
0663:                assertEquals("resulted string", "asdf", c.getSelectedText());
0664:                c = getInitedComponent(0, null);
0665:                performAction(c, action);
0666:                assertNull("resulted string", c.getSelectedText());
0667:            }
0668:
0669:            public void testSelectParagraphActionPerformed() throws Exception {
0670:                String text = "\t012345  6789\nasfd\n\n\tasd  asd";
0671:                Action action = getAction(DefaultEditorKit.selectParagraphAction);
0672:                JTextArea c = getInitedComponent(6, text);
0673:                performAction(c, action);
0674:                String res = "\t012345  6789" + "\n";
0675:                assertEquals("resulted string", res, c.getSelectedText());
0676:                c = getInitedComponent(15, text);
0677:                performAction(c, action);
0678:                res = "asfd" + "\n";
0679:                assertEquals("resulted string", res, c.getSelectedText());
0680:                c = getInitedComponent(20, text);
0681:                performAction(c, action);
0682:                res = "\tasd  asd";
0683:                assertEquals("resulted string", res, c.getSelectedText());
0684:                c = getInitedComponent(0, null);
0685:                performAction(c, action);
0686:                assertNull("resulted string", c.getSelectedText());
0687:            }
0688:
0689:            public void testSelectAllActionPerformed() throws Exception {
0690:                String text = "0123456789\nasdasd";
0691:                Action action = getAction(DefaultEditorKit.selectAllAction);
0692:                JTextArea c = getInitedComponent(2, 7, text);
0693:                performAction(c, action);
0694:                assertEquals("resulted string", text, c.getSelectedText());
0695:                c = getInitedComponent(0, null);
0696:                performAction(c, action);
0697:                assertNull("resulted string", c.getSelectedText());
0698:            }
0699:
0700:            public void testDeleteNextCharActionPerformed() throws Exception {
0701:                Action action = getAction(DefaultEditorKit.deleteNextCharAction);
0702:                JTextArea c = getInitedComponent(2, 7, "0123456789");
0703:                performAction(c, action);
0704:                assertEquals("resulted string", "01789", c.getText());
0705:                c = getInitedComponent(3, "0123456789");
0706:                performAction(c, action);
0707:                assertEquals("resulted string", "012456789", c.getText());
0708:                c = getInitedComponent(10, "0123456789");
0709:                performAction(c, action);
0710:                assertEquals("resulted string", "0123456789", c.getText());
0711:                c = getInitedComponent(2, 10, "0123456789");
0712:                performAction(c, action);
0713:                assertEquals("resulted string", "01", c.getText());
0714:            }
0715:
0716:            public void testDeletePrevCharActionPerformed() throws Exception {
0717:                Action action = getAction(DefaultEditorKit.deletePrevCharAction);
0718:                JTextArea c = getInitedComponent(2, 7, "0123456789");
0719:                performAction(c, action);
0720:                assertEquals("resulted string", "01789", c.getText());
0721:                c = getInitedComponent(3, "0123456789");
0722:                performAction(c, action);
0723:                assertEquals("resulted string", "013456789", c.getText());
0724:                c = getInitedComponent(0, "0123456789");
0725:                performAction(c, action);
0726:                assertEquals("resulted string", "0123456789", c.getText());
0727:                c = getInitedComponent(5, 0, "0123456789");
0728:                performAction(c, action);
0729:                assertEquals("resulted string", "56789", c.getText());
0730:            }
0731:
0732:            public void testInsertContentActionPerformed() throws Exception {
0733:                Action action = getAction(DefaultEditorKit.insertContentAction);
0734:                JTextArea c = getInitedComponent(2, 7, "0123456789");
0735:                performAction(c, action, "aaa");
0736:                assertEquals("resulted string", "01aaa789", c.getText());
0737:                c = getInitedComponent(2, 7, "0123456789");
0738:                performAction(c, action, null);
0739:                assertEquals("resulted string", "0123456789", c.getText());
0740:                c = getInitedComponent(2, 7, "0123456789");
0741:                performAction(c, action, "command\ncontent");
0742:                assertEquals("resulted string", "01command\ncontent789", c
0743:                        .getText());
0744:            }
0745:
0746:            public void testCopyActionPerformed() throws Exception {
0747:                // TODO: Uncomment when Clipboard is fully supported
0748:                //        DefaultEditorKit.CopyAction action = new DefaultEditorKit.CopyAction();
0749:                //        putStringToClipboard("");
0750:                //        JTextArea c = getInitedComponent(2, 7, "0123456789");
0751:                //        performAction(c, action);
0752:                //        Object result = null;
0753:                //        try {
0754:                //            result = getStringFromClipboard();
0755:                //        } catch (HeadlessException e) {
0756:                //            fail(e.getMessage());
0757:                //        }
0758:                //        assertEquals("selected string", "23456", result);
0759:            }
0760:
0761:            public void testCutActionPerformed() throws Exception {
0762:                // TODO: Uncomment when Clipboard is fully supported
0763:                //        DefaultEditorKit.CutAction action = new DefaultEditorKit.CutAction();
0764:                //        putStringToClipboard("");
0765:                //        JTextArea c = getInitedComponent(2, 7, "0123456789");
0766:                //        performAction(c, action);
0767:                //        Object result = null;
0768:                //        try {
0769:                //            result = getStringFromClipboard();
0770:                //        } catch (HeadlessException e) {
0771:                //            fail(e.getMessage());
0772:                //        }
0773:                //        assertEquals("cut string", "23456", result);
0774:                //        assertEquals("remained string", "01789", c.getText());
0775:            }
0776:
0777:            public void testPasteActionPerformed() throws Exception {
0778:                // TODO: Uncomment when Clipboard is fully supported
0779:                //        DefaultEditorKit.PasteAction action = new DefaultEditorKit.PasteAction();
0780:                //        putStringToClipboard("98765");
0781:                //        JTextArea c = getInitedComponent(2, 7, "0123456789");
0782:                //        performAction(c, action);
0783:                //        assertEquals("resulted string", "0198765789", c.getText());
0784:            }
0785:
0786:            public void testInsertTabActionPerformed() throws Exception {
0787:                DefaultEditorKit.InsertTabAction action = new DefaultEditorKit.InsertTabAction();
0788:                JTextArea c = getInitedComponent(2, 7, "0123456789");
0789:                performAction(c, action);
0790:                assertEquals("resulted string", "01\t789", c.getText());
0791:            }
0792:
0793:            public void testInsertBreakActionPerformed() throws Exception {
0794:                DefaultEditorKit.InsertBreakAction action = new DefaultEditorKit.InsertBreakAction();
0795:                JTextArea c = getInitedComponent(2, 7, "0123456789");
0796:                performAction(c, action);
0797:                assertEquals("resulted string", "01\n789", c.getText());
0798:            }
0799:
0800:            public void testDefaultKeyTypedActionPerformed() throws Exception {
0801:                DefaultEditorKit.DefaultKeyTypedAction action = new DefaultEditorKit.DefaultKeyTypedAction();
0802:                JTextArea c = getInitedComponent(2, 7, "0123456789");
0803:                performAction(c, action, "asd");
0804:                assertEquals("resulted string", "01asd789", c.getText());
0805:            }
0806:
0807:            public void testBeepActionPerformed() throws Exception {
0808:                DefaultEditorKit.BeepAction action = new DefaultEditorKit.BeepAction();
0809:                JComponent c = new JPanel();
0810:                performAction(c, action);
0811:            }
0812:
0813:            public void testNextVisualPositionActionPerformedCaretForward()
0814:                    throws Exception {
0815:                String text = "012345  6789\nasfd\nasd  asd";
0816:                Action action = getAction(DefaultEditorKit.forwardAction);
0817:                JTextArea c = getInitedComponent(8, text);
0818:                performAction(c, action, null);
0819:                assertEquals("caret position", 9, c.getCaretPosition());
0820:                assertNull("selected text ", c.getSelectedText());
0821:                c = getInitedComponent(text.length(), text);
0822:                performAction(c, action, null);
0823:                assertEquals("caret position", text.length(), c
0824:                        .getCaretPosition());
0825:                assertNull("selected text ", c.getSelectedText());
0826:                c = getInitedComponent(5, 7, text);
0827:                performAction(c, action, null);
0828:                assertEquals("caret position", 8, c.getCaretPosition());
0829:                assertNull("selected text ", c.getSelectedText());
0830:            }
0831:
0832:            public void testNextVisualPositionActionPerformedCaretBackward()
0833:                    throws Exception {
0834:                String text = "012345  6789\nasfd\nasd  asd";
0835:                Action action = getAction(DefaultEditorKit.backwardAction);
0836:                JTextArea c = getInitedComponent(8, text);
0837:                performAction(c, action);
0838:                assertEquals("caret position", 7, c.getCaretPosition());
0839:                assertNull("selected text ", c.getSelectedText());
0840:                c = getInitedComponent(0, text);
0841:                performAction(c, action);
0842:                assertEquals("caret position", 0, c.getCaretPosition());
0843:                assertNull("selected text ", c.getSelectedText());
0844:                c = getInitedComponent(5, 7, text);
0845:                performAction(c, action);
0846:                assertEquals("caret position", 6, c.getCaretPosition());
0847:                assertNull("selected text ", c.getSelectedText());
0848:            }
0849:
0850:            public void testNextVisualPositionActionPerformedSelectionForward()
0851:                    throws Exception {
0852:                String text = "012345  6789\nasfd\nasd  asd";
0853:                Action action = getAction(DefaultEditorKit.selectionForwardAction);
0854:                JTextArea c = getInitedComponent(8, text);
0855:                performAction(c, action);
0856:                assertEquals("caret position", 9, c.getCaretPosition());
0857:                assertEquals("selected text ", "6", c.getSelectedText());
0858:                c = getInitedComponent(text.length(), text);
0859:                performAction(c, action);
0860:                assertEquals("caret position", text.length(), c
0861:                        .getCaretPosition());
0862:                assertNull("selected text ", c.getSelectedText());
0863:                c = getInitedComponent(3, 7, text);
0864:                performAction(c, action);
0865:                assertEquals("caret position", 8, c.getCaretPosition());
0866:                assertEquals("selected text ", "345  ", c.getSelectedText());
0867:            }
0868:
0869:            public void testNextVisualPositionActionPerformedSelectionBackward()
0870:                    throws Exception {
0871:                String text = "012345  6789\nasfd\nasd  asd";
0872:                Action action = getAction(DefaultEditorKit.selectionBackwardAction);
0873:                JTextArea c = getInitedComponent(8, text);
0874:                performAction(c, action);
0875:                assertEquals("caret position", 7, c.getCaretPosition());
0876:                assertEquals("selected text ", " ", c.getSelectedText());
0877:                c = getInitedComponent(0, text);
0878:                performAction(c, action);
0879:                assertEquals("caret position", 0, c.getCaretPosition());
0880:                assertNull("selected text ", c.getSelectedText());
0881:                c = getInitedComponent(8, 5, text);
0882:                performAction(c, action);
0883:                assertEquals("caret position", 4, c.getCaretPosition());
0884:                assertEquals("selected text ", "45  ", c.getSelectedText());
0885:            }
0886:
0887:            public void testNextVisualPositionActionPerformedCaretUp()
0888:                    throws Exception {
0889:                String text = "012345  6789\nasfd\nasd  asd";
0890:                Action action = getAction(DefaultEditorKit.upAction);
0891:                JTextArea c = getInitedComponent(15, text);
0892:                performAction(c, action);
0893:                assertEquals("caret position", 2, c.getCaretPosition());
0894:                assertNull("selected text ", c.getSelectedText());
0895:                performAction(c, action);
0896:                assertEquals("caret position", 2, c.getCaretPosition());
0897:                assertNull("selected text ", c.getSelectedText());
0898:                c = getInitedComponent(24, 26, text);
0899:                performAction(c, action);
0900:                assertEquals("caret position", 17, c.getCaretPosition());
0901:                assertNull("selected text ", c.getSelectedText());
0902:            }
0903:
0904:            public void testNextVisualPositionActionPerformedCaretDown()
0905:                    throws Exception {
0906:                String text = "012345  6789\nasfd\nasd  asd";
0907:                Action action = getAction(DefaultEditorKit.downAction);
0908:                JTextArea c = getInitedComponent(8, text);
0909:                performAction(c, action);
0910:                assertEquals("magic caret pos", new Point(48, 0), c.getCaret()
0911:                        .getMagicCaretPosition());
0912:                assertEquals("caret position", 17, c.getCaretPosition());
0913:                assertNull("selected text ", c.getSelectedText());
0914:                c = getInitedComponent(text.length(), text);
0915:                performAction(c, action);
0916:                assertEquals("magic caret pos", 48, c.getCaret()
0917:                        .getMagicCaretPosition().x);
0918:                assertEquals("caret position", text.length(), c
0919:                        .getCaretPosition());
0920:                assertNull("selected text ", c.getSelectedText());
0921:                c = getInitedComponent(5, 7, text);
0922:                performAction(c, action);
0923:                assertEquals("magic caret pos", new Point(42, 0), c.getCaret()
0924:                        .getMagicCaretPosition());
0925:                performAction(c, action);
0926:                assertEquals("magic caret pos", new Point(42, 0), c.getCaret()
0927:                        .getMagicCaretPosition());
0928:                assertEquals("caret position", 25, c.getCaretPosition());
0929:                assertNull("selected text ", c.getSelectedText());
0930:            }
0931:
0932:            public void testNextVisualPositionActionPerformedSelectionUp()
0933:                    throws Exception {
0934:                String text = "012345  6789\nasfd\nasd  asd";
0935:                Action action = getAction(DefaultEditorKit.selectionUpAction);
0936:                JTextArea c = getInitedComponent(15, text);
0937:                performAction(c, action);
0938:                assertEquals("caret position", 2, c.getCaretPosition());
0939:                assertEquals("selected text ", "2345  6789\nas", c
0940:                        .getSelectedText());
0941:                performAction(c, action);
0942:                assertEquals("caret position", 2, c.getCaretPosition());
0943:                assertEquals("selected text ", "2345  6789\nas", c
0944:                        .getSelectedText());
0945:                c = getInitedComponent(26, 24, text);
0946:                performAction(c, action);
0947:                assertEquals("caret position", 17, c.getCaretPosition());
0948:                assertEquals("selected text ", "\nasd  asd", c
0949:                        .getSelectedText());
0950:            }
0951:
0952:            public void testNextVisualPositionActionPerformedSelectionDown()
0953:                    throws Exception {
0954:                String text = "012345  6789\nasfd\nasd  asd";
0955:                Action action = getAction(DefaultEditorKit.selectionDownAction);
0956:                JTextArea c = getInitedComponent(8, text);
0957:                performAction(c, action);
0958:                assertEquals("caret position", 17, c.getCaretPosition());
0959:                assertEquals("selected text ", "6789\nasfd", c
0960:                        .getSelectedText());
0961:                c = getInitedComponent(text.length(), text);
0962:                performAction(c, action);
0963:                assertEquals("caret position", text.length(), c
0964:                        .getCaretPosition());
0965:                assertNull("selected text ", c.getSelectedText());
0966:                c = getInitedComponent(5, 7, text);
0967:                performAction(c, action);
0968:                performAction(c, action);
0969:                assertEquals("caret position", 25, c.getCaretPosition());
0970:                assertEquals("selected text ", "5  6789\nasfd\nasd  as", c
0971:                        .getSelectedText());
0972:            }
0973:
0974:            public void testDefaultKeyTypedActionFiltering() throws Exception {
0975:                HashSet<Character> nonTypingChars = new HashSet<Character>();
0976:                for (char i = 0; i < 32; i++) {
0977:                    nonTypingChars.add(new Character(i));
0978:                }
0979:                nonTypingChars.add(new Character((char) 127));
0980:                DefaultEditorKit.DefaultKeyTypedAction action = new DefaultEditorKit.DefaultKeyTypedAction();
0981:                JTextArea c = getInitedComponent(4, 5, "0123456789");
0982:                String prevText = c.getText();
0983:                for (char i = 0; i < 255; i++) {
0984:                    performAction(c, action, String.valueOf(i));
0985:                    if (prevText.equals(c.getText())) {
0986:                        if (!nonTypingChars.contains(new Character(i))) {
0987:                            fail("regular character haven't been typed by DEK. code is: "
0988:                                    + (int) i);
0989:                        }
0990:                    } else {
0991:                        prevText = c.getText();
0992:                        if (nonTypingChars.contains(new Character(i))) {
0993:                            fail("non-typing character have been typed by DEK. code is: "
0994:                                    + (int) i);
0995:                        }
0996:                    }
0997:                }
0998:                assertEquals("resulted string length", 231, c.getText()
0999:                        .length());
1000:            }
1001:
1002:            public void testConstants() {
1003:                assertEquals("caret-backward", DefaultEditorKit.backwardAction);
1004:                assertEquals("beep", DefaultEditorKit.beepAction);
1005:                assertEquals("caret-begin", DefaultEditorKit.beginAction);
1006:                assertEquals("caret-begin", DefaultEditorKit.beginAction);
1007:                assertEquals("caret-begin-line",
1008:                        DefaultEditorKit.beginLineAction);
1009:                assertEquals("caret-begin-paragraph",
1010:                        DefaultEditorKit.beginParagraphAction);
1011:                assertEquals("caret-begin-word",
1012:                        DefaultEditorKit.beginWordAction);
1013:                assertEquals("copy-to-clipboard", DefaultEditorKit.copyAction);
1014:                assertEquals("cut-to-clipboard", DefaultEditorKit.cutAction);
1015:                assertEquals("default-typed",
1016:                        DefaultEditorKit.defaultKeyTypedAction);
1017:                assertEquals("delete-next",
1018:                        DefaultEditorKit.deleteNextCharAction);
1019:                assertEquals("delete-previous",
1020:                        DefaultEditorKit.deletePrevCharAction);
1021:                assertEquals("caret-down", DefaultEditorKit.downAction);
1022:                assertEquals("dump-model", DefaultEditorKit.dumpModelAction);
1023:                assertEquals("caret-end", DefaultEditorKit.endAction);
1024:                assertEquals("caret-end-line", DefaultEditorKit.endLineAction);
1025:                assertEquals("__EndOfLine__",
1026:                        DefaultEditorKit.EndOfLineStringProperty);
1027:                assertEquals("caret-end-paragraph",
1028:                        DefaultEditorKit.endParagraphAction);
1029:                assertEquals("caret-end-word", DefaultEditorKit.endWordAction);
1030:                assertEquals("caret-forward", DefaultEditorKit.forwardAction);
1031:                assertEquals("insert-break", DefaultEditorKit.insertBreakAction);
1032:                assertEquals("insert-content",
1033:                        DefaultEditorKit.insertContentAction);
1034:                assertEquals("insert-tab", DefaultEditorKit.insertTabAction);
1035:                assertEquals("caret-next-word", DefaultEditorKit.nextWordAction);
1036:                assertEquals("page-down", DefaultEditorKit.pageDownAction);
1037:                assertEquals("page-up", DefaultEditorKit.pageUpAction);
1038:                assertEquals("paste-from-clipboard",
1039:                        DefaultEditorKit.pasteAction);
1040:                assertEquals("caret-previous-word",
1041:                        DefaultEditorKit.previousWordAction);
1042:                assertEquals("set-read-only", DefaultEditorKit.readOnlyAction);
1043:                assertEquals("select-all", DefaultEditorKit.selectAllAction);
1044:                assertEquals("selection-backward",
1045:                        DefaultEditorKit.selectionBackwardAction);
1046:                assertEquals("selection-begin",
1047:                        DefaultEditorKit.selectionBeginAction);
1048:                assertEquals("selection-begin-line",
1049:                        DefaultEditorKit.selectionBeginLineAction);
1050:                assertEquals("selection-begin-paragraph",
1051:                        DefaultEditorKit.selectionBeginParagraphAction);
1052:                assertEquals("selection-begin-word",
1053:                        DefaultEditorKit.selectionBeginWordAction);
1054:                assertEquals("selection-down",
1055:                        DefaultEditorKit.selectionDownAction);
1056:                assertEquals("selection-end",
1057:                        DefaultEditorKit.selectionEndAction);
1058:                assertEquals("selection-end-line",
1059:                        DefaultEditorKit.selectionEndLineAction);
1060:                assertEquals("selection-end-paragraph",
1061:                        DefaultEditorKit.selectionEndParagraphAction);
1062:                assertEquals("selection-end-word",
1063:                        DefaultEditorKit.selectionEndWordAction);
1064:                assertEquals("selection-forward",
1065:                        DefaultEditorKit.selectionForwardAction);
1066:                assertEquals("selection-next-word",
1067:                        DefaultEditorKit.selectionNextWordAction);
1068:                assertEquals("selection-page-down",
1069:                        DefaultEditorKit.selectionPageDownAction);
1070:                assertEquals("selection-page-left",
1071:                        DefaultEditorKit.selectionPageLeftAction);
1072:                assertEquals("selection-page-right",
1073:                        DefaultEditorKit.selectionPageRightAction);
1074:                assertEquals("selection-page-up",
1075:                        DefaultEditorKit.selectionPageUpAction);
1076:                assertEquals("selection-previous-word",
1077:                        DefaultEditorKit.selectionPreviousWordAction);
1078:                assertEquals("selection-up", DefaultEditorKit.selectionUpAction);
1079:                assertEquals("select-line", DefaultEditorKit.selectLineAction);
1080:                assertEquals("select-paragraph",
1081:                        DefaultEditorKit.selectParagraphAction);
1082:                assertEquals("select-word", DefaultEditorKit.selectWordAction);
1083:                assertEquals("toggle-componentOrientation",
1084:                        DefaultEditorKit.toggleComponentOrientationAction);
1085:                assertEquals("unselect", DefaultEditorKit.unselectAction);
1086:                assertEquals("caret-up", DefaultEditorKit.upAction);
1087:                assertEquals("set-writable", DefaultEditorKit.writableAction);
1088:            }
1089:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.