Project BDE2GIF Part II: JAVA version FINAL REPORT Hua Ren May 5, 1997 97s523: Software Engineering I Instructor: Professor Robert Lechner Department of Computer Science University of Massachusetts at Lowell (last rev.: 97/9/18 - RJL) Final Report of Project BDE2GIF, Part II: JAVA version Principal Author: Hua Ren Instructor: Professor Robert Lechner Course: 91.523, Spring 1997 Software Engineering I Project: BDE2GIF: Part I: C/C++ version Part II: JACA version Team number: Hua Ren Rahim Semy Mikhail A Zelikon Path: /usr/proj3/case/97s523/bde2gif/hren Abstract The Block Diagram Edit (BDE) is a graphics user interface (GUI) based application developed in the Department of Computer Science, University of Massachusetts at Lowell lead by Professor Robert Lechner. One specific task is reported here: To improve the java version of BDE by implementing a converter from BDE graphs to Graphics Interchange Format (GIF) files, as an option for BDE users to generate output files. The BDE2GIF team members in 91.523 Spring semester, 1997 class (Software Engineering) at the University of Massachusetts Lowell distributed their works into two sub projects: one in the C/C++ version of BDE, and another in the Java version of BDE. This is the final report on the BDE Java version carried out by Hua Ren. Table of Contents 1. Introduction 2. Objective and Design of The Project 3. Implementation 4. Other Important Improvements 5. Testing 6. General Data flow Diagram: A Sample Output in GIF Format 7. Suggestions for future Improvement 8. Compiled log 9. Summary Appendix: BDE User Guide for Java Version 1. Introduction The Block Diagram Edit (BDE) is a graphics user interface (GUI) based application developed in the Department of Computer Science, University of Massachusetts at Lowell leaded by Professor Robert Lechner. It is a powerful tool for generating data models graphically. The codes of BDE was originally written in C/C++. In recent years, the Java language provides an unique cross-platform environment for software development. For example, Java bytecodes (Java classes) can be run without recompiling in any platform with Java binaries and lib installed. Current releases of Java include versions for Windows3.x, Windows95/NT, several UNIX/X-window systems, and Linux/Xfree. The Java version of BDE was initially developed after the release of Java. Compared to the C/C++ version of BDE created much earlier, the Java version of BDE has most important facilities but a certain tools are still needed to be implemented. The current Java version of BDE is an application (different than applet-mode programs). Graphics Interchange Format (GIF) is a graphics format adopted by many applications. It is CompuServer's standard for defining generalized color raster images. GIF allows graphics to be saved with 8-bit color and in good quality. Typical file size of GIF is rather small compared to bitmap file (BMP) or postscript file (PS). The most importantly, GIF is among a few graphics format adopted in popular web browsers as default formats. Saving BDE graphs into GIF files will provide convenience for network programming and distributions. 2. Objective and Design of the Project The objective of Project BDE2GIF is to add codes into BDE source files to provide user a choice to save a single BDE diagram or the whole set of BDE diagrams to GIF files. The saved files should be in correct format and can be opened by any graphics viewer support GIF format. The menus should be arranged as clear as possible. The files should be named related to BDE data file or files. The project was designed to be implemented in following steps: (1) Modify an existed GIF encoder or write one to convert standard RGB table into GIF format; (2) Rewrite related classes and methods and add new methods or classes in BDE-Java to connect images drawn in the applets to RGB or Image arrays in memory for converting to GIF; (3) Rewrite menu related classes and methods for arranging new GIF save option. 3. Implementation 3.1 GIF Encoder: Because Java lib only support open GIF file to display through pixel grab procedure and does not have AWTs for direct encoding to graphics format, Internet become a selected place to find some useful tools. A class called "GIFEncoder" was eventually found in GAMELAN site (www.gamelan.com). It was written by Adam Doppelt (http://www.cs.brown.edu/people/amd) based upon a C program for the same purpose gifsave.c written and released by Sverre H. Huseby. After fixed one bug, it works well in a off-line test. GIFEncoder is a class which takes either three byte arrays storing red (R), green (G), and blue (B) or an Image class (Java AWT class) then retrieve RGB byte arrays. The RGB byte array then will be encoded into GIF format and saved to a stream. Several methods can be called inside application classes. Since the image need to be fully loaded to start and the conversion as well as encoding are actually processed in a pixel-grab way, the speed is comparably slower than PS saving where only strings are used. 3.2 Write new methods and modify old classes and methods to use GIFEncoder The most important step to use GIFEncoder is to retrieve an Image class or to derive RGB arrays directly. Because BDE is an interactive drawing application, this Image or the RGB arrays must be able to provide most updated information based on user's actions or any other events. In Java, default graphics device (class Graphics) is always directed to applets as default. Grasping image from display is not supported. Fortunately, Java AWT does support the so-called "double-buffering" method which allow programmer to generate a mirror Image class associated with Graphics class. Applying this method to init()and update()of applet can always keep the Image class being updated. Based on these methods described above, therefore, a method: outputGif (Graphics g, String file_name) was written and added to class bdeAppletFrame (bdeAppletFrame.java). It is called inside method eventHandle() in class bdeAppletFrame. In this method, the related images (either current or whole) or RGB (as an option) are first derived by using double- buffering. Then the GIFEncoder is called to write the images to streams in GIF format. When saving current graph is chosen, method outputGIF will create a single GIF file by setting bdeGraph index to the current and save the image into it. Otherwise when multiple saving option is selected (saving whole graph set), it will get images through a loop to the bdeGraph index and generate associated GIF file inside the loop then save each graph into related GIF file respectively. These files are in GIF87a standard formats and named according to related BDE data file name. Certainly, GIFEncoder has to be listed as imported lib. To implement this in bdeAppletFrame.java an include line as: import GIFEncoder; has been added. 3.3 Rearrange new items in menu bars and add event handling: (1) Rearrange menu bars: The original "Print..."(bde2java 96s523) was just for writing PS ( post script) file. In the new version, Print... has two sub menu bars: Print As GIF Print As PS Then two sub-sub menu bars have been also put under "Print As GIF": Print Current Graph Print All Graph and two sub-sub menu bars under "Print As PS": Current Graph All Graph (2) Add related functions in the method:"public Boolean handleEvent()" of bdeAppletFrame.java class: Function: if (the "Print Current Graph" under the "Print As GIF" was choose) then call outputGIF and set single graph current graph saving option else if (the "Print All Graphs" under the "Print As GIF" was choose) call outputGIF and set multiple saving option to save all graphs (3) Others: Message gave status of GIF saving has been added into the code so that user will be informed when either the saving procedure starts or saving accomplished. Since GIF file may need quite much time to process, this type of information displayed in terminal or console seems very informative. 4. Other Important Improvements (1) Modified the method: public String fprint() in bdeGraph.java by using integer constant instead of String "0, -560" for convenient setting of these parameters. However, because pre-processors are not supported in Java, I can not use #define. (2) Due to String reading performed differently in PCs in the CS Department PC lab, file names were not given properly in the original codes, especially in case of saving PS file or DATA file. To correct this problem, a few lines of codes to delete unnecessary extension have been added to make sure all the output file names including those for both PS and GIF as well as DATA will be given according to rules and relations. (3) eventHandle() method in bdeAppletFrame.java has been rearranged and cleaned up to accept new methods. 5. Testing Revised codes are tested in three platforms: Windows95 (Win32), Linux, and DEC UNIX station. Among them, the Windows95 is the main platform. Under Windows95, revised codes works very well for print GIF files. All active menus (some of the menu bars actually have not been coded to have events in the original version) work properly despite minor problems. Main problems still existed in the current version include: 1) Some menu bars such as "NEW", "CLOSE", "NODE SETTING", "FONT", and all under "EDIT" have not be given events yet and therefore do not work at all. 2) CG->GX+ instances get mixed up. 3) HN->HA+ instances are not display or saved. Due to slow speed in the tested PC (most 486), compile the whole set of classes need considerably long time (~20 minutes on a 486DX33). In the Linux, it works most correctly except that it will cause stall when try to create Text or new Graph probably because of problems in related AWTs. Problems are also existed when using dialogs such as file saving dialog: the path shown in the pop up windows (always point to the highest level /) seems different than the one actually used in program. GIF files can be saved correctly. Open existed data files fine even if Text are included. In the UNIX (jupiter), the testing results are the same as in Linux. The main problem for both Linux and UNIX platform is that their libs or AWTs are not very up-to-date compared to Win32 release (actually there're no official releases for both Linux and DEC UNIX) and still appear to have many bugs. The applet-mode (running program using web browser supported Java) seem in a very preliminary stage. Only a few classes such as bde2JavaApplet can be "brought up" using browsers. A lots of programming efforts are needed. Because of lots of changes have been brought by SUN Java team to JDK1.1 version, BDE Java code can not be run correctly using JDK1.1.1, or the most recent release. 6. General Data flow Diagram: A Sample Output in GIF Format The following is a sample GIF image generated using new BDE Java code revised in BDE2GIF project. It has several different type of nodes. Links and captions are also added using tools. The diagram is in /usr/proj3/case/97s523/bde2gif/hren/DataFlow.gif 7. Suggestions for future Improvement (1) Improve Text related tools and methods, especially in Linux/UNIX platforms; (2) Add events to NEW, CLOSE, and some other important menus; (3) Fix CG->GX+ instances get mixed up problem; (4) Fix HN->HA+ instances display and save problem; (5) Investigate class EndWithFilter in bdeAppletFram.java to see if there's any possible problem cause the application performing differently over different machines; (6) Develop compatible codes for working under JDK 1.1 and after. 8. Compiled log Learning Java: 50 hours Understand the code: 50 hours Adding code: 60 hours Debug and Testing: 80 hours Documentation: 20 hours 9. Summary GIF saving capability has been added into the BDE Java version by BDE2GIF project. The revised program allow user to save any BDE graph interactively into GIF format. As well as works in GIF conversion, several other piece of codes have been also rewritten or modified to fix some problems. Appendix: BDE User Guide for Java Version 1. BDE Java Version: The Block Diagram Edit (BDE) is a graphics user interface (GUI) based application developed in the Department of Computer Science, University of Massachusetts at Lowell leaded by Professor Robert Lechner. It is a powerful tool for generating data models graphically. The codes of BDE was originally written in C/C++. BDE Java version was derived from its C/C++ version. It was designed to run in both application mode and applet mode. This guide is primarily focus on the application mode. 2. Environment: Compiling and running BDE Java version requires Java Development Kit (JDK) version 1.0.2. Current version does not work properly under JDK 1.1 and after. BDE Java has been tested in following platforms with JDK 1.0.2 or compatible libs: Windows 95 (Win32 - should also works in Windows NT too), Linux/XFree, and DEC UNIX/X-window. 3. Files: All source files are in $case/97s523/bde2gif/hren/java, documentation is in $case/97s523/bde2gif/hren/html. 4. Running BDE: 4.1 Set path In Windows95(if files and JDK are in disk C:): include c:\java\bin in path in autoexec.bat or manually type in DOS console and also set path for classes in autoexec.bat or manually type in DOS console: Set CLASSPATH=.;C:\java\lib\classes.zip In UNIX system, include the path of java/bin in c-shell or other initial shell. Also included in the shell or manually type is the path for classes, e.g., in .cshrc, add the following: setenv CLASSPATH .;path/java/lib/classes.zip where path is the full path of Java directory. 4.2 Compile source code: After set up path and environment, change directory to the one thta holds BDE Java codes, e.g., ~bdejava\ (in UNIX ~bdejava/), then type: Prompt:> javac bdeJava.java Note here the J in bdeJava must be capitalized. To recompile an individual file (e.g. to fix a bug), just type: Prompt:> javac source-file-name.java 4.3 Running BDE Java: Inside directory that holds classes files of BDE Java, do: Prompt:> java bdeJava 5. Drawing: Use two groups of tools listed in the left side of the Drawing Canvas to draw a diagram. User can draw a diagram either on the current canvas or on the other ones by selecting Create + Graph. About the detail, please read "BDE User Guide-Version 3.0". The path is /usr/proj3/case/95s523/95sbde/bde/doc/bdeUserGuide.tex 6. Open Data File: BDE data file can be opened through main menu File/Open and the data will be automatically converted to a BDE graph on the Canvas. 7. Save Data File: There are two choices under main menu File for save data file: "File/Save": It will save data into a file with default name "test.dat"; "File/Save As": User can choose file name in pop up dialog window, the filename must be followed by extension “.dat”. Otherwise the fill can not be saved. 8. Print Graph to GIF File: There are two choices under "File/Print…/Print As GIF": "File/Print.../ Print As GIF/Print Current Graph": save the current BDE graph to a GIF file; "File/Print…/ Print As GIF/Print All Graphs": save every BDE graphs into separate GIF files, respectively. Both save procedures will name GIF files as data-file-nameHG#.gif, here data- file-name is the name of related BDE data file without extension of ".dat". 9. Print Graph to PS File: There are two choices under "File/Print.../Print As PS": "File/Print.../ Print As PS/Current Graph": save the current BDE graph to a PS file; "File/Print.../ Print As PS/ All Graphs": save every BDE graphs into separate PS files, respectively. Both save procedures will name PS files as data-file-nameHG#.ps, here data-file- name is the name of related BDE data file without extension of ".dat".