2012/11/22

TWaverGIS Flex/.Net Has Added the Support for E-map

TWaverGIS has already realized the support for engines like Google Map, GeoServer and MapABC as default. Now some clients would like to combine TWaver with E-map engine, so we add the function to support it as default.

2012/11/15

An Appreciation and Analysis on an Enterprise Application of TWaver

Automatic scheduling function for production can be added into ERP software through the interface for Application Modules developed by TWaver with Swing. We find it quite efficient after the test: it will only cost about one hour to list the 2000 progressing production orders of a medium-sized manufacturer enterprise.

This interface will be projected onto the wall-screen of the company through a big screen or a projector, so that all the members will be able to see the arrangement of tasks and the plans at any time. Some technical points:


2012/11/08

To Test the Code Coverage in Flex with FlexCover

During the process of development, when you want to have a look at the current code coverage as whether there are any unexecuted codes, you can do it with FlexCover. Here are the steps:
  1. Download FlexCover-SDK,http://code.google.com/p/flexcover/
  2. Install CoverageViewer.air:
  3. Please copy a sdk, take the edition 4.1 as an example, and then copy the sdk-modifications-4_0 in the download package into sdk, covering the original file.

  4. Add the revised SDK into the Flash Builder.
  5. Set the current SDK in use as copySDK.
  6. The operation you have done is successful if there is a file named *.cvm now in catalogue bin-debug.
  7. Run CoverageViewer and load the cvm file that has been generated.
  8. Run the demo and see the code coverage:

2012/11/01

How to Export the Base64 Message of an Image

The export of network has been provided in TWaver, so the Network in it can be exported as an image and the data of that Network can be done as binary information or Persistent XML data. Now we will emphasize on how to save images in the form of base64 format when serializing a DataBox.

If you have seen TWaver demo, you must know that the button “Save XML File” has been available on the toolbar of TWaver Network. In addition, there is also a button “Save Image Data” which is to save the image of an element and to serialize it into xml in the form of base64 when TWaver is saving XMLs.
Now let’s see the xml after it has been saved:
<void property="imageURL">
     <string>/demo/resource/images/usa.gif</string>
    </void>
   </object>
  </void>
  <void property="images">
   <object>
    <void method="put">
     <string>/resource/image/twaver/node_icon.png</string>
     <string>iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAASElEQVR42mP4TwGYPGnSfwYQ4/z5&#13;
82RhFANKS0tJwqMGjBqA1QBSsMx3GVQDQAxyMQMusGDevP/ImIFUQLIBu3bt+k8KhukDAHrNjasT&#13;
jbHgAAAAAElFTkSuQmCC&#13;
</string>
    </void>
    <void method="put">
     <string>/resource/image/twaver/link_icon.png</string>
     <string>iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAKUlEQVR42mNgoAYoLS39j4zJMgAb&#13;
m74GUOwNbIaNGjKYDRlGKZYqORkAfhloKfeZLLAAAAAASUVORK5CYII=&#13;
</string>
It can be seen that TWaver saves not only the path of the image of an element, but also the Base64 message of it. If you are careful enough, you will find that the Base64 message of the background image of the network is not included in this xml. Rather, it only saves the Base64 data of the image and the icon of that node. If we have other images or we want to invoke the serialize function ourselves, how to save the Base64 message of images? Now let’s first see the realization of “SaverXML” on the toolbar.
DataBoxOutputSetting setting = new DataBoxOutputSetting();
         setting.setWithElementId(saveElementID);
         setting.setWithAlarmState(saveAlarmState);
         setting.setWithLayers(saveLayers);
      if (saveCurrentSubNetwork) {
       TSubNetwork subNetwork = network.getCurrentSubNetwork();
    setting.setElementFilter(new SubNetworkPersistentFilter(subNetwork));
   }
      if(saveImageData){
       Map images = new HashMap();
       Iterator it = network.getDataBox().iterator();
       while(it.hasNext()){
        Element element = (Element)it.next();
        this.addImage(images, element.getImageURL());
        this.addImage(images, element.getIconURL());
       }
       setting.setImages(images);      
      }
      network.getDataBox().output(fileName, setting); 

private void addImage(Map map, String url) {
    ImageIcon image = TWaverUtil.getImageIcon(url, false);
    if (image != null) {
        String formatName = url.substring(url.length() - 3, url.length());
        byte[] data = TWaverUtil.getByteArrayFromImage(image.getImage(), formatName);
        map.put(url, TWaverUtil.encodeBase64Buffer(data));
    }
}

From the codes above, we can see that TWaver saves the corresponding base64 message of the url of an image into a map, and then “setting.setImages(images);”(in this way, everytime TWaver saves images with their urls when serializing, base64 can be used.) When invoking databox.output or databox.toXML by yourself, you can set DataBoxOutputSetting and save the Base64 messages of the images you need.

At last, there is a complete example in which the Base64 messages of the image of an element and the background image of a network are saved.

import java.awt.BorderLayout;
import java.awt.Color;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;

import twaver.DataBoxOutputSetting;
import twaver.Element;
import twaver.Link;
import twaver.Node;
import twaver.TDataBox;
import twaver.TWaverUtil;
import twaver.network.TNetwork;
import twaver.network.background.ImageBackground;

public class Base64ImageDemo extends JPanel {
    private TDataBox box = new TDataBox();
    private TNetwork network = new TNetwork(box);

    public Base64ImageDemo() {
        Node fromNode = new Node();
        fromNode.setLocation(585, 406);
        fromNode.setName("boy");
        fromNode.setImage("/images/boy.png");
        box.addElement(fromNode);

        Node toNode = new Node();
        toNode.setLocation(99, 222);
        toNode.setImage("/images/girl.png");
        toNode.setName("girl");
        box.addElement(toNode);
        this.setLayout(new BorderLayout());
        this.add(network, BorderLayout.CENTER);

        Link link = new Link(fromNode, toNode);
        link.putRenderColor(Color.GREEN);
        box.addElement(link);

        network.setImageBackground("/images/china_map.gif");

        exportDataBox();
    }

    private void exportDataBox() {
        DataBoxOutputSetting setting = new DataBoxOutputSetting();
        Map images = new HashMap();
        // add all element images
        Iterator it = network.getDataBox().iterator();
        while (it.hasNext()) {
            Element element = (Element) it.next();
            this.addImage(images, element.getImageURL());
            this.addImage(images, element.getIconURL());
        }
        // add network background image
        if (network.getDataBox().getBackground() instanceof ImageBackground) {
            ImageBackground imageBackground = (ImageBackground) network
                    .getDataBox().getBackground();
            this.addImage(images, imageBackground.getImageURL());
        }

        setting.setImages(images);
        System.out.println(box.toXML(setting));
    }

    private void addImage(Map map, String url) {
        ImageIcon image = TWaverUtil.getImageIcon(url, false);
        if (image != null) {
            String formatName = url.substring(url.length() - 3, url.length());
            byte[] data = TWaverUtil.getByteArrayFromImage(image.getImage(), formatName);
            map.put(url, TWaverUtil.encodeBase64Buffer(data));
        }
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        Base64ImageDemo demo = new Base64ImageDemo();
        frame.setContentPane(demo);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(880, 800);
        frame.setTitle("Image Base64 Demo");
        TWaverUtil.centerWindow(frame);
        frame.setVisible(true);
    }
}