/** * Simulates a user dropping an item to this fixture's {@code Component}. * * @return this fixture. * @throws IllegalStateException if this fixture's {@code Component} is disabled. * @throws IllegalStateException if this fixture's {@code Component} is not showing on the screen. * @throws org.assertj.swing.exception.ActionFailedException if there is no drag action in effect. */ public final @Nonnull S drop() { driver().drop(target()); return myself(); }
/** * Creates a new {@link AbstractComponentFixture}. * * @param selfType the "self type." * @param robot performs simulation of user events on a {@code Component}. * @param type the type of the {@code Component} to find using the given {@code Robot}. * @throws NullPointerException if {@code robot} is {@code null}. * @throws NullPointerException if {@code type} is {@code null}. * @throws org.assertj.swing.exception.ComponentLookupException if a matching component could not be found. * @throws org.assertj.swing.exception.ComponentLookupException if more than one matching component is found. */ public AbstractComponentFixture(@Nonnull Class<S> selfType, @Nonnull Robot robot, @Nonnull Class<? extends C> type) { this(selfType, robot, findTarget(robot, type)); }
/** * Returns whether showing components are the only ones participating in a component lookup. The returned value is * obtained from the {@link org.assertj.swing.core.Settings#componentLookupScope() component lookup scope} stored in * this fixture's {@link Robot}. * * @return {@code true} if only showing components can participate in a component lookup, {@code false} otherwise. */ protected boolean requireShowing() { return requireShowing(robot()); }
/** * Creates a new {@link AbstractComponentFixture}. * * @param selfType the "self type." * @param robot performs simulation of user events on the given {@code Component}. * @param target the {@code Component} to be managed by this fixture. * @throws NullPointerException if {@code selfType} is {@code null}. * @throws NullPointerException if {@code robot} is {@code null}. * @throws NullPointerException if {@code target} is {@code null}. */ public AbstractComponentFixture(@Nonnull Class<S> selfType, @Nonnull Robot robot, @Nonnull C target) { myself = checkNotNull(selfType).cast(this); this.robot = checkNotNull(robot); this.target = checkNotNull(target); replaceDriverWith(createDriver(robot)); }
/** * Indicates whether this fixture's {@code Component} is enabled. * * @return {@code true} if this fixture's {@code Component} is enabled; {@code false} otherwise. */ public final boolean isEnabled() { return ComponentEnabledQuery.isEnabled(target()); }
@Nonnull private static <C extends Component> C findTarget(@Nonnull Robot robot, @Nullable String name, @Nonnull Class<? extends C> type) { checkNotNull(robot); checkNotNull(type); return robot.finder().findByName(name, type, requireShowing(robot)); }
@NotNull public final Boolean isVisible() { try { me().focus(); return true; } catch (Exception e) { return false; } }
/** * @return a fixture that checks properties of the font of this fixture's {@code Component}. */ public final @Nonnull FontFixture font() { Font font = driver.fontOf(target); return new FontFixture(font, propertyName(target(), FONT_PROPERTY)); }
@Nonnull private static <C extends Component> C findTarget(@Nonnull Robot robot, @Nonnull Class<? extends C> type) { checkNotNull(robot); checkNotNull(type); return robot.finder().findByType(type, requireShowing(robot)); }
/** * Asserts that this fixture's {@code Component} is enabled. * * @param timeout the time this fixture will wait for the component to be enabled. * @return this fixture. * @throws org.assertj.swing.exception.WaitTimedOutError if this fixture's {@code Component} is never enabled. */ public final @Nonnull S requireEnabled(@Nonnull Timeout timeout) { driver.requireEnabled(target(), timeout); return myself(); }
/** * @return a fixture that checks properties of the foreground color of this fixture's {@code Component}. */ public final @Nonnull ColorFixture foreground() { Color foreground = driver.foregroundOf(target); return new ColorFixture(foreground, propertyName(target(), FOREGROUND_PROPERTY)); }
/** * Creates a new {@link AbstractComponentFixture}. * * @param selfType the "self type." * @param robot performs simulation of user events on a {@code Component}. * @param name the name of the {@code Component} to find using the given {@code Robot}. * @param type the type of the {@code Component} to find using the given {@code Robot}. * @throws NullPointerException if {@code robot} is {@code null}. * @throws NullPointerException if {@code type} is {@code null}. * @throws org.assertj.swing.exception.ComponentLookupException if a matching component could not be found. * @throws org.assertj.swing.exception.ComponentLookupException if more than one matching component is found. */ public AbstractComponentFixture(@Nonnull Class<S> selfType, @Nonnull Robot robot, @Nullable String name, @Nonnull Class<? extends C> type) { this(selfType, robot, findTarget(robot, name, type)); }
/** * Simulates a user double-clicking this fixture's {@code Component}. * * @return this fixture. * @throws IllegalStateException if {@link org.assertj.swing.core.Settings#clickOnDisabledComponentsAllowed()} is <code>false</code> and this * fixture's {@code Component} is disabled. * @throws IllegalStateException if this fixture's {@code Component} is not showing on the screen. */ @Override public final @Nonnull S doubleClick() { driver.doubleClick(target()); return myself(); }
/** * @return a fixture that checks properties of the background color of this fixture's {@code Component}. */ public final @Nonnull ColorFixture background() { Color background = driver.backgroundOf(target); return new ColorFixture(background, propertyName(target(), BACKGROUND_PROPERTY)); }
/** * Simulates a user clicking this fixture's {@code Component}. * * @return this fixture. * @throws IllegalStateException if {@link org.assertj.swing.core.Settings#clickOnDisabledComponentsAllowed()} is <code>false</code> and this * fixture's {@code Component} is disabled. * @throws IllegalStateException if this fixture's {@code Component} is not showing on the screen. */ @Override public final @Nonnull S click() { driver.click(target()); return myself(); }
/** * Simulates a user right-clicking this fixture's {@code Component}. * * @return this fixture. * @throws IllegalStateException if {@link org.assertj.swing.core.Settings#clickOnDisabledComponentsAllowed()} is <code>false</code> and this * fixture's {@code Component} is disabled. * @throws IllegalStateException if this fixture's {@code Component} is not showing on the screen. */ @Override public final @Nonnull S rightClick() { driver.rightClick(target()); return myself(); }
/** * Gives input focus to this fixture's {@code Component}. * * @return this fixture. * @throws IllegalStateException if this fixture's {@code Component} is disabled. * @throws IllegalStateException if this fixture's {@code Component} is not showing on the screen. */ public final @Nonnull S focus() { driver.focus(target()); return myself(); }