3461 Model-View Controller Advanced GUI concepts.

Slides:



Advertisements
Similar presentations
Chapter 18 Building the user interface. This chapter discusses n Javas graphical user interface. n Swing: an enhancement of a library called the Abstract.
Advertisements

Designing a Graphical User Interface (GUI) 10 IST – Topic 6.
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
COSC 3461: Module 8 Model-View-Controller (MVC) Architecture.
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.
Automating Tasks With Macros
Graphical User Interface (GUI) Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Graphical User Interface (GUI) Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
0 CS 160: Design Process: Implement Event-based UI Programming, Model-View-Controller, and the Web Jeffrey Nichols IBM Almaden Research Center
Object-Oriented Analysis and Design
Model View Controller (MVC) Architecture. Terminology and History MVC evolved from Smalltalk-80 Has become a key pattern in web based applications – If.
Graphical User Interfaces A Quick Outlook. Interface Many methods to create and “interface” with the user 2 most common interface methods: – Console –
Guide to MCSE , Second Edition, Enhanced 1 Objectives Understand and use the Control Panel applets Describe the versatility of the Microsoft Management.
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 
Cascading Style Sheet. What is CSS? CSS stands for Cascading Style Sheets. CSS are a series of instruction that specify how markup elements should appear.
GUI Programming in Java
MVC pattern and implementation in java
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
Model View Controller (MVC) Rick Mercer with a wide variety of others 1.
Software Construction Lecture 10 Frameworks
Welcome to CIS 083 ! Events CIS 068.
Chapter 8: Writing Graphical User Interfaces
11.10 Human Computer Interface www. ICT-Teacher.com.
Chapter 8: Writing Graphical User Interfaces Visual Basic.NET Programming: From Problem Analysis to Program Design.
CompSci 230 S Software Construction Frameworks & GUI Programming.
(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.
Chapter 19 Designing the GUI front-end: the Model-View-Controller pattern.
Swing and MVCS CompSci 230 Software Construction.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
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.
Automated GUI testing How to test an interactive application automatically?
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 15: GUIs 1.
Model View Controller (MVC) Bigger than a Pattern: It’s an Architecture Rick Mercer with help from many others 1.
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.
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.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 35 MVC and Swing MVC.
Model View Controller (MVC) Bigger than a Pattern: It’s an Architecture Rick Mercer with help from many of others 1.
Review Class Inheritance, Abstract, Interfaces, Polymorphism, GUI (MVC)
1 CSE 331 Model/View Separation and Observer Pattern slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Model View Controller (MVC) an architecture Rick Mercer with help from many of others 1.
MiniDraw Introducing a Framework... and a few patterns.
Java - hello world example public class HelloWorld { public static void main (String args[]) { System.out.println("Hello World"); }
1 Lecture 8: User Interface Components with Swing.
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.
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.
1 A Quick Java Swing Tutorial. 2 Introduction Swing – A set of GUI classes –Part of the Java's standard library –Much better than the previous library:
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
1 Visual Basic: An Object Oriented Approach 7 – The User interface.
Nov 181 Example Program DemoTree2.java DemoTree.java.
Support for the Development of Interactive Systems
CompSci 230 S Software Construction
Chapter 8: Writing Graphical User Interfaces
Event loops 16-Jun-18.
Lecture 27 Creating Custom GUIs
A Quick Java Swing Tutorial
Introduction to Computing Using Java
Event loops.
GRAPHICAL USER INTERFACE
Event loops 17-Jan-19.
Event loops 17-Jan-19.
A Quick Java Swing Tutorial
Event loops 8-Apr-19.
Advanced ProgramMING Practices
Model, View, Controller design pattern
Event loops.
Event loops 19-Aug-19.
Presentation transcript:

3461 Model-View Controller Advanced GUI concepts

3461 Background The model-view controller (MVC) paradigm was developed at the Xerox Palo Alto Research Center (PARC). MVC was central to the architecture of the multi-windowed Smalltalk environment used to create the first graphical user interfaces. The approach taken was borrowed by the developers of the Apple Macintosh and many imitators in the years since. In such an interface, input is primarily by the mouse and keyboard; output is a mix of graphics and textual components as appropriate. MVC is elegant and simple, but rather unlike the approach of traditional application programs.

3461 MVC paradigm  Traditional paradigm…  Input  processing  output  MVC paradigm…  Controller  model  view

3461 MVC Schematic Keyboard Mouse Etc. Controller View Model Display

3461 MVC Architecture

3461 Controller tasks  Receive user inputs from mouse and keyboard  Map these into commands that are sent to the model and/or viewport to effect changes in the view  E.g, detect that a button has been pressed and inform the model that the button stated has changed

3461 Model tasks  Store and manage data elements, such as state information  Respond to queries about its state  Respond to instructions to change its state  E.g., the model for a radio button can be queried to determine if the button is pressed

3461 View tasks  Implements a visual display of the model  E.g., a button has a colored background, appears in a raised perspective, and contains an icon and text; the text is rendered in a certain font in a certain color

3461 MVC Concepts – multiple views  Any number of views can subscribe to the model Radio button model View #1 View #2 View #3

3461 MVC Concepts - model changes  What happens when the model changes?  E.g., a button is pressed (the state of the button has changed!)  The model must notify the view  The view changes the visual presentation of the model on the screen

3461 Benefits of MVC Architecture  Improved maintainability  Due to modularity of software components  Promotes code reuse  Due to OO approach (e.g., subclassing, inheritance)  Model independence  Designers can enhance and/or optimize model without changing the view or controller  Plugable look and feel  New L&F without changing model  Multiple views use the same data

3461 MVC and Swing  Swing designers found it difficult to write a generic controller that didn’t know the specifics about the view  So, they collapsed the view and controller into a single UI (user interface) object known as a delegate (the UI is delegated to this object)  This object is known as a UI delegate

3461 MVC and Swing (2) Keyboard Mouse Etc. Controller View Model Display Swing component UI delegate

3461 M - Swing Models  In Swing, many models exist as interfaces  Eg., ButtonModel, BoundedRangeModel, ComboBoxModel, ListModel, ListSelectionModel, TableModel, Document  The interface is implemented in model classes  Usually there is a default model class that is automatically associated with a component (whew!)  E.g., DefaultButtonModel implements ButtonModel  E.g, AbstractDocument implements Document (PlainDocument is a subclass of AbstractDocument)

3461 Example Program DemoTable2.java Shown earlier Instead of passing the data directly to the JTable object, we create a data model, pass the data to the model, then pass the model to the JTable object.

3461 Example Program DemoInputValidation3.java JTextField ’s default data model is PlainDocument. We can create a custom data model for a JTextField by creating our own data model and substituting it for PlainDocument

3461 VC – Swing Views and Controllers  In Swing, the term look and feel (L&F) is common  The look is the view  The feel is the controller  In practice, the view and controller parts of MVC are very tightly connected  Swing combines the view and controller into a single entity known as a UI delegate  Advantage: combining the view and controller allows the appearance and behaviour (L&F) of a component to be treated as a single unit, thus facilitating changes to the UI are possible  This is known as pluggable look and feel (next 3 slides)

3461 Example Program DemoLookAndFeel.java

3461 Example Program DemoTable3.java

3461 Example Program DemoTree2.java DemoTree.java

3461 ComponentUI Class  The delegate part of a component is derived from an abstract class named ComponentUI  Naming convention: remove the “J” from the component’s class name, then add “UI” to the end (e.g., JButton  ButtonUI) ComponentUIButtonUIBasicButtonUI MenuButtonUI MultiButtonUI OrganicButtonUI

3461 Design Challenge  A corporation specializing in children’s games wishes to use a custom “corporate style” in all their applications  As one example, they’d like the buttons for their applications to look as follows…  Design a custom L&F for a JButton, as above Normal Armed FUNNY STUFF KIDS STUFF FUNNY STUFF KIDS STUFF Pressed FUNNY STUFF KIDS STUFF

3461 Example Program DemoCustomButtonUI.java

3461 Preferred Size Property  An important task for a window manager is determining the size of widgets  What happens when getPreferredSize is invoked on a JButton?  JButton’s getPreferredSize method is inherited from JComponent  Let’s see…

3461 /** * If the preferredSize has been set to a non-null value * just returns it. If the UI delegate's getPreferredSize() * method returns a non null value then return that; otherwise * defer to the component's layout manager. * the value of the preferredSize property #setPreferredSize */ public Dimension getPreferredSize() { if (preferredSize != null) { return preferredSize; } Dimension size = null; if (ui != null) { size = ui.getPreferredSize(this); } return (size != null) ? size : super.getPreferredSize(); } getPreferredSize (from JComponent.java) Returns either… Value set with setPreferredSize, Value from UI delegate, or Value from Container

3461 Next Topic…