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
Introduction to Java 2 Programming
Advertisements

1 G54PRG Programming Lecture 1 Amadeo Ascó Adam Moore 22 GUI Programming I.
Introduction to Eclipse plugin development for CSU 670 course project, Selector language (Xaspect) editor plugin implementation.
Goals Give you a feeling of what Eclipse is.
Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
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.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
Swing CS-328 Dick Steflik John Margulies. Swing vs AWT AWT is Java’s original set of classes for building GUIs Uses peer components of the OS; heavyweight.
Google Android as a mobile development platform T Internet Technologies for Mobile Computing Olli Mäkinen.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
1 Plug-in Development Environment (PDE) Guide. 2 Introduction to PDE l What is PDE: »a tool designed to help you develop platform plug-ins while working.
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.
CC1007NI: Further Programming Week 5 Dhruba Sen Module Leader (Islington College)
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
A.k.a. GUI’s.  If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF 
JFace 吳昆澤. UI framework for plug-ins JFace provides classes for handling common UI programming tasks: Viewers handle the drudgery of populating, sorting,
Software Construction Lecture 10 Frameworks
Definition of the SDK for FIspace Augusto Morales & Hector Bedón UPM.
An Introduction to Software Architecture
Capture and Replay Often used for regression test development –Tool used to capture interactions with the system under test. –Inputs must be captured;
ECE 452 / CS 446 / SE464 Design Patterns: Part 2 - Answers A Tutorial By Peter Kim Partially based on the tutorial by Michał Antkiewicz.
Java Swing, Events and MVC Optional Readings: Eckel’s Thinking in Java: Chap 14 (
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.
CHEF II / Sakai Architecture. CHEF II Changes uPortal replaces Jetspeed –jsr 168 portlet, servlet compliant Spring replaces Turbine component framework.
Extending the Eclipse Framework and Rich Client Platform Jeff Myers Languages for Lunch 10/13/2004.
1 Object-Oriented Software Engineering CS GUI building with NetBeans Contents User Interaction JButtons JTextFields JLabels JForms in NetBeans Practical.
Ex3 Preview, Swing tutorial Ex1 review Amit Shabtay.
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.
Hyper/J and Concern Manipulation Environment. The need for AOSD tools and development environment AOSD requires a variety of tools Life cycle – support.
TOOLS FOR DESIGN AND DEVELOPMENT ENVIRONMENTS. Case study - ECLIPSE Lecture notes 2.
Copyright © Curt Hill First Window Builder Program Easy GUIs in Eclipse.
Objectives of This Session
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 13 : Swing I King Fahd University of Petroleum & Minerals College of Computer Science.
Session 27 Swing vs. AWT. AWT (Abstract Window ToolKit) It is a portable GUI library for stand-alone applications and/or applets. The Abstract Window.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
1 Unit 5 GUI Aum Amriteshwaryai Namah. 2 Overview Shall learn how to reuse the graphics classes provided by Java for constructing Graphical User Interface.
ECE 452 / CS 446 / SE464 Design Patterns: Part 2 - Questions A Tutorial By Peter Kim Partially based on the tutorial by Michał Antkiewicz.
GoF: Document Editor Example Rebecca Miller-Webster.
An Introduction to Programming and Object Oriented Design using Java 3 rd Edition. Dec 2007 Jaime Niño Frederick Hosch Chapter 18 Integrating user interface.
SWING 101. IF YOU GET LOST - IMPORTANT LINKS  Swing articles:
Java GUI building approaches Aleksandar Kartelj Faculty of Mathematics, Belgrade 11 th Workshop “Software Engineering Education 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.
Object Oriented Programming.  Interface  Event Handling.
Swinging in Your Java Playground. Background Swing is a part of the Java Foundation Classes (JFC). The JFC is made up of features intended to give a programmer.
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.
Java Swing One of the most important features of Java is its ability to draw graphics.
Event Driven, GUI Avshalom Elmalech Eliahu Khalastchi 2010.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Developing GUIs With the Eclipse Visual Editor, SWT Edition David Gallardo.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
ECLIPSE RICH CLIENT PLATFORM Part 1 Introduction.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
CSC 205 Programming II Lecture 5 AWT - I.
Welcome To java
Goals Give you a feeling of what Eclipse is.
Java Look-and-Feel Design Guidelines
Lecture 27 Creating Custom GUIs
User Interface Software Look under the hood
Chapter 2: System Structures
An Introduction to Software Architecture
Constructors, GUI’s(Using Swing) and ActionListner
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. 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 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