Thursday, March 29, 2007

Java/XML/DOM Tip - Pretty Printing XML

I came across an awesome tip for "pretty printing" Java DOM objects to XML files. I found that printing to XML resulted in one long string with the whole document in it, which is not very human readable.

The tip was originally published by Roland Turner and is entitled Java, XML and pretty-printing.

Good luck!

Tuesday, March 27, 2007

Server Admin Tip - Creating a Wiki on a Windows XP Machine

I just created a company wiki for the Product Development team at Collis and I came across a very useful article about setting up such a wiki on Windows XP.

Just about everyone has heard of WikiPedia, but there is a huge variety of ways to set up a wiki. I chose to use MediaWiki, which powers WikiPedia.

After much grief from an unco-operative PHP installation, I found this article - Many Ways to Skin a Wiki - Hosting a Wiki on Windows by Dennis Forbes. The step by step guide was invaluable and probably saved me hours of headache.

The process is a bit more long winded than I expected, but we now have an internal wiki which boasts all the power and ability (just about) of WikiPedia. Now just to get people to use it...

Java/SWING Tip - Assigning an accelerator key to a JButton

We haven't been blogging much lately and I have made a decision to post useful tips and tricks I come across that could help someone else out. Many is the time that I need to implement a new feature and my first port of call is the internet.

I would love to leave feedback on many programming sites and blogs, but the fact that most require you to create an account puts me off - I don't have time at work to create a new account, confirm, navigate to the post in question, leave a comment saying "Great tip, thanks!" and unregister from the site. So, I will be reproducing tips on our blog. If this infringes copyright of some sort, let me know and I will remove the tip. I will of course give credit to the original poster.

So tip 1:

Java/SWING - Assigning an accelerator key to a JButton

Original author: Remus Stratulat (2004-08-18)

http://www.stratulat.com/technical/java/j1/

I modified Remus' original clip of code to hook up an exit action to several cancel buttons in my application. I can then deal with any custom close actions in one place:


// Setting the cancelButton to receive action when ESC is pressed
InputMap keyMap = new ComponentInputMap(cancelButton);
keyMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "ExitDialogAction");

ActionMap actionMap = new ActionMapUIResource();
actionMap.put("ExitDialogAction", new ExitDialogAction(this));

SwingUtilities.replaceUIActionMap(cancelButton, actionMap);
SwingUtilities.replaceUIInputMap(cancelButton, JComponent.WHEN_IN_FOCUSED_WINDOW, keyMap);