Java

Text

Other Swing Changes

Default HTML Font Is Now Serif

HTML text -- including HTML text used in labels, buttons, and so on -- used to be in SansSerif font by default. As of v 1.3, the default font is Serif.

HTMLEditorKit insertAtBoundry => insertAtBoundary

A method in HTMLEditorKit.InsertHTMLTextAction, insertAtBoundry, was misspelled. It's been deprecated and insertAtBoundary has been added.

Automatic Handling of DocumentEvents

The default functionality of managing the DocumentEvent has been moved (from CompositeView) and raised from package private to public. Subclassing has been made much easier as the management of the DocumentEvent is now distributed to the protected methods:

To accomplish its behavior, the methods managing the children of the view also needed to be moved from CompositeView to View.

The following methods were added to the javax.swing.text.View:

BoxView: Add axis property, layoutChanged Method

BoxView has an axis argument which subclasses previously could not get at. A subclass that sets it's axis based upon i18n considerations needs this as a property. The layout of the box should also be treated seperate from the requested size as in some cases (such as a table) the layout may become invalid independant of the children's preferences.

The following methods have been added to javax.swing.text.BoxView:

ParagraphView now extends FlowView

The View protocol supports building flows, but the only previous implementation had been ParagraphView which creates relatively simple paragraph flows. The functionality can be generalized substantially to do things like shaped flows, page breaking, etc. Generalizing the functionality will make the creation of alternative flows much easier.

A new class called FlowView takes a strategy to translate the logical structure to a physical structure. The strategy is defined by a nested static class called FlowStrategy. ParagraphView extends FlowView adding just that behavior which is paragraph-specific (i.e line spacing, first line indent, alignment, etc). This change adds the following method to the javax.swing.text.View class:

FormView Localization; SUBMIT, RESET deprecated

Class javax.swing.text.html.FormView was not previously localizable. There are two public static final Strings, SUBMIT and RESET, that are used to determine the text for <form> elements in an HTML document. As they are public static final they can not be localized. SUBMIT and RESET have been deprecated, the values are now obtained from the UIManager properties: FormView.submitButtonText and FormView.resetButtonText.

Serialization

Here's a summary of the serialization related changes in the swing.text package:

HTML Package: Expose More of AbstractWriter

AbstractWriter is used as a base class for developers wishing to provide custom writing out of a text Document. For example, HTMLWriter extends AbstractWriter, and is used in the html package to output html. The problem with AbstractWriter was that most of the methods and ivars it provided were private. Subclasses had to resort to copying numerous methods and ivars to be useful. HTMLWriter extends AbstractWriter, but ended up copying all the ivars, and overriding almost all the methods. The following changes open up the API in AbstractWriter, making it more useful by itself. This makes HTMLWriter much simpler, and it won't have to copy as much from AbstractWriter.

See:

HTML Package: Expose More CSS1 Support

The html package supports CSS 1. One of the abilities of CSS is to support cascading of style sheets (as the name implies), that is more than one style sheet can influence the presentation simultaneously. For example a browser usually has a style sheet that defines the default styles, a particular page might also have a style sheet that overrides those provided by the browser. The following methods expose this to developers, allowing them to link style sheets:

Simplify HTML Insertions

Previously it was not very easy for developers to insert arbitrary html into an existing html document. To accomplish this, the developer needed to have an intimate knowledge of the swing text package, as well as the html package. Many developers have used dynamic html, which provides a handful of methods that make it trivial to insert html into an existing page. To accomodate these users we now expose methods that closely mirror those provided by dynamic html:

And this is constant has been added to class HTMLEditorKit.ParserCallback:

New text Package ZoneView class

Problem:
The swing text package uses View objects to represent a presentation of the document model for the sake of layout and rendering. If the model is large, the number of view objects that get created is large, in spite of only being able to view a small number of them. A View implementation is needed that defers creation of the objects until they are actually needed for display. This can be done by building zones with an estimated size that get replaced with the actual View objects when they are needed. This can substantially reduce the amount of memory used for large documents.

Solution:
The following class called ZoneView supports zones that don't consume much memory until actively viewed or edited. WrappedPlainView which will become more heavyweight with its support of bidi for i18n will benefit substantially from this class by changing it's superclass from BoxView to ZoneView (which is a BoxView).

See:

New text Package AsyncBoxView class

Problem:
The swing text package uses View objects to represent a view of the document model to handle layout and rendering. Layout is done on the event handling thread like most other things. Layout is sometimes quite expensive in terms of cpu time, and causes the user interface to freeze while performing layout. The text package has some support of concurrency however, so this should be extended to include performing layout asynchronous to the gui event handling thread. A View implementation is needed that performs layout asynchronously.

Solution:
To address this need, the following classes are being added to the text package. For more information visit The Swing Connection.

Add getGraphics Method to text View Class

A method is included on the javax.swing.text.View class to fetch the Graphics object that will be used to render.

See:


Copyright © 1999 Sun Microsystems, Inc. All Rights Reserved.

Please send comments to: swing-feedback@java.sun.com. This is not a subscription list.
Sun
Java Software