<commit_before>/*******************************************************************************
 * Copyright (c) 2007, 2009 <NAME> and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     <NAME> - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylyn.internal.wikitext.ui.viewer.annotation;

import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;

public class BulletDrawingStrategy implements IDrawingStrategy {

	public void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color) {
		BulletAnnotation bullet = (BulletAnnotation) annotation;
		if (gc != null) {
			final Color foreground = gc.getForeground();
			final Color background = gc.getBackground();

			if (length < 1) {
				return;
			}

			Point left = textWidget.getLocationAtOffset(offset);
			Point right = textWidget.getLocationAtOffset(offset + length);
			if (left.x > right.x) {
				// hack: sometimes linewrapping text widget gives us the wrong x/y for the first character of a line that
				// has been wrapped.
				left.x = 0;
				left.y = right.y;
			}
			int baseline = textWidget.getBaseline(offset);

			int lineHeight = textWidget.getLineHeight(offset);

			int vcenter = left.y + (baseline / 2) + (baseline / 4);
			int hcenter = left.x + ((right.x - left.x) / 2);

			gc.setLineWidth(0); // NOTE: 0 means width is 1 but with optimized performance
			gc.setLineStyle(SWT.LINE_SOLID);

			// erase whatever character was there
			gc.fillRectangle(left.x, left.y, right.x - left.x, lineHeight);

			// now paint the bullet
			switch (bullet.getIndentLevel()) {
			case 1: // round solid bullet
				gc.setBackground(color);
				gc.fillOval(hcenter - 3, vcenter - 2, 5, 5);
				break;
			case 2: // round empty bullet
				gc.setForeground(color);<commit_msg>NEW - bug 262999: highlighted bullets have the wrong background color https://bugs.eclipse.org/bugs/show_bug.cgi?id=262999<commit_after>/*******************************************************************************
 * Copyright (c) 2007, 2009 <NAME> and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     <NAME> - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylyn.internal.wikitext.ui.viewer.annotation;

import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;

public class BulletDrawingStrategy implements IDrawingStrategy {

	public void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color) {
		BulletAnnotation bullet = (BulletAnnotation) annotation;
		if (gc != null) {
			final Color foreground = gc.getForeground();
			final Color background = gc.getBackground();

			if (length < 1) {
				return;
			}

			Point left = textWidget.getLocationAtOffset(offset);
			Point right = textWidget.getLocationAtOffset(offset + length);
			if (left.x > right.x) {
				// hack: sometimes linewrapping text widget gives us the wrong x/y for the first character of a line that
				// has been wrapped.
				left.x = 0;
				left.y = right.y;
			}
			int baseline = textWidget.getBaseline(offset);

			int lineHeight = textWidget.getLineHeight(offset);

			int vcenter = left.y + (baseline / 2) + (baseline / 4);
			int hcenter = left.x + ((right.x - left.x) / 2);

			gc.setLineWidth(0); // NOTE: 0 means width is 1 but with optimized performance
			gc.setLineStyle(SWT.LINE_SOLID);

			// bug 262999: determine if we're painting in a selection
			Point selection = textWidget.getSelection();
			// non-zero length selection, so see if where we're about to draw is within it
			if (offset >= selection.x && offset < selection.y && selection.x < selection.y) {
				gc.setBackground(textWidget.getSelectionBackground());
				gc.setForeground(textWidget.getSelectionForeground());
			} else {
				gc.setBackground(textWidget.getBackground());
			}

			// erase whatever character was there
			gc.fillRectangle(left.x, left.y, right.x - left.x, lineHeight);

			// now paint the bullet
			switch (bullet.getIndentLevel()) {
			case 1: // round solid bullet
				gc.setBackground(color);
				gc.fillOval(hcenter - 3, vcenter - 2, 5, 5);
				break;
			case 2: // round empty bullet
				gc.setForeground(color);
{'fraction_non_alphanumeric': 0.16301239275500476, 'fraction_numerical': 0.01334604385128694, 'mean_word_length': 3.930451127819549, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '146669', 'n_tokens_mistral': 1770, 'n_tokens_neox': 1485, 'n_words': 444}