Java Code Examples for javax.swing.JDialog#addWindowListener()

The following examples show how to use javax.swing.JDialog#addWindowListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JFontChooser.java    From brModelo with GNU General Public License v3.0 6 votes vote down vote up
/**
 *  Show font selection dialog.
 *  @param parent Dialog's Parent component.
 *  @return OK_OPTION, CANCEL_OPTION or ERROR_OPTION
 *
 *  @see #OK_OPTION 
 *  @see #CANCEL_OPTION
 *  @see #ERROR_OPTION
 **/
public int showDialog(Component parent)
{
    dialogResultValue = ERROR_OPTION;
    JDialog dialog = createDialog(parent);
    dialog.addWindowListener(new WindowAdapter()
    {
        public void windowClosing(WindowEvent e)
        {
            dialogResultValue = CANCEL_OPTION;
        }
    });

    dialog.setVisible(true);
    dialog.dispose();
    dialog = null;

    return dialogResultValue;
}
 
Example 2
Source File: ResizablePopup.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static JDialog getDialog() {
    JDialog dialog = new JDialog(WindowManager.getDefault().getMainWindow(), 
            "", false) 
    {
        private static final long serialVersionUID = -2488334519927160789L;

        public void setVisible(boolean visible) {
            boolean wasVisible = isVisible();
            if (wasVisible && !visible) {
                WebBeansNavigationOptions.setLastBounds(getBounds());
            }
            super.setVisible(visible);
        }
    };
    //dialog.setUndecorated(true);
    dialog.setBounds(WebBeansNavigationOptions.getLastBounds());
    dialog.addWindowListener(windowListener);
    dialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    return dialog;
}
 
Example 3
Source File: JFontChooser.java    From PolyGlot with MIT License 6 votes vote down vote up
/**
 *  Show font selection dialog.
 *  @param parent Dialog's Parent component.
 *  @return OK_OPTION, CANCEL_OPTION or ERROR_OPTION
 *
 *  @see #OK_OPTION 
 *  @see #CANCEL_OPTION
 *  @see #ERROR_OPTION
 **/
public int showDialog(Component parent)
{
    dialogResultValue = ERROR_OPTION;
    JDialog dialog = createDialog(parent);
    dialog.addWindowListener(new WindowAdapter()
    {
        @Override
        public void windowClosing(WindowEvent e)
        {
            dialogResultValue = CANCEL_OPTION;
        }
    });

    dialog.setVisible(true);
    dialog.dispose();

    return dialogResultValue;
}
 
Example 4
Source File: MTGUIComponent.java    From MtgDesktopCompanion with GNU General Public License v3.0 6 votes vote down vote up
public static JDialog createJDialog(MTGUIComponent c, boolean resizable,boolean modal)
{
	JDialog j = new JDialog();
	
	
	j.getContentPane().setLayout(new BorderLayout());
	j.getContentPane().add(c, BorderLayout.CENTER);
	j.setTitle(c.getTitle());
	j.setLocationRelativeTo(null);
	if(c.getIcon()!=null)
		j.setIconImage(c.getIcon().getImage());
	
	j.pack();
	j.setModal(modal);
	j.setResizable(resizable);
	j.addWindowListener(new WindowAdapter() {
		@Override
		public void windowClosing(WindowEvent e) {
			c.onDestroy();
		}
	});
	
	return j;
}
 
Example 5
Source File: RepWizard.java    From nextreports-designer with Apache License 2.0 6 votes vote down vote up
public RepWizard() {
    dialog = new JDialog(Globals.getMainFrame(), I18NSupport.getString("wizard.action.name"), true);
    //dialog.setIconImage(ImageUtil.getImage("wizard.png"));
    Wizard wizard = new Wizard(new StartWizardPanel());
    wizard.getContext().setAttribute(WizardConstants.MAIN_FRAME, dialog);
    wizard.addWizardListener(this);
    dialog.setContentPane(wizard);
    dialog.setSize(600, 450);
    dialog.setLocationRelativeTo(null);
    dialog.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            WizardUtil.disconnect();
        }
    });
    dialog.setVisible(true);
}
 
Example 6
Source File: JFontChooser.java    From Luyten with Apache License 2.0 6 votes vote down vote up
/**
 * Show font selection dialog.
 * 
 * @param parent
 *            Dialog's Parent component.
 * @return OK_OPTION, CANCEL_OPTION or ERROR_OPTION
 *
 * @see #OK_OPTION
 * @see #CANCEL_OPTION
 * @see #ERROR_OPTION
 **/
public int showDialog(Component parent) {
	dialogResultValue = ERROR_OPTION;
	JDialog dialog = createDialog(parent);
	dialog.addWindowListener(new WindowAdapter() {
		public void windowClosing(WindowEvent e) {
			dialogResultValue = CANCEL_OPTION;
		}
	});

	dialog.setVisible(true);
	dialog.dispose();
	dialog = null;

	return dialogResultValue;
}
 
Example 7
Source File: WindowClosedEventOnDispose.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test if a dialog that has never been shown fire
 * the WINDOW_CLOSED event on parent dispose().
 * @throws Exception
 */
public static void testHidenChildDispose() throws Exception {
    JFrame f = new JFrame();
    JDialog dlg = new JDialog(f);
    Listener l = new Listener();
    dlg.addWindowListener(l);
    f.dispose();
    waitEvents();

    assertEquals(0, l.getCount());
}
 
Example 8
Source File: WindowClosedEventOnDispose.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test if a dialog fire the WINDOW_CLOSED event
 * on parent dispose().
 * @throws Exception
 */
public static void testVisibleChildParentDispose() throws Exception {
    JFrame f = new JFrame();
    JDialog dlg = new JDialog(f);
    Listener l = new Listener();
    dlg.addWindowListener(l);
    dlg.setVisible(true);
    f.dispose();
    waitEvents();

    assertEquals(1, l.getCount());
}
 
Example 9
Source File: WindowClosedEventOnDispose.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test if a dialog that has never been shown fire
 * the WINDOW_CLOSED event on parent dispose().
 * @throws Exception
 */
public static void testHidenChildDispose() throws Exception {
    JFrame f = new JFrame();
    JDialog dlg = new JDialog(f);
    Listener l = new Listener();
    dlg.addWindowListener(l);
    f.dispose();
    waitEvents();

    assertEquals(0, l.getCount());
}
 
Example 10
Source File: WindowClosedEventOnDispose.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test if a dialog fire the WINDOW_CLOSED event
 * on parent dispose().
 * @throws Exception
 */
public static void testVisibleChildParentDispose() throws Exception {
    JFrame f = new JFrame();
    JDialog dlg = new JDialog(f);
    Listener l = new Listener();
    dlg.addWindowListener(l);
    dlg.setVisible(true);
    f.dispose();
    waitEvents();

    assertEquals(1, l.getCount());
}
 
Example 11
Source File: PublishBulkWizard.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
public PublishBulkWizard(byte dbObjectType) {
    String message = I18NSupport.getString("publish");        
    dialog = new JDialog(Globals.getMainFrame(), message, true);
    
    //final PublishLoginWizardPanel loginPanel = new PublishLoginWizardPanel(entityPath);
    
    SelectEntityWizardPanel selectPanel = new SelectEntityWizardPanel(dbObjectType);
    Wizard wizard = new Wizard(selectPanel);
    

    wizard.getContext().setAttribute(PublishWizard.MAIN_FRAME, dialog);
    wizard.getContext().setAttribute(PublishWizard.DOWNLOAD, false);
    String entity = WizardConstants.ENTITY_REPORT;
    if (DBObject.CHARTS_GROUP == dbObjectType) {
    	entity = WizardConstants.ENTITY_CHART;
    }
    wizard.getContext().setAttribute(WizardConstants.ENTITY, entity);
    wizard.addWizardListener(this);
    dialog.setContentPane(wizard);
    dialog.setSize(400, 340);
    dialog.setLocationRelativeTo(null);
    dialog.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
        }
    });
    dialog.setVisible(true);
}
 
Example 12
Source File: WindowClosedEventOnDispose.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test if a dialog that has never been shown fire
 * the WINDOW_CLOSED event on parent dispose().
 * @throws Exception
 */
public static void testHidenChildDispose() throws Exception {
    JFrame f = new JFrame();
    JDialog dlg = new JDialog(f);
    Listener l = new Listener();
    dlg.addWindowListener(l);
    f.dispose();
    waitEvents();

    assertEquals(0, l.getCount());
}
 
Example 13
Source File: TestSaveFileWithoutPrinter.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void createAndShowTestDialog() {
    String description =
        " To run this test it is required to delete any installed printers.\r\n" +
        "\r\n" +
        " 1. Verify that saving file via \"Save as PDF\" results in saving file\r\n" +
        " even if there is no installed printer.\r\n" +
        " 2. Click on \"Start Test\" button.\r\n" +
        " 3. In the shown print dialog select \"Save as PDF\" in PDF drop-down list\r\n" +
        " 4. Another dialog opens prompting for filename, enter any filename and press \"Save\".\r\n" +
        "\r\n" +
        " If the file is saved without any PrinterException, click on \"PASS\"\r\n" +
        " button, otherwise click on \"FAIL\" button.";

    final JDialog dialog = new JDialog();
    dialog.setTitle("SaveFileWithoutPrinter");
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            dialog.dispose();
            fail("Main dialog was closed.");
        }
    });

    final JLabel testTimeoutLabel = new JLabel(String.format(
        "Test timeout: %s", convertMillisToTimeStr(testTimeout)));
    final long startTime = System.currentTimeMillis();
    final Timer timer = new Timer(0, null);
    timer.setDelay(1000);
    timer.addActionListener((e) -> {
        int leftTime = testTimeout - (int) (System.currentTimeMillis() - startTime);
        if ((leftTime < 0) || testFinished) {
            timer.stop();
            dialog.dispose();
        }
        testTimeoutLabel.setText(String.format(
            "Test timeout: %s", convertMillisToTimeStr(leftTime)));
    });
    timer.start();

    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);

    final JButton testButton = new JButton("Start Test");
    final JButton passButton = new JButton("PASS");
    final JButton failButton = new JButton("FAIL");
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        new Thread(() -> {
            try {
                doTest();

                SwingUtilities.invokeLater(() -> {
                    passButton.setEnabled(true);
                    failButton.setEnabled(true);
                });
            } catch (Throwable t) {
                t.printStackTrace();
                dialog.dispose();
                fail("Exception occurred in a thread executing the test.");
            }
        }).start();
    });
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        dialog.dispose();
        pass();
    });
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        dialog.dispose();
        fail("PrinterException thrown.");
    });

    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel labelPanel = new JPanel(new FlowLayout());
    labelPanel.add(testTimeoutLabel);
    mainPanel.add(labelPanel, BorderLayout.NORTH);
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);

    dialog.pack();
    dialog.setVisible(true);
}
 
Example 14
Source File: WrongPaperForBookPrintingTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void createAndShowTestDialog() {
    String description =
        " To run this test it is required to have a virtual PDF\r\n" +
        " printer or any other printer supporting A5 paper size.\r\n" +
        "\r\n" +
        " 1. Verify that NOT A5 paper size is set as default for the\r\n" +
        " printer to be used.\r\n" +
        " 2. Click on \"Start Test\" button.\r\n" +
        " 3. In the shown print dialog select the printer and click\r\n" +
        " on \"Print\" button.\r\n" +
        " 4. Verify that a page with a drawn rectangle is printed on\r\n" +
        " a paper of A5 size which is (5.8 x 8.3 in) or\r\n" +
        " (148 x 210 mm).\r\n" +
        "\r\n" +
        " If the printed page size is correct, click on \"PASS\"\r\n" +
        " button, otherwise click on \"FAIL\" button.";

    final JDialog dialog = new JDialog();
    dialog.setTitle("WrongPaperForBookPrintingTest");
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            dialog.dispose();
            fail("Main dialog was closed.");
        }
    });

    final JLabel testTimeoutLabel = new JLabel(String.format(
        "Test timeout: %s", convertMillisToTimeStr(testTimeout)));
    final long startTime = System.currentTimeMillis();
    final Timer timer = new Timer(0, null);
    timer.setDelay(1000);
    timer.addActionListener((e) -> {
        int leftTime = testTimeout - (int) (System.currentTimeMillis() - startTime);
        if ((leftTime < 0) || testFinished) {
            timer.stop();
            dialog.dispose();
        }
        testTimeoutLabel.setText(String.format(
            "Test timeout: %s", convertMillisToTimeStr(leftTime)));
    });
    timer.start();

    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);

    final JButton testButton = new JButton("Start Test");
    final JButton passButton = new JButton("PASS");
    final JButton failButton = new JButton("FAIL");
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        new Thread(() -> {
            try {
                doTest();

                SwingUtilities.invokeLater(() -> {
                    passButton.setEnabled(true);
                    failButton.setEnabled(true);
                });
            } catch (Throwable t) {
                t.printStackTrace();
                dialog.dispose();
                fail("Exception occurred in a thread executing the test.");
            }
        }).start();
    });
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        dialog.dispose();
        pass();
    });
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        dialog.dispose();
        fail("Size of a printed page is wrong.");
    });

    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel labelPanel = new JPanel(new FlowLayout());
    labelPanel.add(testTimeoutLabel);
    mainPanel.add(labelPanel, BorderLayout.NORTH);
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);

    dialog.pack();
    dialog.setVisible(true);
}
 
Example 15
Source File: TestTextPosInPrint.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void createAndShowTestDialog() {
    String description =
        " 1. Click on \"Start Test\" button.\r\n" +
        " 2. Multiple strings will be displayed on console.\r\n" +
        " 3. A print dialog will be shown. Select any printer to print. " +
        "\r\n" +
        " If the printed output of the strings are same without any alignment issue, click on \"PASS\"\r\n" +
        " button, otherwise click on \"FAIL\" button.";

    final JDialog dialog = new JDialog();
    dialog.setTitle("SaveFileWithoutPrinter");
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            dialog.dispose();
            fail("Main dialog was closed.");
        }
    });

    final JLabel testTimeoutLabel = new JLabel(String.format(
        "Test timeout: %s", convertMillisToTimeStr(testTimeout)));
    final long startTime = System.currentTimeMillis();
    final Timer timer = new Timer(0, null);
    timer.setDelay(1000);
    timer.addActionListener((e) -> {
        int leftTime = testTimeout - (int) (System.currentTimeMillis() - startTime);
        if ((leftTime < 0) || testFinished) {
            timer.stop();
            dialog.dispose();
        }
        testTimeoutLabel.setText(String.format(
            "Test timeout: %s", convertMillisToTimeStr(leftTime)));
    });
    timer.start();

    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);

    final JButton testButton = new JButton("Start Test");
    final JButton passButton = new JButton("PASS");
    final JButton failButton = new JButton("FAIL");
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        new Thread(() -> {
            try {
                doTest();

                SwingUtilities.invokeLater(() -> {
                    passButton.setEnabled(true);
                    failButton.setEnabled(true);
                });
            } catch (Throwable t) {
                t.printStackTrace();
                dialog.dispose();
                fail("Exception occurred in a thread executing the test.");
            }
        }).start();
    });
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        dialog.dispose();
        pass();
    });
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        dialog.dispose();
        fail("Printed texts are not aligned as shown in console");
    });

    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel labelPanel = new JPanel(new FlowLayout());
    labelPanel.add(testTimeoutLabel);
    mainPanel.add(labelPanel, BorderLayout.NORTH);
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);

    dialog.pack();
    dialog.setVisible(true);
}
 
Example 16
Source File: TestTextPosInPrint.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void createAndShowTestDialog() {
    String description =
        " 1. Click on \"Start Test\" button.\r\n" +
        " 2. Multiple strings will be displayed on console.\r\n" +
        " 3. A print dialog will be shown. Select any printer to print. " +
        "\r\n" +
        " If the printed output of the strings are same without any alignment issue, click on \"PASS\"\r\n" +
        " button, otherwise click on \"FAIL\" button.";

    final JDialog dialog = new JDialog();
    dialog.setTitle("SaveFileWithoutPrinter");
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            dialog.dispose();
            fail("Main dialog was closed.");
        }
    });

    final JLabel testTimeoutLabel = new JLabel(String.format(
        "Test timeout: %s", convertMillisToTimeStr(testTimeout)));
    final long startTime = System.currentTimeMillis();
    final Timer timer = new Timer(0, null);
    timer.setDelay(1000);
    timer.addActionListener((e) -> {
        int leftTime = testTimeout - (int) (System.currentTimeMillis() - startTime);
        if ((leftTime < 0) || testFinished) {
            timer.stop();
            dialog.dispose();
        }
        testTimeoutLabel.setText(String.format(
            "Test timeout: %s", convertMillisToTimeStr(leftTime)));
    });
    timer.start();

    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);

    final JButton testButton = new JButton("Start Test");
    final JButton passButton = new JButton("PASS");
    final JButton failButton = new JButton("FAIL");
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        new Thread(() -> {
            try {
                doTest();

                SwingUtilities.invokeLater(() -> {
                    passButton.setEnabled(true);
                    failButton.setEnabled(true);
                });
            } catch (Throwable t) {
                t.printStackTrace();
                dialog.dispose();
                fail("Exception occurred in a thread executing the test.");
            }
        }).start();
    });
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        dialog.dispose();
        pass();
    });
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        dialog.dispose();
        fail("Printed texts are not aligned as shown in console");
    });

    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel labelPanel = new JPanel(new FlowLayout());
    labelPanel.add(testTimeoutLabel);
    mainPanel.add(labelPanel, BorderLayout.NORTH);
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);

    dialog.pack();
    dialog.setVisible(true);
}
 
Example 17
Source File: AssistantPane.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new {@code AssistantPane}.
 *
 * @param parent The parent window.
 * @param title  The title of the dialog.
 */
public AssistantPane(Window parent, String title) {

    pageStack = new ArrayDeque<AssistantPage>();

    prevAction = new PrevAction();
    nextAction = new NextAction();
    finishAction = new FinishAction();
    cancelAction = new CancelAction();
    helpAction = new HelpAction();

    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 2, 2));
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    buttonPanel.add(new JButton(prevAction));
    final JButton nextButton = new JButton(nextAction);
    buttonPanel.add(nextButton);
    buttonPanel.add(new JButton(finishAction));
    buttonPanel.add(new JButton(cancelAction));
    buttonPanel.add(new JButton(helpAction));

    titleLabel = new JLabel();
    titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 14.0f));
    titleLabel.setHorizontalAlignment(JLabel.RIGHT);
    titleLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    titleLabel.setForeground(Color.WHITE);

    JPanel titlePanel = new JPanel(new BorderLayout());
    titlePanel.setBackground(titlePanel.getBackground().darker());
    titlePanel.add(titleLabel, BorderLayout.CENTER);

    pagePanel = new JPanel(new BorderLayout());
    pagePanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    dialog = new JDialog(parent, title, Dialog.ModalityType.APPLICATION_MODAL);
    dialog.getContentPane().add(titlePanel, BorderLayout.NORTH);
    dialog.getContentPane().add(pagePanel, BorderLayout.CENTER);
    dialog.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dialog.getRootPane().setDefaultButton(nextButton);
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            cancelAction.cancel();
        }
    });
}
 
Example 18
Source File: WrongPaperForBookPrintingTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void createAndShowTestDialog() {
    String description =
        " To run this test it is required to have a virtual PDF\r\n" +
        " printer or any other printer supporting A5 paper size.\r\n" +
        "\r\n" +
        " 1. Verify that NOT A5 paper size is set as default for the\r\n" +
        " printer to be used.\r\n" +
        " 2. Click on \"Start Test\" button.\r\n" +
        " 3. In the shown print dialog select the printer and click\r\n" +
        " on \"Print\" button.\r\n" +
        " 4. Verify that a page with a drawn rectangle is printed on\r\n" +
        " a paper of A5 size which is (5.8 x 8.3 in) or\r\n" +
        " (148 x 210 mm).\r\n" +
        "\r\n" +
        " If the printed page size is correct, click on \"PASS\"\r\n" +
        " button, otherwise click on \"FAIL\" button.";

    final JDialog dialog = new JDialog();
    dialog.setTitle("WrongPaperForBookPrintingTest");
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            dialog.dispose();
            fail("Main dialog was closed.");
        }
    });

    final JLabel testTimeoutLabel = new JLabel(String.format(
        "Test timeout: %s", convertMillisToTimeStr(testTimeout)));
    final long startTime = System.currentTimeMillis();
    final Timer timer = new Timer(0, null);
    timer.setDelay(1000);
    timer.addActionListener((e) -> {
        int leftTime = testTimeout - (int) (System.currentTimeMillis() - startTime);
        if ((leftTime < 0) || testFinished) {
            timer.stop();
            dialog.dispose();
        }
        testTimeoutLabel.setText(String.format(
            "Test timeout: %s", convertMillisToTimeStr(leftTime)));
    });
    timer.start();

    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);

    final JButton testButton = new JButton("Start Test");
    final JButton passButton = new JButton("PASS");
    final JButton failButton = new JButton("FAIL");
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        new Thread(() -> {
            try {
                doTest();

                SwingUtilities.invokeLater(() -> {
                    passButton.setEnabled(true);
                    failButton.setEnabled(true);
                });
            } catch (Throwable t) {
                t.printStackTrace();
                dialog.dispose();
                fail("Exception occurred in a thread executing the test.");
            }
        }).start();
    });
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        dialog.dispose();
        pass();
    });
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        dialog.dispose();
        fail("Size of a printed page is wrong.");
    });

    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel labelPanel = new JPanel(new FlowLayout());
    labelPanel.add(testTimeoutLabel);
    mainPanel.add(labelPanel, BorderLayout.NORTH);
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);

    dialog.pack();
    dialog.setVisible(true);
}
 
Example 19
Source File: TestTextPosInPrint.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void createAndShowTestDialog() {
    String description =
        " 1. Click on \"Start Test\" button.\r\n" +
        " 2. Multiple strings will be displayed on console.\r\n" +
        " 3. A print dialog will be shown. Select any printer to print. " +
        "\r\n" +
        " If the printed output of the strings are same without any alignment issue, click on \"PASS\"\r\n" +
        " button, otherwise click on \"FAIL\" button.";

    final JDialog dialog = new JDialog();
    dialog.setTitle("SaveFileWithoutPrinter");
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            dialog.dispose();
            fail("Main dialog was closed.");
        }
    });

    final JLabel testTimeoutLabel = new JLabel(String.format(
        "Test timeout: %s", convertMillisToTimeStr(testTimeout)));
    final long startTime = System.currentTimeMillis();
    final Timer timer = new Timer(0, null);
    timer.setDelay(1000);
    timer.addActionListener((e) -> {
        int leftTime = testTimeout - (int) (System.currentTimeMillis() - startTime);
        if ((leftTime < 0) || testFinished) {
            timer.stop();
            dialog.dispose();
        }
        testTimeoutLabel.setText(String.format(
            "Test timeout: %s", convertMillisToTimeStr(leftTime)));
    });
    timer.start();

    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);

    final JButton testButton = new JButton("Start Test");
    final JButton passButton = new JButton("PASS");
    final JButton failButton = new JButton("FAIL");
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        new Thread(() -> {
            try {
                doTest();

                SwingUtilities.invokeLater(() -> {
                    passButton.setEnabled(true);
                    failButton.setEnabled(true);
                });
            } catch (Throwable t) {
                t.printStackTrace();
                dialog.dispose();
                fail("Exception occurred in a thread executing the test.");
            }
        }).start();
    });
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        dialog.dispose();
        pass();
    });
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        dialog.dispose();
        fail("Printed texts are not aligned as shown in console");
    });

    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel labelPanel = new JPanel(new FlowLayout());
    labelPanel.add(testTimeoutLabel);
    mainPanel.add(labelPanel, BorderLayout.NORTH);
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);

    dialog.pack();
    dialog.setVisible(true);
}
 
Example 20
Source File: WrongPaperPrintingTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void createAndShowTestDialog() {
    String description =
        " To run this test it is required to have a virtual PDF\r\n" +
        " printer or any other printer supporting A5 paper size.\r\n" +
        "\r\n" +
        " 1. Verify that NOT A5 paper size is set as default for the\r\n" +
        " printer to be used.\r\n" +
        " 2. Click on \"Start Test\" button.\r\n" +
        " 3. In the shown print dialog select the printer and click\r\n" +
        " on \"Print\" button.\r\n" +
        " 4. Verify that a page with a drawn rectangle is printed on\r\n" +
        " a paper of A5 size which is (5.8 x 8.3 in) or\r\n" +
        " (148 x 210 mm).\r\n" +
        "\r\n" +
        " If the printed page size is correct, click on \"PASS\"\r\n" +
        " button, otherwise click on \"FAIL\" button.";

    final JDialog dialog = new JDialog();
    dialog.setTitle("WrongPaperPrintingTest");
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            dialog.dispose();
            fail("Main dialog was closed.");
        }
    });

    final JLabel testTimeoutLabel = new JLabel(String.format(
        "Test timeout: %s", convertMillisToTimeStr(testTimeout)));
    final long startTime = System.currentTimeMillis();
    final Timer timer = new Timer(0, null);
    timer.setDelay(1000);
    timer.addActionListener((e) -> {
        int leftTime = testTimeout - (int)(System.currentTimeMillis() - startTime);
        if ((leftTime < 0) || testFinished) {
            timer.stop();
            dialog.dispose();
        }
        testTimeoutLabel.setText(String.format(
            "Test timeout: %s", convertMillisToTimeStr(leftTime)));
    });
    timer.start();

    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);

    final JButton testButton = new JButton("Start Test");
    final JButton passButton = new JButton("PASS");
    final JButton failButton = new JButton("FAIL");
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        new Thread(() -> {
            try {
                doTest();

                SwingUtilities.invokeLater(() -> {
                    passButton.setEnabled(true);
                    failButton.setEnabled(true);
                });
            } catch (Throwable t) {
                t.printStackTrace();
                dialog.dispose();
                fail("Exception occurred in a thread executing the test.");
            }
        }).start();
    });
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        dialog.dispose();
        pass();
    });
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        dialog.dispose();
        fail("Size of a printed page is wrong.");
    });

    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel labelPanel = new JPanel(new FlowLayout());
    labelPanel.add(testTimeoutLabel);
    mainPanel.add(labelPanel, BorderLayout.NORTH);
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);

    dialog.pack();
    dialog.setVisible(true);
}