+ All Categories
Home > Documents > Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization,...

Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization,...

Date post: 21-Dec-2015
Category:
View: 240 times
Download: 6 times
Share this document with a friend
Popular Tags:
28
Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, Customization Accessibility History of Animation/Early Cinema Animation how-to Example: Dungeon Dregs
Transcript
Page 1: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Lecture 8

Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, Customization Accessibility History of Animation/Early Cinema Animation how-to Example: Dungeon Dregs

Page 2: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Internationalization

2 System properties are typically used to customize program interface: user.language and user.region There is a standardized set of 2-letter ISO codes for these. Languages: en, fr, de, es, sw, etc. Regions: US, FR, CA, CH, DE, GB, etc. Also called Localization

Page 3: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

I18N How-To

1. Subclass ResourceBundle once for every supported Locale. All locality-specific resources go in here.

2. Load ResourceBundle corresponding to user’s preference.

3. Get all locale-specific Strings and other resources from the bundle. Use wherever appropriate.

Page 4: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

I18N Demo1 Notes

Some redundancy is required and desirable. MyResources, MyResources_en and MyResources_en_US are identical. These provide defaults in case not all system properties are set. Watch for pitfalls: String resources may not be the expected size. Meanings may change in subtle ways.

Page 5: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Formats

To get accents and special characters, need to know some Unicode. \u####NumberFormat, DateFormat. Constructing sentences from pieces is not so easy anymore. Languages differ in sentence structure and ordering. Move all sentence-constructing into bundles. Use MessageFormat class. Bundle format

strings.

Page 6: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Beyond Strings

Can customize look and feel for different locales. ResourceBundles can contain filenames, such as image files, and can even contain customized classes such as dialogs or frames. ResourceBundles can inherit from one another. Might have a single resource file with common data for Europe.

Page 7: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Customization

User may want to change language preference for your program only, or alter other settings from the defaults. Easy to do for one session. Just modify the attributes. Would also like preferences to persist from one session to another. Need to create a preferences file.

Page 8: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Preferences files

Location Preferred location varies with system.

Program directory for single-user PCs, user directory for multi-user systems.

Format Serialized objects? Easy. Hard to edit. Custom format. Must deal with syntax.

Page 9: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Preferences class

Define a preferences class along the same lines as ResourceBundle. Basically a Map or Hashtable of keys and values. Write preference file using Serialize or entry by entry. On startup, load the preferences from the stored file. Defaults if this fails.

Page 10: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

What to customize

A good topic for use case analysis and user surveys. What will the product be used for? What do users ask for? Better to offer users a limited set of ready-made preference sets than to make them choose everything individually. Options to turn “features” off.

Page 11: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

What not to customize

Everything. Want to be able to explain to users how to do any given task, without having to worry about how they customized the application. Menus. Makes sense to have all commands accessible through menus in fixed locations. Customizable toolbars for commonly-used commands.

(This isn’t a hard-and-fast rule)

Page 12: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Accessibility

Swing components have methods to support assistive technologies, which for example may allow vocal control and audio display of a GUI interface. Can play with this: download Monkey. To take advantage, you need to label components with informative text.

Page 13: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Making components accessible

1. Label all JComponents using setToolTipText(String) method. This also serves as help for new users.

2. When JLabels are meant to label something, use JLabel.setLabelFor()

3. JComponent.getAccessibleContext().setA

ccessible*() where *=Name or Description.

Page 14: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

History of the Magic Lantern

Projected Images have been around in one form or another since at least 1420. By 1700’s, used for popular entertainment. Special effects such as rear-projection onto a translucent screen, projection onto cloud of smoke, dissolving views. 1895: Cinematographe invented.

Page 15: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Pre-history of Cinema

As early as 1674, idea of quick succession of glass slides. 1832: Fantoscope, Stroboscope. Illusion of motion created by “persistence of vision” 1870’s: combined with photography. 1890’s: celluloid film.

Page 16: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Persistence of Vision

Images remain on the retina for about 1/14 of a second. Small delay between bright images not visible. Frame rate of 30Hz is generally considered flicker-free. Typical monitor refresh rate is 70-130Hz. (Hz = Hertz = * per second).

Page 17: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Basic Animation

Display image sequence at intervals. Images must line up exactly can detect 1-pixel shift on most monitors

Intervals must be same length movement will appear jerky

Intervals should be short. probably no benefit beyond 1/30 second

User expectations vary with application

Page 18: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Corollaries

Must ensure adequate computational resources. Small delays lead to jerks. Example: scrolling in IE. Less computationally demanding to animate small images, or simple images such as rectangles filled by solid color. Rendering text especially slow in Java.

Page 19: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Simple animation in Swing

Use javax.swing.Timer to generate ticks every N milliseconds. On tick, display current frame, then compute next frame. Order matters: computing frame may

take variable time; displaying should not.

Page 20: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Speed-up tricks: downloads

Downloading: slow, and speed varies. Track downloads with a MediaTracker.

Start animations after downloads complete.

Fewer HTTP connections saves time. Combine images into 1 file; extract with graphics operations. Better still: put all images and source into a jar file, and extract locally.

Generate graphics locally if possible.

Page 21: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Speed-up tricks: precompute

Compute once, draw many times. Avoid Graphics.drawString (very slow) Precompute GlyphVectors or Images for

strings which you draw more than once. Same for digits of numeric displays.

Use antialias and transparency effects in precomputing. For actual display, just copy in the BufferedImage.

Page 22: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

More speed tricks

Don’t repeat graphics ops wastefully e.g. Triple buffering (next slide).

Minimize area to redraw. Small rectangles can be updated

faster.

Graphics.setRenderHints(…RENDER_SPEED) Ask user not to run other jobs.

Page 23: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Case-study: “Dungeon Dregs”

About the lamest of many cool games at J*va On The Brain by Karl Hörnell. In public domain. Lots of game applets on the site, together with notes about their creation, including design choices and implementation details. Go browse it!

Page 24: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Welcome to the Dungeon

Page 25: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Dungeon Graphics

All the graphics for this game have been stored in asingle .gif file. This is downloaded and stored as an

Image. The individual pieces are copied outas needed. This method reduces download time.

Page 26: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Triple-Buffering

There are 2 buffers, farBuffer and nearBuffer (both class Image). farBuffer contains background elements, and is changed rarely. (e.g. crate smashed or prisoner freed). nearBuffer is redrawn frequently, with all the moving elements. nearBuffer drawn to Panel when done.

Page 27: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Triple-Buffering

farBuffer: static elements

nearBuffer: farBuffer + mobile elements

screen: nearBuffer, but drawn in 1 step.

Page 28: Lecture 8 Leftover Demos: JPEGEncoder, Animation-demos. Translucency demos. Internationalization, CustomizationInternationalizationCustomization Accessibility.

Animation Loop

Since this is an Applet, it uses Thread.sleep instead of a Timer. Every 85ms, tick occurs. New positions are computed, farBuffer and nearBuffer are updated, and screen is refreshed. Finite state machine is simulated to minimize processing time. Slow tasks are spread over several ticks.


Recommended