public static PositionsBag getHighlightsBag(Document doc) { if (doc == null) { return null; } PositionsBag bag = (PositionsBag) doc.getProperty(SemanticHighlighter.class); if (bag == null) { doc.putProperty(SemanticHighlighter.class, bag = new PositionsBag(doc)); } return bag; }
private void addHighlightsToBag(PositionsBag bag, int start, int end, AttributeSet attr, String nameToStateInLog) { try { Document doc = getDocument(); if (doc != null) { bag.addHighlight(doc.createPosition(start), doc.createPosition(end), attr); } } catch (BadLocationException ex) { LOG.log(Level.FINE, "Can't add highlight <" + start + ", " + end + ", " + nameToStateInLog + ">", ex); } }
private void clean() { Document doc = getDocument(); if (doc != null) { getHighlightsBag(doc).clear(); OccurrencesMarkProvider.get(doc).setOccurrences(Collections.<Mark>emptySet()); } }
private void update(BaseDocument doc, final Interrupter interrupter) { boolean macroExpansionView = (doc.getProperty(CsmMacroExpansion.MACRO_EXPANSION_VIEW_DOCUMENT) != null); PositionsBag newBag = new PositionsBag(doc); newBag.clear(); final CsmFile csmFile = CsmUtilities.getCsmFile(doc, false, false); long start = System.currentTimeMillis(); PositionsBag tempBag = new PositionsBag(doc); tempBag.addAllHighlights(newBag); HighlightsSequence seq = newBag.getHighlights(0, Integer.MAX_VALUE); Set<AttributeSet> set = new HashSet<AttributeSet>(); while (seq.moveNext()) { set.add(seq.getAttributes()); seq = old.getHighlights(0, Integer.MAX_VALUE); while (seq.moveNext()) { if (!set.contains(seq.getAttributes())) { getHighlightsBag(doc).setHighlights(tempBag); } else { getHighlightsBag(doc).setHighlights(newBag); getHighlightsBag(doc).setHighlights(newBag);
bag = new PositionsBag(doc); bag.addHighlight(start, end, COLORING); getHighlightsBag(doc).setHighlights(bag);
@Override public synchronized void insertUpdate(DocumentEvent e) { if (inSync) return ; inSync = true; region.sync(0); getHighlightsBag(doc).setHighlights(bag); inSync = false; target.repaint(); }
@Override public void removeUpdate(DocumentEvent e) { bagFin.removeHighlights(e.getOffset(), e.getOffset()); }
@SuppressWarnings("empty-statement") private static int findOccurrencePosition(boolean directionForward, Document doc, int curPos) { PositionsBag bag = MarkOccurrencesHighlighter.getHighlightsBag(doc); HighlightsSequence hs = bag.getHighlights(0, doc.getLength());
HighlightsSequence hs = getHighlightsBag(doc).getHighlights(0, doc.getLength() - 1); while (hs.moveNext()) { if (lastPosition >= hs.getStartOffset() && lastPosition <= hs.getEndOffset()) { final PositionsBag obag = new PositionsBag(doc); obag.clear(); final AttributeSet attrs = defaultColors.get(mimeType); if (attrs == null) { getHighlightsBag(doc).setHighlights(obag); OccurrencesMarkProvider.get(doc).setOccurrences( OccurrencesMarkProvider.createMarks(doc, out, ES_COLOR, NbBundle.getMessage(MarkOccurrencesHighlighter.class, "LBL_ES_TOOLTIP")));
@Override public synchronized void removeUpdate(DocumentEvent e) { if (inSync) return ; //#89997: do not sync the regions for the "remove" part of replace selection, //as the consequent insert may use incorrect offset, and the regions will be synced //after the insert anyway. if (doc.getProperty(BaseKit.DOC_REPLACE_SELECTION_PROPERTY) != null) { return ; } inSync = true; region.sync(0); getHighlightsBag(doc).setHighlights(bag); inSync = false; target.repaint(); }
@Override public void insertUpdate(DocumentEvent e) { bagFin.removeHighlights(e.getOffset(), e.getOffset()); }
public static PositionsBag getHighlightsBag(Document doc) { PositionsBag bag = (PositionsBag) doc.getProperty(POSITION_BAG); if (bag == null) { doc.putProperty(POSITION_BAG, bag = new PositionsBag(doc)); } return bag; }
private synchronized void release() { if (target == null) { //already released return; } target.putClientProperty(InstantRenamePerformer.class, null); if (doc instanceof BaseDocument) { ((BaseDocument) doc).removePostModificationDocumentListener(this); } target.removeKeyListener(this); getHighlightsBag(doc).clear(); region = null; doc = null; target = null; instance = null; }
private void addHighlight(BaseDocument doc, PositionsBag obag, CsmReference csmReference, AttributeSet attrs) throws BadLocationException { int usages[][] = CsmMacroExpansion.getUsages(doc, csmReference.getStartOffset()); if (usages != null) { for (int i = 0; i < usages.length; i++) { int startOffset = usages[i][0]; int endOffset = usages[i][1]; if (startOffset < doc.getLength() && endOffset > 0 && startOffset < endOffset) { obag.addHighlight( doc.createPosition((startOffset > 0) ? startOffset : 0), doc.createPosition((endOffset < doc.getLength()) ? endOffset : doc.getLength()), attrs); } } } else { int startOffset = getDocumentOffset(doc, csmReference.getStartOffset()); int endOffset = getDocumentOffset(doc, csmReference.getEndOffset()); if (startOffset < doc.getLength() && endOffset > 0 && startOffset < endOffset) { obag.addHighlight(doc.createPosition((startOffset > 0) ? startOffset : 0), doc.createPosition((endOffset < doc.getLength()) ? endOffset : doc.getLength()), attrs); } } }
public static PositionsBag getHighlightsBag(Document doc) { if (doc == null) { return null; } PositionsBag bag = (PositionsBag) doc.getProperty(MarkOccurrencesHighlighter.class); if (bag == null) { doc.putProperty(MarkOccurrencesHighlighter.class, bag = new PositionsBag(doc, false)); final PositionsBag bagFin = bag; DocumentListener l = new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { bagFin.removeHighlights(e.getOffset(), e.getOffset()); } @Override public void removeUpdate(DocumentEvent e) { bagFin.removeHighlights(e.getOffset(), e.getOffset()); } @Override public void changedUpdate(DocumentEvent e) { } }; doc.addDocumentListener(l); } return bag; }
@Override public void run(Phase phase) { if (phase == Phase.PARSED || phase == Phase.INIT || phase == Phase.PROJECT_PARSED) { InterrupterImpl interrupter = new InterrupterImpl(); try { addCancelListener(interrupter); update(interrupter); } catch (AssertionError ex) { ex.printStackTrace(System.err); } catch (Exception ex) { ex.printStackTrace(System.err); } finally { removeCancelListener(interrupter); } } else if (phase == Phase.CLEANUP) { BaseDocument doc = getDocument(); if (doc != null) { //System.err.println("cleanAfterYourself"); getHighlightsBag(doc).clear(); } } }