Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2009 itemis AG (http://www.itemis.eu) 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 /
  
  package org.eclipse.xtext.ui.editor.syntaxcoloring;
  
 import  org.eclipse.jface.text.Position;
 import  org.eclipse.jface.text.TextAttribute;
 import  org.eclipse.swt.SWT;
 import  org.eclipse.swt.custom.StyleRange;
 
 public class AttributedPosition extends Position {

HighlightingStyle of the position
 
 	private final TextAttribute attribute;

Lock object
 
 	private final Object fLock;

Initialize the position with the given offset, length and foreground color.

Parameters:
offset The position offset
length The position length
attribute The highlighting TextAttribute
lock The lock object
 
 	public AttributedPosition(int offsetint length, TextAttribute attributeObject lock) {
 		super(offsetlength);
 		this. = attribute;
 		 = lock;
 	}

Returns:
Returns a corresponding style range.
 
 	public StyleRange createStyleRange() {
 		int len = getLength();
 
 		TextAttribute textAttribute = ;
 		int style = textAttribute.getStyle();
 		int fontStyle = style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL);
 		StyleRange styleRange = new StyleRange(getOffset(), lentextAttribute.getForeground(),
 				textAttribute.getBackground(), fontStyle);
 		styleRange.strikeout = (style & TextAttribute.STRIKETHROUGH) != 0;
 		styleRange.underline = (style & TextAttribute.UNDERLINE) != 0;
 		styleRange.font = textAttribute.getFont();
 
 		return styleRange;
 	}

Uses reference equality for the highlighting.

Parameters:
off The offset
len The length
other The highlighting TextAttribute to compare with
Returns:
true if the given offset, length and highlighting are equal to the internal ones.
 
 	public boolean isEqual(int offint len, TextAttribute other) {
 		synchronized () {
 			return !isDeleted() && getOffset() == off && getLength() == len &&  == other;
 		}
 	}

Is this position contained in the given range (inclusive)? Synchronizes on position updater.

Parameters:
off The range offset
len The range length
Returns:
true iff this position is not delete and contained in the given range.
 
 	public boolean isContained(int offint len) {
 		synchronized () {
 			return !isDeleted() && off <= getOffset() && off + len >= getOffset() + getLength();
 		}
 	}
 
 	public void update(int offint len) {
 		synchronized () {
 			super.setOffset(off);
 			super.setLength(len);
 		}
 	}
 
 	/*
 	 * @see org.eclipse.jface.text.Position#setLength(int)
	 */
	public void setLength(int length) {
		synchronized () {
			super.setLength(length);
		}
	}
	/*
	 * @see org.eclipse.jface.text.Position#setOffset(int)
	 */
	public void setOffset(int offset) {
		synchronized () {
			super.setOffset(offset);
		}
	}
	/*
	 * @see org.eclipse.jface.text.Position#delete()
	 */
	public void delete() {
		synchronized () {
			super.delete();
		}
	}
	/*
	 * @see org.eclipse.jface.text.Position#undelete()
	 */
	public void undelete() {
		synchronized () {
			super.undelete();
		}
	}

Returns:
Returns the highlighting.
	public TextAttribute getHighlighting() {
		return ;
	}
New to GrepCode? Check out our FAQ X