Advanced User Interfaces with Java SD’98 - Session 3206 Ted Faison Faison Computing Inc.

Slides:



Advertisements
Similar presentations
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 2 2D Graphics: Basics.
Advertisements

Georgia Institute of Technology Drawing in Java – part 2 Barb Ericson Georgia Institute of Technology September 2005.
Java Two Dimensional Graphics with Affine Transforms
CSC1401 Drawing in Java - 2. Reminder from last class How do you save your modified picture? String filename = …; Picture stevePicture = new Picture(filename);
Draw Shapes Introduction to simple graphics. What is a graphics context? An instance of the Graphics class Graphics is ABSTRACT! You can extend Graphics.
More Java Drawing in 2D Animations with Timer. Drawing Review A simple two-dimensional coordinate system exists for each graphics context or drawing surface.
Computer Graphics Lecture 4 Geometry & Transformations.
Chapter 3 Drawing and Composing an Illustration. Objectives Draw straight lines Draw curved lines Draw elements of an illustration Apply attributes to.
Java2 Printing API Jean-Cédric Desrochers March 9, 2000.
Graphics Programming UQC117S2 Semester /4. Session 3 1 Drawing in Java 2D Graphics API.
Lecture07 Graphics Programming in Java. Introduction Most of the graphics programming of java is done with: Most of the graphics programming of java is.
1 L38 Graphics and Java 2D™ (3). 2 OBJECTIVES In this chapter you will learn:  To understand graphics contexts and graphics objects.  To understand.
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
Lecture 7 Graphics under AWT Graphics Attributes Shapes Clips Affine Transformations Strokes, Paints, Colors, Translucency RenderingHints, Anti-aliasing.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 2 2D Graphics: Basics F The architecture.
Swing Graphics ● Empty Swing containers have no visual appearance except for a background color ● Every JComponent must have a paintComponent method that.
Introduction to Computer Graphics
By: Zaiba Mustafa Copyright ©
CS324e - Elements of Graphics and Visualization Java2D Graphics.
Vector Graphics Making custom images. Raster vs. Vector Graphics In computer graphics, a raster graphics image, or bitmap, is a dot matrix data structure.
1 Review of COMPSCI 221  Chapters 1-11 in text  User Interfaces will be addressed as a take- home question.
Java ME & Blackberry APIs for Game Dev Week III. Overview Java 2D API Java 3D API SVG Blackberry APIs
Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating.
1 Graphical User Components (II) Outline JTextArea Creating a Customized Subclass of JPanel JPanel Subclass that Handles Its Own Events Windows: Additional.
(C) 2010 Pearson Education, Inc. All rights reserved. Omer Boyaci.
CS324e - Elements of Graphics and Visualization Compositing.
1.00 Lecture 18 Geometric Transformations in the 2D API.
2D Graphics: Rendering Details
Chapter 15 Graphics and Java 2D™ Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction.
Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction 28.2Graphics Contexts and Graphics Objects 28.3Color Control 28.4Font Control 28.5Drawing.
 Pearson Education, Inc. All rights reserved. 1 Ch 12 Graphics and Java 2D In this chapter you will learn:  To understand graphics contexts.
(C) 2010 Pearson Education, Inc. All rights reserved. Omer Boyaci.
Adobe Illustrator Basics Instructor: Cristol Gregory Assistant: Tara Caimi.
Java Graphics Swing Graphics
Graphics and Java 2D. 2 Introduction Java’s graphics capabilities –Drawing 2D shapes –Controlling colors –Controlling fonts Java 2D API –More sophisticated.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 3 2D Graphics: Rendering Details.
Java Graphics. Review 3 kinds of elements in components API? Layout managers Events Extend vs. Implement.
1 Chapter 3 2D Graphics: Rendering Details  Color spaces, paints stroke types  Affine transforms including translation, rotation, scaling, shearing,
Creating Your Own Widgets CompSci 230 S Software Construction.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Georgia Institute of Technology Drawing in Java Barb Ericson Georgia Institute of Technology August 2005.
Introduction to Java Chapter 8 - Introduction to Java Graphics1 Chapter 8 Introduction to Java Graphics.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
Fall UI Design and Implementation1 Lecture 6: Output.
Georgia Institute of Technology Drawing in Java – part 3 Barb Ericson Georgia Institute of Technology September 2006.
Java Graphics Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignment? zOffset between class.
Creating Vectors – Part One 2.02 Understand Digital Vector Graphics.
Advanced Java Screen Update Techniques SD’98 - Session 4406 Ted Faison Faison Computing Inc.
Projects: not limited to spec Error checking File filters Create multiple file formats Polygons Filled shapes Etc.
IS502:M ULTIMEDIA D ESIGN FOR I NFORMATION S YSTEM D IGITAL S TILL I MAGES Presenter Name: Mahmood A.Moneim Supervised By: Prof. Hesham A.Hefny Winter.
Georgia Institute of Technology Drawing in Java – part 2 Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology North Jeddah.
Main characteristics of Vector graphics  Vector graphics provide an elegant way of constructing digital images (diagrams, technical illustration and.
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
Barb Ericson Georgia Institute of Technology September 2005
Advanced AWT The Rendering Pipeline
Forward Projection Pipeline and Transformations CENG 477 Introduction to Computer Graphics.
12 Graphics and Java 2D™.
Creating Your Own Widgets
Java Graphics CS 2511.
Flash Interface, Commands and Functions
Graphics Fundamentals
Advanced AWT Strokes.
JAVA 2 Design and programming of GUI
Java Graphics The basic rendering mechanism is the drawing system that controls when and how programs can draw on a graphics component. When a component.
2.02 Understand Digital Vector Graphics
Chapter 49 Java 2D.
Creating Vectors – Part One
Creating Vectors – Part One
Barb Ericson Georgia Institute of Technology September 2005
Presentation transcript:

Advanced User Interfaces with Java SD’98 - Session 3206 Ted Faison Faison Computing Inc.

JDK A Better Graphics Framework JDK 1.1 had little or no support for complex shapes, coordinate transformations or pixel blending The graphics extensions were added as new packages under the AWT as the Java 2D API

The Java 2D Packages java.awt.color: Color control java.awt.font: Fonts as complex shapes java.awt.geom: Coordinate transformations and shapes java.awt.print: Advanced printing support –Books, Pages and Paper

Java 2D API Features Support for separate user and device coordinate spaces Coordinates can be integers, floats or doubles User Space Device Space

Java 2D API Features Support for coordinate transformations, for translation, rotation, scaling and shearing User Space Device Space

Java 2D API Features Support for complex shapes and hit- testing Support for complex clipping More precise color control Support for variable transparency, allowing color blending

Java 2D API Features Better image-processing support, with convolution, color look-up, amplitude scaling. Improved screen updating, with offscreen buffers supporting BufferedImages and transparency

Basic Drawing The old Graphics context is still there All 2D drawing done using Graphics2D –Painting: typecasting Graphics into Graphics2D public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.red); //… }

Coordinate Transformations Functions that map a point in one space to a point in another space Represented using a 3x3 matrix Transformations require multiplying each pixel by a transformation matrix Positive angles rotate the X+ axis towards the Y+ axis Can be used to invert axes, bend images, distort space arbitrarily

Coordinate Transformations a 11 a 12 a 13 a 21 a 22 a xy1xy1 a 11 x a 12 y a 13 a 21 x a 22 y a x’ y’ 1 ==

Affine Transforms Maintain straightness and parallelism Translation setToTranslation(double dx, double, dy); used to support graphics scrolling User Space Device Space

Affine Transforms Rotation –Rotating about the origin setToRotation(double theta); User Space Device Space

Affine Transforms –Rotation about an arbitrary point SetToRotation(theta, x, y); User Space Device Space (x, y)

Affine Transforms Shearing setToShear(double sh, double sy) User Space Device Space

Affine Transforms Scaling setToScale(double sx, double sy) anisotropic vs isotropic scaling User Space Device Space

Using class AffineTransform Commands can be cumulative –concatenating transformations Commands are not commutative –Matrix multiplication is not commutative Dealing directly with the transformation matrix, to effect combined transformations in one pass g2D.setTransform(myAffineTransform);

Affine Transforms Handling transformed images with offscreen buffers –Examples ScalingImages.java RotatingImages.java ShearingImages.java

Drawing with Paths All 2D shapes are drawn as paths, including lines and rectangles Class GeneralPath –Used to define arbitrary paths –The outline can be stroked –Graphics2D uses a default stroke: square pen width is 1 pixel continuous drawing - no dashes

Bezier curves Used by the 2D API for cubic curves. Defined by simple control points

Drawing a Straight Line public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.red); GeneralPath path = new GeneralPath(GeneralPath.EVEN_ODD); path.moveTo(50.0f, 50.0f); path.lineTo(200.0f, 200.0f); g2d.draw(path); }

Drawing a Straight Line

Filling a shape public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.blue); GeneralPath path = new GeneralPath(GeneralPath.EVEN_ODD); path.moveTo(20.0f, 20.0f); path.lineTo(100.0f, 20.0f); path.lineTo(100.0f, 70.0f); path.lineTo(20.0f, 70.0f); path.closePath(); g2d.fill(path); }

Filling a shape

Filling a Shape with a Pattern BufferedImage image; // create a buffered image Rectangle2D.Float rect = new Rectangle2D.Float(0.0f, 0.0f, 100.0f, 200.0f); TexturePaint pattern = new TexturePaint(image, rect, TexturePaint.NEAREST_NEIGHBOR); g2d.setPaint(pattern); g2d.drawString(styledString, 10, 10);

Filling a Shape with a Pattern

Filling a Shape with an Image Image image = getToolkit().getImage(url); AffineTransform at = new AffineTransform(); at.setToTranslation(0, 200); g2d.transform(at); g2d.setClip(myShape); at.setToTranslation(0, -200); g2d.drawImage(image, at, this); at.setToTranslation(0, 200); g2d.setClip(null); g2d.draw(myShape);

Filling a Shape with an Image

Filling a Shape with a Gradient Font myFont = new Font("Helvetica", Font.PLAIN, 200); StyledString styledString = new StyledString("AB", myFont); Shape myShape = styledString.getStringOutline(); GradientPaint gradient = new GradientPaint(0.0f, 0.0f, Color.red, 200.0f, 200.0f, Color.yellow); g2d.setPaint(gradient); g2d.drawString(styledString, 10, 200);

Filling a Shape with a Gradient

Custom Strokes Class BasicStroke –simple to use –define common stroke properties width end caps line joins dash attributes

Defining a Custom Stroke g2d.setStroke( new BasicStroke(penWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER ) ); path.moveTo(10.0f, 40.0f); path.lineTo(90.0f, 40.0f); g2d.draw(path);

Defining a Custom Stroke

2D Drawing Shortcuts interface Rectangle2D –Rectangle2D.Float –Rectangle2D.Double RoundRectangle2D Arc2D Ellipse2D

Clipping Graphics2D.setClip(Path); Clipping a circle with a rectangle Ellipse2D.Float circle = new Ellipse2D.Float(10.0f, 10.0f, 100.0f, 100.0f); Rectangle2D.Float rect = new Rectangle2D.Float (10.0f, 30.0f, 100.0f, 70.0f); g2d.setClip(rect); g2d.setColor(Color.red); g2d.fill(circle); g2d.setClip(null); g2d.setColor(Color.black); g2d.draw(rect);

Clipping a Circle with a Rectangle

Clipping with Text Font myFont = new Font("Helvetica",Font.PLAIN,200); StyledString styledString = new StyledString("ABC", myFont); Shape myShape = styledString.getStringOutline(); AffineTransform at = new AffineTransform(); at.setToTranslation(0, 200); g2d.transform(at); Ellipse2D.Float circle = new Ellipse2D.Float(10.0f,-150.0f,400.0f,150.0f); g2d.setClip(myShape); g2d.setColor(Color.red); g2d.fill(circle);

Clipping with Text

Blending objects –Transparency –The Alpha Channel –Compositing Operations called Raster Operations (ROP) in Windows Class AlphaComposite –Implements a subset of the Porter-Duff rules Cd = Cs*Fs + Cd*Fd Ad = As*Fs + Ad*Fd C = Colord = destination F = Fractions = source A = Alpha

Compositing Operations Alpha=1 indicated total opaqueness Setting the Operation AlphaComposite c = AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 0.5f); g2d.setComposite(c);

Porter-Duff Operations Supported CLEAR: destination cleared SRC: source copied to destination SRC_OVER: source is blended over dest SRC_IN: part of source already in dest replaces dest SRC_OUT: part of source not already in dest replaces dest DST_IN, DST_OUT, DEST_OVER

Using the SRC Rule

Using the SRC_OVER Rule

Using the SRC_IN Rule

Using the SRC_OUT Rule

Conclusion The Java 2D API extends the AWT with: –advanced geometric shapes –coordinate transformations –shapes of arbitrary complexity –text as a shape –arbitrary clipping regions –image blending through compositing –image processing capabilities –precise color control