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

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

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

This c# code can connect sharepoint 2013 through restful by username and password

Thanks God, This c# code can connect sharepoint 2013 through restful by username and password

            HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create(&quot;http://win-344c6v6tjp4:88/_api/web/lists&quot;);

            endpointRequest.Method = &quot;GET&quot;;
            endpointRequest.Accept = &quot;application/json;odata=verbose&quot;;
            NetworkCredential cred = new System.Net.NetworkCredential(&quot;administrator&quot;, &quot;this is my password&quot;);
            endpointRequest.Credentials = cred;
            HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
            try
            {
                WebResponse webResponse = endpointRequest.GetResponse();
                Stream webStream = webResponse.GetResponseStream();
                StreamReader responseReader = new StreamReader(webStream);
                string response = responseReader.ReadToEnd();
                JObject jobj = JObject.Parse(response);
                JArray jarr = (JArray)jobj[&quot;d&quot;][&quot;results&quot;];
                foreach (JObject j in jarr)
                {
                    Console.WriteLine(j[&quot;Title&quot;] + &quot; &quot; + j[&quot;Body&quot;]);
                }

                responseReader.Close();
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.Message); Console.ReadLine();
            }

read count : 24

open default editor using netbeans api

		try {
			DataObject.find(FileUtil.toFileObject(new File("/Users/peter/workspace/PeterI/kernel/kernel.cpp"))).
					getLookup().lookup(OpenCookie.class).open();
		} catch (DataObjectNotFoundException ex) {
			Exceptions.printStackTrace(ex);
		}

read count : 6

Powershell commands to upload/download a page to sharepoint 2013

Upload file:

Add-PSSnapIn "Microsoft.SharePoint.Powershell" 
# Set the variables 
$WebURL = “http://your_sharepoint/your_site” 
$DocLibName = "Pages"
$FilePath = “C:\a.aspx” 

# Get a variable that points to the folder 
$Web = Get-SPWeb $WebURL 

$List = $Web.GetFolder($DocLibName) 
$Files = $List.Files 

# Get just the name of the file from the whole path 
$FileName = $FilePath.Substring($FilePath.LastIndexOf("\")+1) 

# Load the file into a variable 
$File= Get-ChildItem $FilePath

# Upload it to SharePoint 
$Files.Add($DocLibName +"/" + $FileName,$File.OpenRead(),$false) 
$web.Dispose()

Download file (Html special characters will be escaped):

Add-PSSnapin Microsoft.Sharepoint.Powershell

$WebURL = “http://kmp21dev.emsd.hksarg/kmp21dev” 
$web = Get-SPWeb $WebURL
$file = $web.GetFile('pages/homepage.aspx');
$bytes = $file.OpenBinary();

[System.IO.File]::WriteAllBytes('c:\users\spadmin\homepage.aspx', $bytes);

read count : 12

bochs breakpoint panel

extended netbeans, auto scan .c/.cc/.cpp files to find my bochs breakpoint marco, double click it will jump to there. Small tool, but save me a lot of time.pause_bochs-panel

read count : 14