Java Code Examples for javax.swing.Timer#setDelay()
The following examples show how to use
javax.swing.Timer#setDelay() .
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: DatabaseScreen.java From open-ig with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onInitialize() { base.setBounds(0, 0, commons.database().background.getWidth(), commons.database().background.getHeight()); expandCollapse = new Timer(0, null); expandCollapse.setDelay(50); highlight = new HashSet<>(); unlight = new HashSet<>(); highlightTimer = new Timer(50, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doHighlight(); } }); prepare(); }
Example 2
Source File: ButtonFactory.java From netbeans with Apache License 2.0 | 5 votes |
private void startTimer() { Timer t = getTimer(); if (t.isRunning()) { return; } repaint(); t.setDelay(400); t.start(); }
Example 3
Source File: BusySpinnerPanel.java From azure-devops-intellij with MIT License | 5 votes |
public BusySpinnerPanel() { timer = new Timer(40, new TimerListener(this)); timer.setRepeats(true); timer.setInitialDelay(40); timer.setDelay(40); start(false); }
Example 4
Source File: MemorySamplerSupport.java From visualvm with GNU General Public License v2.0 | 5 votes |
private String initialize() { int defaultRefresh = GlobalPreferences.sharedInstance().getMonitoredDataPoll() * 1000; processor = getTimer(); heapTimer = new Timer(defaultRefresh, new ActionListener() { public void actionPerformed(ActionEvent e) { heapRefresher.refresh(); } }); heapRefresher = new Refresher() { public final boolean checkRefresh() { if (!heapTimer.isRunning()) return false; return heapView.isShowing(); } public final void doRefresh() { if (heapView.isShowing()) { doRefreshImpl(heapTimer, heapView); } } public final void setRefreshRate(int refreshRate) { heapTimer.setDelay(refreshRate); heapTimer.setInitialDelay(refreshRate); heapTimer.restart(); } public final int getRefreshRate() { return heapTimer.getDelay(); } }; return null; }
Example 5
Source File: TabControlButtonFactory.java From netbeans with Apache License 2.0 | 5 votes |
private void startTimer() { Timer t = getTimer(); if (t.isRunning()) { return; } repaint(); t.setDelay(400); t.start(); }
Example 6
Source File: TestTextPosInPrint.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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 7
Source File: WrongPaperForBookPrintingTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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 8
Source File: WrongPaperPrintingTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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); }
Example 9
Source File: TestTextPosInPrint.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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 10
Source File: WrongPaperPrintingTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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); }
Example 11
Source File: WrongPaperForBookPrintingTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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 12
Source File: TextualDocumentView.java From gate-core with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected void initGUI() { // textView = new JEditorPane(); // textView.setContentType("text/plain"); // textView.setEditorKit(new RawEditorKit()); textView = new JTextArea(); textView.setAutoscrolls(false); textView.setLineWrap(true); textView.setWrapStyleWord(true); // the selection is hidden when the focus is lost for some system // like Linux, so we make sure it stays // it is needed when doing a selection in the search textfield textView.setCaret(new PermanentSelectionCaret()); scroller = new JScrollPane(textView); textView.setText(document.getContent().toString()); textView.getDocument().addDocumentListener(swingDocListener); // display and put the caret at the beginning of the file SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { if(textView.modelToView(0) != null) { textView.scrollRectToVisible(textView.modelToView(0)); } textView.select(0, 0); textView.requestFocus(); } catch(BadLocationException e) { e.printStackTrace(); } } }); // contentPane = new JPanel(new BorderLayout()); // contentPane.add(scroller, BorderLayout.CENTER); // //get a pointer to the annotation list view used to display // //the highlighted annotations // Iterator horizViewsIter = owner.getHorizontalViews().iterator(); // while(annotationListView == null && horizViewsIter.hasNext()){ // DocumentView aView = (DocumentView)horizViewsIter.next(); // if(aView instanceof AnnotationListView) // annotationListView = (AnnotationListView)aView; // } highlightsMinder = new Timer(BLINK_DELAY, new UpdateHighlightsAction()); highlightsMinder.setInitialDelay(HIGHLIGHT_DELAY); highlightsMinder.setDelay(BLINK_DELAY); highlightsMinder.setRepeats(true); highlightsMinder.setCoalesce(true); highlightsMinder.start(); // blinker = new Timer(this.getClass().getCanonicalName() + // "_blink_timer", // true); // final BlinkAction blinkAction = new BlinkAction(); // blinker.scheduleAtFixedRate(new TimerTask(){ // public void run() { // blinkAction.actionPerformed(null); // } // }, 0, BLINK_DELAY); initListeners(); }
Example 13
Source File: WrongPaperForBookPrintingTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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 14
Source File: WrongPaperPrintingTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
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); }
Example 15
Source File: TestTextPosInPrint.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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: WrongPaperForBookPrintingTest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
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 17
Source File: WrongPaperPrintingTest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
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); }
Example 18
Source File: TestSaveFileWithoutPrinter.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
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 19
Source File: TestTextPosInPrint.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
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 |
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); }