|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JTableLocation | Line # 31 | 4 | 0% | 3 | 0 | 100% |
1.0
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| No Tests | |||
| 1 | /* | |
| 2 | * Created on Feb 2, 2008 | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | |
| 5 | * the License. You may obtain a copy of the License at | |
| 6 | * | |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 | * | |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | |
| 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 11 | * specific language governing permissions and limitations under the License. | |
| 12 | * | |
| 13 | * Copyright @2008-2010 the original author or authors. | |
| 14 | */ | |
| 15 | package org.fest.swing.driver; | |
| 16 | ||
| 17 | import java.awt.Point; | |
| 18 | import java.awt.Rectangle; | |
| 19 | ||
| 20 | import javax.swing.JTable; | |
| 21 | ||
| 22 | import org.fest.swing.annotation.RunsInCurrentThread; | |
| 23 | import org.fest.swing.data.TableCell; | |
| 24 | ||
| 25 | /** | |
| 26 | * Understands a visible location on a <code>{@link JTable}</code>. | |
| 27 | * | |
| 28 | * @author Yvonne Wang | |
| 29 | * @author Alex Ruiz | |
| 30 | */ | |
| 31 | public final class JTableLocation { | |
| 32 | ||
| 33 | /** | |
| 34 | * Converts the given row and column into a coordinate pair. It is assumed that the row and column indices are | |
| 35 | * in the <code>{@link JTable}</code>'s bounds. | |
| 36 | * <p> | |
| 37 | * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are | |
| 38 | * responsible for calling this method from the EDT. | |
| 39 | * </p> | |
| 40 | * @param table the target <code>JTable</code>. | |
| 41 | * @param row the given row. | |
| 42 | * @param column the given column. | |
| 43 | * @return the coordinates of the given row and column. | |
| 44 | */ | |
| 45 | 45 |
@RunsInCurrentThread |
| 46 | public Point pointAt(JTable table, int row, int column) { | |
| 47 | 45 | Rectangle cellBounds = cellBounds(table, row, column); |
| 48 | 45 | return new Point(cellBounds.x + cellBounds.width / 2, cellBounds.y + cellBounds.height / 2); |
| 49 | } | |
| 50 | ||
| 51 | /** | |
| 52 | * Returns the bounds of the given cell. | |
| 53 | * <p> | |
| 54 | * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are | |
| 55 | * responsible for calling this method from the EDT. | |
| 56 | * </p> | |
| 57 | * @param table the target <code>JTable</code>. | |
| 58 | * @param cell the given cell. | |
| 59 | * @return the bounds of the given cell. | |
| 60 | */ | |
| 61 | 9 |
@RunsInCurrentThread |
| 62 | public Rectangle cellBounds(JTable table, TableCell cell) { | |
| 63 | 9 | return cellBounds(table, cell.row, cell.column); |
| 64 | } | |
| 65 | ||
| 66 | /** | |
| 67 | * Returns the bounds of the given row and column. | |
| 68 | * <p> | |
| 69 | * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are | |
| 70 | * responsible for calling this method from the EDT. | |
| 71 | * </p> | |
| 72 | * @param table the target <code>JTable</code>. | |
| 73 | * @param row the given row. | |
| 74 | * @param column the given column. | |
| 75 | * @return the bounds of the given row and column. | |
| 76 | */ | |
| 77 | 88 |
@RunsInCurrentThread |
| 78 | public Rectangle cellBounds(JTable table, int row, int column) { | |
| 79 | 88 | return table.getCellRect(row, column, false); |
| 80 | } | |
| 81 | ||
| 82 | } | |
|
||||||||||||