1 Standard Widget Toolkit. 2 SWT l a widget toolkit for Java developers l provides a portable API and tight integration with the underlying native OS.

Slides:



Advertisements
Similar presentations
Module 2 Navigation.     Homepage Homepage  Navigation pane that holds the Applications and Modules  Click the double down arrow on the right of.
Advertisements

What is a Dialog box? A Dialog box is a window or “form” that contains other child windows or “controls” that have a specific appearances and pre-defined.
1 Introduction to Word Chapter 3 Lecture Outline.
© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
© by Pearson Education, Inc. All Rights Reserved. continued …
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
Introduction To Form Builder
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
1 Standard Widget Toolkit. 2 SWT l a widget toolkit for Java developers l provides a portable API and tight integration with the underlying native OS.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Advanced Forms Lesson 10.
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
Inspire students to develop ideas & organize thinking
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Introduction to Eclipse Plug-in Development. Who am I? Scott Kellicker Java, C++, JNI, Eclipse.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Designing Interface Components. Components Navigation components - the user uses these components to give instructions. Input – Components that are used.
Domain 3 Understanding the Adobe Dreamweaver CS5 Interface.
3461A Readings from the Swing Tutorial. 3461A Overview  The follow is the Table of Contents from the trail “Creating a GUI with JFC/Swing” in the “The.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
S511 Session 7, IU-SLIS 1 DB Implementation: MS Access Forms.
IC 3 BASICS, Internet and Computing Core Certification Key Applications Lesson 11 Organizing the Worksheet.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
Exploring Windows and Essential Computing Concepts 1 Windows Desktop u Windows Basics u Icon u Start Button u My Computer u Network Neighborhood u Recycle.
Basic Editing Lesson 2.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 15 Advanced Tables.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
WaveMaker Visual AJAX Studio 4.0 Training Basics: Building Your First Application Designer Basics.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
C# GUI - Basics. Objectives.NET supports two types: WinForms, traditional, desktop GUI apps. WebForms – newer, for Web apps. Visual Studio.NET supports.
Chapter 2 – Introduction to the Visual Studio .NET IDE
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
Graphical Enablement In this presentation… –What is graphical enablement? –Introduction to newlook dialogs and tools used to graphical enable System i.
Object Oriented Programming.  Interface  Event Handling.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
Win32 Controls & ActiveX Integration In this presentation… –Introduction to the new Win32 controls. What they are? How they are enabled? Potential uses.
User Interface Components Lecture # 5 From: interface-elements.html.
Swing - 2 Session 13. Swing - 2 / 2 of 38 Objectives (1) Discuss trees and tables Discuss progress bars Discuss MVC architecture Describe menus.
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
Creating User Interfaces Chapter 13 CSCI CSCI 1302 – Creating User Interfaces2 Outline Introduction Common Features of Swing GUI Components Buttons.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Lesson 4 Inserting.
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
MS WORD INFORMATION TECHNOLOGY MANAGEMENT SERVICE Training & Research Division.
 You won’t write a single line of program code.  Instead, you’ll use visual programming techniques.  Visual Studio processes your actions (such as mouse.
Fundamentals of Windows Mouse n 4 Basic Operations: –Pointing –Clicking –Double Clicking –Dragging.
Java FX: Scene Builder.
Chapter 9: Graphical User Interfaces
Working in the Forms Developer Environment
Building a User Interface with Forms
Java Look-and-Feel Design Guidelines
Program and Graphical User Interface Design
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Program and Graphical User Interface Design
Chapter 2 – Introduction to the Visual Studio .NET IDE
6. WinForms 2003 C# GUI - Basics.
Presentation transcript:

1 Standard Widget Toolkit

2 SWT l a widget toolkit for Java developers l provides a portable API and tight integration with the underlying native OS GUI platform. l Many low level UI programming tasks are handled in higher layers of the Eclipse platform. »The plugin.xml markup for UI contributions specifies menu and toolbar content without requiring any SWT programming. »JFace viewers and actions provide implementations for the common interactions between applications and widgets. l Knowledge of the underlying SWT architecture and design philosophy is important for understanding how the rest of the platform works.

3 Portability and platform integration l issue in widget toolkit design: portable toolkits v.s. platform integration. l AWT : »provides platform integrated widgets for lower level widgets such as lists, text, and buttons, but does not provide access to higher level platform components such as trees or rich text. l SWING: »providing non-native implementations of high level widgets like trees, tables, and text. »more functionality, but applications developed different on platforms, and user interaction is different enough to be noticed. »difficult to use emulated toolkits to build applications that compete with applications developed specifically for a particular OS platform.

4 SWT solution l Define a common portable API that is provided on all supported platforms, l Implement the API on each platform using native widgets where possible. l Allows the toolkit to immediately reflect any changes in the underlying OS GUI look and feel, while maintaining a consistent programming model on all platforms.

5 least common denominator problem solved by SWT l Features not available on all platforms but useful for the workbench and tooling plug-ins »emulated on platforms that provide no native support. »Ex: the OSF/Motif 1.2 widget toolkit does not contain a tree widget. SWT provides an emulated tree widget on Motif 1.2 that is API compatible with the Windows native implementation. l Features not available on all platforms and not widely used »omitted from SWT. For example, Windows provides a widget that implements a calendar, but this is not provided in SWT. l Features specific to a platform, such as ActiveX integration: »provided only on the relevant platform.

6 Consistency with the platform l Platform integration is not strictly a matter of look and feel. l Includes the ability to interact with native desktop features such as drag and drop, integrate with OS desktop applications, and use components developed with OS component models like Win32 ActiveX. l also provide an implementation that looks familiar to the native OS developer. l Rather than hide OS differences in native C code or attempt to build portable and non-portable layers in the Java implementation, SWT provides separate and distinct implementations in Java for each platform. l Natives in C map one to one with calls to the underlying OS.

7 Widgets

8 Typical stand-alone SWT application l Create a Display which represents an SWT session. l Creates one or more Shells which serve as the main window(s) for the application. l Create any other widgets needed inside the shell. l Initialize the sizes and other necessary state for the widgets. Register listeners for widget events that need to be handled. l Open the shell window. l Run the event dispatching loop until an exit condition occurs (typically when the main shell window is closed by the user). l Dispose the display.

9 Example code snippet public static void main (String [] args) { Display display = new Display (); Shell shell = new Shell (display); Label label = new Label (shell, SWT.CENTER); label.setText ("Hello_world"); label.setBounds (shell.getClientArea ()); shell.open (); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); }

10 Display l represents the connection between SWT and the underlying platform's GUI system. l Used to manage the platform event loop and control communication between the UI thread and other threads. l can follow the pattern used above for most app. l Must create a display before creating any windows, and you must dispose of the display when your shell is closed.

11 Shell l is a "window" managed by the OS platform window manager. l Top level shells are those that are created as a child of the display. »are the windows that users move, resize, minimize, and maximize while using the application. l Secondary shells are those that are created as a child of another shell. »typically used as dialog windows or other transient windows that only exist in the context of another window.

12 Parents and Children l All widgets that are not top level shells have a parent. l Top level shells do not have a parent, but they are all created in association with a particular Display. »can be accessed using getDisplay(). »All other widgets are created as descendants (direct or indirect) of top level shells. l Composite widgets are widgets that can have children. l An application window,can be viewed as a widget tree, or hierarchy, whose root is the shell.

13 Widget life cycle l When your application creates a widget, SWT immediately creates the underlying platform widget. l Eliminates the need for code that operates differently depending on whether the underlying OS widget exists. l allows a majority of the widget's data to be kept in the platform layer rather than replicated in the toolkit. l This means that the toolkit's concept of a widget lifecycle must conform to the rules of the underlying GUI system.

14 Widget creation l Most GUI platforms require you to specify a parent when you create a widget. l Since SWT creates a platform widget as soon as you create a toolkit widget, the parent widget must be specified in the constructor for the widget.

15 Style bits l Some widget properties must be set by the OS at the time a widget is created and cannot be changed afterward. »Ex: a list may be single or multi-selection, and may or may not have scroll bars. l These properties, called styles, must be set in the constructor. »All widget constructors take an int argument that specifies the bitwise OR of all desired styles. »A style maybe is considered as a hint, which means that it may not be available on all platforms, but will be gracefully ignored on platforms that do not support it. l The style constants are located in the SWT class as public static fields. A list of applicable constants for each widget class is contained in the API Reference for SWT.

16 Resource disposal l The OS platforms underneath SWT require explicit allocation and freeing of OS resources. »SWT requires that you explicitly free any OS resources that you have allocated. »In SWT, the dispose() method is used to free resources associated with a particular toolkit object. l rule of thumb : »you must dispose of whatever you have created.

17 Examples l create a widget or graphic object using a constructor »you must dispose of it manually when you are finished using it. l If you get a widget or graphic object without using a constructor, »you must not dispose of it manually since you did not allocate it. l If you pass a reference to your widget or graphic object to another object, you must take care not to dispose of it while it is still being used.

18 Examples l When the user closes a Shell, the shell and all of its child widgets are recursively disposed. »In this case, you do not need to dispose of the widgets themselves. »However, you must free any graphics resources allocated in conjunction with those widgets. l If you create a graphic object for use during the lifetime of one of your widgets, you must dispose of the graphic object when the widget is disposed. »can be done by registering a dispose listener for your widget and freeing the graphic object when the dispose event is received.

19 Controls l a Widget is the abstract class for any UI object that can be placed inside another widget. »like component in AWT/SWING l A Control is a widget that typically has a counterpart representation(denoted by an OS window handle) in the underlying platform. »is something you can create and place anywhere you want in your widget parent/child tree. l both terms used interchangeably (although with different meaning) l Non-control Widgets are typically more specialized UI objects that can be created only for certain types of parents. l core set of widgets in SWT defined in the org.eclipse.swt.widgets package

20 Summary of concrete controls (in org.eclipse.swt.widgets package) l Button »Purpose: Selectable control that issues notification when pressed and/or released. »Style: BORDER, ARROW, CHECK, PUSH, RADIO, TOGGLE, FLAT, LEFT, RIGHT, CENTER »Events: Dispose, Control*, Selection l Canvas »Composite control that provides a surface for drawing arbitrary graphics. Often used to implement custom controls. »BORDER, H_SCROLL, V_SCROLL, NO_FOCUS, NO_BACKGROUND, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NORADIOGROUP »Dispose, Control*

21 l Control* = Events inherited from Control: »FocusIn, FocusOut, Help, »KeyDown, KeyUp, »MouseDoubleClick, MouseDown, MouseEnter, MouseExit, MouseHover, MouseUp, MouseMove, »Move, Paint, Resize

22 Available events and supporting widgets (org.eclipse.swt.events.) l Arm »Generated when a widget, such as a menu item, is armed. »MenuItem l Control »Generated when a control is moved or resized. »Control, TableColumn, Tracker l Dispose »Generated when a widget is disposed, either programmatically or by the user. »Widget

23 l Focus »Generated when a control gains or loses focus. »Control l Help »Generated when the user requests help for a widget, such as pressing the F1 key. »Control, Menu, MenuItem l Key »Generated when the user presses or releases a keyboard key when the control has keyboard focus. »Control

24 l Menu »Generated when a menu is hidden or shown. »Menu l Modify »Generated when a widget's text is modified. »CCombo, Combo, Text, StyledText l Mouse »Generated when the user presses, releases, or double clicks the mouse over the control. »Control

25 l MouseMove »Generated as the user moves the mouse across the control. »Control l MouseTrack »Generated when the mouse enters, exits, or hovers over the control. »Control l Paint »Generated when the control needs to be repainted. »Control

26 l Selection »Generated when the user selects an item in the control. »Button, CCombo, Combo, CoolItem, CTabFolder, List, MenuItem, Sash, Scale, ScrollBar, Slider, StyledText, TabFolder, Table, Table Cursor, TableColumn, TableTree, Text, ToolItem, Tree l Shell »Generated when a shell is minimized, maximized, activated, deactivated, or closed. »Shell

27 l Traverse »Generated when a control is traversed by the user using keystrokes. »Control l Tree »Generated when the user expands or collapses items in the tree. »Tree, TableTree l Verify »Generated when a widget's text is about to be modified. Gives the application a chance to alter the text or prevent the modification. »Text, StyledText

28 Untyped events l The typed event system described above is implemented with a low level, untyped widget event mechanism. l Not intended to be used by applications, but »used inside of the SWT implementation and »in many of the workbench wizard page implementations. l mechanism relies on a constant to identify the type of event and defines a generic listener that is supplied with this constant. This allows the listener to implement a "case style" listener.

29 Example l Shell shell = new Shell(); l Listener listener = new Listener() { l public void handleEvent(Event e) { l switch (e.type) { l case SWT.Resize: l System.out.println("Resize received."); break; l case SWT.Paint: l System.out.println(Paint received."); break; l default: l System.out.println("Unknown event received"); l } } }; l shell.addListener(SWT.Resize, listener); l shell.addListener(SWT.Paint, listener);

30 l Caret Caret »An i-beam that is typically used as the insertion point for text. »No style »Dispose l Combo Combo »Selectable control that allows the user to choose a string from a list of strings, or optionally type a new value into an editable text field. Often used when limited space requires a pop-down presentation of the available strings rather than using a single selection list box. »BORDER, DROP_DOWN, READ_ONLY, SIMPLE »Dispose, Control*, DefaultSelection, Modify, Selection

31 l Composite »Control that is capable of containing other widgets. »BORDER, H_SCROLL, V_SCROLL »Dispose, Control* l CoolBar »Composite control that allows users to dynamically reposition the cool items contained in the bar. »BORDER »Dispose, Control*

32 l CoolItem »Selectable user interface object that represents a dynamically positionable area of a cool bar. »DROP_DOWN »Dispose l Group »Composite control that groups other widgets and surrounds them with an etched border and/or label. »BORDER, SHADOW_ETCHED_IN, SHADOW_ETCHED_OUT, SHADOW_IN, SHADOW_OUT, SHADOW_NONE »Dispose, Control*

33 l Label Label »Non-selectable control that displays a string or an image. »BORDER, CENTER, LEFT, RIGHT, WRAP, SEPARATOR (with HORIZONTAL, SHADOW_IN, SHADOW_OUT, SHADOW_NONE, VERTICAL) »Dispose, Control* l List List »Selectable control that allows the user to choose a string or strings from a list of strings. »BORDER, H_SCROLL, V_SCROLL, SINGLE, MULTI »Dispose, Control*, Selection, DefaultSelection

34 l Menu Menu »User interface object that contains menu items. »BAR, DROP_DOWN, POP_UP »Dispose, Help, Hide, Show l MenuItem MenuItem »Selectable user interface object that represents an item in a menu. »CHECK, CASCADE, PUSH, RADIO, SEPARATOR »Dispose, Arm, Help, Selection

35 l ProgressBar ProgressBar »Non-selectable control that displays progress to the user, typically in the form of a bar graph. »BORDER, SMOOTH, HORIZONTAL, VERTICAL »Dispose, Control* l Scale Scale »Selectable control that represents a range of numeric values. »BORDER, HORIZONTAL, VERTICAL »Dispose, Control*, Selection

36 l Sash Sash »Selectable control that allows the user to drag a rubber banded outline of the sash within the parent window. Used to allow users to resize child widgets by repositioning their dividing line. »BORDER, HORIZONTAL, VERTICAL »Dispose, Control*, Selection

37 l ScrollBar ScrollBar »Selectable control that represents a range of positive numeric values. Used in a Composite that has V_SCROLL and/or H_SCROLL styles. »HORIZONTAL, VERTICAL »Dispose, Selection

38 l Shell Shell »Window that is managed by the OS window manager. »Shells can be parented by a Display (top level shells) or by another shell (secondary shells). »BORDER, H_SCROLL, V_SCROLL, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE (see also SHELL_TRIM, DIALOG_TRIM) »Dispose, Control*, Activate, Close, Deactivate, Deiconify, Iconify

39 l Slider Slider »Selectable control that represents a range of numeric values. »A slider is distinguished from a scale by providing a draggable thumb that can adjust the current value along the range. »BORDER, HORIZONTAL, VERTICAL »Dispose, Control*, Selection

40 l TabFolder TabFolder »Composite control that groups pages that can be selected by the user using labeled tabs. »BORDER »Dispose, Control*, Selection l TabItem TabItem »Selectable user interface object corresponding to a tab for a page in a tab folder. »Dispose

41 l Table Table »Selectable control that displays a list of table items that can be selected by the user. Items are presented in rows that display multiple columns representing different aspects of the items. »BORDER, H_SCROLL, V_SCROLL, SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION »Dispose, Control*, Selection, DefaultSelection

42 l TableColumn TableColumn »Selectable user interface object that represents a column in a table. »LEFT, RIGHT, CENTER »Dispose, Move, Resize, Selection l TableItem TableItem »Selectable user interface object that represents an item in a table. »Dispose

43 l Text Text »Editable control that allows the user to type text into it. »BORDER, H_SCROLL, V_SCROLL, MULTI, SINGLE, READ_ONLY, WRAP »Dispose, Control*, DefaultSelection, Modify, Verify

44 l ToolBar ToolBar »Composite control that supports the layout of selectable tool bar items. »BORDER, FLAT, WRAP, RIGHT, HORIZONTAL, VERTICAL »Dispose, Control*, l ToolItem ToolItem »Selectable user interface object that represents an item in a tool bar. »PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN »Dispose, Selection

45 l Tracker Tracker »User interface object that implements rubber banding rectangles. »LEFT, RIGHT, UP, DOWN, RESIZE »Dispose, Move

46 l Tree Tree »Selectable control that displays a hierarchical list of tree items that can be selected by the user. »BORDER, H_SCROLL, V_SCROLL, SINGLE, MULTI, CHECK »Dispose, Control*, Selection, DefaultSelection, Collapse, Expand l TreeItem TreeItem »Selectable user interface object that represents a hierarchy of tree items in a tree. »Dispose