1 / 28

Lecture 8

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

oren
Download Presentation

Lecture 8

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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

  3. I18N How-To • Subclass ResourceBundle once for every supported Locale. All locality-specific resources go in here. • Load ResourceBundle corresponding to user’s preference. • Get all locale-specific Strings and other resources from the bundle. Use wherever appropriate.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

  11. 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)

  12. 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.

  13. Making components accessible • Label all JComponents using setToolTipText(String) method. This also serves as help for new users. • When JLabels are meant to label something, use JLabel.setLabelFor() • JComponent.getAccessibleContext().setAccessible*() where *=Name or Description.

  14. 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.

  15. 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.

  16. 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).

  17. 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

  18. 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.

  19. 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.

  20. 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.

  21. 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.

  22. 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.

  23. 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!

  24. Welcome to the Dungeon

  25. Dungeon Graphics All the graphics for this game have been stored in a single .gif file. This is downloaded and stored as an Image. The individual pieces are copied out as needed. This method reduces download time.

  26. 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.

  27. Triple-Buffering farBuffer: static elements nearBuffer: farBuffer + mobile elements screen: nearBuffer, but drawn in 1 step.

  28. 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.

More Related