Document | |
Author/Editor |
C. Haag (GMD) |
Status |
Draft Version 1, SEMPER internal |
TinguinSession TinguinManager::newSession(String name);
void TinguinManager::endSession(TinguinSession session);
Each created session appears in the "Sessions" menu in the TINGUIN and gets a button in the ButtonWindow at the top of the TINGUIN. The user is able to select the current viewable session by selecting its menuitem in the "Sessions" menu or selecting its button in the ButtonWindow. The endSession method closes all open windows of the session and removes the menuitem and button of the session. In order to initialize the TINGUIN the
void TinguinManager::init()method has to be called. This creates a toplevel window with an menu, a window for the session buttons and a window for the status messages in it. The init method also loads previously saved preferences for the colors and background images of the elements of the TINGUIN. These preferences can be changed in the "Tinguin" menu. The newSesssion method returns a reference to a TinguinSession . To add your own menues to the TINGUIN menu the
MenuItem TinguinManager::addMenu(String title)method has to be called. It adds a new menu with the text title an returns the corresponding menuitem under which you can create your own menu structure. Finally the methods
void TinguinManager::setStatusText(String text) void TinguinManager::addStatusText(String text)can be called to set/add text to the status window at the bottom of the TINGUIN.
void TinguinSession::acquire()before displaying output or waiting for input and
void TinguinSession::release()after it needs no longer control of the TINGUIN. Example:
... create the output doc to be displayed be the TinguinSession ses ses.acquire(); ses.addWindow(doc, ...); ses.release();
void TinguinSession::addWindow(InternalWindow win) void TinguinSession::addWindow(InternalWindow win, int placement)The placement variable decide where and at which size the windows are shown.
AUTO_PLACE_VERT: the windows are maximized in the height and share the width equally.
AUTO_PLACE_HORIZ: the windows are maximized in the width and share the height equally.
AUTO_PLACE_CENTER_AND_MAXED: only the actually added window is centered and also maxed in its size. This is the default for addWindow(InternalWindow win).
AUTO_PLACE_CENTER: only the actually added window is centered, but its size is not changed (useful for ProgressBar).
SELF_PLACE: neither the position nor the size of the actually added window are changed.
To remove a window from a session call
void TinguinSession::removeWindow(InternalWindow win)or to remove all windows
void TinguinSession::removeAllWindows()Note: When a session is closed all windows of the session are closed automatically.
HTMLDoc(String title) HTMLDoc(String title, int xPos, int yPos, int width, int height)where title is the title of the window. Optionally can be passed the x- and y-position and the width and height of the window. HTML-Text can be added either by String
void HTMLDoc::HTMLFromString(String html)or from an URL
void HTMLDoc::HTMLFromUrl(String url)Here an example:
// Make a session TinguinSession ses = TinguinManager.newSession("Test"); // Make a HTMLDoc HTMLDoc doc = new HTMLDoc("Html-Text"); // Add HTML-Text doc.HTMLFromString("<HTML><HEAD></HEAD><BODY><H1>Hello</H1></BODY></HTML>"); // acquire display ses.acquire(); // Add the HTMLDoc to the session and show it ses.addWindow(doc); // release display ses.release(); ... // remove HTMLDoc from the session ses.removeWindow(doc); // end session TinguinManager.endSession(ses);
ConfirmHTML(String html) ConfirmHTML(String html, String buttonText) ConfirmHTML(String html, String buttonText, Color htmlBackgroundColor, Color buttonBackgroundColor) ConfirmHTML(String html, String buttonText, Color htmlBackgroundColor, Color buttonBackgroundColor, int xPos, int yPos, int width, int height)Optionally can be passed the title of the button, the background color of the Html text, the background color of the button and the position, width and height of the window. The example follows the one above (HTMLDoc):
// Make a session TinguinSession ses = TinguinManager.newSession("Test"); // Make a ConfirmHTML ConfirmHTML doc = new ConfirmHTML("<HTML><HEAD></HEAD><BODY><H1>Hello</H1></BODY></HTML>"); // acquire display ses.acquire(); // Add the HTMLDoc to the session and show it ses.addWindow(doc); // wait until the user pressed the button doc.modally(); // release display ses.release(); ... // remove HTMLDoc from the session ses.removeWindow(doc); // end session TinguinManager.endSession(ses);The method
void ConfirmHTML::modally()returns only if the user pressed the button and is used as shown above. The TINGUIN should be acquired when you call it.
YesNoHTML(String html) YesNoHTML(String html, String leftButtonText, String rightButtonText) YesNoHTML(String html, String leftButtonText, String rightButtonText, Color htmlBackgroundColor, Color buttonBackgroundColor) YesNoHTML(String html, String leftButtonText, String rightButtonText, Color htmlBackgroundColor, Color buttonBackgroundColor, int xPos, int yPos, int width, int height)Optionally can be passed the title of the buttons, the background color of the Html text, the background color of the buttons and the position, width and height of the window. The Example is nearly identical with the one of ConfirmHTML, except the return value of the method modally():
... YesNoHTML doc = new YesNoHTML("<HTML><HEAD></HEAD><BODY><H1>Hello</H1></BODY></HTML>"); ... // determine which button was pressed String result = doc.modally(); if(result.equals("OK") { // do something } else { // do another thing } ...
FreeDialog(String title) FreeDialog(String title, int xPos, int yPos, int width, int height)where title is the title of the window. Optionally can be passed the position, width and height of the window. Example:
FreeDialog doc = new FreeDialog("Order");You can add the following views to a FreeDialog:
void FreeDialog::addText(String text) void FreeDialog::addText(String text, int fontsize) void FreeDialog::addText(String text, Color bg, Color fg) void FreeDialog::addText(String text, Color bg, Color fg2, Font font)methods. The first one adds text to the FreeDialog with the background color gray, the textcolor black and with the font Helvetica 12. In the second method you can change the fontsize, and in the third one you can change the background color and the textcolor. In the last method you can also change the font.
doc.addText("Size"); doc.addText("Size", 14); doc.addText("Size", Color.red, Color.white); doc.addText("Size", Color.red, Color.white, new Font("Helvetica", Font.BOLD, 20));
void FreeDialog::addButtonGroup(Vector elements, int alignment)method. This method constructs a ButtonGroup, where the button labels are determined by the toString() method of the elements. The buttons can be ordered vertically (alignment=ButtonGroup.NORTHSOUTH) or horizontally (alignment= ButtonGroup.WESTEAST).
Vector elements = new Vector(); elements.addElement("S"); elements.addElement("M"); elements.addElement("L"); doc.addButtonGroup(elements, ButtonGroup.WESTEAST);
void FreeDialog::addRadioGroup(String title, Vector elements, int alignment)method. This method constructs a RadioGroup, where the button labels are determined by the toString() method of the elements. On top of the buttons the text title is shown. The buttons can be ordered vertically (alignment=ButtonGroup.NORTHSOUTH) or horizontally (alignment= ButtonGroup.WESTEAST).
Vector elements = new Vector(); elements.addElement("Red"); elements.addElement("Blue"); elements.addElement("Green"); doc.addRadioGroup("Choose a color:", elements, ButtonGroup.NORTHSOUTH);
void FreeDialog::addPopupGroup(Vector elements)method. This method constructs a PopupGroup, where the item labels are determined by the toString() method of the elements.
Vector elements = new Vector(); elements.addElement("Red"); elements.addElement("Green"); elements.addElement("Blue"); doc.addPopupGroup(elements);
void FreeDialog::addHTMLText(String html)method. This method adds the HTML 1.0 Text html to the FreeDialog.
doc.addHTMLText("<hr><h1>Kundennummer:</h1>");
void FreeDialog::addEditField(String text, String edittext) void FreeDialog::addEditField(String text, String edittext, boolean mustInput)method. text is shown on the left side and the editable edittext on the right side. If mustInput is true, the dialog is only left when something is entered.
doc.addEditField("Kundennummer: ","123456");
void FreeDialog::addPasswordField(String text, String passtext) void FreeDialog::addPasswordField(String text, String passtext, boolean mustInput) void FreeDialog::addPasswordField(String text, String passtext, boolean mustInput, boolean wantsKeyEvents)methods. This method adds an EditField to the FreeDialog, where the input is shown as "*". If wantsKeyEvents is true, the FreeDialog can be exited by pressing RETURN or ESC in the password. If RETURN is pressed the left button is simulated and if ESC is pressed the right button is simulated.
doc.addPasswordField("secret key: ", ""); doc.addPasswordField("secret key: ", "1234", true);
void FreeDialog::addEditGroup(Vector editFields)method. An EditGroup can only hold EditFields (and also PasswordFields which are EditFields). It draws a frame around the EditFields and makes them all the same size.
Vector elements = new Vector(); EditField edit1 = new EditField("Name: ", "schmidt"); elements.addElement(edit1); EditField edit2 = new EditField("secret key: ", "", true); elements.addElement(edit2); doc.addEditGroup(elements);
void FreeDialog::addGroup(Vector views)method. An ContainerGroup can hold all kind of the above views. It draws a frame around its elements.
Vector elements = new Vector(); EditField edit1 = new EditField("Name: ", "schmidt"); elements.addElement(edit1); HTMLText html1 = new HTMLText("<hr><h1>Kundennummer:</h1>"); elements.addElement(html1); Vector elements2 = new Vector(); elements2.addElement("Red"); elements2.addElement("Blue"); elements2.addElement("Green"); RadioGroup radio1 = new RadioGroup("Choose a color:", elements2, ButtonGroup.NORTHSOUTH); elements.addElement(radio1); doc.addGroup(elements);
void FreeDialog::addSpace(int pixel)method. It is added between the last added view and the next view.
doc.addSpace(10);
void FreeDialog::endDialog() void FreeDialog::endDialog(String leftButtonText, String rightButtonText)The default is "OK" for the left button and "Cancel" for the right one. You can change this with the second method. Now you can add the FreeDialog to a TinguinSession.
Hashtable FreeDialog::getResult()method. The getResult() method returns a Hashtable with the results of the user interaction. Since getResult() is an implementation of the Result interface, and all the views you can add to a FreeDialog must implement it, you can also call getResult() of each view directly. On RadioGroups and PopupGroups you can also call selected(), which returns the selected Object.
// Make a session TinguinSession ses = TinguinManager.newSession("Test"); FreeDialog doc = new FreeDialog("Order"); Vector elements = new Vector(); EditField edit1 = new EditField("Name: ", "schmidt"); elements.addElement(edit1); HTMLText html1 = new HTMLText("<hr><h1>Kundennummer:</h1>"); elements.addElement(html1); Vector elements2 = new Vector(); elements2.addElement("Red"); elements2.addElement("Blue"); elements2.addElement("Green"); RadioGroup radio1 = new RadioGroup("Choose a color:", elements2, ButtonGroup.NORTHSOUTH); elements.addElement(radio1); doc.addGroup(elements); doc.endDialog(); // acquire display ses.acquire(); // Add the FreeDialog to the session and show it ses.addWindow(doc); // wait for user pressing a button String button = doc.modally(); // release display ses.release(); // get the results Hashtable hash = doc.getResult(); System.out.println(User pressed button: " + button); System.out.println("Name: " + hash.get("Name: ")); System.out.println("Color: " + radio1.selected().toString()); ...
ProgressBar(String title) ProgressBar(String title, int xPos, int yPos)where title is the title of the InternalWindow and xPos and yPos are the coordinates of the window. You can then set the action and subaction text with
void ProgressBar::setActionText(String text) void ProgressBar::setSubActionText(String text)You can now set the percentage of the ProgressBar directly with
void ProgressBar::setProgress(int percentage)or you can define the number of subactions with
void ProgressBar::setNumberOfActions(int number)and increase it with
void ProgressBar::incNumberOfActions()Example:
... ProgressBar p = new ProgressBar("Get html-page"); p.setActionText("getting html-page..."); p.setSubActionText("contacting host..."); p.setNumberOfActions(3); ses.addWindow(p, TinguinSession.AUTO_PLACE_CENTERED); // do something p.incNumberOfActions(); p.setSubActionText("host contacted, waiting for reply..."); // do something p.incNumberOfActions(); p.setSubActionText("getting html..."); // do something p.incNumberOfActions(); p.setSubActionText("done"); ses.removeWindow(p); ...
#semper.tinguin.imagePath: This is the path to the images of the buttons, ... When you start semper without this entry it uses the Method semper.util.install.Installer.getSEMPERRoot() to calculate this path. The images should reside in the path "semperroot"/data/tinguin. When you get an error about images you should first try to delete this entry in _sempconfig.
#semper.tinguin.backImagePath: This is the path to the background images. When you start semper without this entry it uses the Method semper.util.install.Installer.getSEMPERRoot() to calculate this path. The background images should reside in the path "semperroot"/data/tinguin/background. When you get an error about images you should first try to delete this entry in _sempconfig.
The following entries can all be set with the ColorChooser or ImageChooser per Drag-and-Drop or in the Options-menu. The entries can be saved with the "Save Options"-entry in the Options-menu.
#semper.tinguin.RootView.Color: The negativ value of this entry defines the background color of the main Tinguin-window. If it is not set, the default color is grey.
#semper.tinguin.RootView.Image: Defines the name of an image which is displayed in the main Tinguin-window. The image must reside in the background-images-directory.
#semper.tinguin.StatusWindow.Show: The value of this entry can be 0 or 1. If it is 0 the StatusWindow is NOT shown and if it is 1 the StatusWindow is shown.
#semper.tinguin.StatusWindow.Color: The negativ value of this entry defines the background color of the StatusWindow. If it is not set, the default color is grey.
#semper.tinguin.SessionWindow.Show: The value of this entry can be 0 or 1. If it is 0 the SessionWindow is NOT shown and if it is 1 the SessionWindow is shown.
#semper.tinguin.SessionWindow.Color: The negativ value of this entry defines the background color of the SessionWindow. If it is not set, the default color is grey.
#semper.tinguin.SessionWindow.Image: Defines the name of an image which is displayed in the SessionWindow. The image must reside in the background-images-directory.
#semper.tinguin.AutoSave: The value of this entry can be 0 or 1. If it is 1 the colors, images, ... are saved before the Tinguin is quit. If it is 0 they are not saved.
#semper.tinguin.FreeDialog.Color: The negativ value of this entry defines the background color of FreeDialogs. If it is not set, the default color is grey.
#semper.tinguin.ConfirmHTML.Color: The negativ value of this entry defines the background color of ConfirmHTMLs. If it is not set, the default color is grey.
#semper.tinguin.HTMLDoc.Color: The negativ value of this entry defines the background color of HTMLDocs. If it is not set, the default color is grey.
#semper.tinguin.YesNoHTML.Color: The negativ value of this entry defines the background color of YesNoHTMLs. If it is not set, the default color is grey.