Netbeans mini code map

I am creating Netbeans mini code map, now eye ball comfortable. Netbeans’ editor is using different mechanism to store syntax hightlight, in traditional swing, we use “Element” and “AttributeSet” to represent a tree-view for syntax highlighting in JEditorPane. But Mr Miloslav Metelka told me :

Elements are perfect for advanced styling i.e. word like documents e.g. when a text is selected and made bold. It's also natural that this change is an undoable Element update. But we don't find Elements useful for things like syntax highlighting etc. since they are too heavyweight to operate - we would have to update the (nested) element structure upon each its modification and handle undoability.
Instead we use z-ordered highlighting layers i.e. a sequence of an attributed offset ranges." , 

so netbeans is using “HighlightsContainer” to store highlighting information, below is the example code to dump out the syntax highlighting information:

try {
	JEditorPane editorPane = (JEditorPane) jtc;
	Lookup lookup = MimeLookup.getLookup(editorPane.getContentType());
	FontColorSettings settings = lookup.lookup(FontColorSettings.class);
	Color defaultColor = (Color) settings.getTokenFontColors("default").getAttribute(StyleConstants.Foreground);

	HighlightsContainer hc = HighlightingManager.getInstance(jtc).getBottomHighlights();
	HighlightsSequence hq = hc.getHighlights(0, document.getLength());
	String lines[] = jtc.getText().split("\n");
	int noOfLine = lines.length;

	int longestLined = Integer.MIN_VALUE;
	for (int x = 0; x < lines.length; x++) {
		if (lines[x].length() > longestLined) {
			longestLined = lines[x].length();
		}
	}

	final int blockWidth = 10;
	final int blockHeight = 10;
	final int margin = 2;
	BufferedImage tempImage = new BufferedImage(longestLined * blockWidth, noOfLine * blockHeight, BufferedImage.TYPE_INT_ARGB);
	Graphics2D imageG = tempImage.createGraphics();
	int offsetX = 0;
	int offsetY = 0;
	Color lastColor = Color.white;
	while (hq.moveNext()) {
		AttributeSet as = hq.getAttributes();
		for (int x = 0; x < hq.getEndOffset() - hq.getStartOffset(); x++) {
			String text = document.getText(hq.getStartOffset() + x, 1);
			Color fc;
			if (text.equals(" ") || text.equals("\t")) {
				fc = lastColor;
			} else if (text.equals("\n")) {
				offsetX = 0;
				offsetY += blockHeight;
				lastColor = Color.white;
				continue;
			} else {
				if (as == null || as.getAttribute(StyleConstants.Foreground) == null) {
					fc = defaultColor;
				} else {
					fc = (Color) as.getAttribute(StyleConstants.Foreground);
				}
			}
			lastColor = fc;
			//ModuleLib.log(text + " : " + hq.getStartOffset() + " -> " + hq.getEndOffset() + " = (" + offsetX + "," + offsetY + ") " + fc);
			imageG.setColor(fc);
			imageG.fillRect(offsetX, offsetY + margin, blockWidth, blockHeight - (margin * 2));
			offsetX += blockWidth;
		}
	}
	return tempImage;
} catch (BadLocationException ex) {
	ModuleLib.log(CommonLib.printException(ex));
	return null;
}

read count : 22