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: JTableMouseDriver.java,v 1.7 2007/10/05 11:37:34 jskrivanek Exp $ $Revision: 1.7 $ $Date: 2007/10/05 11:37:34 $
044: *
045: */
046:
047: package org.netbeans.jemmy.drivers.tables;
048:
049: import java.awt.Point;
050: import java.awt.Rectangle;
051:
052: import java.awt.event.KeyEvent;
053:
054: import javax.swing.text.JTextComponent;
055:
056: import org.netbeans.jemmy.QueueTool;
057:
058: import org.netbeans.jemmy.drivers.DriverManager;
059: import org.netbeans.jemmy.drivers.LightSupportiveDriver;
060: import org.netbeans.jemmy.drivers.TableDriver;
061: import org.netbeans.jemmy.drivers.TextDriver;
062:
063: import org.netbeans.jemmy.operators.ComponentOperator;
064: import org.netbeans.jemmy.operators.JTableOperator;
065: import org.netbeans.jemmy.operators.JTextComponentOperator;
066:
067: /**
068: * TableDriver for javax.swing.JTableDriver component type.
069: *
070: * @author Alexandre Iline(alexandre.iline@sun.com)
071: */
072: public class JTableMouseDriver extends LightSupportiveDriver implements
073: TableDriver {
074: QueueTool queueTool;
075:
076: /**
077: * Constructs a JTableMouseDriver.
078: */
079: public JTableMouseDriver() {
080: super (
081: new String[] { "org.netbeans.jemmy.operators.JTableOperator" });
082: ;
083: queueTool = new QueueTool();
084: }
085:
086: public void selectCell(ComponentOperator oper, int row, int column) {
087: clickOnCell((JTableOperator) oper, row, column, 1);
088: }
089:
090: public void editCell(ComponentOperator oper, int row, int column,
091: Object value) {
092: JTableOperator toper = (JTableOperator) oper;
093: toper.scrollToCell(row, column);
094: if (!toper.isEditing() || toper.getEditingRow() != row
095: || toper.getEditingColumn() != column) {
096: clickOnCell((JTableOperator) oper, row, column, 2);
097: }
098: JTextComponentOperator textoper = new JTextComponentOperator(
099: (JTextComponent) toper
100: .waitSubComponent(new JTextComponentOperator.JTextComponentFinder()));
101: TextDriver text = DriverManager
102: .getTextDriver(JTextComponentOperator.class);
103: text.clearText(textoper);
104: text.typeText(textoper, value.toString(), 0);
105: DriverManager.getKeyDriver(oper).pushKey(
106: textoper,
107: KeyEvent.VK_ENTER,
108: 0,
109: oper.getTimeouts().create(
110: "ComponentOperator.PushKeyTimeout"));
111: }
112:
113: /**
114: * Clicks on JTable cell.
115: * @param oper Table operator.
116: * @param row Cell row index.
117: * @param column Cell column index.
118: * @param clickCount Count to click.
119: */
120: protected void clickOnCell(final JTableOperator oper,
121: final int row, final int column, final int clickCount) {
122: queueTool.invokeSmoothly(new QueueTool.QueueAction(
123: "Path selecting") {
124: public Object launch() {
125: Point point = oper.getPointToClick(row, column);
126: DriverManager.getMouseDriver(oper).clickMouse(
127: oper,
128: point.x,
129: point.y,
130: clickCount,
131: oper.getDefaultMouseButton(),
132: 0,
133: oper.getTimeouts().create(
134: "ComponentOperator.MouseClickTimeout"));
135: return (null);
136: }
137: });
138: }
139: }
|