Tuesday, September 26, 2006

An inclination to be idle

Been readin' my son's book: "A Dangerous Book For Boys". In it there is the story of Scott of the Antarctic and his doomed mission to the south pole. I was struck by the letter he wrote to his wife, it was one of the last things he did before he died. In particular I like the last line.

He is talking about his son:

"I had looked forward to helping you to bring him up, but it is a satisfaction to know that he will be safe with you...Make the boy interested in natural history if you can. It is better than games. They encourage it in some schools. I know you will keep him in the open air. Try to make him believe in a God, it is comforting...and guard him against indolence. Make him a strenuous man. I had to force myself into being strenuous, as you know--had always an inclination to be idle"

Fab. If Scott of the Antarctic was a bit of lazy bastard then anything is possible my little cheesy computer chums.

An inclination to be idle

Been readin' my son's book: "A Dangerous Book For Boys". In it there is the story of Scott of the Antarctic and his doomed mission to the south pole. I was struck by the letter he wrote to his wife, it was one of the last things he did before he died. In particular I like the last line.

He is talking about his son:

"I had looked forward to helping you to bring him up, but it is a satisfaction to know that he will be safe with you...Make the boy interested in natural history if you can. It is better than games. They encourage it in some schools. I know you will keep him in the open air. Try to make him believe in a God, it is comforting...and guard him against indolence. Make him a strenuous man. I had to force myself into being strenuous, as you know--had always an inclination to be idle"

Fab. If Scott of the Antarctic was a bit of lazy bastard then anything is possible my little cheesy computer chums.

Monday, September 25, 2006

The Internet's future.

From the BBC

"Mobile internet will be dominant," he explained. "By 2020, most mobile networks will provide one-gigabit-per-second-minimum speed, anywhere, anytime.

"Dominant access tools will be mobile, with powerful infrastructure characteristics. All applications will come from the net."


but then I can't help agreeing with this bloke too.

"The problem of the digital divide is too complex and the power of legacy telco regulatory regimes too powerful to achieve this utopian dream globally within 15 years."

Friday, September 22, 2006

j2me Polish: Making your midlets purdy.

J2me or Java Me or whatever it is called has a high level and low level user interface API

The high level UI API is quite simple and allows you to create forms and add fields and lists; check boxes, radio buttons and soft key commands; event handling etc etc.

This is all dandy but its not very nice to look at and varies quite considerably from device to device. Fonts will change and soft keys will (as if by magic) jump from button to button depending on the whims of who put the jvm together for the phone. Midp2 improves this a little but not much,.

What you get is stuff that looks likes this.




The only alternative to this is to develop you own custom interface in the low level api. This is low level in that you are writing you own paint() routines and drawing text on the screen and doing the word wrapping your self etc. This is ok for Johnny Game developers, but is just plain bleedin awful for the rest of us.

To get round this you can use the UI features of j2me Polish. This is a tools suite that is a big help in developing j2me applications. Using the UI libraries of j2mepolish and the preprocessor directives you are able to continue to create midlets using the simple high level but translate them into purdy looking applications by running the source thru the j2mepolish preprocessor.

For instance to create a list in the high level api I would use the following code.


List list = new List("Mobile Researcher" mTitle, javax.microedition.lcdui.List.IMPLICIT);

list.this.append(menuItem1, null ) ;
list.append(menuItem2, null ) ;
list.append(menuItem3, null ) ;


This would produce a midlet looking something like this.




To pretty it up with Polish I would create a polish.css file and fill it full of familiar css code like this:


.menuUI {


background-color: lightblue;
focused-style: menuUIFocused ;

}

.menuUIItem {
margin-left: 10 ;
margin-right: 10 ;
margin-top: 4 ;

font-face: proportional;
font-size: small;
font-color: black;
padding: 4 ;
background-color: white;
layout: left | horizontal-expand;
border-color: black;
border-width: 1 ;

}

.menuUIFocused extends .menuUIItem{

background-color: rgb(49,106,197) ;
font-color: white;
font-style: bold;
}



Then I would add some preprocessor directives above the high level ui statements like so:


//#style menuUI
List list = new List("Mobile Researcher" mTitle, javax.microedition.lcdui.List.IMPLICIT);
//#style menuUIItem
list.append(menuItem1, null ) ;
//#style menuUIItem
list.append(menuItem2, null ) ;
//#style menuUIItem
list.append(menuItem3, null ) ;



Then run it throught the preprocessor and out pops a list that looks like this:



What polish is doing is just preprocessing the code so that rather than using the regular high level ui it using the groovy polish ui which of course has all been painstakingly created in the low level ui, thankfully by someone else.

Phew.

This is lot nicer and demonstrates only a small portion of the tools provided by j2me polish.

This is only a small bit of what polish can do. More later.

Monday, September 18, 2006

Bestival

Sadly the ukeing is all over. Out with a bang at possibly the best little festival of them all - Bestival on the Isle of Wight. Fancy dress and everything.

Sunday, September 17, 2006

Mobriz

Clearly I don't spend all year acting the goat and playing the ukulele. I also create mobile software and services, like Mobriz.

Sunday, September 03, 2006

Specialist Shops in France

Here's a specialist shop my cousin spotted in France. I wonder if they do frilly ones.

Vlad the Impaler, DWR, Struts, Validation and The Beatles

Now open source software is a very splendid thing. Sometimes however, when things don't work quite as you expected or you go off piste slightly you can find your self alone. Now this is not just regular alone of course but really really alone, worse than being left behind on the moon when the spaceship leaves without you.

What I am talking about of course is searching an open source software mailing list archive (in my case Commones Validator) and getting no search results back. when this happens you are really alone.

The next most frustrating thing is when you search the mailing list archive and you get one result back from a bloke in Serbia called Vlad. Vlad has the same problem as you but no-one has replied, worse than that his post was submitted at the sametime as the Beatles "Please Please Me" went to number one.

What I had been trying to do was getting the Apache Commons Validator framework to work with my DWR based AJAX code.

What is good about this is that you can add some @attributes above soome getters in you model code, ala:


/**
* @return Returns the qTxt.
* @hibernate.property
* @struts.form-field
* @struts.validator type="required"
* @struts.validator type="maxlength" arg1value="100"
* @struts.validator-var name="maxlength" value="100" arg1value="100"

*/
public String getQTxt() {
return qTxt;
}


from this you can generate via Xdoclet all validation code like required and maximum length.

This all works nicley if you are on the straight and narrow and are just using JSPs and Struts. If like me you need to to run the validator from Java code because you have gone AJAX crazy then sadly you end up having a night out with Vlad.

So in the spirit of the caring, sharing internet here is my validation code, it's a bit shonky but it does work, so far. Basically you pass in the name of the form and the bean you want to validate and the function populates an array of erro messages.



/**
* @param formName
* @param bean
* @param errorMessages
* runs the stuts validator on a form.
*/
private void validateForm(String formName, Object bean,
ArrayList errorMessages) {

ValidatorResources resources = getResources();
MessageResources messageResources = MessageResources
.getMessageResources(Constants.BUNDLE_KEY);

// set up the validator
Validator validator = new Validator(resources, formName);
validator.setParameter(Validator.BEAN_PARAM, bean);
validator.setOnlyReturnErrors(true);

// run the validator
ValidatorResults results = null;
try {
results = validator.validate();
} catch (ValidatorException ex) {

log.error("Exeception in in validator:" + ex.toString());

}

// iterate over list and build error messages
Iterator itr = results.getPropertyNames().iterator();
Form form = resources.getForm(Locale.getDefault(), formName);

while (itr.hasNext()) {
String name = (String) itr.next();

Field field = form.getField(name);

ValidatorResult result = results.getValidatorResult(name);

String prettyName = messageResources.getMessage(formName + "."
+ name);

Object[] argVals = new Object[2];

argVals[0] = prettyName;

Map actionMap = result.getActionMap();
Iterator keys = actionMap.keySet().iterator();

while (keys.hasNext()) {
String actName = (String) keys.next();
ValidatorAction action = resources.getValidatorAction(actName);

argVals[1] = field.getVarValue(action.getName());

errorMessages.add(messageResources.getMessage(action.getMsg(),
argVals));

}
}

}

Saturday, September 02, 2006

Flickr

Flickr is rather fab isn't it. See my flickr "badge" to the right. Easy peasy cut and past from the Flickt site after following a simple wizard. Hey presto.

God I am easily pleased.

ooof

offf

This page is powered by Blogger. Isn't yours?