Friday, June 11, 2010

Java Date Parsing down to the millisecond

Today I ran into a problem where a String needed to be converted into a java.util.Date. The String looked like this:


String date = "16MAR2010:09:08:27.126000";


So the code to parse the date was originally written like this:


String date = "16MAR2010:09:08:27.126000";

SimpleDateFormat format = new SimpleDateFormat("ddMMMyyyy:HH:mm:ss.SSSSSS");
Date value = format.parse(date);

System.out.println(value);



The problem was that the value printed out was several minutes ahead, 9:10 instead of 8:27. The problem turns out to be that the date parsing format does not allow more then 3 values of "S" in the milliseconds placeholder.

Solution
Strip off the last 3 zeros and change the parse pattern to


SimpleDateFormat format = new SimpleDateFormat("ddMMMyyyy:HH:mm:ss.SSS");

Wednesday, June 9, 2010

Syntax Highlighter for Bloggers

Just so I don't forget and I can easily find it again I decided I would make a blog entry on where to find Alex Gorbatchev syntax highlighter. Adding the appropriate CSS and javascript references to the HEAD of my blog on blogspot allows me to use the simple syntax of this library anytime I need to show a code snippet in my blog. Thanks Alex!!

Syntax Library

A good example of using this library on blogspot can be found here

Blogger Instructions

The basics is to click on Edit Posts > Layout > Edit HTML and add the following to the header section.



Friday, June 4, 2010

Skillcaster uses GWT

For those folks that missed my talk last night on Skillcaster here is the video that I was going to show. One of the things covered last night was why GWT was chosen to build Skillcaster. The video does a nice job of explaining some of the interesting parts of GWT and does it in a way that is more interesting them me yammering at the front of a room.



I went over the application and then technologies used to build the tool.


  • GWT - Rich UI Framwork

  • Guice - Server side injection

  • Gin - Client side injection (Javascript)

  • gwt-dispatcher - Command pattern RPC

  • gwt-presenter - MVP framwork

  • gwt-log - logging framework

  • gwt-pectin - binding framework



I will be working on getting the project moved to Google Code soon and I will send out links for everyone that may be interested in learning more or contributing to the development of Skillcaster.

Friday, May 14, 2010

Communication

The other day I came to the realization that what I need to be good at is communication. Sure my programming skills are still important and my ability to right solid code is a must, but if I can not wrap it in a useful and stunning user interface my coding may be in vain. Many times when I am reviewing applications online I spend less then 10 seconds on their website. If it doesn't load quickly and isn't impressive at first glance I move on. How do I make a stunning interface? How can I get people to pause and learn more when they visit my site?

I know that this sounds silly, but it all started when I started working for an Ad Agency in Cincinnati. As a web developer and a backend, server side programmer, I had spent years developing web based applications that typically were targeted at a single browser, internal audience. Now the applications where public facing and the browser or platform was not controlled. I learned very quickly how hard developing UI and cross browser functionality could be. This wasn't necessarily new as I have known of these issues, at least their existence , for a while now. I have been investigating Google Web Toolkit as a way of navigating around some of these issues. GWT does not provide very much in the way of UI components and most of there stuff is very basic. However if someone knows CSS and HTML fairly well then they can enhance and use the basic components to build more sophisticated components that work well across the browsers. I was determined that CSS was a must to know.

Learning CSS I started with this book. Now for the past several months I carry this thing under my arm as a reference when working on website user interfaces.




During this same period of time I was asked to give a couple different presentations. I had been to the No Fluff Just Stuff conferences and seen some really good presenters. I knew that I did not want to give a boring, read from the slide, bullet riddled presentation. How do you create a stunning presentation? Luckily I work with some really smart people that had already turned me on to a book on Zen presentations. I found it at the book store and glanced through it. It gave me some good ideas that boiled down to finding beautiful pictures from stockphoto. There had to be more then that though. I was very much interested in how to communicate using my presentation tools. After all this post is about communication.

I finally found this version of the book by the same author and it gives details starting with the idea of Zen presentations, going through the different type faces, color themes, photo/video techniques etc...



Conclusion is that I need not only to write good code, but I need to articulate my thoughts in narrative form (blog), live (presentation), and finally in my craft as stunning UI.

GWT: Dealing with the MenuBar inside MVP

Okay so I am trying to follow the MVP pattern of having a View interface that hides the details of the implementation. This has worked great up to the point where I need to add a MenuBar. Normally I would use on of the Has.... interfaces as a return value of a method on the view interface. The presenter then simply calls the getSomeAction().addHandler(....) but this doesn't exist for the MenuItem which uses the Command interface to respond to clicks on menus.

My first response was to create a component that encapsulated the Menu inside a control that had one button per menu item. The view interface could register click handlers by using the buttons on the menu and the menu items would simply fire the click() method on the buttons to execute all registered handlers.

Problem: Button.click() doesn't work if you have not added the Button to the DOM. I don't want the buttons in the DOM and it felt like a kluge to have the buttons in the DOM button hidden.

So my solution was to create a simple interface HasCommand that has one method setCommand.


public interface HasCommand{
setCommand(Command command);
}


Then I extended the MenuItem component overriding the 4 public constructors and implementing the new HasCommand interface. Now I simply use the HasCommand interface in my View definition and this makes it so I can sleep at night.