@Before public void setUp() { mongoEditionPanel = GuiActionRunner.execute(new GuiQuery<MongoEditionPanel>() { protected MongoEditionPanel executeInEDT() { return new MongoEditionPanel(mockMongoOperations, mockActionCallback) { @Override void buildPopupMenu() { } }; } }); }
@Before public void setUp() { MockitoAnnotations.initMocks(MongoResultPanelTest.class); mongoResultPanel = GuiActionRunner.execute(new GuiQuery<MongoResultPanel>() { protected MongoResultPanel executeInEDT() { return new MongoResultPanel(DummyProject.getInstance(), mongoDocumentOperations, notifierMock); } }); frameFixture = Containers.showInFrame(mongoResultPanel); }
@Before public void setUp() { mongoManager = Mockito.spy(new MongoManager()); configurationPanel = GuiActionRunner.execute(new GuiQuery<ServerConfigurationPanel>() { protected ServerConfigurationPanel executeInEDT() { return new ServerConfigurationPanel(DummyProject.getInstance(), mongoManager); } }); frameFixture = Containers.showInFrame(configurationPanel); }
/** * Returns the parent of the given AWT or Swing {@code Component}. This query is executed in the event dispatch thread * (EDT). * * @param component the given {@code Component}. * @return the parent of the given {@code Component}. * @see Component#getParent() */ @RunsInEDT @Nullable public static Container parentOf(final @Nonnull Component component) { return execute(() -> component.getParent()); }
@RunsInEDT static @Nullable Object singleSelectionValue(final @Nonnull JList<?> list, final @Nonnull JListCellReader cellReader) { return execute(() -> { int selectedIndex = list.getSelectedIndex(); return (selectedIndex >= 0) ? cellReader.valueAt(list, selectedIndex) : NO_SELECTION_VALUE; }); }
@RunsInEDT static void checkHasSelection(final @Nonnull JTree tree, final @Nonnull String[] selection, final @Nonnull JTreePathFinder pathFinder, final @Nonnull Description errMsg) { execute(() -> checkSelection(tree, selection, pathFinder, errMsg)); }
@RunsInEDT private static void appendComponents(final @Nonnull StringBuilder message, final @Nonnull Collection<Component> found) { execute(() -> { for (Component c : found) { message.append(String.format("%n%s", format(c))); } }); }
@RunsInEDT static @Nonnull String textOf(final @Nonnull AbstractButton button) { String result = execute(() -> button.getText()); return result == null ? "" : result; }
/** * Returns the editor for the given {@code JTable} cell. This method is executed in the EDT. * * @param table the given {@code JTable}. * @param row the row index of the cell. * @param column the column index of the cell. * @return the editor for the given {@code JTable} cell. */ @RunsInEDT @Nullable protected static TableCellEditor cellEditor(final @Nonnull JTable table, final int row, final int column) { return execute(() -> table.getCellEditor(row, column)); }
@RunsInEDT static @Nonnull String[] contents(final @Nonnull JList<?> list, final @Nonnull JListCellReader cellReader) { String[] result = execute(() -> { String[] values = new String[list.getModel().getSize()]; for (int i = 0; i < values.length; i++) { values[i] = cellReader.valueAt(list, i); } return values; }); return checkNotNull(result); }
/** * Brings the given {@code JInternalFrame} to the front. * * @param internalFrame the target {@code JInternalFrame}. */ @RunsInEDT public void moveToFront(final @Nonnull JInternalFrame internalFrame) { execute(() -> // it seems that moving to front always works, regardless if the internal frame is invisible and/or // disabled. internalFrame.toFront()); }
/** * Verifies that the given AWT or Swing {@code Component} is showing on the screen. * * @param c the {@code Component} to check. * @throws IllegalStateException if the {@code Component} is not showing on the screen. */ @RunsInEDT protected static void checkInEdtShowing(final @Nonnull Component c) { execute(() -> checkShowing(c)); }
@RunsInEDT @Nullable private static String cellValue(final @Nonnull JTable table, final @Nonnull TableCell cell, final @Nonnull JTableCellReader cellReader) { return execute(() -> { JTableCellPreconditions.checkCellIndicesInBounds(table, cell); return cellReader.valueAt(table, cell.row, cell.column); }); }
@RunsInEDT static void setSelectedFile(final @Nonnull JFileChooser fileChooser, final @Nonnull File file) { execute(() -> { checkEnabledAndShowing(fileChooser); checkSelectionMode(fileChooser, file); fileChooser.setSelectedFile(file); }); }
@RunsInEDT private static int itemIndex(final @Nonnull JList<?> list, final @Nonnull TextMatcher matcher, final @Nonnull JListCellReader cellReader) { Integer result = execute(() -> matchingItemIndex(list, matcher, cellReader)); return checkNotNull(result); }
/** * Returns the background color of the given AWT or Swing {@code Component}. * * @param c the given {@code Component}. * @return the background color of the given {@code Component}. */ @RunsInEDT @Nonnull public Color backgroundOf(final @Nonnull Component c) { Color result = execute(() -> c.getBackground()); return checkNotNull(result); }
@RunsInEDT @Nonnull private static Point scrollToPosition(final @Nonnull JTextComponent textBox, final int index) { Point result = execute(() -> scrollToVisible(textBox, index)); return checkNotNull(result); }
@RunsInEDT private static void performAndValidateTextSelection(final @Nonnull JTextComponent textBox, final int start, final int end) { execute(() -> { selectTextInRange(textBox, start, end); verifyTextWasSelected(textBox, start, end); }); }
@RunsInEDT private static void doDisposeFrames() { execute(() -> { for (Frame f : Frame.getFrames()) { f.dispose(); } }); } }
@RunsInEDT private void checkSafelyIfReady(final @Nonnull Window w) { if (!windows.isShowingButNotReady(w)) { return; } execute(() -> makeLargeEnoughToReceiveEvents(w)); mouseMove(w, centerOf(w)); }