Building World-Class User Interfaces with Java Foundation Classes - PowerPoint PPT Presentation

About This Presentation
Title:

Building World-Class User Interfaces with Java Foundation Classes

Description:

W14 - Building World-Class UIs with JFC - Ted Faison. 1 ... Default focus navigator moves focus in locale's natural reading order ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 38
Provided by: tedfa
Category:

less

Transcript and Presenter's Notes

Title: Building World-Class User Interfaces with Java Foundation Classes


1
Building World-Class User Interfaces with Java
Foundation Classes
  • Ted Faison
  • Faison Computing Inc.
  • tedfaison_at_msn.com

2
Work is still in progress !
  • Several areas arent yet finalized
  • Drag and Drop
  • Multiplexing UIFactories
  • 2D API, Shape support, Batch Painting
  • Focus navigation and keyboard support
  • Several high-level controls
  • The text support framework

3
The AWT isnt enough !
4
AWT Limitations
  • Few controls
  • Uses heavyweight objects (peers)
  • Platform-dependent Look and Feel
  • no support for pluggable LFs
  • no support for 2D or 3D operations
  • Bezier Curves, Shapes, Transparency
  • Rotation, Shading, Clipping

5
JFC Goals
  • 100 pure Java
  • Lightweight
  • Pluggable LF
  • Keyboard support
  • High-level controls
  • Simple class hierarchy

6
Comparing hierarchies
  • Menu/Button hierarchies under AWT
  • Component
  • Button
  • Checkbox
  • Object
  • MenuComponent
  • MenuItem
  • CheckboxMenuItem

7
Comparing hierarchies
  • Menu/Button hierarchies under JFC
  • JComponent
  • AbstractButton
  • JButton
  • JMenuButton
  • JCheckboxMenuItem
  • JMenu
  • JToggleButton
  • JCheckbox
  • JRadioButton

8
Some JFC high-level controls
  • JSplitPane, JTabbedPane
  • JTree
  • JProgressBar
  • JSlider
  • JSpinner
  • JTextPane
  • JTable

9
Other useful JFC controls
  • JInternalFrame
  • A lightweight frame
  • Z order set using layer
  • example
  • JToolBar
  • JToolTip
  • JLayeredPane
  • allows management of children in layers

10
The MVC Architecture
  • Model holds view-independent data
  • View observes model
  • provides screen printer output
  • Controller interacts with user
  • user interacts with controller through views
  • in JFC, controller and view are integrated
  • ComponentUI, used by all JComponents

11
The ComponentUI Interface
  • public interface ComponentUI
  • void installUI(JComponent c)
  • void deinstallUI(JComponent c)
  • void paint(Graphics g, JComponent c)
  • Dimension getPreferredSize(JComponent c)
  • Dimension getMinimumSize(JComponent c)
  • Dimension getMaximumSize(JComponent c)
  • Insets getInsets(JComponent c)

12
Pluggable Look Feel
  • Provided through a delegation model
  • components delegate rendering and event handling
    to their ComponentUI
  • The ComponentUI derived classes
  • BasicComponentUI, ButtonUI, ComboBoxUI,
    InternalFrameUI, LabelUI, ListBoxUI, MenuBarUI,
  • MenuItemUI, MenuUI, PopupMenuUI, etc.
  • You can extend ComponentUI for your own classes

13
Creating a JFC component
  • Create a model
  • Create a componentUI
  • UIFactory
  • Set the UI

14
Creating a JFC component
  • public class JTree extends JComponent
  • protected TreeModel treeModel new
    TreeModel()
  • public JTree ()
  • setModel(treeModel)
  • String fallbackUI
  • "com.sun.java.swing.BasicTreeUI"
  • BasicTreeUI treeUI
  • (BasicTreeUI) UIManager.getUI("BasicTreeUI",
  • fallbackUI,
  • this)
  • setUI(treeUI)

15
Pluggable LF
  • JFC comes with a built-in Win95 LF
  • The Basic ComponentUIs
  • Win95 is the normal fallback LF
  • You can create your own custom, or corporate LF

16
Changing LF
  • At compile time
  • using a different ComponentUI
  • At runtime
  • using a different UIFactory
  • UIManager.setUIFactory(UIFactory f,
  • Container c)
  • Passing a container will reset all its children

17
Multiplexing UIFactories
  • Allow one factory to control the LF of an entire
    group of components
  • API not fully finalized yet
  • Use
  • setUI((BasicTreeUI) UIManager.getUI(
  • "BasicTreeUI",
  • "com.sun.java.swing.basic.BasicTreeUI",
  • this))

18
JFC Components delegate painting to their
ComponentUI
  • public class JComponent
  • //
  • public void paint(Graphics g)
  • if (ui ! null)
  • ui.paint(g, this)
  • super.paint(g) // paint children if any

19
JFC MFC Model objects
  • They implement a model interface
  • interface TreeModel
  • class JTreeModel implements TreeModel
  • They support a listener, which is typically a
    JComponent, e.g. JTree.
  • Changes are broadcast to the listener
  • The listener syncs the UI with the model

20
Keyboard Focus Management
  • Navigating inside groups and between groups
  • Arrow and tab keys
  • Focus navigation keys are hardwired in native
    GUIs and AWT
  • Navigator can be customized in JFC
  • Implementation not released yet
  • Default focus navigator moves focus in locales
    natural reading order

21
Accelerator Key Management
  • Not finalized yet
  • The Keyboard Action registry
  • registerKeyboardAction(JAction a,
  • JKeyStroke k,
  • int when)
  • JAction objects that can receive an
    actionPerformed(ActionEvent) call.
  • JKeyStroke encapsulates charCode and modifier

22
Accelerator Key Management
  • The When Condition
  • WHEN_FOCUSED
  • WHEN_FOCUSED_COMPONENT_PARENT
  • WHEN_IN_FOCUSED_WINDOW
  • ALWAYS

23
An example
  • class MyComponent extends JComponent
  • MyComponent()
  • myComponent.registerKeyboardAction(
  • new AltKHandler(),
  • JKeyStroke.getKeyStroke('K',
  • InputEvent.ALT_MASK),
  • WHEN_IN_FOCUSED_WINDOW)
  • class AltKHandler extends JAction
  • public void actionPerformed(ActionEvent e)

24
Accelerator key management
  • Default key dispatching policy
  • The focused component
  • The focused component parents tree
  • Components with same parent as focused component
  • Components with condition ALWAYS

25
Advanced text handling
  • Support for rich text, e.g. multiple fonts,
    sizes, colors, etc.
  • JTextComponent
  • designed to handle SGML-type capabilities
  • TextUI the viewer
  • An abstract class

26
The Document interface
  • Structures text as arrays of elements
  • Each element is a stream of characters
  • The location of characters
  • class Position (not finalized)
  • Selecting text
  • class Range
  • encodes pairs of Positions (not finalized)

27
The Document Interface
  • A quick look at the decompiled code
  • The interface doesnt enforce a policy of
    character management or storage

28
Document events and listeners
  • Listeners are document viewers
  • Events indicate changes to the underlying text.

29
Interface DocumentEvent
  • public interface DocumentEvent
  • Range getRange()
  • Document getDocument()
  • UndoableEdit getEdit()
  • boolean isModified(Element p0)
  • Element elementsModified()
  • Element childrenRemoved(Element p0)
  • Element childrenAdded(Element p0)

30
Advanced Text Features
  • Highlighting
  • coloring the background of text
  • Generic attributes
  • custom text attributes, with (key, value) pairs
  • Flow control
  • Elements can be assigned to boxes that
    constrain their exact position and flow.
  • Embedded pictures
  • class JIconView

31
Advanced Text Features
  • Integration with Java 2D API
  • Transparency
  • Rotation, Scaling, Sheering
  • Characters along paths
  • using characters as clipping paths
  • custom character fill-in

32
Other JFC enhancements
  • Standardized Component Borders
  • All JComponents use JBorders
  • lines, grooves, titled, raised, recessed borders
  • Support for an Undo/Redo framework
  • Popup menus
  • Tables
  • Drag and Drop

33
Other JFC enhancements
  • Optimized drawing (not finalized yet)
  • Reduces multiple screen updates to a single
    operation
  • Based on the new class DirtyRegionManger
  • Manager stores a list of the out-of-date regions
  • Regions can have arbitrary shape, which are
    objects implementing the Shape interface

34
The DirtyRegionManager
  • interface DirtyRegionManager
  • public void addDirtyRegion(Component c,
  • Shape dirtyRegion)
  • public void addDirtyRegion(Component c, int x,
  • int y, nt w, int h)
  • public void paintDirtyRegions()
  • public void markCompletelyDirty()
  • public void markCompletelyClean()

35
Installing a custom manager
  • Call the JComponent method
  • setManagerForComponent(DirtyRegionManager m,
  • Component c)
  • Getting the current manager
  • getManagerForComponent(Component c)

36
Drag and Drop
  • Not finalized yet
  • Diverges from earlier JDK 1.1 model, due to JFC
    MVC addition
  • Platform independent
  • works across Java and native applications
  • Uses a DragSource and a DropTarget
  • Data can be moved or copied
  • MIME DataFlavors

37
Conclusion
  • The JFC is a big deal
  • JDK 1.2 will contain the JFC
  • JFC positions Java for high-end applications
  • JFC leverages existing JDK work
  • Migration of existing code to JFC is not too hard
  • JFC is designed to use services provided by the
    upcoming Java 2D API
Write a Comment
User Comments (0)
About PowerShow.com