001 /*
002 * Created on Feb 2, 2008
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
005 * the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
010 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
011 * specific language governing permissions and limitations under the License.
012 *
013 * Copyright @2008-2010 the original author or authors.
014 */
015 package org.fest.swing.driver;
016
017 import java.awt.Point;
018 import java.awt.Rectangle;
019
020 import javax.swing.JTable;
021
022 import org.fest.swing.annotation.RunsInCurrentThread;
023 import org.fest.swing.data.TableCell;
024
025 /**
026 * Understands a visible location on a <code>{@link JTable}</code>.
027 *
028 * @author Yvonne Wang
029 * @author Alex Ruiz
030 */
031 public final class JTableLocation {
032
033 /**
034 * Converts the given row and column into a coordinate pair. It is assumed that the row and column indices are
035 * in the <code>{@link JTable}</code>'s bounds.
036 * <p>
037 * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
038 * responsible for calling this method from the EDT.
039 * </p>
040 * @param table the target <code>JTable</code>.
041 * @param row the given row.
042 * @param column the given column.
043 * @return the coordinates of the given row and column.
044 */
045 @RunsInCurrentThread
046 public Point pointAt(JTable table, int row, int column) {
047 Rectangle cellBounds = cellBounds(table, row, column);
048 return new Point(cellBounds.x + cellBounds.width / 2, cellBounds.y + cellBounds.height / 2);
049 }
050
051 /**
052 * Returns the bounds of the given cell.
053 * <p>
054 * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
055 * responsible for calling this method from the EDT.
056 * </p>
057 * @param table the target <code>JTable</code>.
058 * @param cell the given cell.
059 * @return the bounds of the given cell.
060 */
061 @RunsInCurrentThread
062 public Rectangle cellBounds(JTable table, TableCell cell) {
063 return cellBounds(table, cell.row, cell.column);
064 }
065
066 /**
067 * Returns the bounds of the given row and column.
068 * <p>
069 * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
070 * responsible for calling this method from the EDT.
071 * </p>
072 * @param table the target <code>JTable</code>.
073 * @param row the given row.
074 * @param column the given column.
075 * @return the bounds of the given row and column.
076 */
077 @RunsInCurrentThread
078 public Rectangle cellBounds(JTable table, int row, int column) {
079 return table.getCellRect(row, column, false);
080 }
081
082 }