****************************************************************** * COPYRIGHT & LICENSE * ****************************************************************** This code is Copyright (c) Jere E. McDevitt, 1996. I make its use freely available to anyone who wishes to use it. If the code is used as part of a commercial product, where the functionality of the converter is included as part of the product functionality, then I require that my copyright notice be included in the product copyright notice. Also, the source code for the converter must be made available, at no charge, upon request. NOTE: This does not apply to just utilizing the set/get methods of the ReadGuiPropertyList class which is needed by the converted Presentations. It only applies to the ability to create those text files with the dumpPresentation method. ****************************************************************** * DESCRIPTION * ****************************************************************** This is release 1.1.1 of a basic GUI to JAVA converter. It has been tested on the WIDGETS.GUI demo that comes with the Bongo distribution. I added a TableWidget, SparseTableWidget and a custom widget that I did that extends a TextBoxWidget just to be certain everything works correctly. ****************************************************************** * USAGE * ****************************************************************** The converter, in its present form (Ver 1.0.1 [see COMING ATTRACTIONS]) is command line driven. Typical invocation is: java JEM.Utils.ReadGui -i MyGui -o MyGui -sf "file://c:/rundir/" where the -i and -o fields are required. The options are -i Name of GUI file (input) -o Name of JAVA class (output) [if file doesn't exist, creates Name.JAVA using NAME as the class name] -sf Source function The source function was added because of the way Bongo handles the setting of images and audio files in widgets. For example, if you were developing a GUI and had saved it into the directory c:\mydevelopment\GUIs and had an image widget (or pattern for your gui) that used a bitmap located in c:\mydevelopment\GUIs\images then the "src" property for your widget would have the value: images\mybitmap.gif This would be fine if you are executing your application is launched from a directory with the necessary images directory off of it. However, if the location of the images is set to say a common directory, then you can use the -sf flag to put the initial path information into the code. You can also use the -sf function to write a call to a function. For example, if -sf="file://c:/" then setString("src","file://c:/images/mybitmap.gif",null); would be written to the java file. If -sf=m_ownerFrame.getImage(\"%\") then setString("src",m_ownerFrame.getImage("images/mybitmap.gif"),null); would be written. Note that the % is replaced with the src text directly so surrounding quotation marks must be added. ****************************************************************** * FILE PREPERATION * ****************************************************************** The first thing to consider is the names of your widgets in you Presentation. If a widget has a name (set in the name property), then that is the name that will be assigned to the variable in the java file. If the widget does not have a name, then one will be generated using the widget class name and a one up counter. This will make using the widgets a bit more cumbersome and if others are added, then the number may change. It is better to give each widget a name. The use of this code is, to my mind, extremely simple. Basically there are two times when the converter will be run. 1. The first time after a GUI file is created. This means that there is not an existing JAVA file to write the code into. If the JAVA file does not exist, the converter will create one that extends Presentation. It will write a basic constructor, init() method and the additionalInit() method that is called from init. It will add the necessary comment block markers. 2. The other time the converter can be run is when the JAVA file already exists. If the JAVA file was created by the converter when using it in step 1, then nothing further is needed to be done to the file. If, however, the file is an existing file that you would like to place all of the GUI information to, some minor preparation must take place first. 1) If there is an existing method public void init() rename that method to public void additionalInit() 2) Next, in the main body of the java class (not within a method) add the following lines of text: //{{ //}} These are the markers the converter looks for to write the code into. All of the widgets will be declared/constructed here and an init() method will be written that has all of the necessary setProperties() calls for each widget. 3) The last step is to make the ReadGuiPropertyList class available to your new JAVA file using an import. ****************************************************************** * NEW FILE HEADER * ****************************************************************** The converter, when it creates a file for the first time, will read, if present in the current directory, a text file named `readgui.comments'. If this file is found, the contents of the file are added to the beginning of the created JAVA file. This allows adding common comments and package names to your new files. There are three codes which can be placed in the comments file that will be replaced: %CLASSNAME% - same as the name used for the -o option %GUINAME% - same as the name used for the -i option %FILENAME% - name of the .JAVA file being created ****************************************************************** * WHAT WORKS, WHAT DOESN'T * ****************************************************************** Currently all Bongo widgets are converted correctly. All of the properties are utilized except 1. The CLAZZ property. This is a byte array which represents the compiled scripted version of a widget. This isn't currently used. 2. Scripts. The text for a script is written out into the java file in a commented out fashion. See COMING ATTACTIONS. 3. Properties of type objectArray. Because the object array can consist of any type of objects (which may or may not support the getProperties/setProperties methods), it is possible to correctly reconstruct each object. Default constructors could be used, but after that it would be the programmers responsibility to set each attribute. 4. The WIDGETs array. Because the converter correctly adds a new component to it's parent, the widgets[] property is created dynamically, and therefor does not need to be explicitly create by the converter. 5. Row data for a TableWidget. Because row data is made up of a vector of objects (of any type), properly reconstructing those objects would not be possible. Normal objects do not have the set/get properties methods. All column information is reproduced correctly, but the and rows of data will not be re-created. If the data is known, place addRow() statements in the additionalInit() method. ****************************************************************** * COMING ATTRACTIONS * ****************************************************************** I am currently working on a GUI front end that will display all of the Presentation files in a directory and allow processing of each into a java file just by clicking. I am enhancing the capability of the system to write the code to the java file by making area specific comment markers. This means that the constructors will be written within one marker block pair and the initialization within another. This will eliminate the need for an additionalInit method because the initialization markers could be placed within a method. I am working on a method of utilizing the scripts. My idea is to parse out the script code, determine which type of event was scripted, then place it within an event marker block in the handleEvent method, with the necessary "if (event.target == theWidget){}" code surrounding the script so that it functions for the desired widget. ****************************************************************** * FULL EXAMPLE * ****************************************************************** This example will be made using the username.gui in the \marimba\bongo\demo\programming directory. NOTE: there already exists a UserName.java file. It is NOT incorporated here. This is just a dump of the GUI file. (This is a small one suitable for the documenation file, that is why I chose it.) The readgui.comments file contains: package COM.MyCompany.Utils; /* * %CLASSNAME% created from the gui file %GUINAME% * * $ARCHIVE: $ * * $AUTHOR: $ * * $REVISION: $ * * $HISTORY: $ */ command: java JEM.Utils.ReadGui -i username -o UserName creates the file UserName.java which contains ====================FILE BEGIN=================== /* * Produced by ReadGui from GUI file: UserName.gui * * Version Copyright 1996, Jere E. McDevitt Ver. 1.0.1 * */ package COM.MyCompany.Utils; /* * UserName created from gui file UserName.gui * * $ARCHIVE: $ * * $AUTHOR: $ * * $REVISION: $ * * $HISTORY: $ */ import marimba.gui.*; import marimba.text.*; import java.awt.*; public class UserName extends Presentation { public UserName() { super(); } //{{ Will be overwritten by ReadGui public void init() { String scriptStr = null; byte[] ba = null; Object[] oa = null; ReadGuiPropertyList rgpl = new ReadGuiPropertyList(); rgpl.clear(); rgpl.setInteger("width",470,0); rgpl.setInteger("height",161,0); rgpl.setOption("fillmode",m_dtPresentation_1.getFillOptions(),1,0); rgpl.setColor("foreground",new Color(0,0,0),Color.black); rgpl.setString("title","UserName",null); rgpl.setColor("background",new Color(221,221,221),Color.black); rgpl.setInteger("west",0,0); rgpl.setFont("font",new Font("Dialog",0,18),null); rgpl.setOption("linemode",m_dtPresentation_1.getLineOptions(),9,0); rgpl.setString("pattern",m_pTheFrame.getURLString("images/rain.gif"),null); rgpl.setInteger("north",0,0); rgpl.setInteger("south",0,0); rgpl.setInteger("y",139,0); rgpl.setInteger("x",581,0); rgpl.setInteger("east",0,0); rgpl.setColor("hilite",new Color(255,255,255),Color.black); setProperties(rgpl); rgpl.clear(); rgpl.setInteger("width",280,0); rgpl.setInteger("height",30,0); rgpl.setColor("background",new Color(238,238,238),Color.black); rgpl.setBoolean("savetext",false,false); rgpl.setString("name","userName",null); rgpl.setInteger("y",65,0); rgpl.setInteger("x",155,0); rgpl.setOption("style",userName.getStyleOptions(),26,0); rgpl.setBoolean("editable",true,false); userName.setProperties(rgpl); userName.setName("userName"); this.add(userName); rgpl.clear(); rgpl.setInteger("width",100,0); rgpl.setInteger("height",30,0); rgpl.setString("text","Name:",null); rgpl.setColor("background",new Color(238,238,238),Color.black); rgpl.setInteger("y",65,0); rgpl.setInteger("x",50,0); m_dtTextBoxWidget_1.setProperties(rgpl); m_dtTextBoxWidget_1.setName("m_dtTextBoxWidget_1"); this.add(m_dtTextBoxWidget_1); rgpl.clear(); rgpl.setInteger("width",430,0); rgpl.setInteger("height",30,0); rgpl.setString("text","Please enter your name.",null); rgpl.setColor("background",new Color(238,238,238),Color.black); rgpl.setString("name","message",null); rgpl.setInteger("y",20,0); rgpl.setInteger("x",15,0); message.setProperties(rgpl); message.setName("message"); this.add(message); rgpl.clear(); rgpl.setInteger("width",100,0); rgpl.setInteger("height",30,0); rgpl.setString("label","Cancel",""); rgpl.setString("name","cancelButton",null); rgpl.setInteger("y",125,0); rgpl.setInteger("x",320,0); cancelButton.setProperties(rgpl); cancelButton.setName("cancelButton"); this.add(cancelButton); rgpl.clear(); rgpl.setInteger("width",100,0); rgpl.setInteger("height",30,0); rgpl.setBoolean("default",true,false); rgpl.setString("label","Ok",""); rgpl.setString("name","okButton",null); rgpl.setInteger("y",125,0); rgpl.setInteger("x",210,0); okButton.setProperties(rgpl); okButton.setName("okButton"); this.add(okButton); additionalInit(); } /* * Defined in GUI file. */ Presentation m_dtPresentation_1 = this; TextBoxWidget userName = new TextBoxWidget(); TextBoxWidget m_dtTextBoxWidget_1 = new TextBoxWidget(); TextBoxWidget message = new TextBoxWidget(); CommandButtonWidget cancelButton = new CommandButtonWidget(); CommandButtonWidget okButton = new CommandButtonWidget(); //}}Add additional definitions after here. public void additionalInit() { /* add any initialization code that shouldn't be overwritten here. */ } } ====================FILE ENDS================= ****************************************************************** * History and Credits * ****************************************************************** Version 1.1.1 Scrollbars inside of TextWidgets were being added twice. These have been filtered out. Version 1.1.0 This release re-worked the ReadGuiListEntry helper class to save the default value so that the build of the output string has the correct default value as used by the widgets when the property list was orignally built. Version 1.0.1 First publicly available version. Contains basic functionality to convert Presentations to JAVA files. ****************************************************************** * Copyrights * ****************************************************************** ReadGui is Copyright (c) Jere E. McDevitt, All Rights Reserved Bongo is Copyright (c) Marimba, Inc. Java is Copyright (c) Sun, Inc.