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 262163
Collapse All | Expand All

(-)a/lib.terminalemulator/nbproject/project.properties (-1 / +1 lines)
Lines 37-43 Link Here
37
# Contributor(s):
37
# Contributor(s):
38
is.autoload=true
38
is.autoload=true
39
javac.compilerargs=-Xlint -Xlint:-serial
39
javac.compilerargs=-Xlint -Xlint:-serial
40
javac.source=1.7
40
javac.source=1.8
41
javadoc.arch=${basedir}/arch.xml
41
javadoc.arch=${basedir}/arch.xml
42
javadoc.apichanges=${basedir}/apichanges.xml
42
javadoc.apichanges=${basedir}/apichanges.xml
43
nbm.homepage=http://wiki.netbeans.org/TerminalEmulator
43
nbm.homepage=http://wiki.netbeans.org/TerminalEmulator
(-)a/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/Highlight.java (+173 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 */
40
package org.netbeans.lib.terminalemulator;
41
42
import java.awt.Color;
43
import java.awt.Dimension;
44
import java.awt.Graphics;
45
import java.awt.Point;
46
import java.awt.Rectangle;
47
import java.util.Arrays;
48
49
/**
50
 * @author Ilia Gromov
51
 */
52
public class Highlight {
53
54
    private final Term term;
55
    private final State state;
56
57
    private Extent[] highlightExtents = new Extent[0];
58
59
    Highlight(Term term, State state) {
60
        this.term = term;
61
        this.state = state;
62
    }
63
64
    public Extent[] getHighlightExtents() {
65
        Extent[] copy = new Extent[highlightExtents.length];
66
        for (int i = 0; i < highlightExtents.length; i++) {
67
            Extent x = highlightExtents[i];
68
            copy[i] = new Extent(x.begin, x.end);
69
        }
70
        return copy;
71
    }
72
73
    public void setHighlightExtents(Extent[] highlightExtents) {
74
        this.highlightExtents = Arrays.copyOf(highlightExtents, highlightExtents.length);
75
        for (Extent extent : highlightExtents) {
76
            extent.order();
77
        }
78
    }
79
80
    // properties:
81
    private Color color = new Color(230, 230, 255);  // swing color
82
83
    void setColor(Color color) {
84
        this.color = color;
85
    }
86
87
    Color getColor() {
88
        return color;
89
    }
90
91
    private Color xor_color = Color.white;
92
93
    void setXORColor(Color color) {
94
        xor_color = color;
95
    }
96
97
    Color getXORColor() {
98
        return xor_color;
99
    }
100
101
    /**
102
     * Select inside one line Rows and columns are in absolute coords.
103
     */
104
    private void paint(Graphics g, int row, int bcol, int ecol) {
105
106
        // Instead of doing this SHOULD clip the Extent to what's in view
107
        // Row is outside the view
108
        if (row < state.firstx) {
109
            return;
110
        }
111
        if (row > state.firstx + state.rows) {
112
            return;
113
        }
114
115
        // Construct the rectangle we're going to paint
116
        BCoord begin = new BCoord(row, bcol);
117
        BCoord end = new BCoord(row, ecol);
118
119
        begin = term.toViewCoord(begin);
120
        end = term.toViewCoord(end);
121
122
        //Hotfix for issue 40189
123
        if (begin == null || end == null) {
124
            return;
125
        }
126
127
        int lw;		// width of last character in selection
128
        Line l = term.buf().lineAt(row);
129
        lw = l.width(term.metrics(), ecol);
130
131
        Point pbegin = term.toPixel(begin);
132
        Point pend = term.toPixel(end);
133
        pend.y += term.metrics().height;
134
        pend.x += term.metrics().width * lw;	// xterm actually doesn't do this
135
136
        Dimension dim = new Dimension(pend.x - pbegin.x,
137
                pend.y - pbegin.y);
138
        Rectangle rect = new Rectangle(pbegin, dim);
139
140
        if (term.isSelectionXOR()) {
141
            g.setXORMode(xor_color);
142
        } else {
143
            g.setColor(color);
144
        }
145
146
        g.fillRect(rect.x, rect.y, rect.width, rect.height);
147
    }
148
149
    void paint(final Graphics g) {
150
        /*
151
	 * Paint the selection.
152
         */
153
154
        for (Extent x : highlightExtents) {
155
            if (x == null) {
156
                continue;
157
            }
158
            x.order();
159
160
            // DEBUG System.out.println("Sel.paint extent: " + x);	// NOI18N
161
            term.visitLines(x.begin, x.end, true, new LineVisitor() {
162
                public boolean visit(Line l, int row, int bcol, int ecol) {
163
                    paint(g, row, bcol, ecol);
164
                    return true;
165
                }
166
            });
167
        }
168
    }
169
170
    public void clear() {
171
        highlightExtents = new Extent[0];
172
    }
173
}
(-)a/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/Term.java (+21 lines)
Lines 255-260 Link Here
255
255
256
    private State st = new State();
256
    private State st = new State();
257
    private Sel sel = new Sel(this, st);
257
    private Sel sel = new Sel(this, st);
258
    private Highlight highlight = new Highlight(this, st);
259
258
    private transient Ops ops = new OpsImpl();
260
    private transient Ops ops = new OpsImpl();
259
    private int top_margin = 0;		// 0 means default (see topMargin())
261
    private int top_margin = 0;		// 0 means default (see topMargin())
260
    private int bot_margin = 0;
262
    private int bot_margin = 0;
Lines 3198-3203 Link Here
3198
            // draw over this. Lines that are attributed end up doing some
3200
            // draw over this. Lines that are attributed end up doing some
3199
            // redundant work repainting.
3201
            // redundant work repainting.
3200
3202
3203
            highlight.paint(g);
3201
            sel.paint(g);
3204
            sel.paint(g);
3202
        }
3205
        }
3203
3206
Lines 5396-5401 Link Here
5396
        repaint(false);
5399
        repaint(false);
5397
    }
5400
    }
5398
5401
5402
    public Extent[] getHighlightExtents() {
5403
        return highlight.getHighlightExtents();
5404
    }
5405
5406
    public void setHighlightExtents(Extent[] extents) {
5407
        for (Extent extent : extents) {
5408
            extent.begin.clip(buf.nlines(), buf.totalCols(), firsta);
5409
            extent.end.clip(buf.nlines(), buf.totalCols(), firsta);
5410
        }
5411
        highlight.setHighlightExtents(extents);
5412
        repaint(false);
5413
    }
5414
5415
    public void clearHighlight() {
5416
        highlight.clear();
5417
        repaint(false);
5418
    }
5419
5399
    /**
5420
    /**
5400
     * Set whether slections automatically get copied to the systemSelection
5421
     * Set whether slections automatically get copied to the systemSelection
5401
     * when the selection is completed (the button is released).
5422
     * when the selection is completed (the button is released).
(-)a/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/support/HiglightMatchesFindState.java (+122 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 */
40
package org.netbeans.lib.terminalemulator.support;
41
42
import java.util.ArrayList;
43
import java.util.List;
44
import java.util.regex.Matcher;
45
import java.util.regex.Pattern;
46
import org.netbeans.lib.terminalemulator.Coord;
47
import org.netbeans.lib.terminalemulator.Extent;
48
import org.netbeans.lib.terminalemulator.LogicalLineVisitor;
49
import org.netbeans.lib.terminalemulator.Term;
50
51
/**
52
 *
53
 * @author Ilia Gromov
54
 */
55
public class HiglightMatchesFindState implements FindState {
56
57
    private final FindState findState;
58
    private final Term term;
59
60
    public HiglightMatchesFindState(FindState findState, Term term) {
61
        this.findState = findState;
62
        this.term = term;
63
    }
64
65
    @Override
66
    public void setPattern(String pattern) {
67
        findState.setPattern(pattern);
68
    }
69
70
    @Override
71
    public String getPattern() {
72
        return findState.getPattern();
73
    }
74
75
    @Override
76
    public void setVisible(boolean visible) {
77
        findState.setVisible(visible);
78
        if (!visible) {
79
            term.clearHighlight();
80
        }
81
    }
82
83
    @Override
84
    public boolean isVisible() {
85
        return findState.isVisible();
86
    }
87
88
    private void findAll() {
89
        Pattern pattern = Pattern.compile(getPattern(), Pattern.LITERAL);
90
        List<Extent> extents = new ArrayList<>();
91
        term.visitLogicalLines(null, null, new LogicalLineVisitor() {
92
            @Override
93
            public boolean visit(int line, Coord begin, Coord end, String text) {
94
                Matcher matcher = pattern.matcher(text);
95
                while (matcher.find()) {
96
                    Extent extent = term.extentInLogicalLine(begin, matcher.start(), getPattern().length());
97
                    extents.add(extent);
98
                }
99
                return true;
100
            }
101
        });
102
        term.setHighlightExtents(extents.toArray(new Extent[0]));
103
    }
104
105
    @Override
106
    public void next() {
107
        findAll();
108
        findState.next();
109
    }
110
111
    @Override
112
    public void prev() {
113
        findAll();
114
        findState.prev();
115
116
    }
117
118
    @Override
119
    public Status getStatus() {
120
        return findState.getStatus();
121
    }
122
}
(-)a/terminal.nb/src/org/netbeans/modules/terminal/ioprovider/Terminal.java (-1 / +2 lines)
Lines 132-137 Link Here
132
import org.netbeans.lib.terminalemulator.TermAdapter;
132
import org.netbeans.lib.terminalemulator.TermAdapter;
133
import org.netbeans.lib.terminalemulator.TermListener;
133
import org.netbeans.lib.terminalemulator.TermListener;
134
import org.netbeans.lib.terminalemulator.TermStream;
134
import org.netbeans.lib.terminalemulator.TermStream;
135
import org.netbeans.lib.terminalemulator.support.HiglightMatchesFindState;
135
import org.netbeans.modules.terminal.nb.actions.ActionFactory;
136
import org.netbeans.modules.terminal.nb.actions.ActionFactory;
136
import org.netbeans.modules.terminal.nb.actions.PinTabAction;
137
import org.netbeans.modules.terminal.nb.actions.PinTabAction;
137
import org.netbeans.modules.terminal.api.IOResizable;
138
import org.netbeans.modules.terminal.api.IOResizable;
Lines 377-383 Link Here
377
378
378
        this.term.setCursorVisible(true);
379
        this.term.setCursorVisible(true);
379
380
380
        findState = new DefaultFindState(term);
381
        findState = new HiglightMatchesFindState(new DefaultFindState(term), term);
381
382
382
        term.setHorizontallyScrollable(false);
383
        term.setHorizontallyScrollable(false);
383
        term.setEmulation("xterm");	// NOI18N
384
        term.setEmulation("xterm");	// NOI18N

Return to bug 262163