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):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. 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: package org.netbeans.test.umllib.namers;
043:
044: import java.awt.event.KeyEvent;
045: import org.netbeans.jemmy.EventTool;
046: import org.netbeans.jemmy.Timeout;
047: import org.netbeans.jemmy.operators.ComponentOperator;
048: import org.netbeans.test.umllib.EditControlOperator;
049: import org.netbeans.test.umllib.SetName;
050:
051: public class LifelineNamer implements SetName {
052:
053: public LifelineNamer() {
054: }
055:
056: /**
057: * names lifeline
058: * if there is no ':' in name name consider as lifeline name
059: */
060: public void setName(ComponentOperator drawingArea, int x, int y,
061: String name) {
062: int semicolonPos = name.indexOf(':');
063: String lineName = "";
064: lineName = name;
065: String classifierName = "";
066: if (semicolonPos > 0) {
067: lineName = name.substring(0, semicolonPos);
068: }
069: //if (semicolonPos<name.length()-1){
070: if (semicolonPos > -1) {
071: classifierName = name.substring(semicolonPos + 1);
072: }
073: new EventTool().waitNoEvent(1000);
074: try {
075: Thread.sleep(100);
076: } catch (Exception ex) {
077: }
078: drawingArea.clickMouse(x, y, 1);
079: try {
080: Thread.sleep(100);
081: } catch (Exception ex) {
082: }
083: new EventTool().waitNoEvent(1000);
084:
085: EditControlOperator ec = null;
086: /*try
087: {
088: ec=new EditControlOperator();
089: }
090: catch(org.netbeans.jemmy.TimeoutExpiredException ex)
091: {*/
092: drawingArea.pushKey(KeyEvent.VK_F2);
093: try {
094: Thread.sleep(100);
095: } catch (Exception ex2) {
096: }
097: ec = new EditControlOperator();
098: //}
099: //remove old and shifts to left
100: for (int i = ec.getTextFieldOperator().getText().length() + 3; i >= 0; i--) {
101: ec.getTextFieldOperator().pushKey(KeyEvent.VK_BACK_SPACE);
102: }
103:
104: for (int i = 0; i < lineName.length(); i++) {
105: ec.getTextFieldOperator().typeKey(lineName.charAt(i));
106: new Timeout("", 100).sleep();
107: }
108: if (semicolonPos > -1)
109: ec.getTextFieldOperator().typeKey(':');
110: for (int i = 0; i < classifierName.length(); i++) {
111: ec.getTextFieldOperator().typeKey(classifierName.charAt(i));
112: new Timeout("", 100).sleep();
113: }
114:
115: new EventTool().waitNoEvent(1000);
116:
117: ec.getTextFieldOperator().typeKey('\n');
118:
119: new Timeout("", 500).sleep();
120: }
121: }
|