This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 82647
Collapse All | Expand All

(-)core/output2/nbproject/project.xml (-18 / +18 lines)
Lines 22-27 Link Here
22
    <configuration>
22
    <configuration>
23
        <data xmlns="http://www.netbeans.org/ns/nb-module-project/2">
23
        <data xmlns="http://www.netbeans.org/ns/nb-module-project/2">
24
            <code-name-base>org.netbeans.core.output2</code-name-base>
24
            <code-name-base>org.netbeans.core.output2</code-name-base>
25
            <test-dependencies>
26
                <test-type>
27
                    <name>unit</name>
28
                    <test-dependency>
29
                        <code-name-base>org.netbeans.core.output2</code-name-base>
30
                        <recursive/>
31
                        <compile-dependency/>
32
                    </test-dependency>
33
                    <test-dependency>
34
                        <code-name-base>org.openide.nodes</code-name-base>
35
                        <compile-dependency/>
36
                    </test-dependency>
37
                </test-type>
38
                <test-type>
39
                    <name>qa-functional</name>
40
                </test-type>
41
            </test-dependencies>
25
            <module-dependencies>
42
            <module-dependencies>
26
                <dependency>
43
                <dependency>
27
                    <code-name-base>org.openide.actions</code-name-base>
44
                    <code-name-base>org.openide.actions</code-name-base>
Lines 44-50 Link Here
44
                    <build-prerequisite/>
61
                    <build-prerequisite/>
45
                    <compile-dependency/>
62
                    <compile-dependency/>
46
                    <run-dependency>
63
                    <run-dependency>
47
                        <specification-version>1.11</specification-version>
64
                        <implementation-version/>
48
                    </run-dependency>
65
                    </run-dependency>
49
                </dependency>
66
                </dependency>
50
                <dependency>
67
                <dependency>
Lines 72-94 Link Here
72
                    </run-dependency>
89
                    </run-dependency>
73
                </dependency>
90
                </dependency>
74
            </module-dependencies>
91
            </module-dependencies>
75
          <test-dependencies>
76
              <test-type>
77
                  <name>unit</name>
78
                  <test-dependency>
79
                      <code-name-base>org.netbeans.core.output2</code-name-base>
80
                      <recursive/>
81
                      <compile-dependency/>
82
                  </test-dependency>
83
                  <test-dependency>
84
                      <code-name-base>org.openide.nodes</code-name-base>
85
                      <compile-dependency/>
86
                  </test-dependency>
87
              </test-type>
88
              <test-type>
89
                  <name>qa-functional</name>
90
              </test-type>
91
            </test-dependencies>
92
            <public-packages/>
92
            <public-packages/>
93
        </data>
93
        </data>
94
    </configuration>
94
    </configuration>
(-)core/output2/src/org/netbeans/core/output2/AbstractLines.java (-1 / +22 lines)
Lines 31-44 Link Here
31
import java.util.regex.Pattern;
31
import java.util.regex.Pattern;
32
import javax.swing.event.ChangeEvent;
32
import javax.swing.event.ChangeEvent;
33
import javax.swing.event.ChangeListener;
33
import javax.swing.event.ChangeListener;
34
import org.netbeans.modules.openide.io.OutputScrollHandler;
35
import org.netbeans.modules.openide.io.ScrollerAccessor;
34
import org.openide.util.Exceptions;
36
import org.openide.util.Exceptions;
35
import org.openide.util.Mutex;
37
import org.openide.util.Mutex;
36
import org.openide.windows.OutputListener;
38
import org.openide.windows.OutputListener;
39
import org.openide.windows.OutputScroller;
37
40
38
/**
41
/**
39
 * Abstract Lines implementation with handling for getLine wrap calculations, etc.
42
 * Abstract Lines implementation with handling for getLine wrap calculations, etc.
40
 */
43
 */
41
abstract class AbstractLines implements Lines, Runnable {
44
abstract class AbstractLines implements Lines, Runnable, OutputScrollHandler {
42
    /** A collections-like lineStartList that maps file positions to getLine numbers */
45
    /** A collections-like lineStartList that maps file positions to getLine numbers */
43
    IntList lineStartList;
46
    IntList lineStartList;
44
    /** Maps output listeners to the lines they are associated with */
47
    /** Maps output listeners to the lines they are associated with */
Lines 513-518 Link Here
513
            if (important) {
516
            if (important) {
514
                importantLines.add(line);
517
                importantLines.add(line);
515
            }
518
            }
519
            if (l instanceof OutputScroller) {
520
                ScrollerAccessor.assignHandler((OutputScroller) l, this);
521
            }
516
        }
522
        }
517
    }
523
    }
518
    
524
    
Lines 859-863 Link Here
859
865
860
    public String toString() {
866
    public String toString() {
861
        return lineStartList.toString();
867
        return lineStartList.toString();
868
    }
869
    
870
    public void requestScroll(OutputScroller scroller) {
871
        //Safe cast - we are not handling anything else
872
        OutputListener l = (OutputListener) scroller;
873
        int[] lns = this.linesToListeners.getKeys();
874
        for (int i = 0; i < lns.length; i++) {
875
            OutputListener check = (OutputListener) linesToListeners.get(lns[i]);
876
            if (check == l) {
877
                getIO().post(new IOEvent(getIO(), IOEvent.CMD_SCROLL, 
878
                        new Integer(lns[i])));
879
                return;
880
            }
881
        }
882
        throw new IllegalArgumentException ("No known line for " + scroller);
862
    }
883
    }
863
}
884
}
(-)core/output2/src/org/netbeans/core/output2/Controller.java (+9 lines)
Lines 1044-1049 Link Here
1044
        OutWriter out = io.out();
1044
        OutWriter out = io.out();
1045
1045
1046
        switch (command) {
1046
        switch (command) {
1047
            case IOEvent.CMD_SCROLL :
1048
                int line = ((Integer) data).intValue();
1049
                scrollTo (win, tab, line);
1050
                break;
1047
            case IOEvent.CMD_CREATE :
1051
            case IOEvent.CMD_CREATE :
1048
                createOutputTab(win, io, io.isFocusTaken(), value);
1052
                createOutputTab(win, io, io.isFocusTaken(), value);
1049
                break;
1053
                break;
Lines 1410-1415 Link Here
1410
        if (in != null) {
1414
        if (in != null) {
1411
            in.eof();
1415
            in.eof();
1412
        }
1416
        }
1417
    }
1418
1419
    private void scrollTo(OutputWindow win, OutputTab tab, int line) {
1420
        win.setSelectedTab(tab);
1421
        tab.scrollTo (line);
1413
    }
1422
    }
1414
}
1423
}
1415
1424
(-)core/output2/src/org/netbeans/core/output2/IOEvent.java (-1 / +9 lines)
Lines 108-113 Link Here
108
    static final int CMD_DETACH = 11;
108
    static final int CMD_DETACH = 11;
109
    
109
    
110
    /**
110
    /**
111
     * Used by OutputScroller callback to request that the output window scroll
112
     * to a particular location.
113
     */ 
114
    static final int CMD_SCROLL = 12;
115
    
116
    /**
111
     * Array of IDs for checking legal values and generating a string representing the event.
117
     * Array of IDs for checking legal values and generating a string representing the event.
112
     */
118
     */
113
    private static final int[] IDS = new int[] {
119
    private static final int[] IDS = new int[] {
Lines 123-128 Link Here
123
        CMD_RESET,
129
        CMD_RESET,
124
        CMD_SET_TOOLBAR_ACTIONS,
130
        CMD_SET_TOOLBAR_ACTIONS,
125
        CMD_DETACH,
131
        CMD_DETACH,
132
        CMD_SCROLL,
126
    };
133
    };
127
134
128
    /**
135
    /**
Lines 140-146 Link Here
140
        "STREAM_CLOSED", //NOI18N
147
        "STREAM_CLOSED", //NOI18N
141
        "RESET", //NOI18N
148
        "RESET", //NOI18N
142
        "SET_TOOLBAR_ACTIONS", //NOI18N
149
        "SET_TOOLBAR_ACTIONS", //NOI18N
143
        "DETACH"  //NOI18N
150
        "DETACH",  //NOI18N
151
        "SCROLL",  //NOI18N
144
    };
152
    };
145
153
146
    /**
154
    /**
(-)core/output2/src/org/netbeans/core/output2/Lines.java (+2 lines)
Lines 290-293 Link Here
290
     * @return True if there is still an open stream which may write to the backing storage and no error has occured
290
     * @return True if there is still an open stream which may write to the backing storage and no error has occured
291
     */
291
     */
292
    boolean isGrowing();
292
    boolean isGrowing();
293
    
294
    NbIO getIO();
293
}
295
}
(-)core/output2/src/org/netbeans/core/output2/OutWriter.java (+4 lines)
Lines 569-573 Link Here
569
        protected void handleException (Exception e) {
569
        protected void handleException (Exception e) {
570
            OutWriter.this.handleException(e);
570
            OutWriter.this.handleException(e);
571
        }
571
        }
572
        
573
        public NbIO getIO() {
574
            return OutWriter.this.owner;
575
        }
572
    }
576
    }
573
}
577
}
(-)core/output2/src/org/netbeans/core/output2/ui/AbstractOutputTab.java (-1 / +4 lines)
Lines 286-290 Link Here
286
        getOutputPane().lockScroll();
286
        getOutputPane().lockScroll();
287
        getOutputPane().ensureCaretPosition();
287
        getOutputPane().ensureCaretPosition();
288
    }
288
    }
289
289
    
290
    public void scrollTo (int line) {
291
        getOutputPane().sendCaretToLine(line, true);
292
    }
290
}
293
}
(-)core/output2/test/unit/src/org/netbeans/core/output2/ScrollerTest.java (+106 lines)
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
}

Return to bug 82647