private AutoCloseable configGC(final GC gc) { final int lineStyle = gc.getLineStyle(); final int alpha = gc.getAlpha(); final int[] lineDash = gc.getLineDash(); final Color foreground = gc.getForeground(); final Color background = gc.getBackground(); gc.setForeground(this.indentGuide.getColor(styledText)); gc.setBackground(styledText.getBackground()); gc.setAlpha(this.indentGuide.getTransparency()); gc.setLineStyle(SWT.LINE_CUSTOM); gc.setLineDash(new int[] {1, 2}); return new AutoCloseable() { @Override public void close() throws Exception { gc.setForeground(foreground); gc.setBackground(background); gc.setAlpha(alpha); gc.setLineStyle(lineStyle); gc.setLineDash(lineDash); } }; }
/** @param gc */ private void paintSpellError(GC gc) { if (ranges.isEmpty()) return; int lineStyle = gc.getLineStyle(); int lineWidth = gc.getLineWidth(); Color lineColor = gc.getForeground(); gc.setLineWidth(2); gc.setLineStyle(SWT.LINE_DOT); gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_RED)); int charCount = contentAdapter.getControlContents(control).length(); Rectangle clipping = gc.getClipping(); lineCache.clear(); for (Object obj : ranges.values().toArray()) { SpellCheckEvent range = (SpellCheckEvent) obj; int start = range.getWordContextPosition(); if (start < 0 || start >= charCount) continue; int length = Math.min(range.getInvalidWord().length(), charCount - start); if (length <= 0) continue; drawLines(gc, start, start + length - 1, clipping); } gc.setLineWidth(lineWidth); gc.setLineStyle(lineStyle); gc.setForeground(lineColor); }