assertTrue("View 3D printed not checked", view3DPrintedCheckBox.isSelected());
// 3. Change dialog box values
planPrintedCheckBox.setSelected(false);
// Click on Ok in dialog box
final JOptionPane pageSetupOptionPane = (JOptionPane)TestUtilities.findComponent(
pageSetupDialog, JOptionPane.class);
tester.invokeAndWait(new Runnable() {
public void run() {
// Select Ok option to hide dialog box in Event Dispatch Thread
pageSetupOptionPane.setValue(JOptionPane.OK_OPTION);
}
});
assertFalse("Page setup dialog still showing", pageSetupDialog.isShowing());
PageFormat pageFormat = PrinterJob.getPrinterJob().defaultPage();
// Check home print attributes are modified accordingly
assertHomePrintEqualPrintAttributes(pageFormat, true, false, true, home);
// 4. Undo changes
runAction(controller, HomePane.ActionType.UNDO);
// Check home attributes have previous values
assertEquals("Home print set", null, home.getPrint());
// Redo
runAction(controller, HomePane.ActionType.REDO);
// Check home attributes are modified accordingly
assertHomePrintEqualPrintAttributes(pageFormat, true, false, true, home);
// 5. Show print preview dialog box
tester.invokeLater(new Runnable() {
public void run() {
// Display dialog box later in Event Dispatch Thread to avoid blocking test thread
runAction(controller, HomePane.ActionType.PRINT_PREVIEW);
}
});
// Wait for print preview to be shown
tester.waitForFrameShowing(new AWTHierarchy(), preferences.getLocalizedString(
PrintPreviewPanel.class, "printPreview.title"));
// Check dialog box is displayed
JDialog printPreviewDialog = (JDialog)new BasicFinder().find(frame,
new ClassMatcher (JDialog.class, true));
assertTrue("Print preview dialog not showing", printPreviewDialog.isShowing());
// Retrieve PageSetupPanel components
PrintPreviewPanel printPreviewPanel = (PrintPreviewPanel)TestUtilities.findComponent(
frame, PrintPreviewPanel.class);
JToolBar toolBar =
(JToolBar)TestUtilities.getField(printPreviewPanel, "toolBar");
JButton previousButton = (JButton)toolBar.getComponent(0);
final JButton nextButton = (JButton)toolBar.getComponent(1);
HomePrintableComponent printableComponent =
(HomePrintableComponent)TestUtilities.getField(printPreviewPanel, "printableComponent");;
// Check if buttons are enabled and if printable component displays the first page
assertFalse("Previous button is enabled", previousButton.isEnabled());
assertTrue("Next button is disabled", nextButton.isEnabled());
assertEquals("Printable component doesn't display first page", 0, printableComponent.getPage());
assertEquals("Wrong printable component page count", 2, printableComponent.getPageCount());
// 6. Click on next page button
tester.invokeAndWait(new Runnable() {
public void run() {
nextButton.doClick();
}
});
// Check if buttons are enabled and if printable component displays the second page
assertTrue("Previous button is enabled", previousButton.isEnabled());
assertFalse("Next button is disabled", nextButton.isEnabled());
assertEquals("Printable component doesn't display second page", 1, printableComponent.getPage());
// Click on Ok in dialog box
final JOptionPane printPreviewOptionPane = (JOptionPane)TestUtilities.findComponent(
printPreviewDialog, JOptionPane.class);
tester.invokeAndWait(new Runnable() {
public void run() {
// Select Ok option to hide dialog box in Event Dispatch Thread
printPreviewOptionPane.setValue(JOptionPane.OK_OPTION);
}
});
assertFalse("Print preview dialog still showing", printPreviewDialog.isShowing());
// 7. Check the created PDF file doesn't exist