Layout. Dynamic layout Layout design pattern Layout strategies

Similar documents
Layout. Dynamic layout Layout design pattern Layout strategies. 2.6 Layout 2

Layout. Dynamic layout, Swing and general layout strategies

YouTube Break.

Laying Out Components. What is Widget Layout?

What is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs

Resizing a Window. COSC 3461: Module 5B. What is Widget Layout? Size State Transitions. What is Widget Layout? Hierarchical Widget Layout.

What is Widget Layout? COSC 3461 User Interfaces. Hierarchical Widget Layout. Resizing a Window. Module 5 Laying Out Components

Containers and Components

CS 251 Intermediate Programming GUIs: Components and Layout

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

Output in Window Systems and Toolkits

Introduction to the JAVA UI classes Advanced HCI IAT351

More Swing. Chapter 14. Chapter 14 1

Basicsof. JavaGUI and SWING

More UI Output Tasks: Damage Management & Layout

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1

Graphical User Interface (GUI)

No SVN checkout today. Object-Oriented Design

Graphical User Interfaces. Swing. Jose Jesus García Rueda

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

KF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation

Welcome to CIS 068! 1. GUIs: JAVA Swing 2. (Streams and Files we ll not cover this in this semester, just a review) CIS 068

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI

11/6/15. Objec&ves. RouleQe. Assign 8: Understanding Code. Assign 8: Bug. Assignment 8 Ques&ons? PROGRAMMING PARADIGMS

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Graphical User Interface (GUI)

Chapter 14. More Swing

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

Part I: Learn Common Graphics Components

Dr. Hikmat A. M. AbdelJaber

CS11 Java. Fall Lecture 4

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

Widgets. Widgets Widget Toolkits. User Interface Widget

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

Window Interfaces Using Swing Objects

CSE 1325 Project Description

Apéndice A. Código fuente de aplicación desarrollada para probar. implementación de IPv6

Graphical User Interfaces. Comp 152

Chapter 5: Patterns and GUI Programming

Parts of a Contract. Contract Example. Interface as a Contract. Wednesday, January 30, 13. Postcondition. Preconditions.

Graphical User Interfaces in Java - SWING

Window Interfaces Using Swing Objects

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

News and info. Array. Feedback. Lab 4 is due this week. It should be easy to change the size of the game grid.

Java Programming Lecture 6

Summary Chapter 25 GUI Components: Part 2

Programming graphics

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling

Automatic layout Constraints Model-based UI. Declarative programming. Procedural programming. Saying what you want. Saying how to achieve it

Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski

JFrame In Swing, a JFrame is similar to a window in your operating system

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Chapter 6: Graphical User Interfaces

Hints for Assignment I

Building Graphical User Interfaces. GUI Principles

Prototyping a Swing Interface with the Netbeans IDE GUI Editor

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Part 3: Graphical User Interface (GUI) & Java Applets

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

Graphical User Interfaces

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Chapter 13 Lab Advanced GUI Applications

CS 3331 Advanced Object-Oriented Programming Final Exam

- learnability. - efficiency. - graphic design

Widgets. Overview. Widget. Widgets Widget toolkits Lightweight vs. heavyweight widgets Swing Widget Demo

Graphical User Interface (GUI)

CSE Lab 8 Assignment Note: This is the last lab for CSE 1341

Today. cisc3120-fall2012-parsons-lectiii.3 2

Agenda. Container and Component

Event Driven Programming

CS 180 Final Exam Review 12/(11, 12)/08

Building Graphical User Interfaces. Overview

Java: Graphical User Interfaces (GUI)

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

CSC 161 SPRING 17 LAB 2-1 BORDERLAYOUT, GRIDLAYOUT, AND EVENT HANDLING

CS 349 Midterm Exam Spring 2014

Tool Kits, Swing. Overview. SMD158 Interactive Systems Spring Tool Kits in the Abstract. An overview of Swing/AWT

Using Several Components

CS11 Java. Fall Lecture 3

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science

2IS45 Programming

Chapter 12 Advanced GUIs and Graphics

Object Oriented Design & Patterns. Part 1

Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus

Top-Level Containers

Human-Computer Interaction IS4300

Jonathan Aldrich Charlie Garrod

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

The Composite Pattern

Swing UI. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

Graphical User Interface (Part-3) Supplementary Material for CPSC 233

SWING - GROUPLAYOUT CLASS

encompass a group of features for building Graphical User Interfaces (GUI).

Swing/GUI Cheat Sheet

CSC207H: Software Design Lecture 11

Transcription:

Layout Dynamic layout Layout design pattern Layout strategies

2.6 Layout 2

https://www.bostonglobe.com/ 2.6 Layout 3

Responsive vs. Adaptive Responsive: universal design reflows spatial layout to fit width Adaptive: switch between optimized spatial layouts to fit devices In practice, the two approaches can be combined Article and Demo https://css-tricks.com/the-difference-between-responsive-and-adaptive-design/ 2.6 Layout 4

Two Interface Layout Tasks 1. Designing a spatial layout of widgets in a container 2. Adjusting that spatial layout when container is resized can be done by hand (i.e. graphic design) or automatically (i.e. with algorithms). (spatial layout is one component of visual design ) 2.6 Layout 5

Dynamic Layout If a window is resized, we want to: 1. maximize use of available space for displaying widgets but we want to do this such that: 2. maintain consistency with spatial layout 3. preserve visual quality of spatial layout Need to dynamically modify the layout: - re-allocate space for widgets - adjust location and size of widgets - perhaps even change visibility, look, and/or feel of widgets 2.6 Layout 6

Layout uses Composite Design Pattern Treat leaf objects and compositions of objects uniformly Creates a tree data structure In Swing, a leaf is a simple widget like a button and a composite is a container widget like a JPanel 2.6 Layout 7

Composite Pattern with Swing JFrame JLabel WidgetDemo.java JButton JSlider JMenuBar JMenu JPanel JMenuItem JRadioButton 2.6 Layout 8

Widget Size To make a layout dynamic, widgets need to be flexible - x,y position may be changed - width and height may be changed Widgets give the layout algorithm a range of sizes as hints A containers size hints usually consider size hints of children getminimumsize() < getpreferredsize() < getmaximumsize() But Button Button Button 2.6 Layout 9

LayoutManager is a Strategy Design Pattern Factors out an algorithm into a separate object, allowing a client to dynamically switch algorithms 2.6 Layout 10

Java LayoutManager Container widgets can use different LayoutManagers - a LayoutManager is an strategy object that factors out the layout algorithm to size and position child widgets Example: container.setlayout(new GridLayout(2, 3)); 2.6 Layout 11

Code Demo: LayoutDemo.java 2.6 Layout 12

General Layout Strategies Fixed layout Intrinsic size layout Variable intrinsic size layout Struts and springs layout Relative layout Custom layout 2.6 Layout 13

Fixed Layout Widgets have a fixed size, fixed position In Java, achieved by setting LayoutManager to null Where/when is this practical? How can it break down even when windows aren t resized? 2.6 Layout 14

Intrinsic Size Layout Query each item for its preferred size Grow the widget to perfectly contain each item A bottom-up approach where top-level widget s size completely dependent on its contained widgets Example LayoutManagers: BoxLayout, FlowLayout Examples of use in interface design? How to handle when too big? 2.6 Layout 15

Variable Intrinsic Size Layout Layout determined in two-passes (bottom-up, top-down) 1. Get each child widget s preferred size (includes recursively asking all of its children for their preferred size ) 2. Decide on a layout that satisfies everyone s preferences, then iterate through each child, and set it s layout (size/position) Example LayoutManagers: GridBagLayout, BorderLayout 2.6 Layout 16

Struts and Springs Layout Layout specified by marking space as fixed or stretchable Strut is a fixed space (width/height) - Specifies invariant relationships in a layout Spring stretches to fill space (or expand widget size) - Specifies variable relationships - (springs called glue in Java) Example LayoutManagers: SpringLayout, BoxLayout 2.6 Layout 17

Struts and Springs in GUI Design Tools Very common, especially in Interactive GUI design tools - Can be more difficult to do in code Good metaphors for people performing layout Google WindowBuilder Eclipse Plug-in 2.6 Layout 18

Struts and Springs ( Glue ) in Java javax.swing.box has useful widgets for any layout manager - Glue to expand/contract to fill space (i.e. Springs ) Box.createHorizontalGlue(), Box.createVerticalGlue() - Rigid Areas and Struts to occupy space Box.createHorizontalStrut(...), Box.createVerticalStrut(...) Box.createRigidArea(...) glue A strut glue A strut 2.6 Layout 19

Relative Layout Relative position constraints too - e.g. widget must be EAST of another widget Example LayoutManagers in Java SpringLayout 2.6 Layout 20

Custom Layout Implement the LayoutManager Interface void addlayoutcomponent(string, Component) void removelayoutcomponent(component) Dimension preferredlayoutsize(container) Dimension minimumlayoutsize(container) void layoutcontainer(container) 2.6 Layout 21

Custom Layout Example: DemoAlignLayout.java layout components in horizontal row equally spaced row of components is centred in window 2.6 Layout 22

DemoAlignLayout.java class AlignLayout implements LayoutManager { public AlignLayout(int minspacing, int preferredspacing) {... } public Dimension preferredlayoutsize(container parent) {... } public Dimension minimumlayoutsize(container parent) {... } public void layoutcontainer(container parent) {... } private Dimension calculatespace(container parent, boolean ispreferred) {... } 2.6 Layout 23

DemoAlignLayout.java Dimension calculatespace(container parent, boolean ispreferred) { Dimension result = new Dimension(0,0); int ncomponents = parent.getcomponentcount(); for (int i = 0; i < ncomponents; i++) { } Dimension d; if (ispreferred) { d = parent.getcomponent(i).getpreferredsize(); } else { d = parent.getcomponent(i).getminimumsize(); } // update the total width and height required result.width += d.width; result.height = Math.max(result.height, d.height); // add spacing in between components if (ispreferred) { result.width += (ncomponents - 1) * preferredspacing; } else { result.width += (ncomponents - 1) * minimumspacing; } } return result; 2.6 Layout 24

DemoAlignLayout.java public void layoutcontainer(container parent) { Dimension space = calculatespace(parent, true); // this container's padding Insets insets = parent.getinsets(); // get actual space available in parent int w = parent.getwidth() - insets.left - insets.right; int h = parent.getheight() - insets.top - insets.bottom; // vertical centre line to layout component int y = h / 2; // starting x is left side of all components to lay out int x = (w - space.width) / 2; int ncomponents = parent.getcomponentcount(); for (int i = 0; i < ncomponents; i++) { Component c = parent.getcomponent(i); Dimension d = c.getpreferredsize(); c.setbounds(x, y - d.height / 2, d.width, d.height); } x += d.width + preferredspacing; } 2.6 Layout 25

(Extra) DemoFormLayout.java Custom Layout Manager widgets organized in two columns order widget added determines column 2.6 Layout 26

How to implement an Accordion LayoutManager? 2.6 Layout 27

How to implement a Ribbon LayoutManager? 2.6 Layout 28

Tips and Strategies Break up the UI recursively with panels that contain panels. Cluster components into panels based on layout needs Provide a layout manager for each panel 2.6 Layout 29