Layout. Dynamic layout, Swing and general layout strategies

Similar documents
Layout. Dynamic layout Layout design pattern Layout strategies

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

YouTube Break.

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

Laying Out Components. What is Widget Layout?

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

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

CS 251 Intermediate Programming GUIs: Components and Layout

Containers and Components

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1

Basicsof. JavaGUI and SWING

Graphical User Interface (GUI)

Introduction to the JAVA UI classes Advanced HCI IAT351

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

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

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

Widgets. Widgets Widget Toolkits. User Interface Widget

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

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

No SVN checkout today. Object-Oriented Design

CS11 Java. Fall Lecture 4

Chapter 14. More Swing

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

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

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

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

Graphical User Interfaces. Comp 152

Window Interfaces Using Swing Objects

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

More Swing. Chapter 14. Chapter 14 1

CS 349 Midterm Exam Spring 2014

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!

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

Window Interfaces Using Swing Objects

Output in Window Systems and Toolkits

- learnability. - efficiency. - graphic design

Graphical User Interface (GUI)

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

Dr. Hikmat A. M. AbdelJaber

Part I: Learn Common Graphics Components

Prototyping a Swing Interface with the Netbeans IDE GUI Editor

Graphical User Interface (GUI)

Graphical User Interfaces in Java - SWING

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

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

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

CSE 1325 Project Description

More UI Output Tasks: Damage Management & Layout

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

Chapter 5: Patterns and GUI Programming

Chapter 6: Graphical User Interfaces

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

Java Programming Lecture 6

The Composite Pattern

Summary Chapter 25 GUI Components: Part 2

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

Sri Vidya College of Engineering & Technology

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

Event Driven Programming

Human-Computer Interaction IS4300

Systems Programming Graphical User Interfaces

Human-Computer Interaction IS4300

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

Java: Graphical User Interfaces (GUI)

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

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

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

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

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

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

Programming graphics

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

Is image everything?

Java Swing. Lists Trees Tables Styled Text Components Progress Indicators Component Organizers

Fall UI Design and Implementation 1

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

Jonathan Aldrich Charlie Garrod

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Building Graphical User Interfaces. GUI Principles

CSE 331 Software Design & Implementation

GUI Programming. Chapter. A Fresh Graduate s Guide to Software Development Tools and Technologies

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

CSC207H: Software Design Lecture 11

Lecture 18 Java Graphics and GUIs

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

Model-view-controller View hierarchy Observer

Top-Level Containers

Object-Oriented Programming

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

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

Graphic User Interfaces. - GUI concepts - Swing - AWT

BASICS OF GRAPHICAL APPS

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

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

Outline. Composite Pattern. Model-View-Controller Pattern Callback Pattern

INTRODUCTION TO (GUIS)

Hints for Assignment I

CS11 Java. Fall Lecture 3

Transcription:

Layout Dynamic layout, Swing and general layout strategies

Two Interface Layout Tasks Designing a spatial layout of widgets in a container Adjusting that spatial layout when container is resized Both can be done by hand (i.e. graphic design) or automatically (i.e. with algorithms). Spatial layout is one component of visual design, so: should use/maintain Gestalt Principles should use/maintain grouping, hierarchy, relationships, balance to achieve organization and structure 3

Dynamic Layout If a window is resized, we want to: maximize use of available space for displaying widgets but we want to do this such that : maintain consistency with spatial layout 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 4

Adaptive/Responsive Layout Changing layout to adapt/respond to different devices e.g. same web page with layouts for desktop, tablet, smartphone Often goes beyond spatial layout to swapping widgets Dynamic layout a special case of adaptive/responsive layout http://www.amazium.co.uk/ 5

Widget Size and Position To make a layout dynamic, widgets need to be flexible x,y position may be changed width and height may be changed However, these changes can be constrained Widgets give the layout algorithm constraints on position e.g. must be anchored on the left side of the window Widgets give the layout algorithm a range of sizes: minimum size < preferred size < maximum size But Button Button Button 6

Layout Managers A Layout Manager provides a layout algorithm to size and position child widgets. Java s Swing package provides a number of layout managers: Grid, Box, Border, Flow, GridBag, etc. A widget can set the most appropriate layout strategy: container.setlayout(new GridLayout(2, 3)); Most useful for container widgets like JPanel 7

Layout Manager Attributes Does it respect a widget's preferred/min/max size? Always ignored? Always respected, even if parts of a widget extend off the edge? Respected in some dimensions but not others? How does it handle extra space? Add extra space around widgets? Give it equally to all widgets? Give it unequally to widgets? Do widgets require additional constraints? Where in the layout manager? Alignment? Share of additional space? 8

Code Demo: LayoutDemo.java 9

Layout Design Patterns Layout in Java makes heavy use of two design patterns: Composite Pattern Strategy Pattern 10

Composite Design Pattern The composite pattern specifies that a group of objects are to be treated in the same way as a single instance of an object. The intent of a composite is to compose objects into tree structures to represent part-whole hierarchies. Implementing the composite pattern lets clients treat individual objects and compositions uniformly. 11

Composite Pattern with Swing JFrame JLabel JButton JSlider JMenuBar JPanel JMenu JRadioButton JMenuItem 12

Strategy Design Pattern Factors out an algorithm into separate object, allowing a client to dynamically switch algorithms e.g. Java Comparator strategy for a Collection context, switching a game s move selection algorithm from easy to hard, text formatter for textboxes, etc. 13

How to implement this layout? 14

General Layout Strategies Fixed layout Intrinsic size Variable intrinsic size Struts and springs Constraints 15

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? 16

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 is completely dependent on its contained widgets Example LayoutManagers in Java that use this strategy BoxLayout, FlowLayout Examples of use in interface design? Special needs? 17

Variable Intrinsic Size Layout Layout determined in bottom-up and top-down phases Get each child widget s preferred size Child may need to ask all of its children Set each child widget s size and location based on the child s preferences and the parent s algorithm Each child needs to do layout Ask children how big they want to be Set each child widget s size and location Example LayoutManagers in Java GridBagLayout BorderLayout 18

Struts and Springs Layout Layout specified by marking aspects of widgets that are fixed vs. those that can stretch 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 are called glue in Java Can add more general constraints too e.g. widget must be EAST of another widget Example LayoutManagers in Java SpringLayout, BoxLayout (pretty restricted form) 19

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

Java Tips and Strategies 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 21

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 Consider making each panel into a view (see MVC lecture) 22

Custom Layout Managers Creating Ribbon? Can t push it quite far enough with standard Java layouts 23 Need custom layout manager See RandomLayout in sample code for an example public interface LayoutManager { void addlayoutcomponent(string name, Component comp); void removelayoutcomponent(component comp); Dimension preferredlayoutsize(container parent); Dimension minimumlayoutsize(container parent); void layoutcontainer(container parent); }