# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: C:\Users\pt102560\Code\main-silver # 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: gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageHighlightsContainer.java --- gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageHighlightsContainer.java +++ gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageHighlightsContainer.java @@ -49,17 +49,17 @@ import java.util.Comparator; import java.util.List; import java.util.NoSuchElementException; + +import javax.swing.UIManager; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.Document; import javax.swing.text.Position; -import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; -import org.netbeans.api.editor.mimelookup.MimeLookup; + import org.netbeans.api.editor.settings.AttributesUtilities; -import org.netbeans.api.editor.settings.FontColorSettings; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; import org.netbeans.editor.BaseDocument; @@ -79,6 +79,11 @@ * @author Tor Norbye */ public class CoverageHighlightsContainer extends AbstractHighlightsContainer implements DocumentListener { + + private static final Color DEFAULT_COVERED = new Color(0xCC, 0xFF, 0xCC); + private static final Color DEFAULT_UNCOVERED = new Color(0xFF, 0xCC, 0xCC); + private static final Color DEFAULT_INFERED = new Color(0xE0, 0xFF, 0xE0); + private static final Color DEFAULT_PARTIAL = new Color(0xFF, 0xFF, 0xE0); private AttributeSet covered; private AttributeSet uncovered; private AttributeSet inferred; @@ -89,7 +94,6 @@ private boolean listening; private final BaseDocument doc; private final String mimeType; - private long version = 0; private FileObject fileObject; private Project project; @@ -102,6 +106,7 @@ this.mimeType = (String) document.getProperty("mimeType"); } + @Override public HighlightsSequence getHighlights(int startOffset, int endOffset) { enabled = false; CoverageManagerImpl manager = CoverageManagerImpl.getInstance(); @@ -135,57 +140,38 @@ doc.addDocumentListener(WeakListeners.document(this, null)); } - return new Highlights(0, startOffset, endOffset, details); + return new Highlights(startOffset, endOffset, details); } - private static Color getColoring(FontColorSettings fcs, String tokenName) { - AttributeSet as = fcs.getTokenFontColors(tokenName); - if (as != null) { - return (Color) as.getAttribute(StyleConstants.Background); //NOI18N - } - return null; - } - private void initColors() { if (covered != null) { return; } - Color coveredBc = null; - Color uncoveredBc = null; - Color inferredBc = null; - Color partialBc = null; - FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class); - if (fcs != null) { - coveredBc = getColoring(fcs, "covered"); // NOI18N - uncoveredBc = getColoring(fcs, "uncovered"); // NOI18N - inferredBc = getColoring(fcs, "inferred"); // NOI18N - partialBc = getColoring(fcs, "partial"); // NOI18N - } + Color coveredBc = (Color) UIManager.get("nb.diff.added.color"); + Color uncoveredBc = (Color) UIManager.get("nb.diff.deleted.color"); + Color inferredBc = (Color) UIManager.get("nb.diff.added.color"); + Color partialBc = (Color) UIManager.get("orange"); if (coveredBc == null) { - coveredBc = new Color(0xCC, 0xFF, 0xCC); + coveredBc = DEFAULT_COVERED; } if (uncoveredBc == null) { - uncoveredBc = new Color(0xFF, 0xCC, 0xCC); + uncoveredBc = DEFAULT_UNCOVERED; } if (inferredBc == null) { - inferredBc = new Color(0xE0, 0xFF, 0xE0); + inferredBc = DEFAULT_INFERED; } if (partialBc == null) { - partialBc = new Color(0xFF, 0xFF, 0xE0); + partialBc = DEFAULT_PARTIAL; } - covered = coveredBc == null ? SimpleAttributeSet.EMPTY : AttributesUtilities.createImmutable( - StyleConstants.Background, coveredBc, + covered = AttributesUtilities.createImmutable(StyleConstants.Background, coveredBc, ATTR_EXTENDS_EOL, Boolean.TRUE, ATTR_EXTENDS_EMPTY_LINE, Boolean.TRUE); - uncovered = uncoveredBc == null ? SimpleAttributeSet.EMPTY : AttributesUtilities.createImmutable( - StyleConstants.Background, uncoveredBc, + uncovered = AttributesUtilities.createImmutable(StyleConstants.Background, uncoveredBc, ATTR_EXTENDS_EOL, Boolean.TRUE, ATTR_EXTENDS_EMPTY_LINE, Boolean.TRUE); - inferred = inferredBc == null ? SimpleAttributeSet.EMPTY : AttributesUtilities.createImmutable( - StyleConstants.Background, inferredBc, + inferred = AttributesUtilities.createImmutable(StyleConstants.Background, inferredBc, ATTR_EXTENDS_EOL, Boolean.TRUE, ATTR_EXTENDS_EMPTY_LINE, Boolean.TRUE); - partial = partialBc == null ? SimpleAttributeSet.EMPTY : AttributesUtilities.createImmutable( - StyleConstants.Background, partialBc, + partial = AttributesUtilities.createImmutable(StyleConstants.Background, partialBc, ATTR_EXTENDS_EOL, Boolean.TRUE, ATTR_EXTENDS_EMPTY_LINE, Boolean.TRUE); } @@ -213,9 +199,9 @@ // add and subtract spaces to the document to implement // smart-indent if ((s.trim().length() == 0)) { // whitespace changes only? - if (Utilities.isRowEmpty(doc, offset) || - (offset >= Utilities.getRowLastNonWhite(doc, offset) + 1) || - (offset <= Utilities.getRowFirstNonWhite(doc, offset))) { + if (Utilities.isRowEmpty(doc, offset) + || (offset >= Utilities.getRowLastNonWhite(doc, offset) + 1) + || (offset <= Utilities.getRowFirstNonWhite(doc, offset))) { fireHighlightsChange(offset, offset + length); return; } @@ -231,7 +217,7 @@ int positionIndex = findPositionIndex(positions, lineStart); if (positionIndex >= 0) { // Create a new list to avoid sync problems - List copy = new ArrayList(positions); + List copy = new ArrayList<>(positions); copy.remove(positionIndex); lastPositions = copy; fireHighlightsChange(offset, offset + length); @@ -242,27 +228,32 @@ } } + @Override public void insertUpdate(DocumentEvent ev) { if (enabled) { handleEdits(ev.getOffset(), ev.getLength(), true); } } + @Override public void removeUpdate(DocumentEvent ev) { //if (enabled) { // handleEdits(ev.getOffset(), ev.getLength(), false); //} } + @Override public void changedUpdate(DocumentEvent ev) { } private int findPositionIndex(List positions, final int target) { return Collections.binarySearch(positions, new Position() { + @Override public int getOffset() { return target; } }, new Comparator() { + @Override public int compare(Position pos1, Position pos2) { return pos1.getOffset() - pos2.getOffset(); } @@ -270,9 +261,9 @@ } private class Highlights implements HighlightsSequence { + private final List positions; private final List types; - private final long version; private final int startOffsetBoundary; private final int endOffsetBoundary; private int startOffset; @@ -281,18 +272,17 @@ private boolean finished = false; private int index; - private Highlights(long version, int startOffset, int endOffset, FileCoverageDetails details) { - this.version = version; + private Highlights(int startOffset, int endOffset, FileCoverageDetails details) { this.startOffsetBoundary = startOffset; this.endOffsetBoundary = endOffset; if (lastPositions == null) { - positions = new ArrayList(); - types = new ArrayList(); + positions = new ArrayList<>(); + types = new ArrayList<>(); for (int lineno = 0, maxLines = details.getLineCount(); lineno < maxLines; lineno++) { CoverageType type = details.getType(lineno); - if (type == CoverageType.COVERED || type == CoverageType.INFERRED || - type == CoverageType.NOT_COVERED || type == CoverageType.PARTIAL) { + if (type == CoverageType.COVERED || type == CoverageType.INFERRED + || type == CoverageType.NOT_COVERED || type == CoverageType.PARTIAL) { try { int offset = Utilities.getRowStartFromLineOffset(doc, lineno); if (offset == -1) { @@ -381,19 +371,19 @@ return false; } + @Override public boolean moveNext() { synchronized (CoverageHighlightsContainer.this) { - if (checkVersion()) { if (_moveNext()) { return true; } } - } finished = true; return false; } + @Override public int getStartOffset() { synchronized (CoverageHighlightsContainer.this) { if (finished) { @@ -404,6 +394,7 @@ } } + @Override public int getEndOffset() { synchronized (CoverageHighlightsContainer.this) { if (finished) { @@ -414,6 +405,7 @@ } } + @Override public AttributeSet getAttributes() { synchronized (CoverageHighlightsContainer.this) { if (finished) { @@ -423,9 +415,5 @@ } } } - - private boolean checkVersion() { - return this.version == CoverageHighlightsContainer.this.version; } } -}