old netbeans api code to get each line

g.setColor(Color.red);
		int lastLineNo = -1;
		while (hq.moveNext()) {
			AttributeSet as = hq.getAttributes();
			if (as != null) {
				try {
					lineNo = NbDocument.findLineNumber((StyledDocument) document, hq.getStartOffset());
					if (lineNo != lastLineNo) {
						lastLineNo = lineNo;
						g.drawString(String.valueOf(lineNo + 1), 0, fontHeight * (lineNo + 1) - 3);
					}
				} catch (Exception ex) {
					ModuleLib.log(CommonLib.printException(ex));
				}
			}
		}

read count : 13

get netbeans current row highlight color

		FontColorSettings fcs = MimeLookup.getLookup(MimePath.EMPTY).lookup(FontColorSettings.class);
		Coloring c = Coloring.fromAttributeSet(fcs.getFontColors(FontColorNames.CARET_ROW_COLORING));
		g.setColor(c.getBackColor());

read count : 2

Script to browse every pages of sharepoint 2013

Add-PSSnapin Microsoft.SharePoint.PowerShell
$creds = [System.Net.CredentialCache]::DefaultCredentials
$DEBUGLOG = "c:\SharePoint.log"
$SPECIFICURLs= "c:\SharePoint.URLs.txt"

function Log([string] $msg,[string] $colour)
{
    if($colour -ne "") {
        Write-Host $msg -ForegroundColor $colour
    }
    else {
        Write-Host $msg
    }
}

function Debug([string] $msg)
{
    echo $msg >> $DEBUGLOG
}

function JoinURL([string]$a,[string]$b)
{
    if($a.EndsWith('/')) { $a=$a.Substring(0,$a.length-1) }
    if($b.StartsWith('/')) { $b=$b.Substring(1) }
    return $a + '/' + $b
}

function Fetch-WebPage([string]$url,[bool]$ignoreErrors = $false)
{
    $bypassonlocal = $false
    $proxyuri = "http://" + $env:COMPUTERNAME
    $proxy = New-Object system.Net.WebProxy($proxyuri, $bypassonlocal)

    $client = New-Object Net.WebClient
    $client.Credentials = $creds
    $client.Proxy = $proxy
    Debug "Fetching $url" 
    try {
        $pageContents = $Client.DownloadString($url) 2>&1 | Out-Null
    }
    catch {
        $msg = $error[0].ToString()
        if($ignoreErrors -eq $false) {
            Log "ERROR: $msg" "Red" 
            Debug "ERROR: $msg"
        }
    }
    $client.Dispose()
    ###Debug $pageContents
}

function ProcessWebApplication ([string]$url)
{ 
    Log "-- Root site URL: $url" "Green"
    $sitecollections = Get-SPSite $url 2>$null
    if($sitecollections -eq $null) { 
        Log "  -- No site collections found under this URL" "Cyan"
        return
    }

    $IsCA = $false
    if($sitecollections.WebApplication.IsAdministrationWebApplication) {
        Log " -- This is Central Administration" "Blue"
        $IsCA = $true
    }

    foreach($sc in $sitecollections) {
        $scUrl = JoinURL $url $sc.ServerRelativeUrl
        Log "  -- $scUrl" "Green"
        $subsites = $sc | Get-SPWeb -Limit 20
        if($subsites -eq $null) {
            Log "    -- No site collections found under this URL" "Cyan"
            continue
        }

        foreach($site in $subsites) {
            $siteUrl = JoinURL $scUrl $site.ServerRelativeUrl
            Log "    -- Fetching $siteUrl" "White"
            Fetch-WebPage $siteUrl

            # For non-Central Admin sites, try a search
            if($IsCA -eq $false) {
                # See if this site has a standard search results page
                $siteSearchUrl = JoinURL $siteUrl "/_layouts/osssearchresults.aspx?k=test"
                Log "    -- Fetching $siteSearchUrl" "White"
                Fetch-WebPage $siteSearchUrl $true

                # Bonus fetch of site search results page for Search Center sites
                $webTemplate = $site.WebTemplate
                if($webTemplate.StartsWith("SRCHCEN")) {
                    $siteSearchUrl = JoinURL $site.Url "/Pages/results.aspx?k=test"
                    Log "    -- Fetching $siteSearchUrl" "White"
                    Fetch-WebPage $siteSearchUrl
                }
            }
            $site.Dispose()
        }
    }
    Log ""
}

$zones=("Default", "Intranet", "Internet", "Custom", "Extranet")
foreach($zone in $zones) {
    Log "$zone Zone" "Yellow"
    $altURLs = Get-SPAlternateUrl -Zone $zone
    if($altURLs -eq $null) {
        Log "-- No URLs under this zone"
        continue
    }
    foreach($url in $altURLs) {
        ProcessWebApplication $url.IncomingUrl
    }
}

# Process any specific URLs
$URLFile = Get-Content $SPECIFICURLs -ErrorAction SilentlyContinue
if($URLFile -eq $null) {
    exit
}
Log ""
Log "Fetching custom URLs" "Yellow"
foreach($u in $URLFile) {
    Log "  -- Fetching $u" "White"
    Fetch-WebPage $u
}

Log "Finished."

read count : 0

Start bochs with a fixed window location

Bochs doesn’t has a parameter to specific the startup window position on screen. If you are compiling boots with SDL2. You can edit boots_source/gui/sdl2.cc, and change the first SDL_WINDOWPOS_UNDEFINED to x position and second SDL_WINDOWPOS_UNDEFINED to y position.

  window = SDL_CreateWindow(
    BOCHS_WINDOW_NAME,
    SDL_WINDOWPOS_UNDEFINED,
    SDL_WINDOWPOS_UNDEFINED,
    640,
    480,
    SDL_WINDOW_SHOWN
    );

read count : 1

Netbeans minimap design

I think atom editor has the best minimap, but there are places for enhancements:

1) Ignore the middle white space can increase the clarity.
2) If the document is too long, atomic editor’s minimap will become scrollable. Because it is scrollable so it will not display the whole code map, this make programmer can’t feel the overall code look like.

read count : 23

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 : 18

This code print all elements and styles of JEditorPane

This code print all elements and styles of JEditorPane

		HTMLDocument doc = (HTMLDocument) jEditorPane1.getDocument();
		printElements(doc.getRootElements(), "");
	void printElements(Element elements[], String tabs) {
		for (Element element : elements) {
			//System.out.println("element=" + element.getDocument());
			int start = element.getStartOffset();
			int end = element.getEndOffset();
			try {
				System.out.println(tabs + element.getDocument().getText(start, end - start));
			} catch (BadLocationException ex) {
				ex.printStackTrace();
			}
			AttributeSet as = element.getAttributes();
			Enumeration e = as.getAttributeNames();
			while (e.hasMoreElements()) {
				Object o = e.nextElement();
				//System.out.println("	o=" + o.getClass());
				if (o instanceof String) {
					String attrName = (String) o;
					System.out.println(tabs + "	string=" + attrName);
				} else if (o instanceof StyleConstants) {
					System.out.println(tabs + "	FontSize=" + as.getAttribute(StyleConstants.Size));
					System.out.println(tabs + "	FontFamily=" + as.getAttribute(StyleConstants.FontFamily));
					System.out.println(tabs + "	Foreground=" + as.getAttribute(StyleConstants.Foreground));
				} else if (o instanceof CSS.Attribute) {
					CSS.Attribute a = (CSS.Attribute) o;
					System.out.println(tabs + "	" + a.toString() + " - " + a.getDefaultValue());
				} else {
					System.out.println("	o=" + o.getClass());
				}
			}
			System.out.println(tabs + "------------------------------------------------------------------");
			for (int x = 0; x < element.getElementCount(); x++) {
				printElements(new Element[]{element.getElement(x)}, tabs + "   ");
			}
		}
	}

read count : 4