Swing Rocks - A Tribute to Filthy Rich Clients

Similar documents
Computer Science 210: Data Structures. Intro to Java Graphics

Filthy Rich Clients: Filthier. Richer. Clientier. Romain Guy, Google Chet Haase, Adobe Systems

Swing and you are winning

PESIT Bangalore South Campus

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

Bringing Life to Swing Desktop Applications

Programming Languages and Techniques (CIS120)

Overview. Applets. A Java GUI inside your browser! Important methods Drawing images Playing audio Getting input parameters Double buffering

Programming Languages and Techniques (CIS120)

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

G51PRG: Introduction to Programming Second semester Applets and graphics

Week 4 Part 2. Introduction to 2D Graphics & Java 2D

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2,

Object Orientated Programming in Java. Benjamin Kenwright

Programming Languages and Techniques (CIS120)

Applet which displays a simulated trackball in the upper half of its window.

Windows and Events. created originally by Brian Bailey

UI Software Organization

Programming Languages and Techniques (CIS120)

Assignment 2. Application Development

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

Lecture 3: Java Graphics & Events

Programming Languages and Techniques (CIS120)

CSCI 053. Week 5 Java is like Alice not based on Joel Adams you may want to take notes. Rhys Price Jones. Introduction to Software Development

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction

HW#1: Pencil Me In Status!? How was Homework #1? Reminder: Handouts. Homework #2: Java Draw Demo. 3 Handout for today! Lecture-Homework mapping.

Graphical User Interfaces 2

UCLA PIC 20A Java Programming

class BankFilter implements Filter { public boolean accept(object x) { BankAccount ba = (BankAccount) x; return ba.getbalance() > 1000; } }

Unit 7: Event driven programming

Lecture 5: Java Graphics

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like:

Programmierpraktikum

Java 2D Graphics. Drawing Primitives, Affine Transformations, Scene Graphs, Hit Tests. Drawing Primitives 2/9/2014. Using it is simple.

CSIS 10A Practice Final Exam Solutions

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

Java Coordinate System

User interfaces and Swing

Clipboard and Drag-and-Drop

Agenda. Programming Seminar. By: dr. Amal Khalifa. Coordinate systems Colors Fonts Drawing shapes Graphics2D API

IT101. Graphical User Interface

Graphic User Interfaces. - GUI concepts - Swing - AWT

Rendering with Java. Jim Graham Staff Engineer JavaSoft

Outline. More on the Swing API Graphics: double buffering and timers Model - View - Controller paradigm Applets

public void mouseexited (MouseEvent e) setminute(getminute()+increment); 11.2 public void mouseclicked (MouseEvent e) int x = e.getx(), y = e.gety();

Question 1. Show the steps that are involved in sorting the string SORTME using the quicksort algorithm given below.

1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring Quiz 2

Graphic Interface Programming II Events and Threads. Uppsala universitet

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

Object Design with GoF Patterns, continued. Curt Clifton Rose-Hulman Institute of Technology

Advanced Effects in Java Desktop Applications

CS/120 Final Exam. Name

6.092 Introduction to Software Engineering in Java January (IAP) 2009

Graphics and Painting

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology:

J.73 J.74 THE I/O PACKAGE. Java I/O is defined in terms of streams. Streams are ordered sequences of data that have a source and a destination.

NITI NITI I PRIORITET

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Graphics in Swing. Engineering 5895 Faculty of Engineering & Applied Science Memorial University of Newfoundland

FirstSwingFrame.java Page 1 of 1

2. (10 pts) Which of the following classes implements the Shape interface? Circle all that apply. a) Ellipse2D b) Area c) Stroke d) AffineTransform e)

Advanced Java Programming

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

Java for Interfaces and Networks (DT3010, HT10)

Lab & Assignment 1. Lecture 3: ArrayList & Standard Java Graphics. Random Number Generator. Read Lab & Assignment Before Lab Wednesday!

GUI in Java TalentHome Solutions

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Avoid Common Pitfalls when Programming 2D Graphics in Java: Lessons Learnt from Implementing the Minueto Toolkit

(C) 2010 Pearson Education, Inc. All rights reserved. Omer Boyaci

CS61B Lecture #36. DSIJ, Chapter 10, HFJ, pp Today: A Brief Side Trip: Enumeration types.

Software Construction

ISO-2022-JP (JIS ) 1 2. (Windows95/98 MacOS ) Java UNICODE UNICODE. Java. .java.java.txt native2ascii. .java

Interactors. Brahm Capoor.

Come & Join Us at VUSTUDENTS.net

P 6.3) import java.util.scanner;

CS 120 Fall 2008 Practice Final Exam v1.0m. Name: Model Solution. True/False Section, 20 points: 10 true/false, 2 points each

Graphical User Interfaces 2

CIS 120 Programming Languages and Techniques. Final Exam, May 3, 2011

UML and OOD. Some terms related to OOD. Dependency. Coupling. Interfaces. Multiple Interfaces

Chapter 14: Applets and More

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More

Dartmouth College Computer Science 10, Winter 2012 Solution to Midterm Exam

UNIT-3 : MULTI THREADED PROGRAMMING, EVENT HANDLING. A Multithreaded program contains two or more parts that can run concurrently.

L4,5: Java Overview II

Inheritance Systems. Merchandise. Television Camcorder Shirt Shoe Dress 9.1.1

Kirill Grouchnikov, Amdocs Desktop Matters Conference San Jose, March

I/O Framework and Case Study. CS151 Chris Pollett Nov. 2, 2005.

Aggregation. Chapter 8. Java By Abstraction Chapter 8. Outline. 8.1 What is Aggregation? Copyright 2006 Pearson Education Canada Inc.

Chapter 14: Applets and More

OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613

: 15. (x, y) (x, y ) (x, y) ( x x = 1 y = y ) (x = x y y = 1) (12.1.1)

The Nervous Shapes Example

Chapter 1 GUI Applications

The AWT Package, Graphics- Introduction to Images

Reviewing OO Concepts

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Graphical User Interfaces 2

Programming Languages and Techniques (CIS120)

Transcription:

Swing Rocks - A Tribute to Filthy Rich Clients Pär Sikö, Martin Gunnarsson Epsilon Information Technology

One way that Pollak has found to speed up JavaTM programs is to rewrite their user interfaces in Microsoft's Visual Basic. 2

Sure it looks like shit, but at least it does so consistently on all operating systems. 3

and that's why Java on the desktop is as dead as an Egyptian mummy.

How bad can it possibly be? 5

What s the problem? 9

10

11

The Swing Rocks Formula Subtle effects Smooth animations Custom components Good performance 12

Demo: Feedjii 13

Under the hood 14

15

16

17

paint(graphics g) paintcomponent(graphics g) paintborder(graphics g) paintchildren(graphics g) 18

19

Feed component 20

public class FeedComponent extends JComponent { private String headline, text; public FeedComponent(String title, String text) { this.headline = title; this.text = text; } @Override protected void paintcomponent(graphics g) { // Paint code goes here } } 21

Graphics2D g2 = (Graphics2D) g; // Enable antialiasing g2.setrenderinghint(renderinghints.key_antialiasing, RenderingHints.VALUE_ANTIALIAS_ON); 22

// Create gradient paint Point top = new Point(0, 0); Point bottom = new Point(0, getheight()); Color topcolor = new Color(192, 192, 192); Color bottomcolor = new Color(95, 95, 95); Paint paint = new GradientPaint(top, topcolor, bottom, bottomcolor); // Set paint g2.setpaint(paint); 23

// Draw background int radius = 10; g2.fillroundrect(0, 0, getwidth(), getheight(), radius, radius); 24

// Draw headline g2.setpaint(color.black); g2.drawstring(this.headline, 15, 15); // Draw body g2.drawstring(this.text, 15, 40); JavaOne The conference where all the cool people hang out 25

What about animations? 26

Timing Framework public class AnimationExample implements TimingTarget { public void createanimation() { Animator animator = new Animator(2000, this); animator.setresolution(10); animator.setacceleration(0.3f); animator.setdeceleration(0.3f); animator.start(); } @Override public void timingevent(float progress) { // Update and redraw } } 27

Step 4: Timing event (Called multiple times) Move the list Step 3: Mouse button released Calculate total distance to scroll Step 2: Mouse dragged (Called multiple times) Update component position Step 1: Mouse button pressed Save start time Save vertical position 28

Kinetic Scrolling public class KineticScrolling extends JComponent implements MouseListener, MouseMotionListener, TimingTarget { private private private private private private private JComponent componenttoscroll; Animator animator; long starttime; int startposition; int distancetoscroll; MouseEvent previousmouseevent; final int animationduration = 1300; 29

Kinetic Scrolling public KineticScrolling(JComponent component) { setlayout(null); addmouselistener(this); addmousemotionlistener(this); componenttoscroll = component; add(componenttoscroll); } 30

Kinetic Scrolling @Override public void mousepressed(mouseevent e) { starttime = System.currentTimeMillis(); startposition = componenttoscroll.gety(); previousmouseevent = e; } 31

Kinetic Scrolling @Override public void mousedragged(mouseevent e) { int diff = e.getyonscreen() previousmouseevent.getyonscreen(); int newyposition = componenttoscroll.gety() + diff; componenttoscroll.setlocation(0, newyposition); previousmouseevent = e; repaint(); } 32

Kinetic Scrolling @Override public void mousereleased(mouseevent e) { int ydiff = componenttoscroll.gety() - startposition; double elapsedtime = System.currentTimeMillis() starttime; double speed = ydiff / elapsedtime; distancetoscroll = (int) (speed * animationduration); startposition = componenttoscroll.gety(); animator = new Animator(animationDuration, this); animator.setresolution(0); animator.setdeceleration(1); animator.start(); } 33

Kinetic Scrolling @Override public void timingevent(float progress) { int newy = (int)(startposition + distancetoscroll * progress); componenttoscroll.setlocation(0, newy); repaint(); } 34

Demo: Kinetic scrolling 35

Performance: Five steps to success 36

1. Hardware Acceleration Flags > > -Dsun.java2d.opengl=true -Dsun.java2d.d3d=true java -Dsun.java2d.opengl=true Feedjii 37

2. Timing issues public class CustomTimer extends TimingSource { private long resolution; private boolean stop = false; public void start() {... } public void stop() { stop = true; } public void setresolution(int resolution) { this.resolution = resolution; } } 38

2. Timing issues continued public void start() { new Thread() { public void run() { while (!stop) { try { sleep(resolution); } catch (Exception e) { } timingevent(); } } }.start(); } 39

3. Cache is king protected void paintcomponent(graphics g) { if(cachedimage == null) { cachedimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = (Graphics2D) cachedimage.getgraphics(); // Paint your component on the cachedimage graphics.drawline(10, 10, 100, 100); } g.drawimage(cachedimage, 0, 0, null); } 40

4. Compatible Images // Regular buffered image cachedimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); // Compatible image GraphicsConfiguration conf = getgraphicsconfiguration(); cachedimage = conf.createcompatibleimage(width, height); 41

5. Avoid unnecessary transparency cachedimage = conf.createcompatibleimage(width, height, Transparency.TRANSLUCENT); cachedimage = conf.createcompatibleimage(width, height, Transparency.OPAQUE); 42

Performance summary 250 200 1 50 1 00 50 0 S tandard D 3D OpenG L C ache C ached compatible 43

Summary 44

What s next? www.swing-rocks.com 45

Books 46

Questions 47

Pär Sikö, Martin Gunnarsson www.swing-rocks.com per.siko@epsilon.nu martin.gunnarsson@epsilon.nu 48