Java client uses swt to develop svg-based electronic map applications-solution Selection
1. The goal of the Target description is to implement a java client program. This program can display an electronic map in svg format, which can be zoomed in, zoomed out, or translated. You can add custom annotations to the map, you can move the annotation to configure a map. You can double-click and right-click the annotation to perform custom operations. The annotation can be a region, which is associated with another map. You can double-click the annotation to jump to the map. The annotation can also be an object, double-click or right-click an object to display its description or perform corresponding operations. The basemap of a map supports images in the svg format and images in the jpg and png formats. After the map is configured, it is saved as the svg format, the previously configured map content is loaded and displayed normally when other clients are enabled. 2. solution introduction: first explain why images in svg format are required: Scalable Vector Graphics is based on Extensible Markup Language (XML ), A format used to describe 2D vector images. The image we usually see is a grating image. The digitization of images. There are two solutions to store images as data. One is a bitmap, also known as a grating. That is to say, the image is a collection of dense arranged points on the plane from the perspective of natural optics. The light emitted by each vertex has an independent frequency and intensity, which is reflected in the Visual Color and brightness. This information has different encoding schemes. The most common on the internet is RGB. As needed, the encoded information can have different bit values-bit depth. The higher the number of digits, the clearer the color, the higher the contrast, and the larger the occupied space. Another item that determines the fineness of a bitmap is the number of vertices. A bitmap file is a collection of all the data that makes up its points. Its size is equal to the number of points multiplied by the bit depth. The bitmap format is a huge family, including common JPEG/JPG, GIF, TIFF, PNG, and BMP formats. The second solution is vector graph. It looks at the image from an abstract perspective and records the presentation mode instead of the original data of each point. It regards an image as a combination of various "objects", uses a curve to record the outline of an object, and uses a certain color pattern to describe the internal pattern of the object (such as gradient to describe gradient ). For example, a shadow is regarded as a combination of various scenes in different figures and backgrounds. This more advanced perspective is exactly the reflection of human beings looking at the world in consciousness. Vector image formats include CGM, SVG, AI (Adobe Illustrator), CDR (CorelDRAW), PDF, SWF, and VML. Well, simply put, it's a vector image like svg. If you want to represent a red circle, in the xml file of the image, you only need to save the values of the center, radius, and fill color. You do not need to record each pixel like a grating, therefore, svg images in xml format are usually smaller and more suitable for transmission over the network. Here, we will reference the advantages of Baidu's vector images to help you understand: vector images use vertices and lines to describe objects, so the files will be relatively small and provide high-definition images, suitable for Direct Printing or output. The storage unit of bitmap images is the pixel value of each point on the image. Therefore, generally, image files are large and occupy a large amount of network bandwidth. SVG is a vector image format, and GIF and JPEG are grating file formats. With the two concepts, SVG has obvious advantages over GIF and JPEG. 1. arbitrary scaling. Users can scale the image display without compromising the definition and details of the image. 2. The text is independent. The text in an SVG image is independent of the image, and the text is editable and searchable. There will be no more font restrictions. Even if the user system does not install a certain field, it will also see the same screen as they made. 3. Small files. In general, SVG files are much smaller than those in GIF and JPEG formats, so they are downloaded quickly. 4. super-strong display effects SVG images always have clear edges on the screen. Its clarity is suitable for any screen resolution and print resolution. 5. Super color control. SVG images provide a 6 million color palette that supports the ICC Color description file standard, RGB, Line X fill, gradient, and mask. 6. Interaction X and intelligence. One of the main problems faced by SVG is how to compete with Flash, a vector graphics format that already occupies an important market share, and the other is the degree of support provided by manufacturers in the local operating environment of SVG. Based on svg, it has many advantages, so it is widely used in the power industry equipment description diagram. This is exactly why the current target must be in the svg format. 2.1 JFreeSVG SVG has many applications on the web, but it is rarely used in java client programs. Therefore, there are not many corresponding svg libraries, we found that JFreeSVG is a good one, and we have used JFreeChart before. It feels pretty good. They should be together. A fast and lightweight java vector graphics library that simplifies the generation of image output in svg format. When I was doing this function, it was in February March. At that time, I found that the library was updated frequently. I was worried that there were many bugs and I did not study it carefully. 2.2 Batik is a java-based toolkit and is an open-source project under Apache. The main function is to provide methods for java programs to operate svg files. The latest version of Batik is 1.7 and 2012, so it is much more mature than JFreeSVG. because it provides a lot of svg image processing functions, the library file is large, with more than 7 MB. The usage of Batik on the internet is relatively basic. The main reference is the API document. Based on the collected information, a demo of the simplest parsing svg file is written in java. The JSVGCanvas module provided by the Batik toolkit is a swing component used to display static or dynamic SVG documents. With the JSVGCanvas module, developers can easily display and operate SVG documents (through URI addresses or DOM trees), such as rotating, scaling, shaking, selecting text, or activating hyperlinks. Because our clients use swt for interface development, we need to embed the swing language development interface in the swt program. The following key code can be used to embed the swing interface in swt.
Final Composite comp = new Composite (this, SWT. EMBEDDED); final Frame f = SWT_AWT.new_Frame (comp); SwingUtilities. invokeLater (new Runnable () {public void run () {// creation code of the Swing window });
Then, use the JSVGCanvas class in the swing code to parse the svg file. The method is simple: svgCanvas. setURI (newURI), you can parse the svg file in the corresponding path. Final Implementation (display an image in svg format): wps71C1. other tmp functions, such as generating svg files, embedding bmp files, and editing svg files. In the future development process, check the information, this survey at least proves that it is feasible to use the batik library to process svg files, and it is also a mature solution.