Source Code Cross Referenced for JTextComponentOperator.java in  » Testing » jemmy » org » netbeans » jemmy » operators » 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 » Testing » jemmy » org.netbeans.jemmy.operators 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s): Alexandre Iline.
0025:         *
0026:         * The Original Software is the Jemmy library.
0027:         * The Initial Developer of the Original Software is Alexandre Iline.
0028:         * All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         *
0041:         *
0042:         *
0043:         * $Id: JTextComponentOperator.java,v 1.16 2007/10/05 11:35:46 jskrivanek Exp $ $Revision: 1.16 $ $Date: 2007/10/05 11:35:46 $
0044:         *
0045:         */
0046:
0047:        package org.netbeans.jemmy.operators;
0048:
0049:        import org.netbeans.jemmy.Action;
0050:        import org.netbeans.jemmy.ActionProducer;
0051:        import org.netbeans.jemmy.ComponentChooser;
0052:        import org.netbeans.jemmy.ComponentSearcher;
0053:        import org.netbeans.jemmy.JemmyException;
0054:        import org.netbeans.jemmy.JemmyInputException;
0055:        import org.netbeans.jemmy.JemmyProperties;
0056:        import org.netbeans.jemmy.Outputable;
0057:        import org.netbeans.jemmy.TestOut;
0058:        import org.netbeans.jemmy.Timeoutable;
0059:        import org.netbeans.jemmy.TimeoutExpiredException;
0060:        import org.netbeans.jemmy.Timeouts;
0061:
0062:        import org.netbeans.jemmy.util.EmptyVisualizer;
0063:
0064:        import org.netbeans.jemmy.drivers.DriverManager;
0065:        import org.netbeans.jemmy.drivers.TextDriver;
0066:
0067:        import java.awt.Component;
0068:        import java.awt.Container;
0069:        import java.awt.Color;
0070:        import java.awt.Dimension;
0071:        import java.awt.Insets;
0072:        import java.awt.Point;
0073:        import java.awt.Rectangle;
0074:
0075:        import java.awt.event.InputEvent;
0076:        import java.awt.event.KeyEvent;
0077:
0078:        import java.io.IOException;
0079:        import java.io.Reader;
0080:        import java.io.Writer;
0081:
0082:        import java.util.Hashtable;
0083:
0084:        import javax.swing.JScrollPane;
0085:
0086:        import javax.swing.event.CaretListener;
0087:
0088:        import javax.swing.plaf.TextUI;
0089:
0090:        import javax.swing.text.BadLocationException;
0091:        import javax.swing.text.Caret;
0092:        import javax.swing.text.Document;
0093:        import javax.swing.text.Highlighter;
0094:        import javax.swing.text.JTextComponent;
0095:        import javax.swing.text.Keymap;
0096:
0097:        /**
0098:         *	
0099:         * Class provides basic functions to operate with JTextComponent
0100:         * (selection, typing, deleting)
0101:         *
0102:         * <BR><BR>Timeouts used: <BR>
0103:         * JTextComponentOperator.PushKeyTimeout - time between key pressing and releasing during text typing <BR>
0104:         * JTextComponentOperator.BetweenKeysTimeout - time to sleep between two chars typing <BR>
0105:         * JTextComponentOperator.ChangeCaretPositionTimeout - maximum time to chenge caret position <BR>
0106:         * JTextComponentOperator.TypeTextTimeout - maximum time to type text <BR>
0107:         * ComponentOperator.WaitComponentTimeout - time to wait component displayed <BR>
0108:         * ComponentOperator.WaitFocusTimeout - time to wait component focus <BR>
0109:         * ComponentOperator.WaitStateTimeout - time to wait for text <BR>
0110:         * JScrollBarOperator.OneScrollClickTimeout - time for one scroll click <BR>
0111:         * JScrollBarOperator.WholeScrollTimeout - time for the whole scrolling <BR>.
0112:         *
0113:         * @see org.netbeans.jemmy.Timeouts
0114:         *
0115:         * @author Alexandre Iline (alexandre.iline@sun.com)
0116:         */
0117:
0118:        public class JTextComponentOperator extends JComponentOperator
0119:                implements  Timeoutable, Outputable {
0120:
0121:            /**
0122:             * Identifier for a "text" property.
0123:             * @see #getDump
0124:             */
0125:            public static final String TEXT_DPROP = "Text";
0126:
0127:            /**
0128:             * Identifier for a "selected text" property.
0129:             * @see #getDump
0130:             */
0131:            public static final String SELECTED_TEXT_DPROP = "Selected text";
0132:
0133:            /**
0134:             * Identifier for a "editable" property.
0135:             * @see #getDump
0136:             */
0137:            public static final String IS_EDITABLE_DPROP = "Editable";
0138:
0139:            private final static long PUSH_KEY_TIMEOUT = 0;
0140:            private final static long BETWEEN_KEYS_TIMEOUT = 0;
0141:            private final static long CHANGE_CARET_POSITION_TIMEOUT = 60000;
0142:            private final static long TYPE_TEXT_TIMEOUT = 60000;
0143:
0144:            private Timeouts timeouts;
0145:            private TestOut output;
0146:
0147:            /**
0148:             * Notifies what modifiers are pressed.
0149:             * @deprecated All text operations are performed by TextDriver regitered for this operator type.
0150:             */
0151:            protected int modifiersPressed = 0;
0152:
0153:            private TextDriver driver;
0154:
0155:            /**
0156:             * Constructor.
0157:             * @param b Component to operate with.
0158:             */
0159:            public JTextComponentOperator(JTextComponent b) {
0160:                super (b);
0161:                driver = DriverManager.getTextDriver(getClass());
0162:            }
0163:
0164:            /**
0165:             * Constructs a JTextComponentOperator object.
0166:             * @param cont a container
0167:             * @param chooser a component chooser specifying searching criteria.
0168:             * @param index an index between appropriate ones.
0169:             */
0170:            public JTextComponentOperator(ContainerOperator cont,
0171:                    ComponentChooser chooser, int index) {
0172:                this ((JTextComponent) cont.waitSubComponent(
0173:                        new JTextComponentFinder(chooser), index));
0174:                copyEnvironment(cont);
0175:            }
0176:
0177:            /**
0178:             * Constructs a JTextComponentOperator object.
0179:             * @param cont a container
0180:             * @param chooser a component chooser specifying searching criteria.
0181:             */
0182:            public JTextComponentOperator(ContainerOperator cont,
0183:                    ComponentChooser chooser) {
0184:                this (cont, chooser, 0);
0185:            }
0186:
0187:            /**
0188:             * Constructor.
0189:             * Waits component in container first.
0190:             * Uses cont's timeout and output for waiting and to init operator.
0191:             * @param cont a container
0192:             * @param text Button text. 
0193:             * @param index Ordinal component index.
0194:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0195:             * @throws TimeoutExpiredException
0196:             */
0197:            public JTextComponentOperator(ContainerOperator cont, String text,
0198:                    int index) {
0199:                this ((JTextComponent) waitComponent(cont,
0200:                        new JTextComponentByTextFinder(text, cont
0201:                                .getComparator()), index));
0202:                copyEnvironment(cont);
0203:            }
0204:
0205:            /**
0206:             * Constructor.
0207:             * Waits component in container first.
0208:             * Uses cont's timeout and output for waiting and to init operator.
0209:             * @param cont a container
0210:             * @param text Button text. 
0211:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0212:             * @throws TimeoutExpiredException
0213:             */
0214:            public JTextComponentOperator(ContainerOperator cont, String text) {
0215:                this (cont, text, 0);
0216:            }
0217:
0218:            /**
0219:             * Constructor.
0220:             * Waits component in container first.
0221:             * Uses cont's timeout and output for waiting and to init operator.
0222:             * @param cont a container
0223:             * @param index Ordinal component index.
0224:             * @throws TimeoutExpiredException
0225:             */
0226:            public JTextComponentOperator(ContainerOperator cont, int index) {
0227:                this ((JTextComponent) waitComponent(cont,
0228:                        new JTextComponentFinder(), index));
0229:                copyEnvironment(cont);
0230:            }
0231:
0232:            /**
0233:             * Constructor.
0234:             * Waits component in container first.
0235:             * Uses cont's timeout and output for waiting and to init operator.
0236:             * @param cont a container
0237:             * @throws TimeoutExpiredException
0238:             */
0239:            public JTextComponentOperator(ContainerOperator cont) {
0240:                this (cont, 0);
0241:            }
0242:
0243:            static {
0244:                Timeouts.initDefault("JTextComponentOperator.PushKeyTimeout",
0245:                        PUSH_KEY_TIMEOUT);
0246:                Timeouts.initDefault(
0247:                        "JTextComponentOperator.BetweenKeysTimeout",
0248:                        BETWEEN_KEYS_TIMEOUT);
0249:                Timeouts.initDefault(
0250:                        "JTextComponentOperator.ChangeCaretPositionTimeout",
0251:                        CHANGE_CARET_POSITION_TIMEOUT);
0252:                Timeouts.initDefault("JTextComponentOperator.TypeTextTimeout",
0253:                        TYPE_TEXT_TIMEOUT);
0254:            }
0255:
0256:            /**
0257:             * Searches JTextComponent in container.
0258:             * @param cont Container to search component in.
0259:             * @param chooser a component chooser specifying searching criteria.
0260:             * @param index Ordinal component index.
0261:             * @return JTextComponent instance or null if component was not found.
0262:             */
0263:            public static JTextComponent findJTextComponent(Container cont,
0264:                    ComponentChooser chooser, int index) {
0265:                return ((JTextComponent) findComponent(cont,
0266:                        new JTextComponentFinder(chooser), index));
0267:            }
0268:
0269:            /**
0270:             * Searches JTextComponent in container.
0271:             * @param cont Container to search component in.
0272:             * @param chooser a component chooser specifying searching criteria.
0273:             * @return JTextComponent instance or null if component was not found.
0274:             */
0275:            public static JTextComponent findJTextComponent(Container cont,
0276:                    ComponentChooser chooser) {
0277:                return (findJTextComponent(cont, chooser, 0));
0278:            }
0279:
0280:            /**
0281:             * Searches JTextComponent by text.
0282:             * @param cont Container to search component in.
0283:             * @param text Component text.
0284:             * @param ce Compare text exactly.
0285:             * @param ccs Compare text case sensitively.
0286:             * @param index Ordinal component index.
0287:             * @return JTextComponent instance or null if component was not found.
0288:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0289:             */
0290:            public static JTextComponent findJTextComponent(Container cont,
0291:                    String text, boolean ce, boolean ccs, int index) {
0292:                return (findJTextComponent(cont,
0293:                        new JTextComponentByTextFinder(text,
0294:                                new DefaultStringComparator(ce, ccs)), index));
0295:            }
0296:
0297:            /**
0298:             * Searches JTextComponent by text.
0299:             * @param cont Container to search component in.
0300:             * @param text Component text.
0301:             * @param ce Compare text exactly.
0302:             * @param ccs Compare text case sensitively.
0303:             * @return JTextComponent instance or null if component was not found.
0304:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0305:             */
0306:            public static JTextComponent findJTextComponent(Container cont,
0307:                    String text, boolean ce, boolean ccs) {
0308:                return (findJTextComponent(cont, text, ce, ccs, 0));
0309:            }
0310:
0311:            /**
0312:             * Waits JTextComponent in container.
0313:             * @param cont Container to search component in.
0314:             * @param chooser a component chooser specifying searching criteria.
0315:             * @param index Ordinal component index.
0316:             * @return JTextComponent instance.
0317:             * @throws TimeoutExpiredException
0318:             */
0319:            public static JTextComponent waitJTextComponent(
0320:                    final Container cont, final ComponentChooser chooser,
0321:                    final int index) {
0322:                return ((JTextComponent) waitComponent(cont,
0323:                        new JTextComponentFinder(chooser), index));
0324:            }
0325:
0326:            /**
0327:             * Waits JTextComponent in container.
0328:             * @param cont Container to search component in.
0329:             * @param chooser a component chooser specifying searching criteria.
0330:             * @return JTextComponent instance.
0331:             * @throws TimeoutExpiredException
0332:             */
0333:            public static JTextComponent waitJTextComponent(Container cont,
0334:                    ComponentChooser chooser) {
0335:                return (waitJTextComponent(cont, chooser, 0));
0336:            }
0337:
0338:            /**
0339:             * Waits JTextComponent by text.
0340:             * @param cont Container to search component in.
0341:             * @param text Component text.
0342:             * @param ce Compare text exactly.
0343:             * @param ccs Compare text case sensitively.
0344:             * @param index Ordinal component index.
0345:             * @return JTextComponent instance.
0346:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0347:             * @throws TimeoutExpiredException
0348:             */
0349:            public static JTextComponent waitJTextComponent(Container cont,
0350:                    String text, boolean ce, boolean ccs, int index) {
0351:                return (waitJTextComponent(cont,
0352:                        new JTextComponentByTextFinder(text,
0353:                                new DefaultStringComparator(ce, ccs)), index));
0354:            }
0355:
0356:            /**
0357:             * Waits JTextComponent by text.
0358:             * @param cont Container to search component in.
0359:             * @param text Component text.
0360:             * @param ce Compare text exactly.
0361:             * @param ccs Compare text case sensitively.
0362:             * @return JTextComponent instance.
0363:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
0364:             * @throws TimeoutExpiredException
0365:             */
0366:            public static JTextComponent waitJTextComponent(Container cont,
0367:                    String text, boolean ce, boolean ccs) {
0368:                return (waitJTextComponent(cont, text, ce, ccs, 0));
0369:            }
0370:
0371:            public void setTimeouts(Timeouts times) {
0372:                timeouts = times;
0373:                timeouts
0374:                        .setTimeout(
0375:                                "ComponentOperator.PushKeyTimeout",
0376:                                timeouts
0377:                                        .getTimeout("JTextComponentOperator.PushKeyTimeout"));
0378:                super .setTimeouts(timeouts);
0379:            }
0380:
0381:            public Timeouts getTimeouts() {
0382:                return (timeouts);
0383:            }
0384:
0385:            public void setOutput(TestOut out) {
0386:                output = out;
0387:                super .setOutput(output.createErrorOutput());
0388:            }
0389:
0390:            public TestOut getOutput() {
0391:                return (output);
0392:            }
0393:
0394:            public void copyEnvironment(Operator anotherOperator) {
0395:                super .copyEnvironment(anotherOperator);
0396:                driver = (TextDriver) DriverManager.getDriver(
0397:                        DriverManager.TEXT_DRIVER_ID, getClass(),
0398:                        anotherOperator.getProperties());
0399:            }
0400:
0401:            /**
0402:             * Finds start text position.
0403:             * @param text Text to be searched.
0404:             * @param tChooser Additional search criteria.
0405:             * @param index Index of text instance (first instance has index 0)
0406:             * @return Caret position correspondent to text start.
0407:             * @see JTextComponentOperator.TextChooser
0408:             */
0409:            public int getPositionByText(String text, TextChooser tChooser,
0410:                    int index) {
0411:                output.printLine("Find " + tChooser.getDescription() + "\""
0412:                        + text + "\" text in text component\n    : "
0413:                        + toStringSource());
0414:                output.printGolden("Find " + tChooser.getDescription() + "\""
0415:                        + text + "\" text in text component");
0416:                String allText = getDisplayedText();
0417:                Document doc = getDocument();
0418:                int position = 0;
0419:                int ind = 0;
0420:                while ((position = allText.indexOf(text, position)) >= 0) {
0421:                    if (tChooser.checkPosition(doc, position)) {
0422:                        if (ind == index) {
0423:                            return (position);
0424:                        } else {
0425:                            ind++;
0426:                        }
0427:                    }
0428:                    position = position + text.length();
0429:                }
0430:                return (-1);
0431:            }
0432:
0433:            /**
0434:             * Finds start text position.
0435:             * @param text Text to be searched.
0436:             * @param tChooser Additional search criteria.
0437:             * @return Caret position correspondent to text start.
0438:             */
0439:            public int getPositionByText(String text, TextChooser tChooser) {
0440:                return (getPositionByText(text, tChooser, 0));
0441:            }
0442:
0443:            /**
0444:             * Finds start text position.
0445:             * @param text Text to be searched.
0446:             * @param index Index of text instance (first instance has index 0)
0447:             * @return Caret position correspondent to text start.
0448:             */
0449:            public int getPositionByText(String text, int index) {
0450:                return (getPositionByText(text, new TextChooser() {
0451:                    public boolean checkPosition(Document doc, int offset) {
0452:                        return (true);
0453:                    }
0454:
0455:                    public String getDescription() {
0456:                        return ("any");
0457:                    }
0458:                }, index));
0459:            }
0460:
0461:            /**
0462:             * Finds start text position.
0463:             * @param text Text to be searched.
0464:             * @return Caret position correspondent to text start.
0465:             */
0466:            public int getPositionByText(String text) {
0467:                return (getPositionByText(text, 0));
0468:            }
0469:
0470:            /**
0471:             * Requests a focus, clears text, types new one and pushes Enter.
0472:             * @param text New text value. Shouln't include final '\n'.
0473:             * @throws TimeoutExpiredException
0474:             */
0475:            public void enterText(final String text) {
0476:                makeComponentVisible();
0477:                produceTimeRestricted(new Action() {
0478:                    public Object launch(Object obj) {
0479:                        driver.enterText(JTextComponentOperator.this , text);
0480:                        return (null);
0481:                    }
0482:
0483:                    public String getDescription() {
0484:                        return ("Text entering");
0485:                    }
0486:                }, getTimeouts().getTimeout(
0487:                        "JTextComponentOperator.TypeTextTimeout"));
0488:            }
0489:
0490:            /**
0491:             * Changes caret position.
0492:             * @param position Position to move caret to.
0493:             * @see #changeCaretPosition(String, int, boolean)
0494:             * @throws TimeoutExpiredException
0495:             */
0496:            public void changeCaretPosition(final int position) {
0497:                output.printLine("Change caret position to "
0498:                        + Integer.toString(position));
0499:                makeComponentVisible();
0500:                produceTimeRestricted(new Action() {
0501:                    public Object launch(Object obj) {
0502:                        driver.changeCaretPosition(JTextComponentOperator.this ,
0503:                                position);
0504:                        return (null);
0505:                    }
0506:
0507:                    public String getDescription() {
0508:                        return ("Caret moving");
0509:                    }
0510:                }, getTimeouts().getTimeout(
0511:                        "JTextComponentOperator.ChangeCaretPositionTimeout"));
0512:                if (getVerification()) {
0513:                    waitCaretPosition(position);
0514:                }
0515:            }
0516:
0517:            /**
0518:             * Puts caret before or after text.
0519:             * @param text Text to be searched.
0520:             * @param index Index of text instance (first instance has index 0)
0521:             * @param before If true put caret before text, otherwise after.
0522:             * @see #changeCaretPosition(int)
0523:             * @see #getPositionByText(String, int)
0524:             * @throws TimeoutExpiredException
0525:             * @throws NoSuchTextException
0526:             */
0527:            public void changeCaretPosition(String text, int index,
0528:                    boolean before) {
0529:                output.printLine("Put caret " + (before ? "before" : "after")
0530:                        + " " + Integer.toString(index) + "'th instance of \""
0531:                        + text + "\" text");
0532:                makeComponentVisible();
0533:                int offset = getPositionByText(text, index);
0534:                if (offset == -1) {
0535:                    throw (new NoSuchTextException(text));
0536:                }
0537:                offset = before ? offset : offset + text.length();
0538:                changeCaretPosition(offset);
0539:            }
0540:
0541:            /**
0542:             * Puts caret before or after text.
0543:             * @param text Text to be searched.
0544:             * @param before If true put caret before text, otherwise after.
0545:             * @see #changeCaretPosition(int)
0546:             * @see #getPositionByText(String, int)
0547:             * @throws TimeoutExpiredException
0548:             * @throws NoSuchTextException
0549:             */
0550:            public void changeCaretPosition(String text, boolean before) {
0551:                changeCaretPosition(text, 0, before);
0552:            }
0553:
0554:            /**
0555:             * Types text starting from known position.
0556:             * If verification mode is on, checks that right text has been typed
0557:             * and caret has been moved to right position.
0558:             * @param text Text to be typed.
0559:             * @param caretPosition Position to start type text
0560:             * @see #typeText(String)
0561:             * @throws TimeoutExpiredException
0562:             * @throws NoSuchTextException
0563:             */
0564:            public void typeText(final String text, final int caretPosition) {
0565:                output.printLine("Typing text \"" + text + "\" from "
0566:                        + Integer.toString(caretPosition) + " position "
0567:                        + "in text component\n    : " + toStringSource());
0568:                output.printGolden("Typing text \"" + text
0569:                        + "\" in text component");
0570:                makeComponentVisible();
0571:                produceTimeRestricted(new Action() {
0572:                    public Object launch(Object obj) {
0573:                        driver.typeText(JTextComponentOperator.this , text,
0574:                                caretPosition);
0575:                        return (null);
0576:                    }
0577:
0578:                    public String getDescription() {
0579:                        return ("Text typing");
0580:                    }
0581:                }, getTimeouts().getTimeout(
0582:                        "JTextComponentOperator.TypeTextTimeout"));
0583:                if (getVerification()) {
0584:                    waitText(text, -1);
0585:                }
0586:            }
0587:
0588:            /**
0589:             * Types text starting from the current position.
0590:             * @param text Text to be typed.
0591:             * @see #typeText(String, int)
0592:             * @throws TimeoutExpiredException
0593:             */
0594:            public void typeText(String text) {
0595:                typeText(text, getCaretPosition());
0596:            }
0597:
0598:            /**
0599:             * Selects a part of text.
0600:             * @param startPosition Start caret position
0601:             * @param finalPosition Final caret position
0602:             * @see #selectText(String, int)
0603:             * @see #selectText(String)
0604:             * @throws TimeoutExpiredException
0605:             */
0606:            public void selectText(final int startPosition,
0607:                    final int finalPosition) {
0608:                output.printLine("Select text from "
0609:                        + Integer.toString(startPosition) + " to "
0610:                        + Integer.toString(finalPosition)
0611:                        + " in text component\n    : " + toStringSource());
0612:                makeComponentVisible();
0613:                produceTimeRestricted(new Action() {
0614:                    public Object launch(Object obj) {
0615:                        driver.selectText(JTextComponentOperator.this ,
0616:                                startPosition, finalPosition);
0617:                        return (null);
0618:                    }
0619:
0620:                    public String getDescription() {
0621:                        return ("Text selecting");
0622:                    }
0623:                }, getTimeouts().getTimeout(
0624:                        "JTextComponentOperator.TypeTextTimeout"));
0625:            }
0626:
0627:            /**
0628:             * Selects a part of text.
0629:             * @param text Text to be selected
0630:             * @param index Index of text instance (first instance has index 0)
0631:             * @see #selectText(int, int)
0632:             * @see #selectText(String)
0633:             * @see #getPositionByText(String, int)
0634:             * @throws TimeoutExpiredException
0635:             * @throws NoSuchTextException
0636:             */
0637:            public void selectText(String text, int index) {
0638:                output.printLine("Select " + Integer.toString(index)
0639:                        + "'th instance of \"" + text
0640:                        + "\" text in component\n    : " + toStringSource());
0641:                makeComponentVisible();
0642:                int start = getPositionByText(text, index);
0643:                if (start == -1) {
0644:                    throw (new NoSuchTextException(text));
0645:                }
0646:                selectText(start, start + text.length());
0647:            }
0648:
0649:            /**
0650:             * Selects a part of text.
0651:             * @param text Text to be selected
0652:             * @see #selectText(String, int)
0653:             * @see #selectText(int, int)
0654:             * @throws TimeoutExpiredException
0655:             * @throws NoSuchTextException
0656:             */
0657:            public void selectText(String text) {
0658:                selectText(text, 0);
0659:            }
0660:
0661:            /**
0662:             * Clears text.
0663:             * @throws TimeoutExpiredException
0664:             */
0665:            public void clearText() {
0666:                output.printLine("Clearing text in text component\n    : "
0667:                        + toStringSource());
0668:                output.printGolden("Clearing text in text component");
0669:                makeComponentVisible();
0670:                produceTimeRestricted(new Action() {
0671:                    public Object launch(Object obj) {
0672:                        driver.clearText(JTextComponentOperator.this );
0673:                        return (null);
0674:                    }
0675:
0676:                    public String getDescription() {
0677:                        return ("Text clearing");
0678:                    }
0679:                }, getTimeouts().getTimeout(
0680:                        "JTextComponentOperator.TypeTextTimeout"));
0681:            }
0682:
0683:            /**
0684:             * Scrolls to a text poistion.
0685:             * @param position a position to scroll.
0686:             * @throws TimeoutExpiredException
0687:             */
0688:            public void scrollToPosition(int position) {
0689:                output.printTrace("Scroll JTextComponent to "
0690:                        + Integer.toString(position) + " position\n    : "
0691:                        + toStringSource());
0692:                output.printGolden("Scroll JTextComponent to "
0693:                        + Integer.toString(position) + " position");
0694:                makeComponentVisible();
0695:                //try to find JScrollPane under.
0696:                JScrollPane scroll = (JScrollPane) getContainer(new JScrollPaneOperator.JScrollPaneFinder(
0697:                        ComponentSearcher.getTrueChooser("JScrollPane")));
0698:                if (scroll == null) {
0699:                    return;
0700:                }
0701:                JScrollPaneOperator scroller = new JScrollPaneOperator(scroll);
0702:                scroller.copyEnvironment(this );
0703:                scroller.setVisualizer(new EmptyVisualizer());
0704:                Rectangle rect = modelToView(position);
0705:                scroller.scrollToComponentRectangle(getSource(), (int) rect
0706:                        .getX(), (int) rect.getY(), (int) rect.getWidth(),
0707:                        (int) rect.getHeight());
0708:            }
0709:
0710:            /**
0711:             * Returns text which is really displayed.
0712:             * Results returned by <code>getText()</code> and <code>getDisplayedText()</code>
0713:             * are different if text component is used to display <code>javax.swing.text.StyledDocument</code>
0714:             * @return the text which is displayed.
0715:             */
0716:            public String getDisplayedText() {
0717:                try {
0718:                    Document doc = getDocument();
0719:                    return (doc.getText(0, doc.getLength()));
0720:                } catch (BadLocationException e) {
0721:                    throw (new JemmyException(
0722:                            "Exception during text operation with\n    : "
0723:                                    + toStringSource(), e));
0724:                }
0725:            }
0726:
0727:            /**
0728:             * Wait for text to be displayed starting from certain position.
0729:             * @param text text to wait.
0730:             * @param position starting text position.
0731:             */
0732:            public void waitText(final String text, final int position) {
0733:                getOutput().printLine(
0734:                        "Wait \"" + text + "\" text starting from "
0735:                                + Integer.toString(position)
0736:                                + " position in component \n    : "
0737:                                + toStringSource());
0738:                getOutput().printGolden(
0739:                        "Wait \"" + text + "\" text starting from "
0740:                                + Integer.toString(position) + " position");
0741:                waitState(new ComponentChooser() {
0742:                    public boolean checkComponent(Component comp) {
0743:                        String alltext = getDisplayedText();
0744:                        if (position >= 0) {
0745:                            if (position + text.length() <= alltext.length()) {
0746:                                return (alltext.substring(position, position
0747:                                        + text.length()).equals(text));
0748:                            } else {
0749:                                return (false);
0750:                            }
0751:                        } else {
0752:                            return (alltext.indexOf(text) >= 0);
0753:                        }
0754:                    }
0755:
0756:                    public String getDescription() {
0757:                        return ("Has \"" + text + "\" text starting from "
0758:                                + Integer.toString(position) + " position");
0759:                    }
0760:                });
0761:            }
0762:
0763:            /**
0764:             * Waits for certain text.
0765:             * @param text Text to be compared by getComparator() comparator.
0766:             */
0767:            public void waitText(String text) {
0768:                getOutput().printLine(
0769:                        "Wait \"" + text + "\" text in component \n    : "
0770:                                + toStringSource());
0771:                getOutput().printGolden("Wait \"" + text + "\" text");
0772:                waitState(new JTextComponentByTextFinder(text, getComparator()));
0773:            }
0774:
0775:            /**
0776:             * Wait for caret to be moved to certain position.
0777:             * @param position a position which caret supposed to be moved to.
0778:             */
0779:            public void waitCaretPosition(final int position) {
0780:                getOutput().printLine(
0781:                        "Wait caret to be at \"" + Integer.toString(position)
0782:                                + " position in component \n    : "
0783:                                + toStringSource());
0784:                getOutput().printGolden(
0785:                        "Wait caret to be at \"" + Integer.toString(position)
0786:                                + " position");
0787:                waitState(new ComponentChooser() {
0788:                    public boolean checkComponent(Component comp) {
0789:                        return (getCaretPosition() == position);
0790:                    }
0791:
0792:                    public String getDescription() {
0793:                        return ("Has caret at " + Integer.toString(position) + " position");
0794:                    }
0795:                });
0796:            }
0797:
0798:            public Hashtable getDump() {
0799:                Hashtable result = super .getDump();
0800:                result
0801:                        .put(TEXT_DPROP, ((JTextComponent) getSource())
0802:                                .getText());
0803:                if (((JTextComponent) getSource()).getSelectedText() != null
0804:                        && !((JTextComponent) getSource()).getSelectedText()
0805:                                .equals("")) {
0806:                    result.put(SELECTED_TEXT_DPROP,
0807:                            ((JTextComponent) getSource()).getSelectedText());
0808:                }
0809:                result.put(IS_EDITABLE_DPROP, ((JTextComponent) getSource())
0810:                        .isEditable() ? "true" : "false");
0811:                return (result);
0812:            }
0813:
0814:            ////////////////////////////////////////////////////////
0815:            //Mapping                                             //
0816:
0817:            /**Maps <code>JTextComponent.addCaretListener(CaretListener)</code> through queue*/
0818:            public void addCaretListener(final CaretListener caretListener) {
0819:                runMapping(new MapVoidAction("addCaretListener") {
0820:                    public void map() {
0821:                        ((JTextComponent) getSource())
0822:                                .addCaretListener(caretListener);
0823:                    }
0824:                });
0825:            }
0826:
0827:            /**Maps <code>JTextComponent.copy()</code> through queue*/
0828:            public void copy() {
0829:                runMapping(new MapVoidAction("copy") {
0830:                    public void map() {
0831:                        ((JTextComponent) getSource()).copy();
0832:                    }
0833:                });
0834:            }
0835:
0836:            /**Maps <code>JTextComponent.cut()</code> through queue*/
0837:            public void cut() {
0838:                runMapping(new MapVoidAction("cut") {
0839:                    public void map() {
0840:                        ((JTextComponent) getSource()).cut();
0841:                    }
0842:                });
0843:            }
0844:
0845:            /**Maps <code>JTextComponent.getActions()</code> through queue*/
0846:            public javax.swing.Action[] getActions() {
0847:                return ((javax.swing.Action[]) runMapping(new MapAction(
0848:                        "getActions") {
0849:                    public Object map() {
0850:                        return (((JTextComponent) getSource()).getActions());
0851:                    }
0852:                }));
0853:            }
0854:
0855:            /**Maps <code>JTextComponent.getCaret()</code> through queue*/
0856:            public Caret getCaret() {
0857:                return ((Caret) runMapping(new MapAction("getCaret") {
0858:                    public Object map() {
0859:                        return (((JTextComponent) getSource()).getCaret());
0860:                    }
0861:                }));
0862:            }
0863:
0864:            /**Maps <code>JTextComponent.getCaretColor()</code> through queue*/
0865:            public Color getCaretColor() {
0866:                return ((Color) runMapping(new MapAction("getCaretColor") {
0867:                    public Object map() {
0868:                        return (((JTextComponent) getSource()).getCaretColor());
0869:                    }
0870:                }));
0871:            }
0872:
0873:            /**Maps <code>JTextComponent.getCaretPosition()</code> through queue*/
0874:            public int getCaretPosition() {
0875:                return (runMapping(new MapIntegerAction("getCaretPosition") {
0876:                    public int map() {
0877:                        return (((JTextComponent) getSource())
0878:                                .getCaretPosition());
0879:                    }
0880:                }));
0881:            }
0882:
0883:            /**Maps <code>JTextComponent.getDisabledTextColor()</code> through queue*/
0884:            public Color getDisabledTextColor() {
0885:                return ((Color) runMapping(new MapAction("getDisabledTextColor") {
0886:                    public Object map() {
0887:                        return (((JTextComponent) getSource())
0888:                                .getDisabledTextColor());
0889:                    }
0890:                }));
0891:            }
0892:
0893:            /**Maps <code>JTextComponent.getDocument()</code> through queue*/
0894:            public Document getDocument() {
0895:                return ((Document) runMapping(new MapAction("getDocument") {
0896:                    public Object map() {
0897:                        return (((JTextComponent) getSource()).getDocument());
0898:                    }
0899:                }));
0900:            }
0901:
0902:            /**Maps <code>JTextComponent.getFocusAccelerator()</code> through queue*/
0903:            public char getFocusAccelerator() {
0904:                return (runMapping(new MapCharacterAction("getFocusAccelerator") {
0905:                    public char map() {
0906:                        return (((JTextComponent) getSource())
0907:                                .getFocusAccelerator());
0908:                    }
0909:                }));
0910:            }
0911:
0912:            /**Maps <code>JTextComponent.getHighlighter()</code> through queue*/
0913:            public Highlighter getHighlighter() {
0914:                return ((Highlighter) runMapping(new MapAction("getHighlighter") {
0915:                    public Object map() {
0916:                        return (((JTextComponent) getSource()).getHighlighter());
0917:                    }
0918:                }));
0919:            }
0920:
0921:            /**Maps <code>JTextComponent.getKeymap()</code> through queue*/
0922:            public Keymap getKeymap() {
0923:                return ((Keymap) runMapping(new MapAction("getKeymap") {
0924:                    public Object map() {
0925:                        return (((JTextComponent) getSource()).getKeymap());
0926:                    }
0927:                }));
0928:            }
0929:
0930:            /**Maps <code>JTextComponent.getMargin()</code> through queue*/
0931:            public Insets getMargin() {
0932:                return ((Insets) runMapping(new MapAction("getMargin") {
0933:                    public Object map() {
0934:                        return (((JTextComponent) getSource()).getMargin());
0935:                    }
0936:                }));
0937:            }
0938:
0939:            /**Maps <code>JTextComponent.getPreferredScrollableViewportSize()</code> through queue*/
0940:            public Dimension getPreferredScrollableViewportSize() {
0941:                return ((Dimension) runMapping(new MapAction(
0942:                        "getPreferredScrollableViewportSize") {
0943:                    public Object map() {
0944:                        return (((JTextComponent) getSource())
0945:                                .getPreferredScrollableViewportSize());
0946:                    }
0947:                }));
0948:            }
0949:
0950:            /**Maps <code>JTextComponent.getScrollableBlockIncrement(Rectangle, int, int)</code> through queue*/
0951:            public int getScrollableBlockIncrement(final Rectangle rectangle,
0952:                    final int i, final int i1) {
0953:                return (runMapping(new MapIntegerAction(
0954:                        "getScrollableBlockIncrement") {
0955:                    public int map() {
0956:                        return (((JTextComponent) getSource())
0957:                                .getScrollableBlockIncrement(rectangle, i, i1));
0958:                    }
0959:                }));
0960:            }
0961:
0962:            /**Maps <code>JTextComponent.getScrollableTracksViewportHeight()</code> through queue*/
0963:            public boolean getScrollableTracksViewportHeight() {
0964:                return (runMapping(new MapBooleanAction(
0965:                        "getScrollableTracksViewportHeight") {
0966:                    public boolean map() {
0967:                        return (((JTextComponent) getSource())
0968:                                .getScrollableTracksViewportHeight());
0969:                    }
0970:                }));
0971:            }
0972:
0973:            /**Maps <code>JTextComponent.getScrollableTracksViewportWidth()</code> through queue*/
0974:            public boolean getScrollableTracksViewportWidth() {
0975:                return (runMapping(new MapBooleanAction(
0976:                        "getScrollableTracksViewportWidth") {
0977:                    public boolean map() {
0978:                        return (((JTextComponent) getSource())
0979:                                .getScrollableTracksViewportWidth());
0980:                    }
0981:                }));
0982:            }
0983:
0984:            /**Maps <code>JTextComponent.getScrollableUnitIncrement(Rectangle, int, int)</code> through queue*/
0985:            public int getScrollableUnitIncrement(final Rectangle rectangle,
0986:                    final int i, final int i1) {
0987:                return (runMapping(new MapIntegerAction(
0988:                        "getScrollableUnitIncrement") {
0989:                    public int map() {
0990:                        return (((JTextComponent) getSource())
0991:                                .getScrollableUnitIncrement(rectangle, i, i1));
0992:                    }
0993:                }));
0994:            }
0995:
0996:            /**Maps <code>JTextComponent.getSelectedText()</code> through queue*/
0997:            public String getSelectedText() {
0998:                return ((String) runMapping(new MapAction("getSelectedText") {
0999:                    public Object map() {
1000:                        return (((JTextComponent) getSource())
1001:                                .getSelectedText());
1002:                    }
1003:                }));
1004:            }
1005:
1006:            /**Maps <code>JTextComponent.getSelectedTextColor()</code> through queue*/
1007:            public Color getSelectedTextColor() {
1008:                return ((Color) runMapping(new MapAction("getSelectedTextColor") {
1009:                    public Object map() {
1010:                        return (((JTextComponent) getSource())
1011:                                .getSelectedTextColor());
1012:                    }
1013:                }));
1014:            }
1015:
1016:            /**Maps <code>JTextComponent.getSelectionColor()</code> through queue*/
1017:            public Color getSelectionColor() {
1018:                return ((Color) runMapping(new MapAction("getSelectionColor") {
1019:                    public Object map() {
1020:                        return (((JTextComponent) getSource())
1021:                                .getSelectionColor());
1022:                    }
1023:                }));
1024:            }
1025:
1026:            /**Maps <code>JTextComponent.getSelectionEnd()</code> through queue*/
1027:            public int getSelectionEnd() {
1028:                return (runMapping(new MapIntegerAction("getSelectionEnd") {
1029:                    public int map() {
1030:                        return (((JTextComponent) getSource())
1031:                                .getSelectionEnd());
1032:                    }
1033:                }));
1034:            }
1035:
1036:            /**Maps <code>JTextComponent.getSelectionStart()</code> through queue*/
1037:            public int getSelectionStart() {
1038:                return (runMapping(new MapIntegerAction("getSelectionStart") {
1039:                    public int map() {
1040:                        return (((JTextComponent) getSource())
1041:                                .getSelectionStart());
1042:                    }
1043:                }));
1044:            }
1045:
1046:            /**Maps <code>JTextComponent.getText()</code> through queue*/
1047:            public String getText() {
1048:                return ((String) runMapping(new MapAction("getText") {
1049:                    public Object map() {
1050:                        return (((JTextComponent) getSource()).getText());
1051:                    }
1052:                }));
1053:            }
1054:
1055:            /**Maps <code>JTextComponent.getText(int, int)</code> through queue*/
1056:            public String getText(final int i, final int i1) {
1057:                return ((String) runMapping(new MapAction("getText") {
1058:                    public Object map() throws BadLocationException {
1059:                        return (((JTextComponent) getSource()).getText(i, i1));
1060:                    }
1061:                }));
1062:            }
1063:
1064:            /**Maps <code>JTextComponent.getUI()</code> through queue*/
1065:            public TextUI getUI() {
1066:                return ((TextUI) runMapping(new MapAction("getUI") {
1067:                    public Object map() {
1068:                        return (((JTextComponent) getSource()).getUI());
1069:                    }
1070:                }));
1071:            }
1072:
1073:            /**Maps <code>JTextComponent.isEditable()</code> through queue*/
1074:            public boolean isEditable() {
1075:                return (runMapping(new MapBooleanAction("isEditable") {
1076:                    public boolean map() {
1077:                        return (((JTextComponent) getSource()).isEditable());
1078:                    }
1079:                }));
1080:            }
1081:
1082:            /**Maps <code>JTextComponent.modelToView(int)</code> through queue*/
1083:            public Rectangle modelToView(final int i) {
1084:                return ((Rectangle) runMapping(new MapAction("modelToView") {
1085:                    public Object map() throws BadLocationException {
1086:                        return (((JTextComponent) getSource()).modelToView(i));
1087:                    }
1088:                }));
1089:            }
1090:
1091:            /**Maps <code>JTextComponent.moveCaretPosition(int)</code> through queue*/
1092:            public void moveCaretPosition(final int i) {
1093:                runMapping(new MapVoidAction("moveCaretPosition") {
1094:                    public void map() {
1095:                        ((JTextComponent) getSource()).moveCaretPosition(i);
1096:                    }
1097:                });
1098:            }
1099:
1100:            /**Maps <code>JTextComponent.paste()</code> through queue*/
1101:            public void paste() {
1102:                runMapping(new MapVoidAction("paste") {
1103:                    public void map() {
1104:                        ((JTextComponent) getSource()).paste();
1105:                    }
1106:                });
1107:            }
1108:
1109:            /**Maps <code>JTextComponent.read(Reader, Object)</code> through queue*/
1110:            public void read(final Reader reader, final Object object) {
1111:                runMapping(new MapVoidAction("read") {
1112:                    public void map() throws IOException {
1113:                        ((JTextComponent) getSource()).read(reader, object);
1114:                    }
1115:                });
1116:            }
1117:
1118:            /**Maps <code>JTextComponent.removeCaretListener(CaretListener)</code> through queue*/
1119:            public void removeCaretListener(final CaretListener caretListener) {
1120:                runMapping(new MapVoidAction("removeCaretListener") {
1121:                    public void map() {
1122:                        ((JTextComponent) getSource())
1123:                                .removeCaretListener(caretListener);
1124:                    }
1125:                });
1126:            }
1127:
1128:            /**Maps <code>JTextComponent.replaceSelection(String)</code> through queue*/
1129:            public void replaceSelection(final String string) {
1130:                runMapping(new MapVoidAction("replaceSelection") {
1131:                    public void map() {
1132:                        ((JTextComponent) getSource()).replaceSelection(string);
1133:                    }
1134:                });
1135:            }
1136:
1137:            /**Maps <code>JTextComponent.select(int, int)</code> through queue*/
1138:            public void select(final int i, final int i1) {
1139:                runMapping(new MapVoidAction("select") {
1140:                    public void map() {
1141:                        ((JTextComponent) getSource()).select(i, i1);
1142:                    }
1143:                });
1144:            }
1145:
1146:            /**Maps <code>JTextComponent.selectAll()</code> through queue*/
1147:            public void selectAll() {
1148:                runMapping(new MapVoidAction("selectAll") {
1149:                    public void map() {
1150:                        ((JTextComponent) getSource()).selectAll();
1151:                    }
1152:                });
1153:            }
1154:
1155:            /**Maps <code>JTextComponent.setCaret(Caret)</code> through queue*/
1156:            public void setCaret(final Caret caret) {
1157:                runMapping(new MapVoidAction("setCaret") {
1158:                    public void map() {
1159:                        ((JTextComponent) getSource()).setCaret(caret);
1160:                    }
1161:                });
1162:            }
1163:
1164:            /**Maps <code>JTextComponent.setCaretColor(Color)</code> through queue*/
1165:            public void setCaretColor(final Color color) {
1166:                runMapping(new MapVoidAction("setCaretColor") {
1167:                    public void map() {
1168:                        ((JTextComponent) getSource()).setCaretColor(color);
1169:                    }
1170:                });
1171:            }
1172:
1173:            /**Maps <code>JTextComponent.setCaretPosition(int)</code> through queue*/
1174:            public void setCaretPosition(final int i) {
1175:                runMapping(new MapVoidAction("setCaretPosition") {
1176:                    public void map() {
1177:                        ((JTextComponent) getSource()).setCaretPosition(i);
1178:                    }
1179:                });
1180:            }
1181:
1182:            /**Maps <code>JTextComponent.setDisabledTextColor(Color)</code> through queue*/
1183:            public void setDisabledTextColor(final Color color) {
1184:                runMapping(new MapVoidAction("setDisabledTextColor") {
1185:                    public void map() {
1186:                        ((JTextComponent) getSource())
1187:                                .setDisabledTextColor(color);
1188:                    }
1189:                });
1190:            }
1191:
1192:            /**Maps <code>JTextComponent.setDocument(Document)</code> through queue*/
1193:            public void setDocument(final Document document) {
1194:                runMapping(new MapVoidAction("setDocument") {
1195:                    public void map() {
1196:                        ((JTextComponent) getSource()).setDocument(document);
1197:                    }
1198:                });
1199:            }
1200:
1201:            /**Maps <code>JTextComponent.setEditable(boolean)</code> through queue*/
1202:            public void setEditable(final boolean b) {
1203:                runMapping(new MapVoidAction("setEditable") {
1204:                    public void map() {
1205:                        ((JTextComponent) getSource()).setEditable(b);
1206:                    }
1207:                });
1208:            }
1209:
1210:            /**Maps <code>JTextComponent.setFocusAccelerator(char)</code> through queue*/
1211:            public void setFocusAccelerator(final char c) {
1212:                runMapping(new MapVoidAction("setFocusAccelerator") {
1213:                    public void map() {
1214:                        ((JTextComponent) getSource()).setFocusAccelerator(c);
1215:                    }
1216:                });
1217:            }
1218:
1219:            /**Maps <code>JTextComponent.setHighlighter(Highlighter)</code> through queue*/
1220:            public void setHighlighter(final Highlighter highlighter) {
1221:                runMapping(new MapVoidAction("setHighlighter") {
1222:                    public void map() {
1223:                        ((JTextComponent) getSource())
1224:                                .setHighlighter(highlighter);
1225:                    }
1226:                });
1227:            }
1228:
1229:            /**Maps <code>JTextComponent.setKeymap(Keymap)</code> through queue*/
1230:            public void setKeymap(final Keymap keymap) {
1231:                runMapping(new MapVoidAction("setKeymap") {
1232:                    public void map() {
1233:                        ((JTextComponent) getSource()).setKeymap(keymap);
1234:                    }
1235:                });
1236:            }
1237:
1238:            /**Maps <code>JTextComponent.setMargin(Insets)</code> through queue*/
1239:            public void setMargin(final Insets insets) {
1240:                runMapping(new MapVoidAction("setMargin") {
1241:                    public void map() {
1242:                        ((JTextComponent) getSource()).setMargin(insets);
1243:                    }
1244:                });
1245:            }
1246:
1247:            /**Maps <code>JTextComponent.setSelectedTextColor(Color)</code> through queue*/
1248:            public void setSelectedTextColor(final Color color) {
1249:                runMapping(new MapVoidAction("setSelectedTextColor") {
1250:                    public void map() {
1251:                        ((JTextComponent) getSource())
1252:                                .setSelectedTextColor(color);
1253:                    }
1254:                });
1255:            }
1256:
1257:            /**Maps <code>JTextComponent.setSelectionColor(Color)</code> through queue*/
1258:            public void setSelectionColor(final Color color) {
1259:                runMapping(new MapVoidAction("setSelectionColor") {
1260:                    public void map() {
1261:                        ((JTextComponent) getSource()).setSelectionColor(color);
1262:                    }
1263:                });
1264:            }
1265:
1266:            /**Maps <code>JTextComponent.setSelectionEnd(int)</code> through queue*/
1267:            public void setSelectionEnd(final int i) {
1268:                runMapping(new MapVoidAction("setSelectionEnd") {
1269:                    public void map() {
1270:                        ((JTextComponent) getSource()).setSelectionEnd(i);
1271:                    }
1272:                });
1273:            }
1274:
1275:            /**Maps <code>JTextComponent.setSelectionStart(int)</code> through queue*/
1276:            public void setSelectionStart(final int i) {
1277:                runMapping(new MapVoidAction("setSelectionStart") {
1278:                    public void map() {
1279:                        ((JTextComponent) getSource()).setSelectionStart(i);
1280:                    }
1281:                });
1282:            }
1283:
1284:            /**Maps <code>JTextComponent.setText(String)</code> through queue*/
1285:            public void setText(final String string) {
1286:                runMapping(new MapVoidAction("setText") {
1287:                    public void map() {
1288:                        ((JTextComponent) getSource()).setText(string);
1289:                    }
1290:                });
1291:            }
1292:
1293:            /**Maps <code>JTextComponent.setUI(TextUI)</code> through queue*/
1294:            public void setUI(final TextUI textUI) {
1295:                runMapping(new MapVoidAction("setUI") {
1296:                    public void map() {
1297:                        ((JTextComponent) getSource()).setUI(textUI);
1298:                    }
1299:                });
1300:            }
1301:
1302:            /**Maps <code>JTextComponent.viewToModel(Point)</code> through queue*/
1303:            public int viewToModel(final Point point) {
1304:                return (runMapping(new MapIntegerAction("viewToModel") {
1305:                    public int map() {
1306:                        return (((JTextComponent) getSource())
1307:                                .viewToModel(point));
1308:                    }
1309:                }));
1310:            }
1311:
1312:            /**Maps <code>JTextComponent.write(Writer)</code> through queue*/
1313:            public void write(final Writer writer) {
1314:                runMapping(new MapVoidAction("write") {
1315:                    public void map() throws IOException {
1316:                        ((JTextComponent) getSource()).write(writer);
1317:                    }
1318:                });
1319:            }
1320:
1321:            //End of mapping                                      //
1322:            ////////////////////////////////////////////////////////
1323:
1324:            /**
1325:             * Can be throught during a text operation 
1326:             * if text has not been found in the component.
1327:             */
1328:            public class NoSuchTextException extends JemmyInputException {
1329:                /**
1330:                 * Constructor.
1331:                 * @param text a nonexistent text.
1332:                 */
1333:                public NoSuchTextException(String text) {
1334:                    super ("No such text as \"" + text + "\"", getSource());
1335:                }
1336:            }
1337:
1338:            /**
1339:             * Interface defining additional text cearch criteria.
1340:             * @see #getPositionByText(java.lang.String, JTextComponentOperator.TextChooser)
1341:             */
1342:            public interface TextChooser {
1343:                /**
1344:                 * Checkes if position fits the criteria.
1345:                 * @param document a document to be checked.
1346:                 * @param offset a checked position
1347:                 * @return true if the position fits the criteria.
1348:                 */
1349:                public boolean checkPosition(Document document, int offset);
1350:
1351:                /**
1352:                 * Returns a printable description of the criteria.
1353:                 * @return a description of this chooser.
1354:                 */
1355:                public String getDescription();
1356:            }
1357:
1358:            /**
1359:             * Allows to find component by text.
1360:             */
1361:            public static class JTextComponentByTextFinder implements 
1362:                    ComponentChooser {
1363:                String label;
1364:                StringComparator comparator;
1365:
1366:                /**
1367:                 * Constructs JTextComponentByTextFinder.
1368:                 * @param lb a text pattern
1369:                 * @param comparator specifies string comparision algorithm.
1370:                 */
1371:                public JTextComponentByTextFinder(String lb,
1372:                        StringComparator comparator) {
1373:                    label = lb;
1374:                    this .comparator = comparator;
1375:                }
1376:
1377:                /**
1378:                 * Constructs JTextComponentByTextFinder.
1379:                 * @param lb a text pattern
1380:                 */
1381:                public JTextComponentByTextFinder(String lb) {
1382:                    this (lb, Operator.getDefaultStringComparator());
1383:                }
1384:
1385:                public boolean checkComponent(Component comp) {
1386:                    if (comp instanceof  JTextComponent) {
1387:                        if (((JTextComponent) comp).getText() != null) {
1388:                            return (comparator.equals(((JTextComponent) comp)
1389:                                    .getText(), label));
1390:                        }
1391:                    }
1392:                    return (false);
1393:                }
1394:
1395:                public String getDescription() {
1396:                    return ("JTextComponent with text \"" + label + "\"");
1397:                }
1398:            }
1399:
1400:            /**
1401:             * Checks component type.
1402:             */
1403:            public static class JTextComponentFinder extends Finder {
1404:                /**
1405:                 * Constructs JTextComponentFinder.
1406:                 * @param sf other searching criteria.
1407:                 */
1408:                public JTextComponentFinder(ComponentChooser sf) {
1409:                    super (JTextComponent.class, sf);
1410:                }
1411:
1412:                /**
1413:                 * Constructs JTextComponentFinder.
1414:                 */
1415:                public JTextComponentFinder() {
1416:                    super (JTextComponent.class);
1417:                }
1418:            }
1419:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.