Embedding Xholon nodes in images

Ken Webb 2010-06-15T00:16:01Z

It's quite easy to embed text inside image files. For example, a .png file may have one or more tEXt chunks that contain some text. Xholon can process this data, if it is formatted in XML as a Xholon sub-tree. This can be very useful for creating Java Swing (or other GUI) content, because you can see in advance what the result will look like. All you have to do is drag the image from a web site or file folder, and drop it on an appropriate node in the Xholon GUI. Xholon will extract the text from the .png file, parse the XML, and build the GUI or other sub-tree. You can drag and drop (or copy and paste) various components to build up larger structures.

For example, the .png file here, contains the following text or comment in a tEXt chunk.

<JFrame Title="A small JFrame">
  <JPanel PreferredSize="Dimension,200,200" Background="ORANGE">
    <JButton Text="Mars" ToolTipText="This is a Martian button." ActionCommand="onToMars"/>
  </JPanel>
</JFrame>

A variety of tools are available to create and view embedded text. One tool that can report detailed information about .png files is pngcheck.

ken@ken-compaq:$ pngcheck -t Mars.png
File: Mars.png (3095 bytes)
Comment:
    <JFrame Title="A small JFrame">
      <JPanel PreferredSize="Dimension,200,200" Background="ORANGE">
        <JButton Text="Mars" ToolTipText="This is a Martian button." ActionCommand="onToMars"/>
      </JPanel>
    </JFrame>
OK: Mars.png (105x116, 24-bit RGB, non-interlaced, 91.5%).

I use the GIMP Image Editor to add comments to a .png file. Load an image into GIMP, and select Image --> ImageProperties --> Comment.

Dr. Andrew Davison discusses a related idea that he calls JavaArt. His Java code converts text into .png files, and the .png files back into text. Instead of storing the text as embedded comments as I describe above, he directly encodes the text characters as pixels in the image. This would be useful in Xholon, effectively compressing Java or XML into a visible chunk that can easily be dragged or copied from a web page, and dropped or pasted into a Xholon node. The advantage is that any text can be readily encoded as an image. The downside is that the image doesn't tell you anything about its content. If the text specifies a GUI component (as described above) then a visually meaningful image makes sense. Otherwise, Dr. Davison's approach is probably better.

return to main page