Wednesday, February 10, 2010

Vaadin Refcard updated

I made a few minor corrections and additions to the Vaadin Refcard, which was released last week at DZone. If you already downloaded it, you might to get the new version.
  • Vaadin is available under Apache License 2.0
  • For Item editors, such as the Form component, you can set the item data source with setItemDataSource()
  • For Container editors, such as the Table or Tree components, you can set the container data source with setContainerDataSource()
  • The book cover on the last page was updated - the cover for Vaadin 6.2 edition is blue
  • The text in the last page was reordered to be more correct
The refcard could be updated next after Vaadin 6.3 is released in the late spring. The major features are use of GWT 2.0 for the client-side, drag'n'drop, and support for portlet flat mode.

    Monday, February 1, 2010

    Vaadin Refcard is out!

    The Vaadin Refcard is finally out at DZone. Download yours now or browse the card on-line.

    If you're a newcomer to Vaadin or interested in finding out what it is, the Refcard offers a great introduction to Vaadin. Much of the reference material should be also useful to those already familiar with Vaadin.


    The six pages of the Refcard present a well thought summary of the most essential features of Vaadin, which are covered in detail in the Book of Vaadin. Much of the reference information is presented in tightly packed diagrams; just look at them for a moment and I hope you'll see the genius of Vaadin as I do.

    The contents are:
    • Creating an Application
    • Components
    • Layout Components
    • Themes
    • Data Binding
    • Creating New Components
    As Vaadin is developing fast, I hope to make updates to the card occasionally. So, especially after update releases (Vaadin 6.3 is coming next), please look out for an update of the card.

    More Information:

    Friday, January 8, 2010

    Client-Side Validation for Vaadin

    I recently created a new component for Vaadin, the CSValidationTextField (suggestions for a better name are welcome), which is an extension of the regular TextField. It can validate the input with a regular expression and/or a JavaScript program.

    Of course, you can't trust the client-side code for validation, so you need to validate the input on the server-side as well. For regular expression validation, you can use the same expression for the server-side RegexpValidator. For example:

    // The Finnish Social Security Number
    final CSValidatedTextField ssn = new CSValidatedTextField("SSN");
    String ssn_regexp = "[0-9]{6}[+-A][0-9]{3}[0-9a-zA-Z]";

    // The client-side validation
    ssn.setRegExp(ssn_regexp, "000000-000A");
    ssn.setAllowInvalid(false); // Prevent typing invalid values

    // The server-side validation
    ssn.addValidator(new RegexpValidator(ssn_regexp, "Invalid SSN"));
    ssn.setRequired(true);
    ssn.setRequiredError("SSN is required");

    form.addField("ssn", ssn);

    Matching partially filled values has some problems currently. If you disallow typing invalid input, as in the example above, the regexp validation currently needs an "example" and is restricted to only fixed-length fields. I'll have to look if the JS regexp matching can somehow report if there's a partial match. If you allow invalid input, there are no restrictions and the fixed-length example is not needed.

    You can validate with JavaScript just as easily:

    CSValidatedTextField postcode = new CSValidatedTextField("Postal Code");
    postcode.setJavaScript("if (value >= 0 && value < 10000)" +
    " \"partial\";" +
    "else if (value >= 10000 && value <= 99999)" +
    " null;" +
    "else" +
    " \"Postal Code must be a 5-digit number between 10000 and 99999\";");
    layout.addComponent(postcode);

    The server-side validation needs separate Java code though, unless you use some JavaScript execution library.

    You must validate the input on the server-side as well, as the client-side validation does not actually prevent inputting invalid values (unless you set setAllowInvalid(false), but that's a bit restricted at the moment).

    See the example source codes (link below) for more examples.

    See:

    Included are also handy interactive editors for the regular expressions and JavaScript validators, as you can see in the demos.

    The component is not packaged yet, so using it may require some effort. I'll have to look into the packaging.

    Thursday, October 29, 2009

    Playing in Order

    I've been fighting with my E90 for a few hours to get it play the MP3s of the Lord of the Rings audio books in proper order. It's not so easy.

    First, I had to set proper track and disk information in the MP3s. This was easy enough with the Amarok music player for KDE. It allows easily editing the metadata, also in a group of files. There was some hand work to edit the track numbers, which took about half an hour for the 20-disk set.

    Another and a more strange problem was that my E90 orders the MP3s to play in the directory order. The directory order is a low-level technical order in which files are stored in a directory (folder), and is not necessarily the same as the alphabetical order. Apparently, in FAT, the directory order is the order in which the files are written. In Linux, however, the directory order can be about anything, depending on the file system. In the EXT3 filesystem, the order seems pretty random and is probably the order of some hash table.

    Unfortunately, every copy program, such as Konqueror, scp, or the command line "cp", copies the files in the directory order, so it's not possible to trivially copy files to a phone or MP3 player in alphabetical order. One solution is to use a specially ordered copy operation from command-line.

    In my case, I had the MPs of the 20 CD audio book ordered under per-disk directories, so I had to use the following somewhat complex copy command:
    for dir in `ls /home/magi/data/mp3/Sormuksen\ ritarit/`; do
    echo `ls -Q /home/magi/data/mp3/Sormuksen\ ritarit/$dir/*.mp3` "/media/Magi\ 2G\ u1/Sounds/Digital/Sormuksen\ ritarit/$dir/" | xargs cp -v
    done
    An alternative would be to first write everything to the player in any order and then use the "mv" command to move the files to a temporary directory, and then remove the original directory and rename the temporary directory as the original.

    Moreover, if you have earlier written the MP3s to E90 in one order, it remembers the order even if you rewrite the files in another order. You first have to remove them from the player application, then write them again in the proper order, and only then you can play them properly.

    References
    Some other solutions in Linux Forum: Change the order of files in a directory.

    Tuesday, October 27, 2009

    Vaadin Cheat Sheets

    I designed the Vaadin Cheat Sheet last summer. I really like it, especially its style that follows the Vaadin graphical style.

    During the last few weeks, the demand for the cheat sheets has been growing. There's one on display at the ICT building in Turku, where you can get a free copy of Book of Vaadin. This week, I got some more lamination pockets to make more laminated cards. The new pockets with matt finish are nice, you can even write on them with a pencil.

    I somewhat enjoy laminating the cards. Even though it's purely manual labour, it's quite relaxing to work manually by a routine for a change and not have to think or design anything. This also means that I can't make the cards by the thousands, like the books. Nevertheless, I try to make enough for IT Mill customers, some community members, and for special promotion purposes.

    Just today, I corrected a small error: the CSS style class of the ComboBox component is v-filterselect, not v-combobox. There might be other similar errors.

    Thursday, August 27, 2009

    N900 vs iPhone

    Hi, I collected a rough list of some features. The list is not exhaustive and there may be some important features in software and interoperability that are not covered. Please comment and I'll add new notes.

    N900iPhone 3GS
    Basic stuff
    Size111x60x18mm116x62x12mm
    Weight181 g133 g
    Screen Size3.5 inch3.5 inch
    Screen Resolution800x480320x480
    Screen Colors65536 colors?262144 colors
    Screen materialplastic?glass
    Touchscreen techresistivecapacitive
    Touchscreen fingersonetwo
    Built-in keyboardyesno
    Screen keyboardyesyes
    Computing
    ProcessorARM Cortex A8ARM Cortex A8
    Processor speed600 MHz600 MHz
    Graphics acceleratorPowerVR SGXPowerVR SGX
    RAM256 MB256 MB
    Virtual memory768 MBnone
    SSD storage, internal32 GB16/32 GB
    External storageup to 16 GB (MicroSD)none
    Software
    Operating systemLinux-basedDarwin-based
    Web BrowserMozilla-basedSafari
    Zoomingyes, one-fingeryes, two-finger
    Adobe Flash supportFlash 9.4none
    Javapossiblynone
    Skypeyesno
    Video formatsmp4, .avi, .wmv, .3gpmp4, m4v, mov?
    Video codecsH.264, MPEG-4, Xvid, WMV, H.263H.264, MPEG-4?
    Music formats.wav, .mp3, .AAC, .eAAC, .wma, .m4am4a, ...?
    Open application developmentyesno
    Music/software storeNokia OviiTunes, App Store
    Operator locknoyes
    Misc hardware
    Camera5 Mpix3 Mpix
    Video recordingyes, 16:9yes
    Video size and rate848x480 @ 25fps640x480 @ 30fps
    Microphonestereomono?
    Geotaggingyesyes
    GPSA-GPSA-GPS
    Cell-based navigationyesyes
    Accelometeryesyes
    Wireless network802.11 b/g802.11 b/g
    Video outyes (PAL/NTSC, WLAN/UPnP)yes
    FM transmitteryesno
    Headphone connector3.5 mm3.5 mm
    Compassnoyes
    Replaceable batteryyesno
    Other
    Designed in Finlandyesno
    Jesus uses itnoyes

    Sunday, July 27, 2008

    First Impressions with Suunto Core Wristop Computer

    I bought a Suunto Core "wristop computer" yesterday and as usual, I wish to write a bit about my first experiences with the device. So far, the compass is very problematic and the temperature meter is useless. The compass is the most important feature for me and it really should work.


    Suunto Lumi was my second choise and just fifteen minutes after buying the Core I regretted not buying Lumi instead. Core is HUGE, basicly a UFO strapped to your wrist and distinguishable from at least lower Earth orbits. Lumi is essentially the same device but it's half the size, so it's more of the size of a conventional men's watch. For some strange reason, Lumi is marketed for women. While the Suunto Core marketing talks about traveling in wilderness and scaling mountains, Lumi marketing talks about finding directions in rock festivals. Ok, the wrist strap is a bit ornamental in a feminine way and a regular black strap might be more mannish, but Suunto sells separate straps so that should not be a problem. The only missing features in Lumi are the rotating bevel (it's useful) and the depth meter (very rarely useful). And Lumi is 50 euros more expensive than Core (250 vs 200 euros).

    In this article, I will go through the main features.

    Construction

    As I said, it's HUGE. The only reason that I can think of for the size is that you can use it with the gloves on. Strangely, the Suunto webpages do not advertise this reason. The size is a problem in so many ways. It doesn't really fit under the sleeves and it makes more difficult to don a jacket. As I need the watch when traveling, I don't want my watch to draw the attention of the natives who make 30 euros a month and the watch worth their six months salary (not that my pro-looking camera equipment draw any attention). On the other hand, I wish I had had the watch when I went snorkling in the coral reefs at Keys. Anyhow, I would have preferred Suunto Lumi.


    Despite the size the watch is really light. The size is apparently just empty space and not because the electronics require that much space. It's not light enough to float though - I tried. The wrist strap is a bit gelatine-like material and it's somewhat difficult to open the lock. You can not adjust the strap, or more accurately, you have to adjust it every time you put it on your wrist. There are so many holes that it's not easy to know which one is the best. Because of the gelatinish material, the skin under the strap sweats like a pig. The reason to have a metal wrist strap is not that it looks pretty but because it conducts heat.

    Another problem with the strap is that it's positioned so that it is not possible to put the watch on a table surface (see the figure below). This makes use and especially calibration of the compass very very very difficult, because the compass must be leveled very precisely. Also, the back-side of the watch is nowhere near flat. It also makes setting compass direction on a map much more difficult. Have the designers actually used the watch?


    Some people at Suunto discussion forums complained about too loose or tight compass bezels. The rotation stiffness of my bezel is excellent, but in small scale the bezel is loose and moves even if you touch is only lightly. The bezel has 60 steps so for compass purposes the steps are 6 degrees. Unfortunately, the compass scale is not written in the bezel and it only has letters indicating the cardinal directions. Some other models have a scale.

    The glass is mineral glass and it is a good thing that it is not plastic as most cell phone displays are. Plastic displays scratch really easily and they are full of scratches in a year or two. The most scratch-resistant glasses are the sapphire-coated ones, but ordinary mineral glass is usually enough. The surface is convex and looks good. If you end up stranded in an island, there's no point in removing the glass and using it as a burning lens to light your campfire, as you can just use the reflection for the same purpose (if it only was reflectively coated). Oh well.

    The Clock

    The clock is such a basic functionality that it is hard to screw it very badly. I have not used the watch long enough to say how well it keeps time. At first, I thought that the watch lost time very fast (10 seconds per day), only to notice that it was my computer's clock that lost time. When comparing to accurate time, the Core seems to have gained about 3 seconds in 4 days, which is not good, but I'm again not certain that I set the time correctly in the first place.

    The clock has a number of views: just time (hh:mm), time and date, time (hh:mm) plus seconds, time (hh:mm) plus time at a secondary timezone, time plus sunset/sunrise times, timer, countdown timer. Why are there so many views with just minor differences? What's the use of showing just time and not date or seconds? Why isn't there a view that shows all time (hh:mm:ss) and date in one view?

    The only really annoying thing is the countdown timer. I need such a timer almost daily for foodmaking purposes. Setting the countdown time requires that you gough the menu: click Menu (2s) - select time-date (2 clicks) - select countdown (2 clicks). Then you can set the countdown time. Why can't you just set the countdown time in the watch view?

    The Altitude Meter / Barometer

    The altimeter in Suunto Core is supposed to have resolution of one meter. I haven't been able to measure this very accurately yet, but it seems believable. I used the altimeter in one measurement to measure the relative height of two pillars 400 meters apart and it gave constant readings within some 2 meters. The problems are in calibration. Core allows you to calibrate the altimeter in two ways: by a known altitude or by local atmospheric pressure at sea level, which you can get from weather stations.

    The problem with the calibration by the atmospheric pressure is that Suunto Core allows setting the pressure with the resolution of one hPa, but the difference of one hPa is 27 meters in altitude! Weather stations give the pressure with one decimal. The advertised one meter altitude accuracy means that Core should be able to measure pressure with about 0,03 hPa resolution, so why can't I calibrate it even with one decimal?

    Another problem with the altimeter and barometer mode is that it's a lot of work to switch between them. Switching between them through the menu (which requires 2s press to open) takes 10 button clicks in all. Not very easy! There is an "automatic mode" though, which should have the altitude meter on when the pressure changes fast (i.e. when you're moving vertically), and barometer on when you're stationary, but it takes a few (2-3) minutes to switch to the altitude mode and a lot longer (15-30 minutes) to switch back to the barometer mode.


    The altiude/barometer mode also shows the temperature. Unfortunately, the body temperature affects the reading strongly, so when you're wearing the watch in your (naked) wrist, it will show 30-33°C if real temperature is 20-30°C. I did a small experiment: digital thermometer shows 28,9°C and Core shows 30°C. I put the watch in my wrist and wait 5 minutes. It will show 32°C. So, it's basicly useless when you're wearing it. Taking it off doesn't help very quickly and it takes maybe 15-30 minutes to stabilize. I would really have expected that the watch would compensate for the body temperature at least a bit, possibly by measuring the temperatures from back, middle and front sides of the watch and extrapolating the temperature. Or just by using a thermometer that measures the air temperature with infrared or something. I suppose there might not be a perfect solution, but currently it's just bad.

    The Compass

    The compass has been nearly useless so far, because it's highly sensitive about tilting and loses calibration all the time. So, while the specs say that it should be accurate to 1 degree, I would say that it's accurate to maybe 180 degrees, because you never know when it has lost the calibration completely or just partially. It doesn't need to be accurate to one degree and some 5° would be acceptable, but now the accuracy is much worse.

    The compass is really the most important feature of the watch for me. I need it for urban orienteering when I'm traveling and for rough directions for amateur astronomical purposes. For example, I want to know the rough direction of the Sun or the Moon or some planet or a star that I see in the horizon. When I'm gazing for satellites and there's a predicted satellite flash at a certain time, I need to know the exact direction where it will show. If I see a meteor (or even a fireball), I need to be able to estimate its radiant. At night, I can usually see the directions from the stars very easily, but in daytime or in dusk I really can't. Finding Venus or Mercury from the sky during daytime requires knowing the exact direction.

    Occasionally, I get happy when the reading looks reasonable, but then I realize that it's the same as a dead wall clock being correct twice a day. Typically, the error is about 20-50 degrees, so in a real situation, you would not really know that there's something badly wrong. For note, I have calibrated the declination, and it's not huge anyhow (+6.5°), so it's not that. Reading the direction at one place can give steady readings, but fifteen minutes later it gives totally different readings. Sometimes the compass goes to an oversensitive state in which, if I turn 90 degrees, the reading changes 180 degrees.

    The problem may be that the compass loses its calibration very easily and needs to be recalibrated, in practice every time you use it. The watch doesn't actually allow recalibrating the compass the same way as it was calibrated on the first use. The manual says that you can recalibrate it just by rotating it slowly around for a full circle, but this method is a bit uncertain as the watch doesn't actually indicate when it has been recalibrated. The watch needs to be kept exactly leveled during calibration, but the badly shaped wrist strap (see above) makes it impossible to level the watch on a flat surface, so you need for example a bottle to put it on. But you can't carry a table and a bottle around the world in your backback, can you?

    The User's Manual says that the compass must be held leveled with the ground for it to be accurate. That' s an accurate statement, even if the compass is not. Tilting the watch even slightly can change the compass reading radically, so that a 1° tilt can sometimes cause 2-3° error in the reading. Sometimes, possibly if calibrated better, the compass is less sensitive to tilting and behaves even reasonably well. The manual says that the watch would warn about tilting (Finnish manual says - English doesn't), but it doesn't give any warning for me however much I tilt or not tilt the watch. I've experimented a lot with this.

    The sensitivity to tilting creates a practical problem: leveling is not easy. You can level the watch most accurately by looking at it horizontally against the horizont, but then you can't read the compass reading without lowering it. The watch isn't really designed to be held leveled. The wrist strap prevents from actually putting the watch on table. I've found a cardboard tube from an empty toilet paper roll to be useful for leveling the watch.

    Pressing the light button creates a really weird light show: the light goes off and on about two times a second so it's flashes quite annoyingly. The display font in the compass mode is really ugly.

    Other

    A hint for Finnish buyers: Kello- ja kultaliike Suominen in Turku sells these for 200 euros while other places demand 250. Also the price for Lumi is 50 euros cheaper than elsewhere.