001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s): Alexandre Iline.
025: *
026: * The Original Software is the Jemmy library.
027: * The Initial Developer of the Original Software is Alexandre Iline.
028: * All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: *
041: *
042: *
043: * $Id: JTextPaneOperator.java,v 1.7 2007/10/05 11:35:14 jskrivanek Exp $ $Revision: 1.7 $ $Date: 2007/10/05 11:35:14 $
044: *
045: */
046:
047: package org.netbeans.jemmy.operators;
048:
049: import java.awt.Component;
050: import java.awt.Container;
051: import java.awt.Font;
052:
053: import javax.swing.Icon;
054: import javax.swing.JTextPane;
055:
056: import javax.swing.text.AttributeSet;
057: import javax.swing.text.Document;
058: import javax.swing.text.Element;
059: import javax.swing.text.MutableAttributeSet;
060: import javax.swing.text.Style;
061: import javax.swing.text.StyledDocument;
062:
063: import org.netbeans.jemmy.ComponentChooser;
064: import org.netbeans.jemmy.ComponentSearcher;
065:
066: /**
067: * <BR><BR>Timeouts used: <BR>
068: * JTextComponentOperator.PushKeyTimeout - time between key pressing and releasing during text typing <BR>
069: * JTextComponentOperator.BetweenKeysTimeout - time to sleep between two chars typing <BR>
070: * JTextComponentOperator.ChangeCaretPositionTimeout - maximum time to chenge caret position <BR>
071: * JTextComponentOperator.TypeTextTimeout - maximum time to type text <BR>
072: * ComponentOperator.WaitComponentTimeout - time to wait component displayed <BR>
073: * ComponentOperator.WaitFocusTimeout - time to wait component focus <BR>
074: * JScrollBarOperator.OneScrollClickTimeout - time for one scroll click <BR>
075: * JScrollBarOperator.WholeScrollTimeout - time for the whole scrolling <BR>.
076: *
077: * @see org.netbeans.jemmy.Timeouts
078: *
079: * @author Alexandre Iline (alexandre.iline@sun.com)
080: *
081: */
082: public class JTextPaneOperator extends JEditorPaneOperator {
083:
084: /**
085: * Constructor.
086: * @param b a component
087: */
088: public JTextPaneOperator(JTextPane b) {
089: super (b);
090: }
091:
092: /**
093: * Constructs a JTextPaneOperator object.
094: * @param cont a container
095: * @param chooser a component chooser specifying searching criteria.
096: * @param index an index between appropriate ones.
097: */
098: public JTextPaneOperator(ContainerOperator cont,
099: ComponentChooser chooser, int index) {
100: this ((JTextPane) cont.waitSubComponent(new JTextPaneFinder(
101: chooser), index));
102: copyEnvironment(cont);
103: }
104:
105: /**
106: * Constructs a JTextPaneOperator object.
107: * @param cont a container
108: * @param chooser a component chooser specifying searching criteria.
109: */
110: public JTextPaneOperator(ContainerOperator cont,
111: ComponentChooser chooser) {
112: this (cont, chooser, 0);
113: }
114:
115: /**
116: * Constructor.
117: * Waits component in container first.
118: * Uses cont's timeout and output for waiting and to init operator.
119: * @param cont a container
120: * @param text Button text.
121: * @param index Ordinal component index.
122: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
123: */
124: public JTextPaneOperator(ContainerOperator cont, String text,
125: int index) {
126: this ((JTextPane) waitComponent(cont, new JTextPaneFinder(
127: new JTextComponentOperator.JTextComponentByTextFinder(
128: text, cont.getComparator())), index));
129: copyEnvironment(cont);
130: }
131:
132: /**
133: * Constructor.
134: * Waits component in container first.
135: * Uses cont's timeout and output for waiting and to init operator.
136: * @param cont a container
137: * @param text Button text.
138: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
139: */
140: public JTextPaneOperator(ContainerOperator cont, String text) {
141: this (cont, text, 0);
142: }
143:
144: /**
145: * Constructor.
146: * Waits component in container first.
147: * Uses cont's timeout and output for waiting and to init operator.
148: * @param cont a container
149: * @param index Ordinal component index.
150: */
151: public JTextPaneOperator(ContainerOperator cont, int index) {
152: this ((JTextPane) waitComponent(cont, new JTextPaneFinder(),
153: index));
154: copyEnvironment(cont);
155: }
156:
157: /**
158: * Constructor.
159: * Waits component in container first.
160: * Uses cont's timeout and output for waiting and to init operator.
161: * @param cont a container
162: */
163: public JTextPaneOperator(ContainerOperator cont) {
164: this (cont, 0);
165: }
166:
167: /**
168: * Searches JTextPane in container.
169: * @param cont Container to search component in.
170: * @param chooser a component chooser specifying searching criteria.
171: * @param index Ordinal component index.
172: * @return JTextPane instance or null if component was not found.
173: */
174: public static JTextPane findJTextPane(Container cont,
175: ComponentChooser chooser, int index) {
176: return ((JTextPane) findJTextComponent(cont,
177: new JTextPaneFinder(chooser), index));
178: }
179:
180: /**
181: * Searches JTextPane in container.
182: * @param cont Container to search component in.
183: * @param chooser a component chooser specifying searching criteria.
184: * @return JTextPane instance or null if component was not found.
185: */
186: public static JTextPane findJTextPane(Container cont,
187: ComponentChooser chooser) {
188: return (findJTextPane(cont, chooser, 0));
189: }
190:
191: /**
192: * Searches JTextPane by text.
193: * @param cont Container to search component in.
194: * @param text Component text.
195: * @param ce Compare text exactly.
196: * @param ccs Compare text case sensitively.
197: * @param index Ordinal component index.
198: * @return JTextPane instance or null if component was not found.
199: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
200: */
201: public static JTextPane findJTextPane(Container cont, String text,
202: boolean ce, boolean ccs, int index) {
203: return (findJTextPane(cont, new JTextPaneFinder(
204: new JTextComponentOperator.JTextComponentByTextFinder(
205: text, new DefaultStringComparator(ce, ccs))),
206: index));
207: }
208:
209: /**
210: * Searches JTextPane by text.
211: * @param cont Container to search component in.
212: * @param text Component text.
213: * @param ce Compare text exactly.
214: * @param ccs Compare text case sensitively.
215: * @return JTextPane instance or null if component was not found.
216: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
217: */
218: public static JTextPane findJTextPane(Container cont, String text,
219: boolean ce, boolean ccs) {
220: return (findJTextPane(cont, text, ce, ccs, 0));
221: }
222:
223: /**
224: * Waits JTextPane in container.
225: * @param cont Container to search component in.
226: * @param chooser a component chooser specifying searching criteria.
227: * @param index Ordinal component index.
228: * @return JTextPane instance.
229: */
230: public static JTextPane waitJTextPane(Container cont,
231: ComponentChooser chooser, int index) {
232: return ((JTextPane) waitJTextComponent(cont,
233: new JTextPaneFinder(chooser), index));
234: }
235:
236: /**
237: * Waits JTextPane in container.
238: * @param cont Container to search component in.
239: * @param chooser a component chooser specifying searching criteria.
240: * @return JTextPane instance.
241: */
242: public static JTextPane waitJTextPane(Container cont,
243: ComponentChooser chooser) {
244: return (waitJTextPane(cont, chooser, 0));
245: }
246:
247: /**
248: * Waits JTextPane by text.
249: * @param cont Container to search component in.
250: * @param text Component text.
251: * @param ce Compare text exactly.
252: * @param ccs Compare text case sensitively.
253: * @param index Ordinal component index.
254: * @return JTextPane instance.
255: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
256: */
257: public static JTextPane waitJTextPane(Container cont, String text,
258: boolean ce, boolean ccs, int index) {
259: return (waitJTextPane(cont, new JTextPaneFinder(
260: new JTextComponentOperator.JTextComponentByTextFinder(
261: text, new DefaultStringComparator(ce, ccs))),
262: index));
263: }
264:
265: /**
266: * Waits JTextPane by text.
267: * @param cont Container to search component in.
268: * @param text Component text.
269: * @param ce Compare text exactly.
270: * @param ccs Compare text case sensitively.
271: * @return JTextPane instance.
272: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
273: */
274: public static JTextPane waitJTextPane(Container cont, String text,
275: boolean ce, boolean ccs) {
276: return (waitJTextPane(cont, text, ce, ccs, 0));
277: }
278:
279: ////////////////////////////////////////////////////////
280: //Mapping //
281:
282: /**Maps <code>JTextPane.addStyle(String, Style)</code> through queue*/
283: public Style addStyle(final String string, final Style style) {
284: return ((Style) runMapping(new MapAction("addStyle") {
285: public Object map() {
286: return (((JTextPane) getSource()).addStyle(string,
287: style));
288: }
289: }));
290: }
291:
292: /**Maps <code>JTextPane.getCharacterAttributes()</code> through queue*/
293: public AttributeSet getCharacterAttributes() {
294: return ((AttributeSet) runMapping(new MapAction(
295: "getCharacterAttributes") {
296: public Object map() {
297: return (((JTextPane) getSource())
298: .getCharacterAttributes());
299: }
300: }));
301: }
302:
303: /**Maps <code>JTextPane.getInputAttributes()</code> through queue*/
304: public MutableAttributeSet getInputAttributes() {
305: return ((MutableAttributeSet) runMapping(new MapAction(
306: "getInputAttributes") {
307: public Object map() {
308: return (((JTextPane) getSource()).getInputAttributes());
309: }
310: }));
311: }
312:
313: /**Maps <code>JTextPane.getLogicalStyle()</code> through queue*/
314: public Style getLogicalStyle() {
315: return ((Style) runMapping(new MapAction("getLogicalStyle") {
316: public Object map() {
317: return (((JTextPane) getSource()).getLogicalStyle());
318: }
319: }));
320: }
321:
322: /**Maps <code>JTextPane.getParagraphAttributes()</code> through queue*/
323: public AttributeSet getParagraphAttributes() {
324: return ((AttributeSet) runMapping(new MapAction(
325: "getParagraphAttributes") {
326: public Object map() {
327: return (((JTextPane) getSource())
328: .getParagraphAttributes());
329: }
330: }));
331: }
332:
333: /**Maps <code>JTextPane.getStyle(String)</code> through queue*/
334: public Style getStyle(final String string) {
335: return ((Style) runMapping(new MapAction("getStyle") {
336: public Object map() {
337: return (((JTextPane) getSource()).getStyle(string));
338: }
339: }));
340: }
341:
342: /**Maps <code>JTextPane.getStyledDocument()</code> through queue*/
343: public StyledDocument getStyledDocument() {
344: return ((StyledDocument) runMapping(new MapAction(
345: "getStyledDocument") {
346: public Object map() {
347: return (((JTextPane) getSource()).getStyledDocument());
348: }
349: }));
350: }
351:
352: /**Maps <code>JTextPane.insertComponent(Component)</code> through queue*/
353: public void insertComponent(final Component component) {
354: runMapping(new MapVoidAction("insertComponent") {
355: public void map() {
356: ((JTextPane) getSource()).insertComponent(component);
357: }
358: });
359: }
360:
361: /**Maps <code>JTextPane.insertIcon(Icon)</code> through queue*/
362: public void insertIcon(final Icon icon) {
363: runMapping(new MapVoidAction("insertIcon") {
364: public void map() {
365: ((JTextPane) getSource()).insertIcon(icon);
366: }
367: });
368: }
369:
370: /**Maps <code>JTextPane.removeStyle(String)</code> through queue*/
371: public void removeStyle(final String string) {
372: runMapping(new MapVoidAction("removeStyle") {
373: public void map() {
374: ((JTextPane) getSource()).removeStyle(string);
375: }
376: });
377: }
378:
379: /**Maps <code>JTextPane.setCharacterAttributes(AttributeSet, boolean)</code> through queue*/
380: public void setCharacterAttributes(final AttributeSet attributeSet,
381: final boolean b) {
382: runMapping(new MapVoidAction("setCharacterAttributes") {
383: public void map() {
384: ((JTextPane) getSource()).setCharacterAttributes(
385: attributeSet, b);
386: }
387: });
388: }
389:
390: /**Maps <code>JTextPane.setLogicalStyle(Style)</code> through queue*/
391: public void setLogicalStyle(final Style style) {
392: runMapping(new MapVoidAction("setLogicalStyle") {
393: public void map() {
394: ((JTextPane) getSource()).setLogicalStyle(style);
395: }
396: });
397: }
398:
399: /**Maps <code>JTextPane.setParagraphAttributes(AttributeSet, boolean)</code> through queue*/
400: public void setParagraphAttributes(final AttributeSet attributeSet,
401: final boolean b) {
402: runMapping(new MapVoidAction("setParagraphAttributes") {
403: public void map() {
404: ((JTextPane) getSource()).setParagraphAttributes(
405: attributeSet, b);
406: }
407: });
408: }
409:
410: /**Maps <code>JTextPane.setStyledDocument(StyledDocument)</code> through queue*/
411: public void setStyledDocument(final StyledDocument styledDocument) {
412: runMapping(new MapVoidAction("setStyledDocument") {
413: public void map() {
414: ((JTextPane) getSource())
415: .setStyledDocument(styledDocument);
416: }
417: });
418: }
419:
420: //End of mapping //
421: ////////////////////////////////////////////////////////
422:
423: /**
424: * Checks component type.
425: */
426: public static class JTextPaneFinder extends Finder {
427: /**
428: * Constructs JTextPaneFinder.
429: * @param sf other searching criteria.
430: */
431: public JTextPaneFinder(ComponentChooser sf) {
432: super (JTextPane.class, sf);
433: }
434:
435: /**
436: * Constructs JTextPaneFinder.
437: */
438: public JTextPaneFinder() {
439: super (JTextPane.class);
440: }
441: }
442: }
|