modern gui systems
play

Modern GUI Systems Beyond X Windows 1 CS 349 - Implementing GUIs - PowerPoint PPT Presentation

Modern GUI Systems Beyond X Windows 1 CS 349 - Implementing GUIs Modern GUI (present) Desktop (WIMP) T ablet (T ouch/Pen) Hybrids Smartphones (WIMP+T ouch (T ouch) +Pen) CS 349 - Implementing GUIs 3 Is X Windows still applicable?


  1. Modern GUI Systems Beyond X Windows 1 CS 349 - Implementing GUIs

  2. Modern GUI (present) Desktop (WIMP) T ablet (T ouch/Pen) Hybrids Smartphones (WIMP+T ouch (T ouch) +Pen) CS 349 - Implementing GUIs 3

  3. Is X Windows still applicable? • X Windows hasn’t aged very well – Based on standard C, not C++/OO – Built using conventions at that time (enums, int constants) • Modern toolkits are object-oriented, and have better abstractions to handle events, drawing. – Required to make systems more extensible. – Also helpful to scale-out to more input and output devices. • Event model assumes a single event loop – As we’ll see, this scales poorly! – Would prefer this to be handled by the underlying system (i.e. not at the application level) CS 349 - Implementing GUIs 4

  4. What stays the same? • Core requirements haven’t changed – Need to manage events from multiple input devices • Events routed to appropriate application/windows • More devices supported but underlying mechanism for handling events is the same – Primarily 2D interfaces • Still need optimized 2D graphics – Clipping, double-buffering etc. – Input is still primarily text + positional • Variation in keyboards, but we still use standard layouts • Variation in pointing devices, but we still need a pointing device to return x,y coordinates (i.e. what to activate) CS 349 - Implementing GUIs 5

  5. What’s changed? • GUI toolkits are more prevalent – Stock components (widgets) often provided by OS vendors. – Supports standard look-and-feel with minimal coding. – Have been expanded to support additional devices/platforms. • New input modalities: speech, touch, pen – Non-mainstream but becoming more popular – Often complementary • New output modalities: VR, AR (virtual and augment reality) – Definitely non-mainstream – Challenges to each CS 349 - Implementing GUIs 6

  6. Widgets • Widget (control, component) is a generic name for parts of an interface that have their own behavior: buttons, progress bars, sliders, drop-down menus, spinners, file dialog boxes etc. – Can have their own appearance – Receive and interpret their own events – Put into libraries (toolkits) for reuse Widget from Wow Wow Wubbzy CS 349 - Implementing GUIs 7

  7. • We have multiple operating systems/platforms/toolkits What has replaced X Windows? – Market share split: Microsoft (desktop), Google (mobile) – Apple (desktop+mobile) • OS vendors typically provide toolkits and development tools/languages, often intended to lock-in to their platform. – Microsoft Windows: C# – Apple macOS: ObjC/Swift – Apple iOS: ObjC/Swift – Google Android: Java/Android • Multi platform tools are rare or have limited capabilities – e.g. Java, Javascript/CSS/HTML (truly cross-platform) – e.g. Swift, .NET core (OSS but limited) – GTK+, Qt (OSS, used in Linux systems on top of X11) CS 349 - Implementing GUIs 8

  8. • Decision 1: Decide which platforms you want to support What’s a programmer to do? • Decision 2: Choose appropriate languages/tools – Platform-specific vs. cross-platform languages and tools • e.g. Java for Android, Swift for iOS, C# for Windows, or build web interfaces using JS/CSS • e.g. JS/CSS or Java everywhere – “Best” tools and support is often platform -specific. • Decision 2: Stock widgets vs. custom – Widget toolkits and common look-and-feel were dominant for years (e.g. standard-looking Windows apps). – Shift towards heavy customization, and custom controls • Allows for more creative expression, removes toolkit limitations • e.g. a streaming music app without a title-bar CS 349 - Implementing GUIs 9

  9. Java GUI Programming A quick-start guide to building Swing applications. 10 CS 349 - Implementing GUIs

  10. The Java Platform Packages, libraries Classes and objects Program structure 11 CS 349 - Implementing GUIs

  11. Everything is a class • Classes, objects are core language constructs • OO features: polymorphism, encapsulation, inheritance (more later) • Static and member variables and methods • Resembles C++ on the surface • Language differences from C++ – No pointers. Really. Not needed. – No type ambiguity; classes resolved at runtime – No destructor (due to garbage collector) – Single inheritance model CS 349 - Implementing GUIs 13

  12. Java Platform (JDK) Includes tools, and libraries - everything from threading, to database access, to UI toolkits – all cross platform and portable. CS 349 - Implementing GUIs 14

  13. • Classes are grouped into packages (i.e. Java Class Library namespaces) to avoid name collisions. • To assign your source code to a package, use the package keyword at the top of source files. • Typically, package = subdirectory – e.g. “graphics” package is in subdirectory of the same name – alt. it can be included in a JAR file. • Use the import keyword to include a class from a different package in your code. – This is how you include bundled Java libraries. CS 349 - Implementing GUIs 15

  14. Common Classes/Packages Package Classes Description (Examples) java.awt Color, Graphics, Contains all of the classes for Graphics2D, event. creating user interfaces and for painting graphics and images. javax.swing JFrame, JButton, Provides a set of "lightweight" (all- JList, JToolbar Java language) components that works the same on all platforms. java.io File, FileReader, Provides for system input and output FileWriter, through data streams, serialization InputStream and the file system. java.lang Boolean, Integer, Provides classes that are String, System, fundamental to the design of the Thread, Math Java programming language. java.util ArrayList, HashMap, Contains the collections framework, Observable legacy collection classes, event model, … Java 8 API Specification: https://docs.oracle.com/javase/8/docs/api/overview-summary.html CS 349 - Implementing GUIs 16

  15. Java Class Hierarchy • Implicit class hierarchy – All classes in Java are derived from the Object class in java.lang defines and implements common class behavior • e.g. clone() , toString(), finalize() methods – Classes you write inherit this basic behavior. CS 349 - Implementing GUIs 17

  16. Structure of a Program (revisit) public class Bicycle { Bicycle.java private String owner = null; private int speed = 0; private int gear = 1; // constructor public Bicycle() { } public Bicycle(String name) { this.owner = name; } // methods public void changeSpeed(int newSp) { this.speed = newSp; } public void changeGear(int newGear) { this.gear = newGear; } public int getSpeed() { return this.speed; } public int getGear() { return this.gear; } // static entry point – main method public static void main(String[] args) { Bicycle adultBike = new Bicycle("Jeff"); adultBike.changeSpeed(20); System. out .println("speed=" + adultBike.getSpeed()); Bicycle kidsBike = new Bicycle("Austin"); kidsBike.changeSpeed(15); System. out .println("speed=" + kidsBike.getSpeed()); } } CS 349 - Implementing GUIs 18

  17. • In Java, Instantiating Objects – Primitive types are allocated on the stack, passed by value. – Objects are allocated on the heap, passed by reference • Technically, value of address passed on the stack, but behaves like pass-by-reference. Both refer to the same memory on the heap • Practically, this means that you don’t need to worry about pointer semantics in parameter passing. CS 349 - Implementing GUIs 19

  18. Composition: Inner Classes Classes can be nested as inner classes. Watch scope! x = 23 this.x = 1 CS 349 - Implementing GUIs ShadowTest.this.x = 0 21

  19. Inheritance • Inheritance: increasing code reusability by allowing a class to inherit some of it’s behavior from a base class (“is a” relationship). – Classes inherit common attributes and behavior from base classes. – e.g. “Mountain Bike” is - a “Bike”. Bike • Common: speed, gear • Unique: engine Mountain – In Java, use extends keyword. Bike CS 349 - Implementing GUIs 22

  20. Subtype Polymorphism Animals1.java The Animal class is abstract, and cannot be instantiated. It’s talk() method is abstract, so derived classes must override it. ” Meow! “ “ Woof! “ CS 349 - Implementing GUIs 23

  21. Single Inheritance • Java only supports single inheritance! • In practice, this simplifies the language. • See the “Diamond Problem” for one example of multiple inheritance being a hard problem. • Solutions to this problem vary by language; Java prevents you from doing it. • It’s very common in Java to derive an existing class and override behavior (even provided classes). • All classes have Object as their ultimate base class (implicit). CS 349 - Implementing GUIs 24

  22. Interfaces • An interface represents a set of methods that must be implemented by a class (“contract”). • Similar to pure abstract classes/methods. – Can’t be instantiated – Class implementing the interface must implement all methods in the interface. – Use implements keyword. • In Java, – extend a class to derive functionality from it – implement an interface when you want to enforce a specific API. CS 349 - Implementing GUIs 25

  23. Interfaces Example • We can replace the abstract class/method with an interface. – Polymorphism still applies to interfaces. Animals2.java We’re treating the interface, Pet, as a type CS 349 - Implementing GUIs 26

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend