Lecture 10 toolkits intrinsics callbacks resources widget hierarchies geometry management
This presentation is the property of its rightful owner.
Sponsored Links
1 / 18

Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management PowerPoint PPT Presentation

  • Uploaded on
  • Presentation posted in: General

Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management. Brad Myers 05-830 Advanced User Interface Software. Widgets as objects. Menus, buttons, scrollbars Refresh themselves and handle input, redraw if change

Download Presentation

Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

Lecture 10 toolkits intrinsics callbacks resources widget hierarchies geometry management

Lecture 10:Toolkits: Intrinsics, Callbacks,Resources, Widget hierarchies,Geometry management

Brad Myers

05-830Advanced User Interface Software

Widgets as objects

Widgets as objects

  • Menus, buttons, scrollbars

  • Refresh themselves and handle input, redraw if change

  • In Motif and Tk each widget is at least one window

    • Also Motif has "gadgets" which aren't windows

    • In Amulet, widgets are not windows

  • Decorative lines, labels and boxes also are "widgets“



  • How the widgets are implemented

  • Motif --  "fake" object system out of C (same in Andrew)

  • Tk -- Tcl language

  • Amulet -- Prototype-instance object system, constraints, Opal graphics model, Interactors input model, command objects



  • Every parameter of widgets in Motif

    • Passed as a parameter to the create routine, set afterwards, or read from a configuration file

  • Called "options" by Tk

  • Amulet doesn't support having them in a file

  • Each resource has a default value defined by the class

  • In an X file = appl.widget1.resource: valueappl.widget1.widget2.resource: value*.resource: value

  • "sensitive" to grey-out

  • "resizable" for windows



  • In Motif, associate C procedures with widgets

    • Many different callbacks for the same widget

      • create, start, abort, finish, destroy, ...

    • Registered (set) at widget creation time, invoked at run time

    • Are "resources"

    • There are also "actions" which are internal to the widget and called by events.

    • Not usually set by programmers

    • Parameters: widget, client data, value

  • In tk, associate tcl script with "events" in widgets

    • or the widget action if it has one

  • In Amulet, invoke Command Objects on "interactors" or widget finish, and call-back is the DO method.

Widget hierarchies

Widget Hierarchies

  • Motif-Primitive adds 3-D shadow

    • (picture)

    • Label adds string or pixmap display

      • Push-button adds accepting input

  • Composite is for geometry management

    • Constraint = how size and position of children managed

      • Manager = 3D shadows

  • Shell = windows

  • Inheritance down the parent or class hierarchy

  • Current Java object hierarchy contains about 4682 interfacs and classes (1.4.1 had 3300: 2300 classes and 1000 interfaces)

    • See the list for 1.4.2

    • How many are for Swing and AWT?

Geometry management

Geometry Management

  • Widgets don't set their own location.

    • Widgets put into special group objects called "geometry managers" that perform the layout by setting the component's positions and size

    • Used in Motif and tk

  • Each widget negotiates with parent for more room when resize

Motif geometry management

Motif Geometry Management

  • Motif

    • RowColumn - add widgets and it lays them out

    • Treats all children the same, so not for ScrollBars

    • (picture)

  • Form - generic constrained layout

    • Put extra resources on the children widgets

    • "For details, see the Motif Reference Manual, because the complete behavior of Form is quite complicated."

    • Each edge can be constrained

      • at a position or offset from an edge of the Form

      • at an offset from an edge of another widget

      • percent of the way across the Form (edge, not center)

      • a percent calculated based on the initial position

    • If wrong, widgets are on top of each other

Motif geometry management1

Motif Geometry Management

  • Two phases: bottom up requesting size, then top down setting size.

    • All done before windows are allocated

  • Unnecessary complexity: "XmCreateMenuBar actually creates a RowColumn widget, but with some special resource settings.... The Motif widget creation routines often have names that are different from the widgets they create."

  • (picture of code)

Tk geometry management

TK Geometry Management

  • All widgets must be in a geometry manager, or else not displayed

  • Any widget with any geometry manager

  • Layout depends on

    • widget specified sizes

    • programmer specifications,

    • size of geometry manager itself

  • Widgets must adjust themselves to the size given

  • Geometry manager requests size recursively

Tk geometry cont

TK Geometry, Cont.

  • Placer - specific location for each widget

    • Each widget treated independently

    • Place "anchor" in absolute coords or as a % of way across

    • then say which part of object is at the anchor

    • n, ne, e, se, ... center

  • Packer - "constraint based"

    • specify position of each widget in available space

    • side left, right, top, bottom

    • fill x, -fill y stretch widget to fill available space

  • Text

  • Canvas - mix graphics and widgets

Amulet geometry management

Amulet geometry management

  • Group can have the Am_LAYOUT slot set with a constraint that depends on other slots

    • Sets positions of parts by side effect

    • Default layout routines: Horizontal and Vertical layout, for lists or tables.

  • Rest done by arbitrary constraints

Standard motif application

Standard Motif Application

  • Include Motif and widget header files

  • Initialize the toolkit: XtAppInitialize

    • reads resources, creates server connection, returns top-level screen pointer

  • Create the widgets and put them in composites ("parent")

    • "manage" the widgets (except when pop-ups)

  • Register call-backs with the widgets

  • "Realize" the top level widget

    • Causes geometry management to be invoked

  • Start the main loop: XtAppMainLoop

Simple hello world program in amulet

Simple Hello World Program in Amulet

#include <amulet.h>

main (void) {

Am_Initialize ();


.Add_Part (Am_Window.Create ("window")

.Set (Am_WIDTH, 200)

.Set (Am_HEIGHT, 50)

.Add_Part (Am_Text.Create ("string")

.Set (Am_TEXT, "Hello World!")));

Am_Main_Event_Loop ();

Am_Cleanup ();


Goodbye world amulet program with button

Goodbye-world Amulet program with button

#include <amulet.h>

main (void) {

Am_Initialize ();


.Add_Part (Am_Window.Create ("window")

.Set (Am_WIDTH, 200)

.Set (Am_HEIGHT, 50)

.Set (Am_FILL_STYLE, Am_Amulet_Purple)

.Add_Part (Am_Button.Create ("button")



.Set (Am_LABEL, "Goodbye, world!"))));

Am_Main_Event_Loop ();

Am_Cleanup ();


Goodbye world amulet program without button

Goodbye-world Amulet program without button

#include <amulet.h>

Am_Define_Method (Am_Object_Method, void, quit_method, (Am_Object)) {

cerr << "It was nice knowing you.\n" << flush;



main (void) {

Am_Object inter;

Am_Initialize ();


.Add_Part(Am_Window.Create ("window")

.Set (Am_WIDTH, 200)

.Set (Am_HEIGHT, 50)

.Add_Part(Am_Text.Create ("string")

.Set (Am_TEXT, "Goodbye World!")

.Add_Part(inter = Am_One_Shot_Interactor.Create())




Set (Am_DO_METHOD, quit_method);

Am_Main_Event_Loop ();

Am_Cleanup ();


Minimal hello world in java as applet using awt

Minimal Hello-World in Java as Applet using AWT

import java.applet.Applet;

import java.awt.Label;

public class AWTHelloWorld

extends Applet


public void init ()


super.init ();

add ( new Label ( "Hello World!" ) );



Java and swing applets

Java and Swing Applets

  • Hello World:

    • AWT HelloWorld Applet (source code)

    • Swing HelloWorld Applet (source code)

  • Goodbye World:

    • AWT GoodbyeWorld Applet (source code)

    • Swing GoodbyeWorld Applet (source code)

  • Login