Image Navigator Help Session. Review Graphics2D class for drawing shapes in a component – paintComponent(Graphics g) – Graphics2D g2 = (Graphics2D)g;

Slides:



Advertisements
Similar presentations
1 Graphical User Interface (GUI) Applications Abstract Windowing Toolkit (AWT) Events Handling Applets.
Advertisements

Introduction to Computation and Problem Solving Class 17: Lab: The Graphics 2D API 1 Prof. Steven R. Lerman and Dr. V. Judson Harward.
Rectangles moving and responding to the mouse. We want a window with a pile of rectangles in it When we click a rectangle it changes from filled to unfilled.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Fun with Swing Chapter 9. Overview Swing vs. AWT Creating windows and panels. Displaying formatted text in panels. Drawing graphics (lines, circles, etc.)
Web Design & Development Lecture 19. Java Graphics 2.
Frame Windows A frame object is used to create a graphical frame window. This frame is used to show information in a graphical application. The JFrame.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Graphics Programming. Introduction GOAL: Build the Indexer Client Event-driven vs. Sequential programs Terminology – Top-level windows are called “frame.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
ObjectDraw and Objects Early Chris Nevison Barbara Wells.
IAT 800 Lecture 8. Oct 13, Fall 2006IAT 8002 Outline  Programming concepts –BImage BFont –Creating XImage –Typography.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Chapter Day 9. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 8 Questions from last Class?? Problem set 2 posted  10 programs from.
Swing Graphics ● Empty Swing containers have no visual appearance except for a background color ● Every JComponent must have a paintComponent method that.
Graphics Images – PictureBox control Drawing graphics - Graphics object Multimedia controls PictureBox control Image property – select image Choose how.
CS324e - Elements of Graphics and Visualization Java2D Graphics.
Chapter 3 Working with Symbols and Interactivity.
Creating Special Effects
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
© 2011 Delmar, Cengage Learning Chapter 3 Working with Symbols and Interactivity.
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
(C) 2010 Pearson Education, Inc. All rights reserved. Omer Boyaci.
Creating a Logo – Lesson 3 1 Creating a Logo Lesson 3.
Adding Graphics to a Frame Application Applets: Can generate drawings by overriding paint Frame: Do not draw directly on a frame. Draw graphics on a JPanel.
tiled Map Case Study: Rendering with JPanel © Allan C. Milne v
Copyright © Curt Hill First Window Builder Program Easy GUIs in Eclipse.
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.
Lesson 34: Layering Images with Java GUI. The FlowLayout RECAP.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Swing Differences between Swing and AWT Naming Conventions All Swing components begin with a capital J -- JPanel, JButton, JScrollBar, JApplet, etc..
CSE 219 Computer Science III Image Manipulation. HW 1 Has been posted on Blackboard Making a Game of Life with limited.
More GUIs, events, static. model.addElement(335); model.addElement(436); } private JTextArea lineDisplay = new JTextArea("Could have\nseveral lines\nhere");
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
Chapter 3 ADOBE INDESIGN CS3 Chapter 3 SETTING UP A DOCUMENT.
Java Direct Manipulation Chris North cs3724: HCI.
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Introduction to Java Chapter 8 - Introduction to Java Graphics1 Chapter 8 Introduction to Java Graphics.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Image Panel & Image Navigator. Review Graphics2D class for drawing shapes in a component – paintComponent(Graphics g) – Graphics2D g2 = (Graphics2D)g;
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
CS COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,
Image Panel & Image Navigator. Review Graphics2D class for drawing shapes in a component – paintComponent(Graphics g) – Graphics2D g2 = (Graphics2D)g;
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
IAT 265 Images in Processing PImage. Jun 27, 2014IAT 2652 Outline  Programming concepts –Classes –PImage –PFont.
CS 240 Week 9. EventQueue.invokeLater In Swing, all user interface operations must occur on the “UI thread” – All components should be created on the.
Computer Science I More class examples. Paths. Jigsaw. Tolerance. Classwork/homework: Your class project. Post proposal for midterm project.
Advanced Java Screen Update Techniques SD’98 - Session 4406 Ted Faison Faison Computing Inc.
Dilations A dilation is a transformation that produces an image that is the same shape as the original, but is a different size. A dilation stretches or.
Layers in Adobe After Effect
Introduction to Illustrator
In the name of God Computer Graphics.
Java Graphics CS 2511.
Learn Animations in Fireworks
Graphics Fundamentals
CT1514 Flash-2.
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
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.
Working with Symbols and Interactivity
Transformations: Translations Reflections Rotations Dilations.
Direct Manipulation.
Transformations Translation Reflection The FRAME Routine
QQ.
Presentation transcript:

Image Navigator Help Session

Review Graphics2D class for drawing shapes in a component – paintComponent(Graphics g) – Graphics2D g2 = (Graphics2D)g; (0, 0) is the components upper-left corner Shapes: Line2D, Rectangle2D,... draw(Shape s) fill(Shape s) drawImage(Image img, – int dx1, int dy1, int dx2, int dy2, – int sx1, int sy1, int sx2, int sy2) drawString(String str, int x, int y)

A Similar Problem: Double Sponge Bob Lets solve a problem that is similar to the Image Navigator problem – Create two frame windows, each containing an instance of the Sponge Bob component – Allow each window to be scaled and translated – Keep the origins of the two windows in synch so that translating one window will perform an equivalent translation in the other window – Demo: Double Sponge Bob (Scaling, Translation, Synch)Double Sponge Bob (Scaling, Translation, Synch)

The Hard Part: Coordinate Transformations Shape dimensions and locations are defined in terms of unscaled, untranslated coordinates – We call these world coordinates Each window has its own scaling and translation settings This complicates three things: – Drawing shapes in each window at the appropriate scale and location – Doing hit testing on the shapes when mouse events occur – Keeping the translation settings of the two windows in synch When drawing shapes in a window, we must convert the shape dimensions and locations defined in world coordinates to device coordinates that can be used for drawing This conversion must account for the current scale and translation settings of the window

The Hard Part: Coordinate Transformations Example – Suppose that a window currently has a scaling factor of 0.5, and a translation of 10 pixels in the X direction and 20 pixels in the Y direction (i.e., Point (10, 20) is in the top-left corner of the window) – A shape that is 400 pixels wide in world coordinates will be drawn only 200 pixels wide in device coordinates – A shape that is located at position (250, 300) in world coordinates will be drawn at position (240, 280) in device coordinates

Scaling Start with code that implements neither scaling nor translation nor window synchronization – Double Sponge Bob (No Transforms) Double Sponge Bob (No Transforms) Now, add code to implement scaling – Add scale field to DrawingComponent and initialize to 1.0 in constructor – Add setScale method to DrawingComponent – Add slider change listener to DrawingFrame – Add methods to DrawingComponent for converting between world and device coordinates (in both directions) – Update draw methods on all DrawingShape sub-classes to handle scale – Double Sponge Bob (Scaling) Double Sponge Bob (Scaling)

Translation Start with code that implements scaling but not translation or window synchronization – Double Sponge Bob (Scaling) Double Sponge Bob (Scaling) Now, add code to implement translation – Add fields to DrawingComponent for tracking the current origin (in world coordinates), and initialize them to (0,0) in the constructor – Modify methods that convert between world and device coordinates to handle translation – Add fields and methods for implementing mouse-based translation of shapes (deltas in device coordinates must be scaled to compute equivalent deltas in world coordinates) – Double Sponge Bob (Scaling & Translation) Double Sponge Bob (Scaling & Translation)

Window Synchronization Start with code that implements scaling and translation but not window synchronization – Double Sponge Bob (Scaling & Translation) Double Sponge Bob (Scaling & Translation) Now, add code to implement translation – Add DrawingListener interface – Add list of listeners and addDrawingListener method to DrawingComponent – Add notifyOriginChanged method to DrawingComponent and call it from mouseDragged – Implement two listeners on the Drawing class (one for each window), add addDrawingListener method to DrawingFrame, and add a listener to each frame in Drawing – Add setOrigin methods to DrawingComponent and DrawingFrame – Double Sponge Bob (Scaling & Translation & Synch) Double Sponge Bob (Scaling & Translation & Synch)

Swing Coordinate Transformations In Swing, there is actually a much easier way to draw shapes according to the current scaling and translation settings The Graphics2D class can be configured to perform scaling, translation, and other transformations automatically on all drawing operations – scale(…), translate(…), rotate(…), shear(…) methods There is no need to manually scale shape sizes or adjust shape locations. Graphics2D does all of this automatically You still need methods to convert between world and device coordinates to do hit testing on mouse events Example: Double Sponge Bob (Swing Transforms)Double Sponge Bob (Swing Transforms)

Image Navigator How can we apply these ideas to keep the Image Panel and Image Navigator in synch in the Record Indexer project?

Image Navigator How can we apply these same ideas to keep the Image Panel and Image Navigator in synch in the Record Indexer project? – The Image Panel has its own scale and translation settings – The Image Navigator has its own scale setting (based on its current size) – Conversions between device and world coordinates are similar to the Double Sponge Bob example – Zooming in Image Panel preserves the center point (i.e., the point at the center of the window should stay fixed during zooming) – Image Panel keeps track of the current center point (in world coordinates) – The Image Navigator can query the Image Panel for the currently visible rectangle (so it can draw the navigator rectangle) – The Image Navigator can adjust the Image Panels center point as the navigator rectangle is dragged