Added
Link Here
|
1 |
/* |
2 |
* The contents of this file are subject to the terms of the Common Development |
3 |
* and Distribution License (the License). You may not use this file except in |
4 |
* compliance with the License. |
5 |
* |
6 |
* You can obtain a copy of the License at http://www.netbeans.org/cddl.html |
7 |
* or http://www.netbeans.org/cddl.txt. |
8 |
* |
9 |
* When distributing Covered Code, include this CDDL Header Notice in each file |
10 |
* and include the License file at http://www.netbeans.org/cddl.txt. |
11 |
* If applicable, add the following below the CDDL Header, with the fields |
12 |
* enclosed by brackets [] replaced by your own identifying information: |
13 |
* "Portions Copyrighted [year] [name of copyright owner]" |
14 |
* |
15 |
* The Original Software is NetBeans. The Initial Developer of the Original |
16 |
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun |
17 |
* Microsystems, Inc. All Rights Reserved. |
18 |
*/ |
19 |
|
20 |
package org.netbeans.core.output2; |
21 |
|
22 |
import java.awt.BorderLayout; |
23 |
import javax.swing.JFrame; |
24 |
import javax.swing.SwingUtilities; |
25 |
import junit.framework.TestCase; |
26 |
import org.netbeans.core.output2.ui.AbstractOutputPane; |
27 |
import org.netbeans.modules.openide.io.ScrollerAccessor; |
28 |
import org.openide.windows.OutputEvent; |
29 |
import org.openide.windows.OutputListener; |
30 |
import org.openide.windows.OutputScroller; |
31 |
|
32 |
/** |
33 |
* Test scrolling behavior when a scroll request is run. |
34 |
* |
35 |
* @author Tim Boudreau |
36 |
*/ |
37 |
public class ScrollerTest extends TestCase { |
38 |
|
39 |
public ScrollerTest(String testName) { |
40 |
super(testName); |
41 |
} |
42 |
|
43 |
public void testScrollBehavior() throws Exception { |
44 |
System.out.println("testScrollBehavior"); |
45 |
Object o = OutputScroller.class; |
46 |
assertNotNull (ScrollerAccessor.DEFAULT); |
47 |
|
48 |
OL ol = new OL(); |
49 |
for (int i = 0; i < 200; i++) { |
50 |
io.getOut().println("This line doesn't have a listener"); |
51 |
if (i == 100) { |
52 |
io.getOut().println ("This line does have a listener", ol, false); |
53 |
} |
54 |
} |
55 |
Thread.currentThread().sleep (1000); |
56 |
win.repaint(); |
57 |
OutputTab tab = win.getTabForIO(io); |
58 |
Thread.currentThread().sleep (1000); |
59 |
AbstractOutputPane pane = tab.getOutputPane(); |
60 |
int currLine = pane.getCaretLine(); |
61 |
boolean val = ol.requestScroll(); |
62 |
assertTrue (val); |
63 |
Thread.currentThread().sleep(1000); |
64 |
win.validate(); |
65 |
win.repaint(); |
66 |
Thread.currentThread().sleep(500); |
67 |
int newCurrLine = pane.getCaretLine(); |
68 |
assertFalse (currLine == newCurrLine); |
69 |
assertEquals (101, newCurrLine); |
70 |
Thread.currentThread().sleep(5000); |
71 |
} |
72 |
|
73 |
private JFrame jf; |
74 |
private OutputWindow win; |
75 |
private NbIOProvider provider; |
76 |
private NbIO io; |
77 |
protected void setUp() throws Exception { |
78 |
jf = new JFrame(); |
79 |
win = new OutputWindow(); |
80 |
OutputWindow.DEFAULT = win; |
81 |
jf.getContentPane().setLayout (new BorderLayout()); |
82 |
jf.getContentPane().add (win, BorderLayout.CENTER); |
83 |
jf.setBounds (20, 20, 700, 300); |
84 |
provider = new NbIOProvider(); |
85 |
io = (NbIO) provider.getIO ("Test", false); |
86 |
SwingUtilities.invokeAndWait (new Shower()); |
87 |
Thread.currentThread().sleep(200); |
88 |
} |
89 |
|
90 |
public class Shower implements Runnable { |
91 |
public void run() { |
92 |
jf.setVisible(true); |
93 |
} |
94 |
} |
95 |
|
96 |
private class OL extends OutputScroller implements OutputListener { |
97 |
public void outputLineSelected(OutputEvent ev) { |
98 |
} |
99 |
|
100 |
public void outputLineAction(OutputEvent ev) { |
101 |
} |
102 |
|
103 |
public void outputLineCleared(OutputEvent ev) { |
104 |
} |
105 |
} |
106 |
} |