Kirill Grouchnikov, Amdocs Desktop Matters Conference San Jose, March 8-9 2007.

Slides:



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

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.
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.
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
Graphics Programming. Introduction GOAL: Build the Indexer Client Event-driven vs. Sequential programs Terminology – Top-level windows are called “frame.
Graphics CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Chapter 4 (Horstmann’s Book) Interface Types and Polymorphism: Graphics, Timer, Animation Hwajung Lee.
Multithreading : animation. slide 5.2 Animation Animation shows different objects moving or changing as time progresses. Thread programming is useful.
Chapter 5 Programming Graphics. Chapter Goals To be able to write applications with simple graphical user interfaces To display graphical shapes such.
More Java Drawing in 2D Animations with Timer. Drawing Review A simple two-dimensional coordinate system exists for each graphics context or drawing surface.
User Interface Programming in C#: Graphics
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.
Jim Priest, Peter Lundgren, Russell Bennett. Background info  A sequence of fames  You have some experience already  Used for some GUI’s and Games.
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
Advanced Java Class GUI – part 1. Intro to GUI GUI = Graphical User Interface -- “Gooey” Just because it’s “gooey” does not mean you may write messy code.
Event Handling. In this class we will cover: Keyboard Events Mouse Events Focus Events Action Interface Multicasting.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Swing Graphics ● Empty Swing containers have no visual appearance except for a background color ● Every JComponent must have a paintComponent method that.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Web Design & Development Lecture 18. Java Graphics.
Java: Animation Chris North cs3724: HCI. Animation? Changing graphics over time Examples: cartoons Clippy, agents/assistants Hour glass Save dohicky Progress.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
6-2 2D Graphics CSNB544 Mobile Application Development Thanks to Utexas Austin.
CS 151: Object-Oriented Design October 3 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
1.00 Lecture 18 Geometric Transformations in the 2D API.
CIS 068 Welcome to CIS 083 ! Introduction to GUIs: JAVA Swing.
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.
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.
Canvas and Graphics CS 21a. 9/26/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L17: Canvas.
Java Graphics. Review 3 kinds of elements in components API? Layout managers Events Extend vs. Implement.
-Sai Phalgun Tatavarthy. Outline What is a “Graphing Calculator”? Graphics, Graphics2D classes Methods of Graphics object Custom Painting The paintComponent()
3461 Model-View Controller Advanced GUI concepts.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Creating Your Own Widgets CompSci 230 S Software Construction.
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
Java Direct Manipulation Chris North cs3724: HCI.
Morphic A highly unusual graphical toolkit! Originates in the Self project at Sun –Self: a prototype-based programming language –No classes---objects inherit/instantiate.
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
XNA Basic Displaying Image & Collision Detect. What’s format image that XNA support? XNA support only.bmp.png and.jpg image..PNG have transparent region.
CS 151: Object-Oriented Design October 31 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Computer Science 209 The Adapter Pattern. The Context of the Adapter Pattern I want to use an existing class (the adaptee) without modifying it The context.
Java Dynamic Graphics.
Image Panel & Image Navigator. Review Graphics2D class for drawing shapes in a component – paintComponent(Graphics g) – Graphics2D g2 = (Graphics2D)g;
Review_6 AWT, Swing, ActionListener, and Graphics.
Chapter 4 Interface Types and Polymorphism: Graphics, Timer, Animation.
Java Swing One of the most important features of Java is its ability to draw graphics.
Image Panel & Image Navigator. Review Graphics2D class for drawing shapes in a component – paintComponent(Graphics g) – Graphics2D g2 = (Graphics2D)g;
FEN 2014UCN Teknologi/act2learn1 Object-Oriented Programming “ The Three Pillars of OOP”: Encapsulation Inheritance Polymorphism The Substitution Principle.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Java Graphics Chris North cs3724: HCI. Presentations peter hou Vote: UI Hall of Fame/Shame?
Advanced Java Screen Update Techniques SD’98 - Session 4406 Ted Faison Faison Computing Inc.
Java Swing and Events Chris North cs3724: HCI. Presentations nadine edwards, steve terhar Vote: UI Hall of Fame/Shame?
Graphics JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin, and Skylight.
Android Application 2D Graphics cs.
Creating Your Own Widgets
Java Graphics.
Java Graphics CS 2511.
Java FX.
Animated picture changes during motion path (Advanced)
Design Patterns A Case Study: Designing a Document Editor
null, true, and false are also reserved.
Introduction to Graphical Interfaces in Java: AWT and Swing
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה
Presentation transcript:

Kirill Grouchnikov, Amdocs Desktop Matters Conference San Jose, March

Show two sample effects on buttons Show how this can be achieved with UI delegates Discuss alternative implementations

Custom component – paintComponent Custom repaint manager Custom glass pane Custom UI delegates

Custom component – paintComponent Custom repaint manager Custom glass pane Custom UI delegates (*) * - next slides describe the UI delegates approach

UI delegates – classes responsible for painting Swing components. The panels are painted by the PanelUI delegate (unless a panel overrides the paintComponent method). The buttons are painted by the ButtonUI delegate (unless a button overrides the paintComponent method).

update() paintBorder() [*] paintComponent() paint() paintIcon() layout text/icon paintText() paintFocus() paintChildren() [*] paint() JComponentButtonUI * - this is why you should override paintComponent() and not paint() for custom painting logic.

We add the custom painting code in the following places: ButtonUI.paintIcon – before calling super(), paint the same icon scaled up and translucent (and offset). PanelUI.update – paint the part of the icon that animates outside the child (button) bounds. In addition, a ChangeListener is registered on the button model, tracking changes to the rollover state.

The icon is not an Image. Call paintIcon after the Graphics has been scaled and a composite has been applied to it. The ghost image must be centered around the original icon. The ghost effect may “spill” from the immediate parent and overlay sibling components.

protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) { Graphics2D graphics = (Graphics2D) g.create(); FadeTracker fadeTracker = FadeTracker.getInstance(); AbstractButton b = (AbstractButton) c; if ((ButtonBackgroundDelegate.getKind(b) == ButtonTitleKind.NONE) && fadeTracker.isTracked(c, null, FadeKind.GHOSTING_ICON_ROLLOVER, true)) { float fade10 = fadeTracker.getFade10(c, FadeKind.GHOSTING_ICON_ROLLOVER); // > 0.5 // > 0.0 float opFactor = -0.5f * fade10 / 10.0f + 0.5f; graphics.setComposite(TransitionLayout.getAlphaComposite(c, opFactor)); Icon icon = SubstanceCoreUtilities.getIcon(b); if (icon != null) {  see the next slide } graphics.setComposite(TransitionLayout.getAlphaComposite(c)); super.paintIcon(graphics, c, iconRect); graphics.dispose(); } Check if the button has ghost fade animation on the icon Get the current animation position (number between 0.0 and 10.0) Compute the ghost image translucency (fades from 50% to 0% opacity) Set the composite for painting the ghost icon Call super implementation to paint the icon itself

double iFactor = fade10 / 10.0; double iWidth = icon.getIconWidth() * iFactor; double iHeight = icon.getIconHeight() * iFactor; BufferedImage iImage = SubstanceCoreUtilities.getBlankImage( (int) iWidth, (int) iHeight); Graphics2D iGraphics = (Graphics2D) iImage.createGraphics(); iGraphics.scale(iFactor, iFactor); icon.paintIcon(b, iGraphics, 0, 0); iGraphics.dispose(); int dx = (int) ((iWidth - icon.getIconWidth()) / 2); int dy = (int) ((iHeight - icon.getIconHeight()) / 2); graphics.drawImage(iImage, iconRect.x - dx, iconRect.y - dy, null); Compute the scale factor and scaled dimensions Create a transparent imageScale its graphicsPaint the icon on the scaled graphics (creates the scaled icon) Paint the scaled icon centered around the original icon

Icon ghosting over multiple components Press ghosting over multiple components Multiple icon and press ghostings

(+) Minimal changes in the application code. (+) No need for custom painting code (+/-) Available only under the specific LAF Can use bytecode injection to change existing third- party LAFs (possible but slightly complicated – stay tuned for more in the future) (-) Handling “spilling” is in container delegates (-) Custom paintComponent implementations

How to handle painting order (background, ghost icon, icon+text)? Custom components (+/-) Work under all LAFs (???) (-) Can handle only painting in the component bounds Custom repaint manager (+/-) Work under all LAFs (???) (-) More complicated to write and test (-) Interfere with existing repaint manager (e.g. from SwingX) Custom glass pane (+/-) Work under all LAFs (???) (+/-) Interfere with existing app glass pane (JXLayer approach)

Kirill’s blog Alex’s blog Substance LAF project Laf-Widget project

@Override public void update(Graphics g, JComponent c) { // Paint regular container stuff. In most cases - // background (fill, gradient, watermark) … // Paint ghost images of the animated overlapping // components GhostPaintingUtils.paintGhostImages(c, g); }

public static void paintGhostImages(Component mainComponent, Graphics g) { Graphics2D graphics = (Graphics2D) g.create(); Rectangle panelRect = mainComponent.getBounds(); panelRect.setLocation(mainComponent.getLocationOnScreen()); if (FadeConfigurationManager.getInstance().fadeAllowed( FadeKind.GHOSTING_ICON_ROLLOVER, mainComponent)) { Set animComps = FadeTracker.getInstance().getAllComponentsByFadeKind( FadeKind.GHOSTING_ICON_ROLLOVER); for (Component comp : animComps) { // see next slide } graphics.dispose(); } Work on disposable graphics contextCompute screen bounds of the containerCheck if the icon ghosting animations are allowedGet all components under icon ghosting animationsFor each such component, do code on next slide

Rectangle compRect = comp.getBounds(); compRect.setLocation(comp.getLocationOnScreen()); int dx = compRect.x - panelRect.x; int dy = compRect.y - panelRect.y; compRect.x -= compRect.width / 2; compRect.y -= compRect.height / 2; compRect.width *= 2; compRect.height *= 2; if (panelRect.intersects(compRect)) { // see next slide } Compute screen bounds of animated component Compute offsets between screen boundsThe icon ghosting can take an area twice as large as the component screen bounds Check if container screen bounds and extended screen bounds of the animated component intersect

float fade10 = FadeTracker.getInstance().getFade10(comp, null, FadeKind.GHOSTING_ICON_ROLLOVER); // > 0.5, > 0.0 float opFactor = 0.5f * (1.0f - fade10 / 10.0f); graphics.setComposite(TransitionLayout.getAlphaComposite(mainComponent, opFactor)); Icon icon = null; Rectangle iconRect = null; if (comp instanceof AbstractButton) { AbstractButton button = (AbstractButton) comp; icon = SubstanceCoreUtilities.getIcon(button, false); iconRect = (Rectangle)button.getClientProperty(SubstanceButtonUI.ICON_RECT); } if ((icon != null) && (iconRect != null)) { // see next slide } Get the current animation positionCompute the ghost image translucency (fades from 50% to 0% opacity) Set the composite for painting the ghost iconGet the icon and the icon rectangle

double iFactor = fade10 / 10.0; double iWidth = icon.getIconWidth() * iFactor; double iHeight = icon.getIconHeight() * iFactor; BufferedImage iImage = SubstanceCoreUtilities.getBlankImage((int) iWidth, (int) iHeight); Graphics2D iGraphics = (Graphics2D) iImage.createGraphics(); iGraphics.scale(iFactor, iFactor); icon.paintIcon(comp, iGraphics, 0, 0); iGraphics.dispose(); dx -= (int) ((iWidth - icon.getIconWidth()) / 2); dy -= (int) ((iHeight - icon.getIconHeight()) / 2); graphics.drawImage(iImage, dx + iconRect.x, dy + iconRect.y, null); Compute the scale factor and scaled dimensionsCreate a transparent imageScale its graphicsPaint the icon on the scaled graphics (creates the scaled icon) Paint the scaled icon centered around the original icon (note the computation of icon offsets)

The ghost image must be centered around the button image. The ghost effect may “spill” from the immediate parent and overlay sibling components.

double iFactor = fade10 / 10.0; double iWidth = bounds.width * iFactor; double iHeight = bounds.height * iFactor; BufferedImage iImage = SubstanceCoreUtilities.getBlankImage( (int) iWidth, (int) iHeight); Graphics2D iGraphics = (Graphics2D)iImage.createGraphics(); iGraphics.scale(iFactor, iFactor); comp.paint(iGraphics); iGraphics.dispose(); dx -= (int) ((iWidth - bounds.width) / 2); dy -= (int) ((iHeight - bounds.height) / 2); graphics.drawImage(iImage, bounds.x - dx, bounds.y - dy, null); Compute the scale factor and scaled dimensionsCreate a transparent imageScale its graphicsPaint the component on the scaled graphics (creates the scaled component) Paint the scaled component centered around the original component (note the computation of component offsets)

Not paint too much (trigger repaint only of the affected area) Handle change in showing / visibility during the animation Account for large button / icons (start from lower alpha) Cache animating child image for reuse during painting in the same animation cycle on different containers