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; |
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; |
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) { |
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())); |
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() + "> " |
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) { |
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 |
|
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 |
} |