Morphic A highly unusual graphical toolkit! Originates in the Self project at Sun –Self: a prototype-based programming language –No classes---objects inherit/instantiate.

Slides:



Advertisements
Similar presentations
Chapter 16 Graphical User Interfaces
Advertisements

Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Understanding an Apps Architecture ASFA Computer Science: Principles Fall 2013.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
OOP - Object Oriented Programming Object Oriented Programming is an approach to programming that was developed to make large programs easier to manage.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
© The McGraw-Hill Companies, 2006 Chapter 14 Abstraction, inheritance and interfaces.
CS 280 Data Structures Professor John Peterson. Quiz 4 Recap Consider the following array: {2, 6, 7, 3, 4, 1, 5, 9}. Draw this in tree form and then show.
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
0 CS 160: Design Process: Implement Event-based UI Programming, Model-View-Controller, and the Web Jeffrey Nichols IBM Almaden Research Center
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Chapter 13: Object-Oriented Programming
Scripts  Director’s scripting language is called Lingo  Lingo can be used to offer your users navigational control of the order of the scenes of your.
WHAT IS INHERITANCE? Java Unit 11: Inheritance I.
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
Java Swing - Lecture 1 An Introduction Milena Radenkovic slides originally by Chris Coleman.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
Written by Liron Blecher
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Model View Controller (MVC) Rick Mercer with a wide variety of others 1.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Chapter 8: Writing Graphical User Interfaces
CSE 3302 Programming Languages Chengkai Li Spring 2008 Object-Oriented Programming Lecture 13 – OO Programming, Spring CSE3302 Programming Languages,
UFCEKU-20-3Web Games Programming Unity 3D Basic Concepts Using and Creating Prefabs.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Chapter 8: Writing Graphical User Interfaces Visual Basic.NET Programming: From Problem Analysis to Program Design.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
Macromedia Dreamweaver 4.0 INTERFACE This presentation will run automatically.
CompSci 230 S Software Construction Frameworks & GUI Programming.
(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.
School of Computer Science & Information Technology G6DICP - Lecture 17 GUI (Graphical User Interface) Programming.
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.
Field Trip #19 Animations with Java By Keith Lynn.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
SWING IF YOU GET LOST - IMPORTANT LINKS  Swing articles:
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
UML Class Diagram Trisha Cummings. What we will be covering What is a Class Diagram? Essential Elements of a UML Class Diagram UML Packages Logical Distribution.
Game Maker – Getting Started What is Game Maker?.
Software Design 5.1 From Using to Programming GUIs l Extend model of "keep it simple" in code to GUI  Bells and whistles ok, but easy to use and hide.
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
Chapter 5 Introduction to Defining Classes
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Basic Organization of UI Software. 2 The User Interface n Typically want to think of “UI” as only one component of an overall system – The part that “deals.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
Introducing, the JFrame Gives us a work area beside System.out.println.
Introducing Scratch Learning resources for the implementation of the scenario
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
The Movement To Objects
Event Loops and GUI Intro2CS – weeks
CompSci 230 S Software Construction
Chapter 8: Writing Graphical User Interfaces
Chap 7. Building Java Graphical User Interfaces
Intent (Thanks to Jim Fawcett for the slides)
Tkinter GUIs Computer Science and Software Engineering
Design Patterns A Case Study: Designing a Document Editor
Model, View, Controller design pattern
Presentation transcript:

Morphic A highly unusual graphical toolkit! Originates in the Self project at Sun –Self: a prototype-based programming language –No classes---objects inherit/instantiate by “cloning” Self design strongly reflected in Morphic –Can create Morphic objects, add properties & behavior without defining classes –All Morphic objects have uniform, “concrete” feel--- e.g., “shadows” when dragging

Morphic, Smalltalk-style Smalltalk is class-based, so Squeak Morphic generates classes “under the hood” You can also use Morphic in traditional (non-prototype-based) style. This tutorial will use a traditional class- based programming style.

Squeak Morphic programming Goal: to get you coding something “interesting” as quickly as possible. Steps: –(Enter a Morphic world) 1.Define & instantiate your own Morph 2.Customizing your Morph 3.Animating Morphs 4.Toolkits and hierarchical composition

Morphs in the class browser All Morphic objects are instances of subclasses of Morph. Squeak looks for Morph subclasses in class categories starting with Morphic- Morphs found in these packages will be shown in the new morph... submenu

1. Defining your own Morph You can add Morph subclasses anywhere. But, you will probably want to create a new class category for your Morphs, e.g. Morphic-Keunwoo In this category, define a new subclass of Morph:

You’re done! But... Your new morph category, and morph, should appear in the new morph... submenu. You inherit all the default Morph behaviors. (The default rendering is a blue rectangle.) Default behaviors are nice, but they’re not yours... (Important: See various online tutorials for information on halos, direct manipulation of Morphs, etc.)

Alternate way to show instances 1.Open a workspace 2.Create an instance with new 3.Send the openInWorld message

What’s the “world”? The global namespace* contains a variable named World. When you enter a Morphic “world”, World is set to point to the current “world” When you send the openInWorld message to a Morph, it gets the current World and adds itself. * For the curious, the global namespace is a dictionary named Smalltalk. Do Smalltalk inspect in any Workspace to get a look at it.

Okay, but what’s a “world”? Q: What’s a “world”? A: An instance of a subclass of PasteUpMorph Q: What’s a PasteUpMorph? A: A Morph where you can drop other morphs, and they stick---think of it as a “desktop-like” morph.

2. Customizing your Morph Morphs are almost endlessly flexible For brevity, we will begin by customizing only two aspects: –Appearance (“look”) –Response to mouse input (“feel”)

2(a). Morph drawing [2] Like most graphics toolkits, components paint themselves onto a graphics context provided by the system. In Squeak, graphics contexts are instances of Canvas Canvas defines many methods for drawing...

Graphical environments: A question Q: When should components paint themselves? A: Often. It’s complicated... –When created –Whenever onscreen area is covered, then uncovered –Whenever it receives input that changes its state (e.g., pressed button must change appearance) –Whenever the state of the thing it represents changes (e.g., an animation of a physics simulation) –...and more...

2(a) Drawing components [2] Therefore, components draw when asked by the system, onto the Canvas provided. When object needs a repaint, it will be sent the drawOn: message, which takes a Canvas:

2(a) Customized drawing [3] To customize drawing, simply override the drawOn: message

Aside: a word about geometry Two natural screen coordinate systems: –“Text-like”: top left corner is (0, 0) Y coordinate increases as you go down screen –“Math-like”: bottom left corner is (0, 0) Y coordinate increases as you go up screen Morphic has both… –x/x: and y/y: methods use math-like –position/position: methods use text-like

2(b) Custom event handling [1] Input events are similar to painting events To define your own event action, override a message that handles the event, e.g. mouseDown:

2(b) Custom event handling [2] An example of handling mouseDown event: However, this is not enough...

2(b) Custom event handling [3] Squeak does not want to dispatch all events to every Morph in the world (inefficient) To register interest in an event, you may have to override a handlesXXX: method, e.g.:

More about events... Event-driven programming is a big idea Good graphical toolkits provide a rich interface to send/receive/register interest in various events. Examine the “event handling” method category in the Morph base class for event handling methods. MorphicEvent (in class category Morphic- Support) is the class of the “evt” parameter received by the event handling methods.

3. Animating Morphs Morph defines a bunch of methods related to time-varying properties. Among the most important: –step –stepTime –startStepping –stopStepping These have the intuitively obvious meanings... As usual, override to make stuff happen

4. Hierarchical composition Most toolkits have a notion of “containers”, embodied in a class. Container is itself usually a subclass of the base Component class, so that Containers can recursively contain Containers. –(“Composite” design pattern – Gamma et al.) In this fashion, arbitrarily complex trees of components can be created.

Hierarchical composition in Morphic Morphic allows all Morphs to be containers –(some are better suited than others) Morph method addMorph: can be used to add any morph to any other. Note that addMorph alone does not constrain the position of submorphs! –A submorph may live outside its parent’s physical area. –But, when this happens, painting often malfunctions

Composition, ct’d If you create your own specialized container (e.g., BouncingAtomsMorph in Morphic- Demos), you probably should not call addMorph directly Instead, create your own method, with a logical name, that calls self addMorph –(e.g., addAtom:)

Composition and delegation Adding components to containers allows the container to delegate responsibility for certain actions to its child objects –BouncingAtomsMorph need not explicitly define behavior of all atoms A fundamental principle of OOD: use hierarchical composition to build objects out of other objects.