# NetBeans IDE HG Patch # This patch file was generated by NetBeans IDE # Following Index: paths are relative to: D:\ws\core-main # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: editor.fold.nbui/src/org/netbeans/modules/editor/fold/ui/CodeFoldingSideBar.java --- editor.fold.nbui/src/org/netbeans/modules/editor/fold/ui/CodeFoldingSideBar.java +++ editor.fold.nbui/src/org/netbeans/modules/editor/fold/ui/CodeFoldingSideBar.java @@ -44,7 +44,6 @@ package org.netbeans.modules.editor.fold.ui; -import java.awt.BasicStroke; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; @@ -54,7 +53,6 @@ import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; -import java.awt.Stroke; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; @@ -234,17 +232,6 @@ */ private static final int NO_MOUSE_POINT = -1; - /** - * Stroke used to draw inactive (regular) fold outlines. - */ - private static Stroke LINE_DASHED = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, - 1f, new float[] { 1f, 1f }, 0f); - - /** - * Stroke used to draw outlines for 'active' fold - */ - private static final Stroke LINE_BOLD = new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER); - private final Preferences prefs; private final PreferenceChangeListener prefsListener = new PreferenceChangeListener() { public void preferenceChange(PreferenceChangeEvent evt) { @@ -354,6 +341,48 @@ }); } + /** + * Compares the brightness of colors regarding the HSB color model. + * + * @param colorA + * @param colorB + * @return the value {@code 0} if the brightness of {@code colorA} is equal + * to the brightness of {@code colorB}; a value less than {@code 0} + * if {@code colorA} is darker than {@code colorB}; and a value + * greater than {@code 0} if {@code colorA} is brighter than + * {@code colorB}. + */ + private int compareBrightness(Color colorA, Color colorB) { + if (null == colorA) { + return -1; + } + if (null == colorB) { + return -1; + } + if (colorA.equals(colorB)) { + return 0; + } + float brightnessA = Color.RGBtoHSB(colorA.getRed(), colorA.getGreen(), colorA.getBlue(), null)[2]; + float brightnessB = Color.RGBtoHSB(colorB.getRed(), colorB.getGreen(), colorB.getBlue(), null)[2]; + return Float.compare(brightnessA, brightnessB); + } + + /** + * Get a brightened color used for highlighting. If the color cannot be brightened, then a darkened color will be returned. + * + * @param color + * @param bg + * @return + */ + private Color getHighlightedColor(Color color) { + Color newColor = color.brighter().brighter(); + if (compareBrightness(newColor, color) <= 0) { + //cannot make it brighter? so make it darker + newColor = color.darker().darker(); + } + return newColor; + } + private void updatePreferredSize() { // do not show at all, if there are no providers registered. if (enabled && !alreadyPresent) { @@ -714,20 +743,6 @@ return result; } - /** - * Returns stroke appropriate for painting (in)active outlines - * @param s the default stroke - * @param active true for active outlines - * @return value of 's' or a Stroke which should be used to paint the outline. - */ - private static Stroke getStroke(Stroke s, boolean active) { - if (active) { - return LINE_BOLD; - } else { - return s; - } - } - private boolean traverseBackwards(Fold f, BaseDocument doc, BaseTextUI btui, int lowerBoundary, int upperBoundary, int level, NavigableMap infos) throws BadLocationException { // System.out.println("~~~ traverseBackwards<" + lowerBoundary + ", " + upperBoundary // + ">: fold=<" + f.getStartOffset() + ", " + f.getEndOffset() + "> " @@ -1015,10 +1030,16 @@ } private void drawFoldLine(Graphics2D g2d, boolean active, int x1, int y1, int x2, int y2) { - Stroke origStroke = g2d.getStroke(); - g2d.setStroke(getStroke(origStroke, active)); + Color backup = g2d.getColor(); + if (active) { + //highlight focused line + Color highlightedColor = getHighlightedColor(g2d.getColor()); + if (null != highlightedColor) { + g2d.setColor(highlightedColor); + } + } g2d.drawLine(x1, y1, x2, y2); - g2d.setStroke(origStroke); + g2d.setColor(backup); } protected @Override void paintComponent(Graphics g) { @@ -1077,27 +1098,43 @@ } if (paintInfo.hasSign()) { + Color backup = null; + if (paintInfo.signActive || paintInfo.lineInActive) { + //highlight focused sign + backup = g2d.getColor(); + Color highlightedColor = getHighlightedColor(g2d.getColor()); + if (null != highlightedColor) { + g2d.setColor(highlightedColor); + } + } + g.drawRect(markX, markY, markSize, markSize); + //minus sign g.drawLine(plusGap + markX, markY + halfMarkSize, markSize + markX - plusGap, markY + halfMarkSize); String opStr = (paintOperation == PAINT_MARK) ? "PAINT_MARK" : "SINGLE_PAINT_MARK"; // NOI18N if (isFolded) { if (LOG.isLoggable(Level.FINER)) { LOG.finer(opStr + ": folded; y=" + y + ", PI:" + paintInfo + "\n"); // NOI18N } + //vertical part of plus sign g.drawLine(lineX, markY + plusGap, lineX, markY + markSize - plusGap); } + if (null != backup) { + g2d.setColor(backup); + } + if (paintOperation != SINGLE_PAINT_MARK) { if (LOG.isLoggable(Level.FINER)) { LOG.finer(opStr + ": non-single; y=" + y + ", PI:" + paintInfo + "\n"); // NOI18N } } if (paintInfo.hasLineIn()) { //[PENDING] - drawFoldLine(g2d, paintInfo.lineInActive, lineX, y, lineX, markY); + drawFoldLine(g2d, paintInfo.lineInActive, lineX, y, lineX, markY - 1); } if (paintInfo.hasLineOut()) { // This is an error in case there's a next paint info at the same y which is an end mark // for this mark (it must be cleared explicitly). - drawFoldLine(g2d, paintInfo.lineOutActive, lineX, markY + markSize, lineX, y + height); + drawFoldLine(g2d, paintInfo.lineOutActive, lineX, markY + markSize + 1, lineX, y + height); } visibleMarks.add(new Mark(markX, markY, markSize, isFolded)); @@ -1113,12 +1150,12 @@ } if (previousInfo == null || y != previousInfo.getPaintY()) { drawFoldLine(g2d, paintInfo.lineInActive, lineX, y, lineX, y + height / 2); - drawFoldLine(g2d, paintInfo.signActive, lineX, y + height / 2, lineX + halfMarkSize, y + height / 2); + drawFoldLine(g2d, paintInfo.signActive, lineX + 1, y + height / 2, lineX + halfMarkSize, y + height / 2); if (paintInfo.getInnerLevel() > 0) {//[PENDING] if (LOG.isLoggable(Level.FINER)) { LOG.finer(" PAINT middle-line\n"); // NOI18N } - drawFoldLine(g2d, paintInfo.lineOutActive, lineX, y + height / 2, lineX, y + height); + drawFoldLine(g2d, paintInfo.lineOutActive, lineX, (y + height / 2) + 1, lineX, y + height); } } } Index: editor.lib/src/org/netbeans/editor/CodeFoldingSideBar.java --- editor.lib/src/org/netbeans/editor/CodeFoldingSideBar.java +++ editor.lib/src/org/netbeans/editor/CodeFoldingSideBar.java @@ -44,7 +44,6 @@ package org.netbeans.editor; -import java.awt.BasicStroke; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; @@ -53,7 +52,6 @@ import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; -import java.awt.Stroke; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; @@ -220,19 +218,8 @@ */ private static final int NO_MOUSE_POINT = -1; - /** - * Stroke used to draw inactive (regular) fold outlines. - */ - private static Stroke LINE_DASHED = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, - 1f, new float[] { 1f, 1f }, 0f); - private boolean alreadyPresent; - /** - * Stroke used to draw outlines for 'active' fold - */ - private static final Stroke LINE_BOLD = new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER); - private final Preferences prefs; private final PreferenceChangeListener prefsListener = new PreferenceChangeListener() { public void preferenceChange(PreferenceChangeEvent evt) { @@ -312,6 +299,48 @@ }); } + /** + * Compares the brightness of colors regarding the HSB color model. + * + * @param colorA + * @param colorB + * @return the value {@code 0} if the brightness of {@code colorA} is equal + * to the brightness of {@code colorB}; a value less than {@code 0} + * if {@code colorA} is darker than {@code colorB}; and a value + * greater than {@code 0} if {@code colorA} is brighter than + * {@code colorB}. + */ + private int compareBrightness(Color colorA, Color colorB) { + if (null == colorA) { + return -1; + } + if (null == colorB) { + return -1; + } + if (colorA.equals(colorB)) { + return 0; + } + float brightnessA = Color.RGBtoHSB(colorA.getRed(), colorA.getGreen(), colorA.getBlue(), null)[2]; + float brightnessB = Color.RGBtoHSB(colorB.getRed(), colorB.getGreen(), colorB.getBlue(), null)[2]; + return Float.compare(brightnessA, brightnessB); + } + + /** + * Get a brightened color used for highlighting. If the color cannot be brightened, then a darkened color will be returned. + * + * @param color + * @param bg + * @return + */ + private Color getHighlightedColor(Color color) { + Color newColor = color.brighter().brighter(); + if (compareBrightness(newColor, color) <= 0) { + //cannot make it brighter? so make it darker + newColor = color.darker().darker(); + } + return newColor; + } + private void updatePreferredSize() { if (enabled && !alreadyPresent) { setPreferredSize(new Dimension(getColoring().getFont().getSize(), component.getHeight())); @@ -642,20 +671,6 @@ return result; } - /** - * Returns stroke appropriate for painting (in)active outlines - * @param s the default stroke - * @param active true for active outlines - * @return value of 's' or a Stroke which should be used to paint the outline. - */ - private static Stroke getStroke(Stroke s, boolean active) { - if (active) { - return LINE_BOLD; - } else { - return s; - } - } - private boolean traverseBackwards(Fold f, BaseDocument doc, BaseTextUI btui, int lowerBoundary, int upperBoundary, int level, NavigableMap infos) throws BadLocationException { // System.out.println("~~~ traverseBackwards<" + lowerBoundary + ", " + upperBoundary // + ">: fold=<" + f.getStartOffset() + ", " + f.getEndOffset() + "> " @@ -932,10 +947,16 @@ } private void drawFoldLine(Graphics2D g2d, boolean active, int x1, int y1, int x2, int y2) { - Stroke origStroke = g2d.getStroke(); - g2d.setStroke(getStroke(origStroke, active)); + Color backup = g2d.getColor(); + if (active) { + //highlight focused line + Color highlightedColor = getHighlightedColor(g2d.getColor()); + if (null != highlightedColor) { + g2d.setColor(highlightedColor); + } + } g2d.drawLine(x1, y1, x2, y2); - g2d.setStroke(origStroke); + g2d.setColor(backup); } protected @Override void paintComponent(Graphics g) { @@ -994,27 +1015,43 @@ } if (paintInfo.hasSign()) { + Color backup = null; + if (paintInfo.signActive || paintInfo.lineInActive) { + //highlight focused sign + backup = g2d.getColor(); + Color highlightedColor = getHighlightedColor(g2d.getColor()); + if (null != highlightedColor) { + g2d.setColor(highlightedColor); + } + } + g.drawRect(markX, markY, markSize, markSize); + //minus sign g.drawLine(plusGap + markX, markY + halfMarkSize, markSize + markX - plusGap, markY + halfMarkSize); String opStr = (paintOperation == PAINT_MARK) ? "PAINT_MARK" : "SINGLE_PAINT_MARK"; // NOI18N if (isFolded) { if (LOG.isLoggable(Level.FINE)) { LOG.fine(opStr + ": folded; y=" + y + ", PI:" + paintInfo + "\n"); // NOI18N } + //vertical part of plus sign g.drawLine(lineX, markY + plusGap, lineX, markY + markSize - plusGap); } + if (null != backup) { + g2d.setColor(backup); + } + if (paintOperation != SINGLE_PAINT_MARK) { if (LOG.isLoggable(Level.FINE)) { LOG.fine(opStr + ": non-single; y=" + y + ", PI:" + paintInfo + "\n"); // NOI18N } } if (paintInfo.hasLineIn()) { //[PENDING] - drawFoldLine(g2d, paintInfo.lineInActive, lineX, y, lineX, markY); + drawFoldLine(g2d, paintInfo.lineInActive, lineX, y, lineX, markY - 1); } if (paintInfo.hasLineOut()) { // This is an error in case there's a next paint info at the same y which is an end mark // for this mark (it must be cleared explicitly). - drawFoldLine(g2d, paintInfo.lineOutActive, lineX, markY + markSize, lineX, y + height); + drawFoldLine(g2d, paintInfo.lineOutActive, lineX, markY + markSize + 1, lineX, y + height); } visibleMarks.add(new Mark(markX, markY, markSize, isFolded)); @@ -1030,12 +1067,12 @@ } if (previousInfo == null || y != previousInfo.getPaintY()) { drawFoldLine(g2d, paintInfo.lineInActive, lineX, y, lineX, y + height / 2); - drawFoldLine(g2d, paintInfo.signActive, lineX, y + height / 2, lineX + halfMarkSize, y + height / 2); + drawFoldLine(g2d, paintInfo.signActive, lineX + 1, y + height / 2, lineX + halfMarkSize, y + height / 2); if (paintInfo.getInnerLevel() > 0) {//[PENDING] if (LOG.isLoggable(Level.FINE)) { LOG.fine(" PAINT middle-line\n"); // NOI18N } - drawFoldLine(g2d, paintInfo.lineOutActive, lineX, y + height / 2, lineX, y + height); + drawFoldLine(g2d, paintInfo.lineOutActive, lineX, (y + height / 2) + 1, lineX, y + height); } } }