Presentation is loading. Please wait.

Presentation is loading. Please wait.

W14 - Building World-Class UIs with JFC - Ted Faison1 Building World-Class User Interfaces with Java Foundation Classes Ted Faison Faison Computing Inc.

Similar presentations


Presentation on theme: "W14 - Building World-Class UIs with JFC - Ted Faison1 Building World-Class User Interfaces with Java Foundation Classes Ted Faison Faison Computing Inc."— Presentation transcript:

1 W14 - Building World-Class UIs with JFC - Ted Faison1 Building World-Class User Interfaces with Java Foundation Classes Ted Faison Faison Computing Inc. tedfaison@msn.com

2 W14 - Building World-Class UIs with JFC - Ted Faison2 Work is still in progress ! Several areas aren’t 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 W14 - Building World-Class UIs with JFC - Ted Faison3 The AWT isn’t enough !

4 W14 - Building World-Class UIs with JFC - Ted Faison4 AWT Limitations Few controls Uses heavyweight objects (peers) Platform-dependent Look and Feel –no support for pluggable L&Fs no support for 2D or 3D operations –Bezier Curves, Shapes, Transparency –Rotation, Shading, Clipping

5 W14 - Building World-Class UIs with JFC - Ted Faison5 JFC Goals 100% pure Java Lightweight Pluggable L&F Keyboard support High-level controls Simple class hierarchy

6 W14 - Building World-Class UIs with JFC - Ted Faison6 Comparing hierarchies Menu/Button hierarchies under AWT: Component Button Checkbox Object MenuComponent MenuItem CheckboxMenuItem

7 W14 - Building World-Class UIs with JFC - Ted Faison7 Comparing hierarchies Menu/Button hierarchies under JFC: JComponent AbstractButton JButton JMenuButton JCheckboxMenuItem JMenu JToggleButton JCheckbox JRadioButton

8 W14 - Building World-Class UIs with JFC - Ted Faison8 Some JFC high-level controls JSplitPane, JTabbedPane JTree JProgressBar JSlider JSpinner JTextPane JTable

9 W14 - Building World-Class UIs with JFC - Ted Faison9 Other useful JFC controls JInternalFrame –A lightweight frame –Z order set using ‘layer’ –example JToolBar JToolTip JLayeredPane –allows management of children in “layers”

10 W14 - Building World-Class UIs with JFC - Ted Faison10 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 W14 - Building World-Class UIs with JFC - Ted Faison11 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 W14 - Building World-Class UIs with JFC - Ted Faison12 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 W14 - Building World-Class UIs with JFC - Ted Faison13 Creating a JFC component Create a model Create a componentUI –UIFactory Set the UI

14 W14 - Building World-Class UIs with JFC - Ted Faison14 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 W14 - Building World-Class UIs with JFC - Ted Faison15 Pluggable L&F JFC comes with a built-in Win95 L&F –The Basic… ComponentUIs Win95 is the normal fallback L&F You can create your own custom, or corporate L&F

16 W14 - Building World-Class UIs with JFC - Ted Faison16 Changing L&F 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 W14 - Building World-Class UIs with JFC - Ted Faison17 Multiplexing UIFactories Allow one factory to control the L&F 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 W14 - Building World-Class UIs with JFC - Ted Faison18 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 W14 - Building World-Class UIs with JFC - Ted Faison19 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 W14 - Building World-Class UIs with JFC - Ted Faison20 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 locale’s natural reading order

21 W14 - Building World-Class UIs with JFC - Ted Faison21 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 W14 - Building World-Class UIs with JFC - Ted Faison22 Accelerator Key Management The When Condition: WHEN_FOCUSED WHEN_FOCUSED_COMPONENT_PARENT WHEN_IN_FOCUSED_WINDOW ALWAYS

23 W14 - Building World-Class UIs with JFC - Ted Faison23 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 W14 - Building World-Class UIs with JFC - Ted Faison24 Accelerator key management Default key dispatching policy: –The focused component –The focused component parent’s tree –Components with same parent as focused component –Components with condition = ALWAYS

25 W14 - Building World-Class UIs with JFC - Ted Faison25 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 W14 - Building World-Class UIs with JFC - Ted Faison26 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 W14 - Building World-Class UIs with JFC - Ted Faison27 The Document Interface A quick look at the decompiled code The interface doesn’t enforce a policy of character management or storage

28 W14 - Building World-Class UIs with JFC - Ted Faison28 Document events and listeners Listeners are document viewers Events indicate changes to the underlying text.

29 W14 - Building World-Class UIs with JFC - Ted Faison29 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 W14 - Building World-Class UIs with JFC - Ted Faison30 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 W14 - Building World-Class UIs with JFC - Ted Faison31 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 W14 - Building World-Class UIs with JFC - Ted Faison32 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 W14 - Building World-Class UIs with JFC - Ted Faison33 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 W14 - Building World-Class UIs with JFC - Ted Faison34 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 W14 - Building World-Class UIs with JFC - Ted Faison35 Installing a custom manager Call the JComponent method: setManagerForComponent(DirtyRegionManager m, Component c) {…} Getting the current manager: getManagerForComponent(Component c) {…}

36 W14 - Building World-Class UIs with JFC - Ted Faison36 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 W14 - Building World-Class UIs with JFC - Ted Faison37 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


Download ppt "W14 - Building World-Class UIs with JFC - Ted Faison1 Building World-Class User Interfaces with Java Foundation Classes Ted Faison Faison Computing Inc."

Similar presentations


Ads by Google