May 3, 2012, 9:14 am
x2go is an awesome remote desktop solution for windows->linux. However, by default, Alt-Tab doesn’t work! Luckily it’s easy to fix. Go into your x2go client settings and set thusly:

I’ve replaced -multiwindow with -rootless, and added -keyhook. You can read about the x-server / xwin options here.
February 7, 2012, 2:51 pm
Solve For X – kinda like TED talks but from Google:
http://www.wesolveforx.com/
Looks neat.
February 6, 2012, 1:10 pm
It seems like such a simple task – my java application uses XML/XHTML; how do I perform an XPath query?
After doing a few days of research, the easiest way I’ve found is by using the open source Saxon-HE XPath / XQuery library. I was even able to use it purely as a maven dependency.
Here are the maven dependencies you need:
<dependency>
<groupId>net.sourceforge.saxon</groupId>
<artifactId>saxon</artifactId>
<version>9.1.0.8</version>
</dependency>
<dependency>
<groupId>net.sourceforge.saxon</groupId>
<artifactId>saxon</artifactId>
<version>9.1.0.8</version>
<classifier>s9api</classifier>
</dependency>
And here’s a very simple example of how to use it:
private static String exampleXML =
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
"\n" +
"<bookstore>\n" +
"\n" +
"<book>\n" +
" <title lang=\"eng\">Harry Potter</title>\n" +
" <price>29.99</price>\n" +
"</book>\n" +
"\n" +
"<book>\n" +
" <title lang=\"eng\">Learning XML</title>\n" +
" <price>39.95</price>\n" +
"</book>\n" +
"\n" +
"</bookstore>";
/**
* A simple example upon which the utils are built.
* Docs: http://www.saxonica.com/documentation/xpath-api/s9api-xpath.xml
*/
public static void simple() {
try {
// XPath objs:
Processor proc = new Processor(false);
XPathCompiler xpath = proc.newXPathCompiler();
DocumentBuilder builder = proc.newDocumentBuilder();
// Load the XML document.
// Note that builder.build() can also take a File arg.
StringReader reader = new StringReader(exampleXML);
XdmNode doc = builder.build(new StreamSource(reader));
// Select all <book> nodes.
// XPath syntax: http://www.w3schools.com/xpath/xpath_syntax.asp
XPathSelector selector = xpath.compile("//book").load();
selector.setContextItem(doc);
// Evaluate the expression.
XdmValue children = selector.evaluate();
for (XdmItem item : children) {
// Each book node has a title and price.
// Get the title and show it.
XdmNode bookNode = (XdmNode) item;
XdmNode titleNode = getChild(bookNode, "title");
String title = titleNode.getStringValue();
String lang = titleNode.getAttributeValue(new QName("lang"));
System.out.println(String.format("%s (%s)", title, lang));
}
} catch (Exception e) {
System.out.println(e.getLocalizedMessage());
}
}
/**
* Helper method to get the first child of an element having a given name.
* If there is no child with the given name it returns null.
*/
public static XdmNode getChild(XdmNode parent, String childName) {
XdmSequenceIterator iter = parent.axisIterator(Axis.CHILD, new QName(childName));
if (iter.hasNext()) {
return (XdmNode)iter.next();
} else {
return null;
}
}
Here is the resulting output:
Harry Potter (eng)
Learning XML (eng)
Want more? I’ve put up an eclipse project on GitHub called XPathDemos. It includes a useful utils class you can copy and paste into your own projects.
I’ve also made a little app that lets your experiment with XPath syntax on-the-fly called XPath UI. It’s a great way to get familiar with XPath syntax.
February 6, 2012, 11:29 am
Probably not terribly accurate, but a cool infographic nonetheless:
The Tools that Software Developers Use [Infographic] – How-To Geek
http://www.howtogeek.com/104549/the-tools-that-software-developers-use-infographic
January 29, 2012, 11:46 pm
Here’s a simple example of a ListActivity with a complex layout and ArrayAdapter, allowing us to display items with descriptions.

public class CustomTwoLineListActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final List<String[]> colorList = new LinkedList<String[]>();
colorList.add(new String[] { "Red", "the color red" });
colorList.add(new String[] { "Green", "the color green" });
colorList.add(new String[] { "Blue", "the color blue" });
// Note - we're specifying android.R.id.text1 as a param, but it's ignored
// because we override getView(). That param usually tells ArrayAdapter
// where to find the one TextView entity in a complex layout.
// If our layout was a simple TextView (like android.R.layout.simple_list_item_1),
// we wouldn't need that param.
setListAdapter(new ArrayAdapter<String[]>(
this,
android.R.layout.simple_list_item_2,
android.R.id.text1,
colorList) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Must always return just a View.
View view = super.getView(position, convertView, parent);
// If you look at the android.R.layout.simple_list_item_2 source, you'll see
// it's a TwoLineListItem with 2 TextViews - text1 and text2.
//TwoLineListItem listItem = (TwoLineListItem) view;
String[] entry = colorList.get(position);
TextView text1 = (TextView) view.findViewById(android.R.id.text1);
TextView text2 = (TextView) view.findViewById(android.R.id.text2);
text1.setText(entry[0]);
text2.setText(entry[1]);
return view;
}
});
}
}
January 18, 2012, 5:14 pm
Here is a simple example of an Activity that displays a dialog (AlertDialog) with a text input field (EditText) box.

public class DialogActivity extends Activity {
private static final String TAG = "DialogActivity";
private static final int DLG_EXAMPLE1 = 0;
private static final int TEXT_ID = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_activity);
}
public void onButtonClick(View button) {
// Creates the dialog if necessary, then shows it.
// Will show the same dialog if called multiple times.
showDialog(DLG_EXAMPLE1);
}
/**
* Called to create a dialog to be shown.
*/
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DLG_EXAMPLE1:
return createExampleDialog();
default:
return null;
}
}
/**
* If a dialog has already been created,
* this is called to reset the dialog
* before showing it a 2nd time. Optional.
*/
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
switch (id) {
case DLG_EXAMPLE1:
// Clear the input box.
EditText text = (EditText) dialog.findViewById(TEXT_ID);
text.setText("");
break;
}
}
/**
* Create and return an example alert dialog with an edit text box.
*/
private Dialog createExampleDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Hello User");
builder.setMessage("What is your name:");
// Use an EditText view to get user input.
final EditText input = new EditText(this);
input.setId(TEXT_ID);
builder.setView(input);
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString();
Log.d(TAG, "User name: " + value);
return;
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
return;
}
});
return builder.create();
}
}
January 13, 2012, 2:52 pm
Eclipse is a great Java IDE, but exporting your meticulously-configured settings is a huge pain. (As of Eclipse 3.7, anyway!)
Of course, there’s the “export preferences” command, which can be found via: File > Export > General > Preferences, which will export code styles, compiler settings, and key bindings. But what about the all-important syntax highlighting and the huge number of other settings tucked away under the Preferences menu?
It turns out there are a lot of other important settings that don’t get carried over via the Export command. However, there are text files you can copy from one workspace to another to truly copy your old settings. They are:
- *.prefs files
- Syntax highlighting, templates, all sorts of settings
- dialog_settings.xml files
- Settings for many IDE dialogs
- workbench.xml files
- IDE settings, such as “show heap space”
I’ve written two Windows batch file scripts to automate the process of exporting and importing all of your Eclipse settings. The process is simple.
- Run export_eclipse.bat – this will export your workspace settings to a local dir named eclipse-settings
- (If you are importing to a different computer, copy the eclipse-settings dir to the target computer)
- Run import_eclipse.bat – this will backup your old settings, then copy over your exported settings
That’s pretty much it – run the scripts, they’ll do the rest. Let me know how it goes for you. Tested on Eclipse 3.7 and SpringSource Tool Suite 2.8.1. Windows 7.
January 6, 2012, 10:48 am
Background: I’ve been an avid iPhone user since the first iPhone came out. I’ve been upgrading every 2 years, in alignment with my phone contract expiring. So I’ve had the iPhone 1, and the iPhone 3GS. I was looking forward to upgrading to the iPhone 4S this year, but the lackluster hardware specs finally turned me off to the iOS platform; instead I got the Galaxy Nexus – my first Android phone.
It’s been about a month since I purchased the Nexus, so I wanted to post my comparison of the two platforms while it was fresh in my mind.
Pros and cons of Android / Galaxy Nexus:
Pros:
- HUGE gorgeous screen
- camera is very fast fast, pics are gorgeous
- apps auto-update OTA!
- Verizon 4G FTW over AT&T (in San Jose, anyway)
- integrated voice recognition is great – much more integrated than iOS
- keyboard is huge and smart – autocomplete is great
- touch vibrate feedback is a simply outstanding feature
- notification light is great
- open platform! I set a 3rd-party SMS as default!
- universal back button is a fantastic OS feature
- don’t have to constantly enter my password to use Android market
- can install apps from the market website on my desktop, OTA right to my phone – no iTunes needed!!
- tight 3rd-party OS integration: take a pic with camera, google goggles analyzes it!
- programming is easy and fun with Java – no more “Objective-C” crap, or paying $99/year just to write private apps
- home screen widgets are neat and responsive
Cons:
- moving icons on the home screen is a pain – icons don’t automatically reshuffle
- face unlock is useless
- volume + power button placement is really annoying
- calendar blows – the UI sucks, adding events sucks
- time picker sucks
- market apps have viruses
Overall I am thrilled by the Galaxy Nexus phone and the Android platform. I was hesitant at first about switching sides, but after experiencing how flexible and intuitive the OS is, and using the massive 4.65″ super AMOLED screen, I can’t imagine going back to iOS.
June 23, 2011, 10:18 am
In my CloudCleaner app I have a JSplitPane that contains two JTrees wrapped by JScrollPanes. A user noticed that the JScrollPane scrollbars were not automatically appearing as the trees filled with data.
It turns out I had set the ‘minimum size’ and ‘preferred size’ fields on the JTrees at some point, and this was confusing the scroll panes. Using the IntelliJ GUI editor I restored these settings to their default values, and voila, the scrollbars worked again.
April 25, 2011, 3:35 pm
In IntelliJ IDEA (best java IDE), for whatever reason, your default UI layout isn’t preserved when you export / import your settings to another computer. It’s kind of annoying if you like to keep your IDE’s in sync across machines.
However – I figured out a workaround. IDEA’s UI layout is stored with each project. So you can follow these steps to easily sync your layout:
- In IntelliJ, create a new, empty java project – call the project “intellij-layout”
- Add a
main.java class, and put some placeholder code in it… a void main() method perhaps
- Apply your default layout
- Save and close the project
- Open this project on another machine – your default layout will be preserved
- Save the project’s layout as the default layout
As for how to get the “intellij-layout” project onto another machine – simply copy the entire folder, or just save the project in a dropbox folder.