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: JTableHeaderOperator.java,v 1.4 2007/10/05 11:35:29 jskrivanek Exp $ $Revision: 1.4 $ $Date: 2007/10/05 11:35:29 $
044: *
045: */
046:
047: package org.netbeans.jemmy.operators;
048:
049: import java.awt.Component;
050: import java.awt.Point;
051: import java.awt.Rectangle;
052:
053: import javax.swing.JTable;
054:
055: import javax.swing.event.ChangeEvent;
056: import javax.swing.event.ListSelectionEvent;
057: import javax.swing.event.TableColumnModelEvent;
058:
059: import javax.swing.plaf.TableHeaderUI;
060:
061: import javax.swing.table.JTableHeader;
062: import javax.swing.table.TableCellRenderer;
063: import javax.swing.table.TableColumn;
064: import javax.swing.table.TableColumnModel;
065:
066: import org.netbeans.jemmy.ComponentChooser;
067: import org.netbeans.jemmy.ComponentSearcher;
068: import org.netbeans.jemmy.Outputable;
069: import org.netbeans.jemmy.TestOut;
070: import org.netbeans.jemmy.Timeoutable;
071: import org.netbeans.jemmy.Timeouts;
072:
073: import org.netbeans.jemmy.drivers.DriverManager;
074: import org.netbeans.jemmy.drivers.OrderedListDriver;
075:
076: /**
077: * ComponentOperator.BeforeDragTimeout - time to sleep before column moving <BR>
078: * ComponentOperator.AfterDragTimeout - time to sleep after column moving <BR>
079: * ComponentOperator.WaitComponentTimeout - time to wait component displayed <BR>.
080: *
081: * @author Alexandre Iline (alexandre.iline@sun.com)
082: *
083: */
084:
085: public class JTableHeaderOperator extends JComponentOperator implements
086: Outputable, Timeoutable {
087:
088: private TestOut output;
089: private Timeouts timeouts;
090:
091: private OrderedListDriver driver;
092:
093: /**
094: * Constructor.
095: * @param b a component
096: */
097: public JTableHeaderOperator(JTableHeader b) {
098: super (b);
099: driver = DriverManager.getOrderedListDriver(getClass());
100: }
101:
102: /**
103: * Constructs a JTableHeaderOperator object.
104: * @param cont a container
105: * @param chooser a component chooser specifying searching criteria.
106: * @param index an index between appropriate ones.
107: */
108: public JTableHeaderOperator(ContainerOperator cont,
109: ComponentChooser chooser, int index) {
110: this ((JTableHeader) cont.waitSubComponent(
111: new JTableHeaderFinder(chooser), index));
112: copyEnvironment(cont);
113: }
114:
115: /**
116: * Constructs a JTableHeaderOperator object.
117: * @param cont a container
118: * @param chooser a component chooser specifying searching criteria.
119: */
120: public JTableHeaderOperator(ContainerOperator cont,
121: ComponentChooser chooser) {
122: this (cont, chooser, 0);
123: }
124:
125: /**
126: * Constructs a JTableHeaderOperator object.
127: * @param cont a container
128: * @param index an index between appropriate ones.
129: */
130: public JTableHeaderOperator(ContainerOperator cont, int index) {
131: this ((JTableHeader) waitComponent(cont, new JTableHeaderFinder(
132: ComponentSearcher.getTrueChooser("Any JTableHeader")),
133: index));
134: copyEnvironment(cont);
135: }
136:
137: /**
138: * Constructs a JTableHeaderOperator object.
139: * @param cont a container
140: */
141: public JTableHeaderOperator(ContainerOperator cont) {
142: this (cont, 0);
143: }
144:
145: public void setTimeouts(Timeouts times) {
146: this .timeouts = times;
147: super .setTimeouts(timeouts);
148: }
149:
150: public Timeouts getTimeouts() {
151: return (timeouts);
152: }
153:
154: public void setOutput(TestOut out) {
155: output = out;
156: super .setOutput(output);
157: }
158:
159: public TestOut getOutput() {
160: return (output);
161: }
162:
163: /**
164: * Selects a column.
165: * @param columnIndex an index of a column to select.
166: */
167: public void selectColumn(int columnIndex) {
168: driver.selectItem(this , columnIndex);
169: }
170:
171: /**
172: * Selects some columns.
173: * @param columnIndices indices of columns to select.
174: */
175: public void selectColumns(int[] columnIndices) {
176: driver.selectItems(this , columnIndices);
177: }
178:
179: /**
180: * Moves a column to a different location.
181: * @param moveColumn an original column index.
182: * @param moveTo a desctination column index.
183: */
184: public void moveColumn(int moveColumn, int moveTo) {
185: driver.moveItem(this , moveColumn, moveTo);
186: }
187:
188: /**
189: * Return a point to click on column header.
190: * @param columnIndex an index of a column to click on.
191: * @return the point to click.
192: */
193: public Point getPointToClick(int columnIndex) {
194: Rectangle rect = getHeaderRect(columnIndex);
195: return (new Point(rect.x + rect.width / 2, rect.y + rect.height
196: / 2));
197: }
198:
199: public void copyEnvironment(Operator anotherOperator) {
200: super .copyEnvironment(anotherOperator);
201: driver = (OrderedListDriver) DriverManager.getDriver(
202: DriverManager.ORDEREDLIST_DRIVER_ID, getClass(),
203: anotherOperator.getProperties());
204: }
205:
206: ////////////////////////////////////////////////////////
207: //Mapping //
208:
209: /**Maps <code>JTableHeader.setTable(JTable)</code> through queue*/
210: public void setTable(final JTable jTable) {
211: runMapping(new MapVoidAction("setTable") {
212: public void map() {
213: ((JTableHeader) getSource()).setTable(jTable);
214: }
215: });
216: }
217:
218: /**Maps <code>JTableHeader.getTable()</code> through queue*/
219: public JTable getTable() {
220: return ((JTable) runMapping(new MapAction("getTable") {
221: public Object map() {
222: return (((JTableHeader) getSource()).getTable());
223: }
224: }));
225: }
226:
227: /**Maps <code>JTableHeader.setReorderingAllowed(boolean)</code> through queue*/
228: public void setReorderingAllowed(final boolean b) {
229: runMapping(new MapVoidAction("setReorderingAllowed") {
230: public void map() {
231: ((JTableHeader) getSource()).setReorderingAllowed(b);
232: }
233: });
234: }
235:
236: /**Maps <code>JTableHeader.getReorderingAllowed()</code> through queue*/
237: public boolean getReorderingAllowed() {
238: return (runMapping(new MapBooleanAction("getReorderingAllowed") {
239: public boolean map() {
240: return (((JTableHeader) getSource())
241: .getReorderingAllowed());
242: }
243: }));
244: }
245:
246: /**Maps <code>JTableHeader.setResizingAllowed(boolean)</code> through queue*/
247: public void setResizingAllowed(final boolean b) {
248: runMapping(new MapVoidAction("setResizingAllowed") {
249: public void map() {
250: ((JTableHeader) getSource()).setResizingAllowed(b);
251: }
252: });
253: }
254:
255: /**Maps <code>JTableHeader.getResizingAllowed()</code> through queue*/
256: public boolean getResizingAllowed() {
257: return (runMapping(new MapBooleanAction("getResizingAllowed") {
258: public boolean map() {
259: return (((JTableHeader) getSource())
260: .getResizingAllowed());
261: }
262: }));
263: }
264:
265: /**Maps <code>JTableHeader.getDraggedColumn()</code> through queue*/
266: public TableColumn getDraggedColumn() {
267: return ((TableColumn) runMapping(new MapAction(
268: "getDraggedColumn") {
269: public Object map() {
270: return (((JTableHeader) getSource()).getDraggedColumn());
271: }
272: }));
273: }
274:
275: /**Maps <code>JTableHeader.getDraggedDistance()</code> through queue*/
276: public int getDraggedDistance() {
277: return (runMapping(new MapIntegerAction("getDraggedDistance") {
278: public int map() {
279: return (((JTableHeader) getSource())
280: .getDraggedDistance());
281: }
282: }));
283: }
284:
285: /**Maps <code>JTableHeader.getResizingColumn()</code> through queue*/
286: public TableColumn getResizingColumn() {
287: return ((TableColumn) runMapping(new MapAction(
288: "getResizingColumn") {
289: public Object map() {
290: return (((JTableHeader) getSource())
291: .getResizingColumn());
292: }
293: }));
294: }
295:
296: /**Maps <code>JTableHeader.setUpdateTableInRealTime(boolean)</code> through queue*/
297: public void setUpdateTableInRealTime(final boolean b) {
298: runMapping(new MapVoidAction("setUpdateTableInRealTime") {
299: public void map() {
300: ((JTableHeader) getSource())
301: .setUpdateTableInRealTime(b);
302: }
303: });
304: }
305:
306: /**Maps <code>JTableHeader.getUpdateTableInRealTime()</code> through queue*/
307: public boolean getUpdateTableInRealTime() {
308: return (runMapping(new MapBooleanAction(
309: "getUpdateTableInRealTime") {
310: public boolean map() {
311: return (((JTableHeader) getSource())
312: .getUpdateTableInRealTime());
313: }
314: }));
315: }
316:
317: /**Maps <code>JTableHeader.setDefaultRenderer(TableCellRenderer)</code> through queue*/
318: public void setDefaultRenderer(
319: final TableCellRenderer tableCellRenderer) {
320: runMapping(new MapVoidAction("setDefaultRenderer") {
321: public void map() {
322: ((JTableHeader) getSource())
323: .setDefaultRenderer(tableCellRenderer);
324: }
325: });
326: }
327:
328: /**Maps <code>JTableHeader.getDefaultRenderer()</code> through queue*/
329: public TableCellRenderer getDefaultRenderer() {
330: return ((TableCellRenderer) runMapping(new MapAction(
331: "getDefaultRenderer") {
332: public Object map() {
333: return (((JTableHeader) getSource())
334: .getDefaultRenderer());
335: }
336: }));
337: }
338:
339: /**Maps <code>JTableHeader.columnAtPoint(Point)</code> through queue*/
340: public int columnAtPoint(final Point point) {
341: return (runMapping(new MapIntegerAction("columnAtPoint") {
342: public int map() {
343: return (((JTableHeader) getSource())
344: .columnAtPoint(point));
345: }
346: }));
347: }
348:
349: /**Maps <code>JTableHeader.getHeaderRect(int)</code> through queue*/
350: public Rectangle getHeaderRect(final int i) {
351: return ((Rectangle) runMapping(new MapAction("getHeaderRect") {
352: public Object map() {
353: return (((JTableHeader) getSource()).getHeaderRect(i));
354: }
355: }));
356: }
357:
358: /**Maps <code>JTableHeader.getUI()</code> through queue*/
359: public TableHeaderUI getUI() {
360: return ((TableHeaderUI) runMapping(new MapAction("getUI") {
361: public Object map() {
362: return (((JTableHeader) getSource()).getUI());
363: }
364: }));
365: }
366:
367: /**Maps <code>JTableHeader.setUI(TableHeaderUI)</code> through queue*/
368: public void setUI(final TableHeaderUI tableHeaderUI) {
369: runMapping(new MapVoidAction("setUI") {
370: public void map() {
371: ((JTableHeader) getSource()).setUI(tableHeaderUI);
372: }
373: });
374: }
375:
376: /**Maps <code>JTableHeader.setColumnModel(TableColumnModel)</code> through queue*/
377: public void setColumnModel(final TableColumnModel tableColumnModel) {
378: runMapping(new MapVoidAction("setColumnModel") {
379: public void map() {
380: ((JTableHeader) getSource())
381: .setColumnModel(tableColumnModel);
382: }
383: });
384: }
385:
386: /**Maps <code>JTableHeader.getColumnModel()</code> through queue*/
387: public TableColumnModel getColumnModel() {
388: return ((TableColumnModel) runMapping(new MapAction(
389: "getColumnModel") {
390: public Object map() {
391: return (((JTableHeader) getSource()).getColumnModel());
392: }
393: }));
394: }
395:
396: /**Maps <code>JTableHeader.columnAdded(TableColumnModelEvent)</code> through queue*/
397: public void columnAdded(
398: final TableColumnModelEvent tableColumnModelEvent) {
399: runMapping(new MapVoidAction("columnAdded") {
400: public void map() {
401: ((JTableHeader) getSource())
402: .columnAdded(tableColumnModelEvent);
403: }
404: });
405: }
406:
407: /**Maps <code>JTableHeader.columnRemoved(TableColumnModelEvent)</code> through queue*/
408: public void columnRemoved(
409: final TableColumnModelEvent tableColumnModelEvent) {
410: runMapping(new MapVoidAction("columnRemoved") {
411: public void map() {
412: ((JTableHeader) getSource())
413: .columnRemoved(tableColumnModelEvent);
414: }
415: });
416: }
417:
418: /**Maps <code>JTableHeader.columnMoved(TableColumnModelEvent)</code> through queue*/
419: public void columnMoved(
420: final TableColumnModelEvent tableColumnModelEvent) {
421: runMapping(new MapVoidAction("columnMoved") {
422: public void map() {
423: ((JTableHeader) getSource())
424: .columnMoved(tableColumnModelEvent);
425: }
426: });
427: }
428:
429: /**Maps <code>JTableHeader.columnMarginChanged(ChangeEvent)</code> through queue*/
430: public void columnMarginChanged(final ChangeEvent changeEvent) {
431: runMapping(new MapVoidAction("columnMarginChanged") {
432: public void map() {
433: ((JTableHeader) getSource())
434: .columnMarginChanged(changeEvent);
435: }
436: });
437: }
438:
439: /**Maps <code>JTableHeader.columnSelectionChanged(ListSelectionEvent)</code> through queue*/
440: public void columnSelectionChanged(
441: final ListSelectionEvent listSelectionEvent) {
442: runMapping(new MapVoidAction("columnSelectionChanged") {
443: public void map() {
444: ((JTableHeader) getSource())
445: .columnSelectionChanged(listSelectionEvent);
446: }
447: });
448: }
449:
450: /**Maps <code>JTableHeader.resizeAndRepaint()</code> through queue*/
451: public void resizeAndRepaint() {
452: runMapping(new MapVoidAction("resizeAndRepaint") {
453: public void map() {
454: ((JTableHeader) getSource()).resizeAndRepaint();
455: }
456: });
457: }
458:
459: /**Maps <code>JTableHeader.setDraggedColumn(TableColumn)</code> through queue*/
460: public void setDraggedColumn(final TableColumn tableColumn) {
461: runMapping(new MapVoidAction("setDraggedColumn") {
462: public void map() {
463: ((JTableHeader) getSource())
464: .setDraggedColumn(tableColumn);
465: }
466: });
467: }
468:
469: /**Maps <code>JTableHeader.setDraggedDistance(int)</code> through queue*/
470: public void setDraggedDistance(final int i) {
471: runMapping(new MapVoidAction("setDraggedDistance") {
472: public void map() {
473: ((JTableHeader) getSource()).setDraggedDistance(i);
474: }
475: });
476: }
477:
478: /**Maps <code>JTableHeader.setResizingColumn(TableColumn)</code> through queue*/
479: public void setResizingColumn(final TableColumn tableColumn) {
480: runMapping(new MapVoidAction("setResizingColumn") {
481: public void map() {
482: ((JTableHeader) getSource())
483: .setResizingColumn(tableColumn);
484: }
485: });
486: }
487:
488: //End of mapping //
489: ////////////////////////////////////////////////////////
490:
491: /**
492: * Checks component type.
493: */
494: public static class JTableHeaderFinder implements ComponentChooser {
495: ComponentChooser subFinder;
496:
497: /**
498: * Constructs JTableHeaderFinder.
499: * @param sf other searching criteria.
500: */
501: public JTableHeaderFinder(ComponentChooser sf) {
502: subFinder = sf;
503: }
504:
505: public boolean checkComponent(Component comp) {
506: if (comp instanceof JTableHeader) {
507: return (subFinder.checkComponent(comp));
508: }
509: return (false);
510: }
511:
512: public String getDescription() {
513: return (subFinder.getDescription());
514: }
515: }
516: }
|