Layout How multiple components are composed to build interfaces.

Slides:



Advertisements
Similar presentations
Android UserInterfaces Nasrullah Niazi. overView All user interface elements in an Android app are built using View and ViewGroup objects. A View is an.
Advertisements

Step-by-Step: Adjust a Chart Axis USE the Pricing Final presentation that is still open from the previous exercise. 1.Click the chart on slide 2 to select.
© 2011 Delmar, Cengage Learning Chapter 10 Positioning Objects with AP Divs.
Graphic User Interfaces Layout Managers Event Handling.
1 Cascading Style Sheets Continued Different kinds of selectors in a style sheet –Simple- Pseudo-Class –Contextual- Pseudo-Element –Class Image Styles.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
1 AVL Trees. 2 AVL Tree AVL trees are balanced. An AVL Tree is a binary search tree such that for every internal node v of T, the heights of the children.
Tutorial 5: Working with Excel Tables, PivotTables, and PivotCharts
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
 Next - Previous  Horizontal Bar  Vertical Menu.
© The McGraw-Hill Companies, 2006 Chapter 18 Advanced graphics programming.
Swinging Into Swing Leo S. Primero III. Understanding what Swing Is Swing is a package that lets you create applications that use a flashy Graphical User.
GUI Layout Managers Arkadiusz Edward Komenda. Outline Components and Containers Layout Managers Flow Layout Grid Layout Border Layout Nested Containers.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Binary Trees Chapter 6.
Office 2003 Advanced Concepts and Techniques M i c r o s o f t Access Project 4 Reports, Forms, and Combo Boxes.
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Tutorial 6 Using Form Tools and Creating Custom Forms
Tutorial 4: Using CSS for Page Layout. 2 Objectives Session 4.1 Explore CSS layout Compare types of floating layouts Examine code for CSS layouts View.
XP New Perspectives on Microsoft Access 2002 Tutorial 51 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and.
XP Using Frames in a Web Site Ali Alfayly. XP Tutorial Objectives Create frames for a Web site Control the appearance and placement of frames Control.
Microsoft PowerPoint Getting Started Guide Prepared for Towson University Dr. Jeff M. Kenton Amy Chase Martin 2007.
Chapter 8: Writing Graphical User Interfaces
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Creating your own form from scratch.. To create a custom form, you can modify an existing form or design and create a form from scratch. In either case,
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Using Android XML Resources.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
CSSE501 Object-Oriented Development. Chapter 12: Implications of Substitution  In this chapter we will investigate some of the implications of the principle.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. ACCESS 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 7 – Adding and.
Chapter 6 Binary Trees. 6.1 Trees, Binary Trees, and Binary Search Trees Linked lists usually are more flexible than arrays, but it is difficult to use.
Working with Objects. Objectives Create an object Transform an object Arrange and lock an object Step and repeat an object Use Live Distribute Use the.
1. Chapter 10 Managing and Printing Documents 3 Working with Files and Printing You can open multiple documents in Word. When multiple documents are.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Laying Out Components Interior Design for GUIs. Nov 042 What is Widget Layout? Positioning widgets in their container (typically a JPanel or a JFrame’s.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
WaveMaker Visual AJAX Studio 4.0 Training Basics: Building Your First Application Designer Basics.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Session 16 Pinball Game Construction Kit:. Pinball Version 1 Replaced the fire button with a mouse event. Multiple balls can be in the air at once. –Uses.
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
3461 Laying Out Components Interior Design for GUIs.
Microsoft Access 2000 Presentation 3 Creating Databases Part II (Creating Forms)
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
Microsoft Office 2013 Try It! Chapter 4 Storing Data in Access.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
Adobe InDesign CS5 – Illustrated Unit C: Working with Objects.
User Interface Components. Layout Placement of UI components in a window – Size & Position Each component occupies a rectangular region in the window.
Object Oriented Programming Lecture 3: Things OO.
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
Microsoft ® Excel ® 2013 Enhanced Tutorial 5: Working with Excel Tables, PivotTables, and PivotCharts.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
CHAPTER 4 Fragments ActionBar Menus. Explore how to build applications that use an ActionBar and Fragments Understand the Fragment lifecycle Learn to.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
Working in the Forms Developer Environment
Implementing Responsive Design
Microsoft Visual Basic 2005 BASICS
Flash Interface, Commands and Functions
Building a User Interface with Forms
Program and Graphical User Interface Design
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Program and Graphical User Interface Design
The structure of Interactive Software
Tutorial 6 Creating Dynamic Pages
Using Templates and Library Items
Layout Organization and Management
Positioning Boxes Using CSS
Presentation transcript:

Layout How multiple components are composed to build interfaces

Placement of widgets We need to be able to control the placement of widgets on the screen Need to be able to handle movement and repositioning and keep these consistent Keeping objects geometrically consistent is a fundamental problem. When the objects are widgets it is called the layout problem. When the objects are other things it is called constraints.

Change in Menu from 1 to 2 lines Moved but same orientation Scroll bars and palette unchaged wrt edge of frame

Layout We need to programme interfaces to ensure all widgets move appropriately. We need to programme interfaces to ensure all widgets move appropriately. Three basic algorithms underpin layout Three basic algorithms underpin layout Fixed positionFixed position Edge anchoredEdge anchored Variable intrinsic sizeVariable intrinsic size For each approach we need to consider For each approach we need to consider 1.what information must be stored with the widgets from which the layout can be computed 2.what is the algorithm for computing the layout, 3.how will the interface designer specify the layout either interactively or programmatically.

Fixed Position Layout Simplest layout approach assign every widget a fixed rectangle Simplest layout approach assign every widget a fixed rectangle Coordinates relative to the parentCoordinates relative to the parent Good for fixed interface that you do not want to resize or whose components do not change.Good for fixed interface that you do not want to resize or whose components do not change.

public class Widget { other fields and methods public Rectangle desiredBounds; public void doLayout(Rectangle newBounds) { setBounds(newBounds); foreach child widget C { Rectangle newChildBounds= new Rectangle(newBounds.left+C.desiredBounds.left, newBounds.Top+C.desiredBounds.top, C.desiredBounds.width, C.desiredBounds.height); C.doLayout(newChildBounds); } Simple rectangle for each widget Simple rectangle for each widget Container widget sets the childs bounds location to its own plus the child’s Container widget sets the childs bounds location to its own plus the child’s

Fixed Layout Advantages a simple algorithm minimal data very simple model to specify. Designing Programmatically Designing Programmatically construct a rectangle with the desired location and size set desiredBounds add the widget to its container. Disadvantage Disadvantage Resizing not handled at all wellResizing not handled at all well To small parts of components clipped or not shown at all To small parts of components clipped or not shown at all To big – all in the top corner To big – all in the top corner

Edge anchored layout Modifying widgets so that their edges can be anchored to the edges of their container’s rectangle. Modifying widgets so that their edges can be anchored to the edges of their container’s rectangle. widget has coordinates for left, right, top and bottom.widget has coordinates for left, right, top and bottom. interpretation depends upon the boolean values anchorLeft, anchorRight, anchorTop, anchorBottom.interpretation depends upon the boolean values anchorLeft, anchorRight, anchorTop, anchorBottom. widget has a desiredWidth and desiredHeight.widget has a desiredWidth and desiredHeight. Edges are either anchored or not Edges are either anchored or not If anchored then it is a fixed distance away from the corresponding container edge.If anchored then it is a fixed distance away from the corresponding container edge. The algorithms for the X and Y axes are independent and identical. The algorithms for the X and Y axes are independent and identical. If only one edge is anchored, then the desired width is used to determine the location of the other edge.If only one edge is anchored, then the desired width is used to determine the location of the other edge. If neither edge is anchored, then the left value is used to compute a proportional distance between the container edges and the desired width is used for the other edge.If neither edge is anchored, then the left value is used to compute a proportional distance between the container edges and the desired width is used for the other edge. Both edges are anchored, they follow their respective edges.Both edges are anchored, they follow their respective edges.

Public class Widget {.... other fields and methods... public Rectangle bounds; public int left, right, top, bottom; public boolean anchorLeft, anchorRight, anchorTop, anchorBottom; public int width, height; public const int MAXSIZE=4096; public void doLayout( Rectangle newBounds) { bounds=newBounds; foreach child widget C { Rectangle childBounds=new Rectangle(); if (C.anchorLeft) { childBounds.left=newBounds.left+C.left; if (C.anchorRight) { childBounds.right=newBounds.right-C.right; } else { childBounds.right=childBounds.left+C.width; } } else if (C.anchorRight) // right is anchored left is not { childBounds.right=newBounds.right-C.right; childBounds.left=childBounds.right-C.width; } else // neither edge is anchored { childBounds.left = newBounds.width*C.left/MAXSIZE; childBounds.right=childBounds.left+C.width; }.... perform similar computation for Y.... C.doLayout(childBounds); }

Key concepts Container does the layout work on the widgets children Container does the layout work on the widgets children To lay out a widget, a programmer sets the various member fields and adds the widget to its container. The container then will make certain that the widget’s bounds are placed in the correct position. Programming this interactively requires a special interface to highlight the edge relationships and specify how they are bound Programming this interactively requires a special interface to highlight the edge relationships and specify how they are bound

resize

Variable intrinsic size layout On many occasions he designer does not want to manually position the widgets Create group and have them position themselves Menus Changes in language/font for labels Want to automatically adapt the layout to changes in interface content Each widget knows how much screen space it can reasonably use (intrinsic size) Each container has a plan for how to allocate screen space based on the needs of its children. Recursively arranging containers with various layout plans This is main approach used in Java

Layout algorithm Based on two recursive passes Based on two recursive passes first pass requests each widget to report its desired size. second pass sets the widget bounds public void doLayout(Rectangle newBounds) { foreach child widget C { ask for desired size of C } //based on desired sizes and newBounds, decide where //each child should go foreach child widget C { C.doLayout( new bounds for C); } }

Intrinsic size layouts ask a widget for Intrinsic size layouts ask a widget for minimum size (the smallest dimensions that it can effectively use), minimum size (the smallest dimensions that it can effectively use), desired size (the dimensions that would work best for this widget) desired size (the dimensions that would work best for this widget) maximum size (the largest dimensions that it can effectively use). maximum size (the largest dimensions that it can effectively use). Determined by nature of each widget Determined by nature of each widget Containers calculate this based on the size of its children Containers calculate this based on the size of its children

Widget class extended to handle sizes for layout Widget class extended to handle sizes for layout Each component implements in own way Each component implements in own way public class Dimension { public int width; public int height; } public class Widget {... other methods and fields... public Dimension getMinSize() {... } public Dimension getDesiredSize() {... } public Dimension getMaxSize() {... } }

Sizes of Simple Widgets

public class Button {... other methods and fields... public Dimension getMinSize() { int minWidth = bevelWidth*2+font.getLength(labelText); int minHeight = bevelWidth*2+font.getHeight(); return new Dimension(minWidth,minHeight); } public Dimension getDesiredSize() { int desWidth = bevelWidth*2+marginWidth*2+font.getLength(labelText); int minHeight=bevelWidth*2+marginHeight*2+font.getHeight(); return new Dimension(desWidth,desHeight) } public Dimension getMaxSize() { return getDesiredSize(); } } Desire sizes includes the margin Desire sizes includes the margin Minimum size looses the margin Minimum size looses the margin Font details used to calculate size based on text in label Font details used to calculate size based on text in label

Simple container layouts Box widgets in Java The simplest containers are the vertical and horizontal stack. Box widgets in Java Vertical Stack Horizontal Stack ABCD

public class HorizontalStack { public Dimension getMinSize() { int minWidth=0; int minHeight=0; foreach child widget C { Dimension childSize = C.getMinSize(); minWidth += childSize.width; if (minHeight<childSize.height) { minHeight=childSize.height; } } return new Dimension(minWidth,minHeight); } public Dimension getDesiredSize() { similar to getMinSize using C.getDesiredSize() } public Dimension getMaxSize() { similar to getMinSize using C.getMaxSize() } } Width1 Width2 Width3 Width4

doLayout() for horizontal stack when a new window is opened request the desired size of the root widget and allocate that as the window size. BUT, there may not be enough screen space for a window that big. Space is allocated among the children depends upon whether the width is less than min greater than min but less than desired greater than desired but less than max greater than max. The idea of the algorithm is to give each child as much as possible and then divide up the remainder proportionally among the children according to their requests.

public class HorizontalStack {... the other methods and fields... public void doLayout(Rectangle newBounds) { Dimension min = getMinSize(); Dimension desired = getDesiredSize(); Dimension max = getMaxSize(); If (min.width>=newBounds.width) { // give all children their minimum and let them be clipped int childLeft=newBounds.left; foreach child widget C { Rectangle childBounds = new Rectangle(); childBounds.top=newBounds.top; childBounds.height=newBounds.height; childBounds.left=childLeft; childBounds.width= C.getMinSize().width; childLeft+=childBounds.width; C.doLayout(childBounds); }

else if (desired.width>=newBounds.width) { // give min to all and proportional on what is available for desired int desiredMargin = desired.width-min.width; float fraction= (float)(newBounds.width-min.width)/desiredMargin; int childLeft=newBounds.left; foreach child widget C { Rectangle childBounds=new Rectangle(); childBounds.top=newBounds.top; childBounds.height=newBounds.height; childBounds.left=childLeft; int minWidth=C.getMinSize().width; int desWidth=C.getDesiredSize().width; childBounds.width=minWidth+(desWidth-minWidth)*fraction; childLeft+=childBounds.width; C.doLayout(childBounds); }

else { // allocate what remains based on maximum widths int maxMargin = max.width-desired.width; float fraction= (float)(newBounds.width-desired.width)/maxMargin; int childLeft=newBounds.left; foreach child widget C {... Similar code to previous case... }

Combining layouts Use multiple horizontal and vertical stacks to produce layouts Use multiple horizontal and vertical stacks to produce layouts

Efficiency of layout Problem 1 : Recursion The window will call the root widget to ask for its desired size. The root widget will recursively call all of its children to compute that size. When the root widget starts to do its layout it will call the Palette group’s desired sizes again. When the Palette group starts its own layout it will call the Colors group’s desired sizes yet again finally when the Colors group does its layout it will call desired sizes on the text box. The desired size methods on the Colors text box was called at least 4 times. Problem 2: Changes. The size of a window may be changed many times but the desires sizes of the various widgets do not change often.Most systems cache but what happens when things do change an invalidate() method is provided that informs the parent widget that the desired sizes are no longer correct. invalidate() method not only sets its own sizes to be invalid, but also sends the invalidate() message to its container. Java/Swing does not propagate invalidate() up the tree causing interfaces not to change when they might be expected to.

public class HorizontalStack { private Dimension minSize; private Dimension desiredSize; private Dimension maxSize; private boolean sizesAreValid; public Dimension getMinSize() { if (sizesAreValid) return minSize; int minWidth=0; int minHeight=0; foreach child widget C { Dimension childSize = C.getMinSize(); minWidth += childSize.width; if (minHeight<childSize.height) { minHeight=childSize.height; } } sizesAreValid=true; return new Dimension(minWidth,minHeight); } public Dimension getDesiredSize() { similar to getMinSize using C.getDesiredSize() } public Dimension getMaxSize() { similar to getMinSize using C.getMaxSize() } public void invalidate() { sizesAreValid=false; if (myContainer!=null) myContainer.invalidate(); }

public class HorizontalStack { private Dimension minSize; private Dimension desiredSize; private Dimension maxSize; private boolean sizesAreValid; public Dimension getMinSize() { if (sizesAreValid) return minSize; int minWidth=0; int minHeight=0; foreach child widget C { Dimension childSize = C.getMinSize(); minWidth += childSize.width; if (minHeight<childSize.height) { minHeight=childSize.height; } } sizesAreValid=true; return new Dimension(minWidth,minHeight); } public Dimension getDesiredSize() { similar to getMinSize using C.getDesiredSize() } public Dimension getMaxSize() { similar to getMinSize using C.getMaxSize() } public void invalidate() { sizesAreValid=false; if (myContainer!=null) myContainer.invalidate(); }

Spatial arrangements Simple Stacks not enough to provide layouts Simple Stacks not enough to provide layouts Need some more control over spacing between components Need some more control over spacing between components We use “spreaders” and “spacers” to do this We use “spreaders” and “spacers” to do this In java this is the role of the Box.Filler classIn java this is the role of the Box.Filler class Special widgets that are not drawn Special widgets that are not drawn InvisibleInvisible Have min, desired and max sizesHave min, desired and max sizes Spacer Spacer min, desired and max sizes set to same value ensuring fixed space between widgetsmin, desired and max sizes set to same value ensuring fixed space between widgets Spreader Spreader Small min and desired but large max making spacing widgets apartSmall min and desired but large max making spacing widgets apart Use of spreaders and spacer is effective but not that intuitive for new designers. Use of spreaders and spacer is effective but not that intuitive for new designers.

Layout Managers Separate objects that handle a particular style of layout Separate objects that handle a particular style of layout Desired layout for containers is a property of the container Desired layout for containers is a property of the container

public interface LayoutManager { public Dimension getMinSize(Widget containerWidget); public Dimension getDesiredSize(Widget containerWidget); public Dimension getMaxSize(Widget containerWidget); public void doLayout(Rectangle newBounds, Widget containerWidget); } public class Widget {... other methods and fields... private Dimension minSize; private Dimension desiredSize; private Dimension maxSize; private boolean sizesAreValid; private LayoutManager myLayout; public LayoutManager getLayoutManager() { return myLayout; } public void setLayoutManager(LayoutManager newLayout ) { myLayout=newLayout; invalidate(); } public Dimension getMinSize() { if (sizesAreValid) return minSize; minSize=myLayout.getMinSize(this); sizesAreValid=true; } public Dimension getDesiredSize() {... similar to getMinSize()... } public Dimension getMaxSize() {... similar to getMinSize()... } public void doLayout(Rectangle newBounds) { myLayout.doLayout(newBounds,this); } }

Summary Introduced the importance of layout and placement Introduced the importance of layout and placement Discussed a series of techniques for layout Discussed a series of techniques for layout Outlined the broad approach of layout managers. Outlined the broad approach of layout managers. Next : Examples of the use of Swing Layouts in practice Next : Examples of the use of Swing Layouts in practice Read through the swing tutorials. Read through the swing tutorials.