Aug 27 2007

Running with Shoes – A Mini GUI Toolkit

Shoes is a cross-platform mini-gooey toolkit for the Ruby programming language written _Why. I installed Shoes on an Ubuntu box ran with it (bad pun intended).

Let’s move from puns to code. A simple Shoes application is wrapped around the following piece of code.

[source:ruby]
Shoes.app :height => 250, :width => 200 do
end
[/source]

As you can see, a Shoes application is simply a Ruby block. You can pass in a hash or arguments with the values for the window’s default height and width. If you save the above piece of code as Appy.rb you can run it from the Shoes installation directory by running the following command.

./shoes Appy.rb

If you run the above application it simply opens a empty application window. An empty window is pretty much useless. An GUI application needs buttons and text fields to be of practical use. Lets add two buttons to our application that when pressed print out an informational bit of text to the console.

[source:ruby]
Shoes.app :height => 200, :width => 200 do
button “Button One” do
puts “Button One Pressed”
end
button “Button Two” do
puts “Button Two Pressed”
end
end
[/source]

When working with soft gooeys the second thing one needs to learn after how to add a button is how to layout it out. As of this writing (Release 117), Shoes provides two layout managers, Stack and Flow. Stack lays out your components from top to bottom. The Flow layout container lays out UI widgets from left to right. Building on top of our Shoes application the following code layouts out the two buttons using the Stack cointainer with a 10 pixel margin.

[source:ruby]
Shoes.app :height => 200, :width => 200 do
stack :margin => 10 do
button “Button One” do
puts “Button One Pressed”
end
button “Button Two” do
puts “Button Two Pressed”
end
end
end
[/source]

To add a simple text field just call the text field with the default text value.

[source:ruby]
Shoes.app :height => 200, :width => 200 do
stack :margin => 10 do
button “Button One” do
puts “Button One Pressed”
end
button “Button Two” do
puts “Button Two Pressed”
end
text “Text Field”
end
end
[/source]

Here is how the above code renders.

Running With Shoes

I would be a bit more practical if we can update the text field based on some condition, say when a button is pressed. Since we need to reference the text field in the code block for each button we need to have a variable for it. Also, instead of printing text to the console, we will display it in the text field.

[source:ruby]
my_text_field = nil
Shoes.app :height => 200, :width => 200 do
stack :margin => 10 do
button “Button One” do
my_text_field.replace “Button One Pressed”
end
button “Button Two” do
my_text_field.replace “Button Two Pressed”
end
my_text_field = text “Text Field”
end
end
[/source]

As you can see, you can get started writing Shoes GUI applications fairly quickly. But as mentioned earlier, Shoes is a mini-GUI toolkit that is still under development. _Why has mentioned that he intends to keep Shoes small. From what I can gather from sample applications and the online code repository Shoes provides additional widgets such as an edit_line, edit_box, and list_box. But I was not able to find any information regarding tabs, check boxes, radio boxes, or trees.

In the next installment of Running with Shoes, I’ll go over it’s 2D and animation capabilities.

Technorati Tags: , , , , ,


Aug 1 2007

Programming Flex 2 – Book Critique

There are many formats in which to write a technology book, such as those nutshell, cookbook, and dummy book formats. There are also a set of books that introduce you to a subject from a distance, those that provide a ton of nitty-gritty code snippets, and those that build a sample, yet trivial, application. I would classify Programming Flex 2, jointly produced by O’Reilly and the Adobe Developer Library, as a high-level introductory text for Flex 2 so that managers that have not written a line of code since Fortran can put it on their bookshelf. I feel that a better suited name for this book might have been ‘A Nice Review for Thinking About Programming Flex 2’ as it does not provide enough reference material to actually program a useful application. Programming Flex 2 is a nice overview of the programming environment for Flex but in my blunt opinion it does not give enough depth in any of the topics it tries to cover. The book breaks down the Flex 2 SDK into the following 19 chapters…

Introducing Flex

The introductory chapter on Flex 2 goes over how Flex runs on top of the ubiquitous Adobe Flash player. The author touts the market share of the Flash plugin which is thought to be installed in nearly 98% of all internet enabled machines.

The Flex platform is based on standards such as XML, HTTP, Web Services, and ECMAScript and leverages rich media support in Flash. The Flex Framework consists of libraries for UI controls such as buttons, text fields, menus, layout containers, data containers, effects, and more which are used to build interactive UI clients. You can program Flex 2 applications coding markup code by hand or break down and shell out close to $500 on Flex Builder 2, a Eclipse-based commercial-grade IDE.

Building Applications with the Flex Framework

This chapter provides a bit more detail into MXML, the markup used in Flex, and ActionScript. MXML is compiled into ActionScript which is then converted into a SWF Flash file. Flex 2 SDK comes with two compilers, mxmlc and compc, to build Flex applications. This chapter goes over the details on how to compile a Flex application using the command line and the mxmlc compiler.

MXML

With the obligatory introduction out of the way, this chapter introduces the MXML markup language used to write Flex applications. MXML is a markup language like XML or HTML, so proficient web developers and designer will pick it up right away.

Here is the take away from this chapter. There are two available root nodes for MXML documents, application and canvas. An application is made of components, such as buttons or text fields. There are several types of components, visual just as buttons and non-visual such as data. MXML supports events similar to the onclick events provided in HTML.
Continue reading


Jul 25 2007

Daylight Standard Time Fiasco with Java

One of the hardest things to get right in Java is to figure out which class to use when working with time and dates. You have a recipe for disaster when you mix Java dates with timezone information with energy policy and a tight schedule. The U.S. Energy Policy Act of 2005 changed the start and end dates used for the Daylight Saving Time (DST). This policy had the potential negative effect of breaking millions of desktop computers, similar to the Y2K bug.

Software updates and patches where provided by software vendors such as Microsoft and Sun with plenty of time to spare before the new DST went into effect. The Microsoft patch was available as one of the thousands of security updates that you need to run on a Windows computer every so often. The Microsoft DST update was simply an exe installer. All you had to do to install the Microsoft DST update was to run it and restart your computer. Sun provided a Timezone Updater tool to patch Java with the new timezone data. The Java Timezone Updater is a jar file that you need to run from the command prompt with a series of command options. You need to run the Java Timezone Updater for each and every JRE available on the client machine! A typical client machine will have four to five different versions of the JRE.

Earlier this year when I was writing documentation and instructions for our field engineers for the new timezone change, I knew that the Java Timezone Updater was difficult for end users, even IT professionals, to run correctly. As mentioned you needed to run the updater manually from the command prompt, for every machine, for every JRE on a given machine, and there is no validation or test to notify you of success.

Well, just last week, three months after the DST change took effect one of our clients site started reporting a bug where they select April 2007 but our date widget rolls back to March 2007. After some time of head scratching, code reviews, and debugging we still were not able to reproduce the problem. After some time, it dawned on me that this might be a DST problem and sure enough we were to reproduce the bug on an updated JRE. For some reason, not yet completely explained but most likely related to human error, a whole set of computers where not patched correctly with the Java Timezone Updater. This DST bug locked out our users at this site from key UI screens at a critical time in their work flow.

We had people at the client’s site try to update our client machines with the Timezone Updater, but the bug still keep popping up. We then thought of fixing this in code with some sort of conditional chunk of code but that is just trying to fix a bad bug caused by a bad policy decision with a bad software hack because of a bad JRE update. Since our desktop client runs on Java Web Start, we thought that the best solution was to have our Web Start client run only on a newer version of the JRE that already has the correct and current timezone data. This is not entirely the most accommodating solution for the end user because each client machine now needs to have the correct JRE installed or else our application will not start.

In the end, we went with that hack, to have our JNLP restrict the version of the JRE used on our application. But this is not the best solution, since you have to update every client machines, just the scenario that Web Start promised you would not have to do! The takeaway message from this experience is that dates in Java are hard.

Technorati Tags: , , , , , ,


Jul 9 2007

iPhone Dev Camp

iPhone Development

The iPhone Dev Camp started on Saturday by a nice presentation by Chritopher Allen, a MacHack veteran, regarding what is known about the iPhone from a web developer’s perspective. What is known is that the iPhone uses web standards (HTML, XHTML, CSS, JavaScript, PDF and Quicktime). Web 2.0 best practices apply for the iPhone, such as the proper use and sepration of HTML, CSS, and JavaScript. Christopher recommends avoiding the use of Flash, SVG, Java applets, embedded video, custom x.509 certificates, and framesets. Christopher also states the the finger is not a mouse and you need to design accordingly with large enough buttons and links with plenty of space between each other.
Fingers can do more than the traditional point and drag cursor such as double tap, touch and hold, one or two finger drag, flick, and pinch.

It might come as a surprise but many of JavaScript events don’t work, such as onscroll, onkeydown, onkeypress, onmousemove, etc. Some web development recommendations for the iPhone are to use columns and small blocks in the layout, such as floating divs. You should also use the tel: and mailto: protocols in links. You can also integrate with Google Maps simply by adding your location search to maps.google.com/maps? URL.

The current activity on the the iPhoneWebDev Google Groups seems to be focused around iPhone specific development libraries, implementing the infamous back button, debugging JS, optimizing application for low bandwidth, and hacking the viewport. There is also a series of open questions such as, what level of support is there for the canvas tag? What level of persistent storage is available, cookies? The right questions will lead to the right answers. I have also published a great list of available iPhone development resources.

Most of time at the iPhone Dev Camp was spent developing a collaborating for the hack-a-thon. This was a working camp focused on developing some really cool applications on the iPhone.
Continue reading


Jul 6 2007

Top 15 iPhone Web Development Resources

Here is a list of links to the best available iPhone development resources such as simulators, development plugins, wikis, and other JavaScript/HTML/Safari documentation.

Bonus Resource

  • IPhoneWebDev – Some nice web examples and tips for the iPhone.

Technorati Tags: , , , , , , , ,


Jul 3 2007

Google Maps Builder

I have a really good friend that runs a small travel related blog and she wanted to add Google Maps to her site to go along with her articles, such as this post on LA restaurants. But she is a not a developer and would never ever want to tinker with the necessary JavaScript code used by the Google Maps API. To help in her task of generating custom maps I quickly whipped up Map Builder. Map Builder allows you to zoom in, center, and add any number of markers to a Google Maps canvas. Once you are happy with how a map looks, you can generate the necessary JavaScript code which can be embedded in you website. You do need to sign up for a Google Maps API key before you can display the map on your domain.

On the technical side, I use the Google Geocoder to resolve the longitude and latitude of a given address. Creating a marker for that location is pretty straight forward and there are plenty of examples in the Google Maps documentation. To generate the custom JavaScript source code I used the JavaScript Templates library from the Trimpath project.

Technorati Tags: , , , , ,