/** * Returns a cell from the given {@code JTable} using the given cell finder. * * @param table the target {@code JTable}. * @param cellFinder knows how to find a cell. * @return the found cell, if any. * @throws NullPointerException if {@code cellFinder} is {@code null}. * @throws IndexOutOfBoundsException if the row or column indices in the found cell are out of * bounds. * @throws ActionFailedException if a matching cell could not be found. */ @RunsInEDT public @Nonnull TableCell cell(@Nonnull JTable table, @Nonnull TableCellFinder cellFinder) { checkNotNull(cellFinder); TableCell cell = cellFinder.findCell(table, cellReader()); checkCellIndicesInBounds(table, cell); return cell; }
@RunsInEDT private static void requireEditableEqualTo( final @Nonnull JTable table, final @Nonnull TableCell cell, boolean editable) { checkNotNull(cell); boolean cellEditable = checkNotNull( execute( new GuiQuery<Boolean>() { @Override protected Boolean executeInEDT() { return isCellEditable(table, cell); } })); assertThat(cellEditable) .as(cellProperty(table, concat(EDITABLE_PROPERTY, " ", cell))) .isEqualTo(editable); }
@RunsInEDT private static @Nonnull Point scrollToPointAtCell( final @Nonnull JTable table, final @Nonnull TableCell cell, final @Nonnull JTableLocation location) { checkNotNull(cell); Point result = execute( new GuiQuery<Point>() { @Override protected Point executeInEDT() { scrollToCell(table, cell, location); return location.pointAt(table, cell.row, cell.column); } }); return checkNotNull(result); }
@RunsInEDT static int matchingItemIndex( final @Nonnull JComboBox comboBox, final @Nonnull TextMatcher matcher, final @Nonnull JComboBoxCellReader cellReader) { Integer result = execute( new GuiQuery<Integer>() { @Override protected @Nullable Integer executeInEDT() { int itemCount = comboBox.getItemCount(); for (int i = 0; i < itemCount; i++) { String value = cellReader.valueAt(comboBox, i); if (value != null && matcher.isMatching(value)) { return i; } } return -1; } }); return Preconditions.checkNotNull(result); }
private void mouseMove(@Nonnull Component target, @Nonnull Point... points) { for (Point p : points) { checkNotNull(p); robot.moveMouse(target, p.x, p.y); } }
/** * Cancels editing the given cell of the {@code JTable}, using this driver's {@link * JTableCellWriter}. This method should be called after manipulating the {@code Component} * returned by {@link #cellEditor(JTable, TableCell)}. * * @param table the target {@code JTable}. * @param cell the given cell. * @throws NullPointerException if the cell is {@code null}. * @throws IllegalStateException if the {@code JTable} is disabled. * @throws IllegalStateException if the {@code JTable} is not showing on the screen. * @throws IllegalStateException if the {@code JTable} cell is not editable. * @throws IndexOutOfBoundsException if any of the indices (row and column) is out of bounds. * @throws ActionFailedException if this writer is unable to handle the underlying cell editor. * @see #replaceCellWriter(JTableCellWriter) */ @RunsInEDT public void cancelCellEditing(@Nonnull JTable table, @Nonnull TableCell cell) { checkNotNull(cell); cellWriter.cancelCellEditing(table, cell.row, cell.column); }
/** * Returns the editor in the given cell of the {@code JTable}, using this driver's {@link * JTableCellWriter}. * * @param table the target {@code JTable}. * @param cell the given cell. * @return the editor in the given cell of the {@code JTable}. * @throws NullPointerException if the cell is {@code null}. * @throws IllegalStateException if the {@code JTable} cell is not editable. * @throws IndexOutOfBoundsException if any of the indices (row and column) is out of bounds. * @see #replaceCellWriter(JTableCellWriter) */ @RunsInEDT public Component cellEditor(@Nonnull JTable table, @Nonnull TableCell cell) { checkNotNull(cell); return cellWriter.editorForCell(table, cell.row, cell.column); }
/** * Enters the given value in the given cell of the {@code JTable}, using this driver's {@link * JTableCellWriter}. * * @param table the target {@code JTable}. * @param cell the given cell. * @param value the given value. * @throws NullPointerException if the cell is {@code null}. * @throws IllegalStateException if the {@code JTable} is disabled. * @throws IllegalStateException if the {@code JTable} is not showing on the screen. * @throws IllegalStateException if the {@code JTable} cell is not editable. * @throws IndexOutOfBoundsException if any of the indices (row and column) is out of bounds. * @throws ActionFailedException if this driver's {@code JTableCellValueReader} is unable to enter * the given value. * @see #replaceCellWriter(JTableCellWriter) */ @RunsInEDT public void enterValueInCell( @Nonnull JTable table, @Nonnull TableCell cell, @Nonnull String value) { checkNotNull(cell); cellWriter.enterValue(table, cell.row, cell.column, value); }
/** * Selects the given cell, if it is not selected already. * * @param table the target {@code JTable}. * @param cell the cell to select. * @throws NullPointerException if the cell is {@code null}. * @throws IllegalStateException if the {@code JTable} is disabled. * @throws IllegalStateException if the {@code JTable} is not showing on the screen. * @throws IndexOutOfBoundsException if any of the indices (row and column) is out of bounds. */ @RunsInEDT public void selectCell(@Nonnull JTable table, @Nonnull TableCell cell) { checkNotNull(cell); selectCell(table, cell.row, cell.column); }
/** * Returns the foreground colour of the given table cell. * * @param table the target {@code JTable}. * @param cell the table cell. * @return the foreground colour of the given table cell. * @throws NullPointerException if the cell is {@code null}. * @throws IndexOutOfBoundsException if any of the indices (row and column) is out of bounds. */ @RunsInEDT public @Nullable Color foreground(@Nonnull JTable table, @Nonnull TableCell cell) { checkNotNull(cell); return cellForeground(table, cell, cellReader()); }
/** * Returns the background colour of the given table cell. * * @param table the target {@code JTable}. * @param cell the table cell. * @return the background colour of the given table cell. * @throws ActionFailedException if the cell is {@code null}. * @throws ActionFailedException if any of the indices (row and column) is out of bounds. */ @RunsInEDT public Color background(@Nonnull JTable table, @Nonnull TableCell cell) { checkNotNull(cell); return cellBackground(table, cell, cellReader()); }
/** * Returns the font of the given table cell. * * @param table the target {@code JTable}. * @param cell the table cell. * @return the font of the given table cell. * @throws NullPointerException if the cell is {@code null}. * @throws IndexOutOfBoundsException if any of the indices (row and column) is out of bounds. */ @RunsInEDT public @Nullable Font font(@Nonnull JTable table, @Nonnull TableCell cell) { checkNotNull(cell); return cellFont(table, cell, cellReader()); }
/** * Returns the {@code String} representation of the value at the given cell, using this driver's * {@link JTableCellReader}. * * @param table the target {@code JTable}. * @param cell the table cell. * @return the {@code String} representation of the value at the given cell. * @throws NullPointerException if the cell is {@code null}. * @throws IndexOutOfBoundsException if any of the indices (row and column) is out of bounds. * @see #replaceCellReader(JTableCellReader) */ @RunsInEDT public @Nullable String value(@Nonnull JTable table, @Nonnull TableCell cell) { checkNotNull(cell); return cellValue(table, cell, cellReader()); }
/** * Interprets a printf-style format {@code String} for failed assertion messages. It is similar to * <code>{@link String#format(String, Object...)}</code>, except for: * * <ol> * <li>the value of the given <code>{@link Description}</code> is used as the first argument * referenced in the format string * <li>each of the arguments in the given array is converted to a {@code String} by invoking * <code>{@link ToString#toStringOf(Object)}</code>. * </ol> * * @param d the description of the failed assertion, may be {@code null}. * @param format the format string. * @param args arguments referenced by the format specifiers in the format string. * @throws NullPointerException if the format string is {@code null}. * @return A formatted {@code String}. */ public String format(Description d, String format, Object... args) { checkNotNull(format); checkNotNull(args); return descriptionFormatter.format(d) + String.format(format, format(args)); }