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

(-)editor.fold.nbui/src/org/netbeans/modules/editor/fold/ui/CodeFoldingSideBar.java (-34 / +71 lines)
Lines 44-50 Link Here
44
44
45
package org.netbeans.modules.editor.fold.ui;
45
package org.netbeans.modules.editor.fold.ui;
46
46
47
import java.awt.BasicStroke;
48
import java.awt.Color;
47
import java.awt.Color;
49
import java.awt.Container;
48
import java.awt.Container;
50
import java.awt.Dimension;
49
import java.awt.Dimension;
Lines 54-60 Link Here
54
import java.awt.Graphics2D;
53
import java.awt.Graphics2D;
55
import java.awt.Point;
54
import java.awt.Point;
56
import java.awt.Rectangle;
55
import java.awt.Rectangle;
57
import java.awt.Stroke;
58
import java.awt.event.MouseAdapter;
56
import java.awt.event.MouseAdapter;
59
import java.awt.event.MouseEvent;
57
import java.awt.event.MouseEvent;
60
import java.util.ArrayList;
58
import java.util.ArrayList;
Lines 234-250 Link Here
234
     */
232
     */
235
    private static final int NO_MOUSE_POINT = -1;
233
    private static final int NO_MOUSE_POINT = -1;
236
    
234
    
237
    /**
238
     * Stroke used to draw inactive (regular) fold outlines.
239
     */
240
    private static Stroke LINE_DASHED = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 
241
            1f, new float[] { 1f, 1f }, 0f);
242
    
243
    /**
244
     * Stroke used to draw outlines for 'active' fold
245
     */
246
    private static final Stroke LINE_BOLD = new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER);
247
    
248
    private final Preferences prefs;
235
    private final Preferences prefs;
249
    private final PreferenceChangeListener prefsListener = new PreferenceChangeListener() {
236
    private final PreferenceChangeListener prefsListener = new PreferenceChangeListener() {
250
        public void preferenceChange(PreferenceChangeEvent evt) {
237
        public void preferenceChange(PreferenceChangeEvent evt) {
Lines 354-359 Link Here
354
        });
341
        });
355
    }
342
    }
356
    
343
    
344
    /**
345
     * Compares the brightness of colors regarding the HSB color model.
346
     *
347
     * @param colorA
348
     * @param colorB
349
     * @return the value {@code 0} if the brightness of {@code colorA} is equal
350
     *         to the brightness of {@code colorB}; a value less than {@code 0}
351
     *         if {@code colorA} is darker than {@code colorB}; and a value
352
     *         greater than {@code 0} if {@code colorA} is brighter than
353
     *         {@code colorB}.
354
     */
355
    private int compareBrightness(Color colorA, Color colorB) {
356
        if (null == colorA) {
357
            return -1;
358
        }
359
        if (null == colorB) {
360
            return -1;
361
        }
362
        if (colorA.equals(colorB)) {
363
            return 0;
364
        }
365
        float brightnessA = Color.RGBtoHSB(colorA.getRed(), colorA.getGreen(), colorA.getBlue(), null)[2];
366
        float brightnessB = Color.RGBtoHSB(colorB.getRed(), colorB.getGreen(), colorB.getBlue(), null)[2];
367
        return Float.compare(brightnessA, brightnessB);
368
    }
369
    
370
    /**
371
     * Get a brightened color used for highlighting. If the color cannot be brightened, then a darkened color will be returned.
372
     *
373
     * @param color
374
     * @param bg
375
     * @return
376
     */
377
    private Color getHighlightedColor(Color color) {
378
        Color newColor = color.brighter().brighter();
379
        if (compareBrightness(newColor, color) <= 0) {
380
            //cannot make it brighter? so make it darker
381
            newColor = color.darker().darker();
382
        }
383
        return newColor;
384
    }
385
    
357
    private void updatePreferredSize() {
386
    private void updatePreferredSize() {
358
        // do not show at all, if there are no providers registered.
387
        // do not show at all, if there are no providers registered.
359
        if (enabled && !alreadyPresent) {
388
        if (enabled && !alreadyPresent) {
Lines 714-733 Link Here
714
        return result;
743
        return result;
715
    }
744
    }
716
    
745
    
717
    /**
718
     * Returns stroke appropriate for painting (in)active outlines
719
     * @param s the default stroke
720
     * @param active true for active outlines
721
     * @return value of 's' or a Stroke which should be used to paint the outline.
722
     */
723
    private static Stroke getStroke(Stroke s, boolean active) {
724
        if (active) {
725
            return LINE_BOLD;
726
        } else {
727
            return s;
728
        }
729
    }
730
    
731
    private boolean traverseBackwards(Fold f, BaseDocument doc, BaseTextUI btui, int lowerBoundary, int upperBoundary, int level, NavigableMap<Integer, PaintInfo> infos) throws BadLocationException {
746
    private boolean traverseBackwards(Fold f, BaseDocument doc, BaseTextUI btui, int lowerBoundary, int upperBoundary, int level, NavigableMap<Integer, PaintInfo> infos) throws BadLocationException {
732
//        System.out.println("~~~ traverseBackwards<" + lowerBoundary + ", " + upperBoundary
747
//        System.out.println("~~~ traverseBackwards<" + lowerBoundary + ", " + upperBoundary
733
//                + ">: fold=<" + f.getStartOffset() + ", " + f.getEndOffset() + "> "
748
//                + ">: fold=<" + f.getStartOffset() + ", " + f.getEndOffset() + "> "
Lines 1015-1024 Link Here
1015
    }
1030
    }
1016
    
1031
    
1017
    private void drawFoldLine(Graphics2D g2d, boolean active, int x1, int y1, int x2, int y2) {
1032
    private void drawFoldLine(Graphics2D g2d, boolean active, int x1, int y1, int x2, int y2) {
1018
        Stroke origStroke = g2d.getStroke();
1033
        Color backup = g2d.getColor();
1019
        g2d.setStroke(getStroke(origStroke, active));
1034
        if (active) {
1035
            //highlight focused line
1036
            Color highlightedColor = getHighlightedColor(g2d.getColor());
1037
            if (null != highlightedColor) {
1038
                g2d.setColor(highlightedColor);
1039
            }
1040
        }
1020
        g2d.drawLine(x1, y1, x2, y2);
1041
        g2d.drawLine(x1, y1, x2, y2);
1021
        g2d.setStroke(origStroke);
1042
        g2d.setColor(backup);
1022
    }
1043
    }
1023
    
1044
    
1024
    protected @Override void paintComponent(Graphics g) {
1045
    protected @Override void paintComponent(Graphics g) {
Lines 1077-1103 Link Here
1077
                }
1098
                }
1078
1099
1079
                if (paintInfo.hasSign()) {
1100
                if (paintInfo.hasSign()) {
1101
		    Color backup = null;
1102
		    if (paintInfo.signActive || paintInfo.lineInActive) {
1103
                        //highlight focused sign
1104
			backup = g2d.getColor();
1105
			Color highlightedColor = getHighlightedColor(g2d.getColor());
1106
                        if (null != highlightedColor) {
1107
                            g2d.setColor(highlightedColor);
1108
                        }
1109
		    }
1110
                    
1080
                    g.drawRect(markX, markY, markSize, markSize);
1111
                    g.drawRect(markX, markY, markSize, markSize);
1112
                    //minus sign
1081
                    g.drawLine(plusGap + markX, markY + halfMarkSize, markSize + markX - plusGap, markY + halfMarkSize);
1113
                    g.drawLine(plusGap + markX, markY + halfMarkSize, markSize + markX - plusGap, markY + halfMarkSize);
1082
                    String opStr = (paintOperation == PAINT_MARK) ? "PAINT_MARK" : "SINGLE_PAINT_MARK"; // NOI18N
1114
                    String opStr = (paintOperation == PAINT_MARK) ? "PAINT_MARK" : "SINGLE_PAINT_MARK"; // NOI18N
1083
                    if (isFolded) {
1115
                    if (isFolded) {
1084
                        if (LOG.isLoggable(Level.FINER)) {
1116
                        if (LOG.isLoggable(Level.FINER)) {
1085
                            LOG.finer(opStr + ": folded; y=" + y + ", PI:" + paintInfo + "\n"); // NOI18N
1117
                            LOG.finer(opStr + ": folded; y=" + y + ", PI:" + paintInfo + "\n"); // NOI18N
1086
                        }
1118
                        }
1119
                        //vertical part of plus sign
1087
                        g.drawLine(lineX, markY + plusGap, lineX, markY + markSize - plusGap);
1120
                        g.drawLine(lineX, markY + plusGap, lineX, markY + markSize - plusGap);
1088
                    }
1121
                    }
1122
		    if (null != backup) {
1123
			g2d.setColor(backup);
1124
		    }
1125
1089
                    if (paintOperation != SINGLE_PAINT_MARK) {
1126
                    if (paintOperation != SINGLE_PAINT_MARK) {
1090
                        if (LOG.isLoggable(Level.FINER)) {
1127
                        if (LOG.isLoggable(Level.FINER)) {
1091
                            LOG.finer(opStr + ": non-single; y=" + y + ", PI:" + paintInfo + "\n"); // NOI18N
1128
                            LOG.finer(opStr + ": non-single; y=" + y + ", PI:" + paintInfo + "\n"); // NOI18N
1092
                        }
1129
                        }
1093
                    }
1130
                    }
1094
                    if (paintInfo.hasLineIn()) { //[PENDING]
1131
                    if (paintInfo.hasLineIn()) { //[PENDING]
1095
                        drawFoldLine(g2d, paintInfo.lineInActive, lineX, y, lineX, markY);
1132
                        drawFoldLine(g2d, paintInfo.lineInActive, lineX, y, lineX, markY - 1);
1096
                    }
1133
                    }
1097
                    if (paintInfo.hasLineOut()) {
1134
                    if (paintInfo.hasLineOut()) {
1098
                        // This is an error in case there's a next paint info at the same y which is an end mark
1135
                        // This is an error in case there's a next paint info at the same y which is an end mark
1099
                        // for this mark (it must be cleared explicitly).
1136
                        // for this mark (it must be cleared explicitly).
1100
                        drawFoldLine(g2d, paintInfo.lineOutActive, lineX, markY + markSize, lineX, y + height);
1137
                        drawFoldLine(g2d, paintInfo.lineOutActive, lineX, markY + markSize + 1, lineX, y + height);
1101
                    }
1138
                    }
1102
                    visibleMarks.add(new Mark(markX, markY, markSize, isFolded));
1139
                    visibleMarks.add(new Mark(markX, markY, markSize, isFolded));
1103
1140
Lines 1113-1124 Link Here
1113
                    }
1150
                    }
1114
                    if (previousInfo == null || y != previousInfo.getPaintY()) {
1151
                    if (previousInfo == null || y != previousInfo.getPaintY()) {
1115
                        drawFoldLine(g2d, paintInfo.lineInActive, lineX, y, lineX, y + height / 2);
1152
                        drawFoldLine(g2d, paintInfo.lineInActive, lineX, y, lineX, y + height / 2);
1116
                        drawFoldLine(g2d, paintInfo.signActive, lineX, y + height / 2, lineX + halfMarkSize, y + height / 2);
1153
                        drawFoldLine(g2d, paintInfo.signActive, lineX + 1, y + height / 2, lineX + halfMarkSize, y + height / 2);
1117
                        if (paintInfo.getInnerLevel() > 0) {//[PENDING]
1154
                        if (paintInfo.getInnerLevel() > 0) {//[PENDING]
1118
                            if (LOG.isLoggable(Level.FINER)) {
1155
                            if (LOG.isLoggable(Level.FINER)) {
1119
                                LOG.finer("  PAINT middle-line\n"); // NOI18N
1156
                                LOG.finer("  PAINT middle-line\n"); // NOI18N
1120
                            }
1157
                            }
1121
                            drawFoldLine(g2d, paintInfo.lineOutActive, lineX, y + height / 2, lineX, y + height);
1158
                            drawFoldLine(g2d, paintInfo.lineOutActive, lineX, (y + height / 2) + 1, lineX, y + height);
1122
                        }
1159
                        }
1123
                    }
1160
                    }
1124
                }
1161
                }
(-)editor.lib/src/org/netbeans/editor/CodeFoldingSideBar.java (-34 / +71 lines)
Lines 44-50 Link Here
44
44
45
package org.netbeans.editor;
45
package org.netbeans.editor;
46
46
47
import java.awt.BasicStroke;
48
import java.awt.Color;
47
import java.awt.Color;
49
import java.awt.Dimension;
48
import java.awt.Dimension;
50
import java.awt.Font;
49
import java.awt.Font;
Lines 53-59 Link Here
53
import java.awt.Graphics2D;
52
import java.awt.Graphics2D;
54
import java.awt.Point;
53
import java.awt.Point;
55
import java.awt.Rectangle;
54
import java.awt.Rectangle;
56
import java.awt.Stroke;
57
import java.awt.event.MouseAdapter;
55
import java.awt.event.MouseAdapter;
58
import java.awt.event.MouseEvent;
56
import java.awt.event.MouseEvent;
59
import java.util.ArrayList;
57
import java.util.ArrayList;
Lines 220-238 Link Here
220
     */
218
     */
221
    private static final int NO_MOUSE_POINT = -1;
219
    private static final int NO_MOUSE_POINT = -1;
222
    
220
    
223
    /**
224
     * Stroke used to draw inactive (regular) fold outlines.
225
     */
226
    private static Stroke LINE_DASHED = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 
227
            1f, new float[] { 1f, 1f }, 0f);
228
    
229
    private boolean alreadyPresent;
221
    private boolean alreadyPresent;
230
    
222
    
231
    /**
232
     * Stroke used to draw outlines for 'active' fold
233
     */
234
    private static final Stroke LINE_BOLD = new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER);
235
    
236
    private final Preferences prefs;
223
    private final Preferences prefs;
237
    private final PreferenceChangeListener prefsListener = new PreferenceChangeListener() {
224
    private final PreferenceChangeListener prefsListener = new PreferenceChangeListener() {
238
        public void preferenceChange(PreferenceChangeEvent evt) {
225
        public void preferenceChange(PreferenceChangeEvent evt) {
Lines 312-317 Link Here
312
        });
299
        });
313
    }
300
    }
314
    
301
    
302
    /**
303
     * Compares the brightness of colors regarding the HSB color model.
304
     *
305
     * @param colorA
306
     * @param colorB
307
     * @return the value {@code 0} if the brightness of {@code colorA} is equal
308
     *         to the brightness of {@code colorB}; a value less than {@code 0}
309
     *         if {@code colorA} is darker than {@code colorB}; and a value
310
     *         greater than {@code 0} if {@code colorA} is brighter than
311
     *         {@code colorB}.
312
     */
313
    private int compareBrightness(Color colorA, Color colorB) {
314
        if (null == colorA) {
315
            return -1;
316
        }
317
        if (null == colorB) {
318
            return -1;
319
        }
320
        if (colorA.equals(colorB)) {
321
            return 0;
322
        }
323
        float brightnessA = Color.RGBtoHSB(colorA.getRed(), colorA.getGreen(), colorA.getBlue(), null)[2];
324
        float brightnessB = Color.RGBtoHSB(colorB.getRed(), colorB.getGreen(), colorB.getBlue(), null)[2];
325
        return Float.compare(brightnessA, brightnessB);
326
    }
327
    
328
    /**
329
     * Get a brightened color used for highlighting. If the color cannot be brightened, then a darkened color will be returned.
330
     *
331
     * @param color
332
     * @param bg
333
     * @return
334
     */
335
    private Color getHighlightedColor(Color color) {
336
        Color newColor = color.brighter().brighter();
337
        if (compareBrightness(newColor, color) <= 0) {
338
            //cannot make it brighter? so make it darker
339
            newColor = color.darker().darker();
340
        }
341
        return newColor;
342
    }
343
    
315
    private void updatePreferredSize() {
344
    private void updatePreferredSize() {
316
        if (enabled && !alreadyPresent) {
345
        if (enabled && !alreadyPresent) {
317
            setPreferredSize(new Dimension(getColoring().getFont().getSize(), component.getHeight()));
346
            setPreferredSize(new Dimension(getColoring().getFont().getSize(), component.getHeight()));
Lines 642-661 Link Here
642
        return result;
671
        return result;
643
    }
672
    }
644
    
673
    
645
    /**
646
     * Returns stroke appropriate for painting (in)active outlines
647
     * @param s the default stroke
648
     * @param active true for active outlines
649
     * @return value of 's' or a Stroke which should be used to paint the outline.
650
     */
651
    private static Stroke getStroke(Stroke s, boolean active) {
652
        if (active) {
653
            return LINE_BOLD;
654
        } else {
655
            return s;
656
        }
657
    }
658
    
659
    private boolean traverseBackwards(Fold f, BaseDocument doc, BaseTextUI btui, int lowerBoundary, int upperBoundary, int level, NavigableMap<Integer, PaintInfo> infos) throws BadLocationException {
674
    private boolean traverseBackwards(Fold f, BaseDocument doc, BaseTextUI btui, int lowerBoundary, int upperBoundary, int level, NavigableMap<Integer, PaintInfo> infos) throws BadLocationException {
660
//        System.out.println("~~~ traverseBackwards<" + lowerBoundary + ", " + upperBoundary
675
//        System.out.println("~~~ traverseBackwards<" + lowerBoundary + ", " + upperBoundary
661
//                + ">: fold=<" + f.getStartOffset() + ", " + f.getEndOffset() + "> "
676
//                + ">: fold=<" + f.getStartOffset() + ", " + f.getEndOffset() + "> "
Lines 932-941 Link Here
932
    }
947
    }
933
    
948
    
934
    private void drawFoldLine(Graphics2D g2d, boolean active, int x1, int y1, int x2, int y2) {
949
    private void drawFoldLine(Graphics2D g2d, boolean active, int x1, int y1, int x2, int y2) {
935
        Stroke origStroke = g2d.getStroke();
950
        Color backup = g2d.getColor();
936
        g2d.setStroke(getStroke(origStroke, active));
951
        if (active) {
952
            //highlight focused line
953
            Color highlightedColor = getHighlightedColor(g2d.getColor());
954
            if (null != highlightedColor) {
955
                g2d.setColor(highlightedColor);
956
            }
957
        }
937
        g2d.drawLine(x1, y1, x2, y2);
958
        g2d.drawLine(x1, y1, x2, y2);
938
        g2d.setStroke(origStroke);
959
        g2d.setColor(backup);
939
    }
960
    }
940
    
961
    
941
    protected @Override void paintComponent(Graphics g) {
962
    protected @Override void paintComponent(Graphics g) {
Lines 994-1020 Link Here
994
                }
1015
                }
995
1016
996
                if (paintInfo.hasSign()) {
1017
                if (paintInfo.hasSign()) {
1018
		    Color backup = null;
1019
		    if (paintInfo.signActive || paintInfo.lineInActive) {
1020
                        //highlight focused sign
1021
			backup = g2d.getColor();
1022
			Color highlightedColor = getHighlightedColor(g2d.getColor());
1023
                        if (null != highlightedColor) {
1024
                            g2d.setColor(highlightedColor);
1025
                        }
1026
		    }
1027
                    
997
                    g.drawRect(markX, markY, markSize, markSize);
1028
                    g.drawRect(markX, markY, markSize, markSize);
1029
                    //minus sign
998
                    g.drawLine(plusGap + markX, markY + halfMarkSize, markSize + markX - plusGap, markY + halfMarkSize);
1030
                    g.drawLine(plusGap + markX, markY + halfMarkSize, markSize + markX - plusGap, markY + halfMarkSize);
999
                    String opStr = (paintOperation == PAINT_MARK) ? "PAINT_MARK" : "SINGLE_PAINT_MARK"; // NOI18N
1031
                    String opStr = (paintOperation == PAINT_MARK) ? "PAINT_MARK" : "SINGLE_PAINT_MARK"; // NOI18N
1000
                    if (isFolded) {
1032
                    if (isFolded) {
1001
                        if (LOG.isLoggable(Level.FINE)) {
1033
                        if (LOG.isLoggable(Level.FINE)) {
1002
                            LOG.fine(opStr + ": folded; y=" + y + ", PI:" + paintInfo + "\n"); // NOI18N
1034
                            LOG.fine(opStr + ": folded; y=" + y + ", PI:" + paintInfo + "\n"); // NOI18N
1003
                        }
1035
                        }
1036
                        //vertical part of plus sign
1004
                        g.drawLine(lineX, markY + plusGap, lineX, markY + markSize - plusGap);
1037
                        g.drawLine(lineX, markY + plusGap, lineX, markY + markSize - plusGap);
1005
                    }
1038
                    }
1039
		    if (null != backup) {
1040
			g2d.setColor(backup);
1041
		    }
1042
1006
                    if (paintOperation != SINGLE_PAINT_MARK) {
1043
                    if (paintOperation != SINGLE_PAINT_MARK) {
1007
                        if (LOG.isLoggable(Level.FINE)) {
1044
                        if (LOG.isLoggable(Level.FINE)) {
1008
                            LOG.fine(opStr + ": non-single; y=" + y + ", PI:" + paintInfo + "\n"); // NOI18N
1045
                            LOG.fine(opStr + ": non-single; y=" + y + ", PI:" + paintInfo + "\n"); // NOI18N
1009
                        }
1046
                        }
1010
                    }
1047
                    }
1011
                    if (paintInfo.hasLineIn()) { //[PENDING]
1048
                    if (paintInfo.hasLineIn()) { //[PENDING]
1012
                        drawFoldLine(g2d, paintInfo.lineInActive, lineX, y, lineX, markY);
1049
                        drawFoldLine(g2d, paintInfo.lineInActive, lineX, y, lineX, markY - 1);
1013
                    }
1050
                    }
1014
                    if (paintInfo.hasLineOut()) {
1051
                    if (paintInfo.hasLineOut()) {
1015
                        // This is an error in case there's a next paint info at the same y which is an end mark
1052
                        // This is an error in case there's a next paint info at the same y which is an end mark
1016
                        // for this mark (it must be cleared explicitly).
1053
                        // for this mark (it must be cleared explicitly).
1017
                        drawFoldLine(g2d, paintInfo.lineOutActive, lineX, markY + markSize, lineX, y + height);
1054
                        drawFoldLine(g2d, paintInfo.lineOutActive, lineX, markY + markSize + 1, lineX, y + height);
1018
                    }
1055
                    }
1019
                    visibleMarks.add(new Mark(markX, markY, markSize, isFolded));
1056
                    visibleMarks.add(new Mark(markX, markY, markSize, isFolded));
1020
1057
Lines 1030-1041 Link Here
1030
                    }
1067
                    }
1031
                    if (previousInfo == null || y != previousInfo.getPaintY()) {
1068
                    if (previousInfo == null || y != previousInfo.getPaintY()) {
1032
                        drawFoldLine(g2d, paintInfo.lineInActive, lineX, y, lineX, y + height / 2);
1069
                        drawFoldLine(g2d, paintInfo.lineInActive, lineX, y, lineX, y + height / 2);
1033
                        drawFoldLine(g2d, paintInfo.signActive, lineX, y + height / 2, lineX + halfMarkSize, y + height / 2);
1070
                        drawFoldLine(g2d, paintInfo.signActive, lineX + 1, y + height / 2, lineX + halfMarkSize, y + height / 2);
1034
                        if (paintInfo.getInnerLevel() > 0) {//[PENDING]
1071
                        if (paintInfo.getInnerLevel() > 0) {//[PENDING]
1035
                            if (LOG.isLoggable(Level.FINE)) {
1072
                            if (LOG.isLoggable(Level.FINE)) {
1036
                                LOG.fine("  PAINT middle-line\n"); // NOI18N
1073
                                LOG.fine("  PAINT middle-line\n"); // NOI18N
1037
                            }
1074
                            }
1038
                            drawFoldLine(g2d, paintInfo.lineOutActive, lineX, y + height / 2, lineX, y + height);
1075
                            drawFoldLine(g2d, paintInfo.lineOutActive, lineX, (y + height / 2) + 1, lineX, y + height);
1039
                        }
1076
                        }
1040
                    }
1077
                    }
1041
                }
1078
                }

Return to bug 262833