GWT: Widgets, Drag and Drop

March 8th, 2010 by jeremychone | No Comments »
  • Smart GWT (demo): Free/LGPL:  Seems to be mature and well maintained
  • GWT drag and drop: Free/Apache 2.0: Seems to be mature and well maintained
  • GWT EXT: Paid/Dual License: Complete and huge libs. Seems to be wrappers on top of ext

Javascript: Online JSON Formatter

March 7th, 2010 by jeremychone | No Comments »

http://jsonformatter.curiousconcept.com/

GWT: JsonpRequestBuilder No source code is available, did you forget to inherit a required module

March 4th, 2010 by jeremychone | No Comments »

To use the JsonpRequestBuilder, you need to inherit the following in your x.gwt.xml

<inherits name="com.google.gwt.jsonp.Jsonp" />

Javascript: Triggering a click event on a element

February 27th, 2010 by jeremychone | No Comments »

Sometime, the jQuery(”#xx”).click() does not work. So, here is a way to do it directly:

var e = document.createEvent('MouseEvents');
e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
var r = $("#myElement").get(0).dispatchEvent(e);

Obviously, you can use the document.getElementById(”myElement”) if you do not want any jQuery dependency.

javascript: Get parent window location href from an iFrame

February 22nd, 2010 by jeremychone | No Comments »

Assuming the iframe is from the same domain that the top window, use frameElement.ownerDocument to get to the parent document.

var topWindowHref = window.frameElement.ownerDocument.location.href

javascript: Remove items from an array

February 22nd, 2010 by jeremychone | No Comments »

From John Resig Javascript array remove

Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};

Examples:

// Remove the second item from the array
array.remove(1);
// Remove the second-to-last item from the array
array.remove(-2);
// Remove the second and third items from the array
array.remove(1,2);
// Remove the last and second-to-last items from the array
array.remove(-2,-1);

Chrome: Cheat Sheet for Writing a Chrome Extension

February 13th, 2010 by jeremychone | No Comments »

Getting started official tutorial

http://code.google.com/chrome/extensions/getstarted.html

manifest.json

{
  "name": "My First Extension",
  "version": "1.0",
  "description": "The first extension that I made.",
  "browser_action": {
    "default_icon": "icon.png",
    "popup": "popup.html"
  },
  "permissions": [
    "http://api.flickr.com/"
  ]
}

See also: Browser Actions

Debug & Inspect extension

  1. chrome-extension://extensionId/popup.html to see the page
  2. got to chrome://extensions/ and click on popup.html
See also: Debug extensions

Android: Take an android screenshot from a PC

February 12th, 2010 by jeremychone | No Comments »
  1. Install Android SDK and Android Driver
  2. Set android USB mode to debug (Settings > Applications > Development > USB Debugging)
  3. Connect Android to PC with USB cable
  4. launch \android-sdk-windows\tools\ddms.bat
  5. Click on Device > Screen Capture (or Ctrl S)
Tutorial video (not sure why the driver need to be installed manually. I installed it normally and it worked)

Java: Move a File to a new Directory (Folder)

February 6th, 2010 by jeremychone | No Comments »

Yes, File.renameTo is used to move file.

// File (or directory) to be moved
    File file = new File("filename");

    // Destination directory
    File dir = new File("directoryname");

    // Move file to new directory
    boolean success = file.renameTo(new File(dir, file.getName()));
    if (!success) {
        // File was not successfully moved
    }

source

jQuery: jQuery event with RaphaelJs

February 5th, 2010 by jeremychone | No Comments »

HTML

<div id="rtest">
</div>

Javascript code

<script type="text/javascript">
 $(document).ready(function(){
	var paper = Raphael("rtest", 320, 200);
	var circle = paper.circle(50, 40, 30);
	circle.attr({
  	 "stroke": "#336699",
	  "fill": "#fbfbfb"
	});

	$(circle.node).click(function(){
		var circle = this.raphael;

                //Toggle the circle fill color
                if (circle.attr("fill") == "#333333") {
		     circle.attr("fill", "#fbfbfb");
                } else {
		     circle.attr("fill", "#333333");
		}
	});
});
</script>

See RaphaelJs Event doc